Merge branch 'develop' into hotfix/taos-tools

* develop: (72 commits)
  [TD_543] fix coverity scan, cid:267845 267846
  [TD_543] fix coverity scan, cid:267831
  failed to open TCP server socket, return error for RPC initialization
  Added errno to Python client, plus minor tweaks
  [TD_543] fix coverity scan, cid:267826
  [TD_543] fix coverity scan, cid:267820 267853
  [TD_543] fix coverity scan, cid:267813
  [TD_543] fix coverity scan, cid:267815
  fix issue that dnodes reploy delete psim log file
  [TD_543] change invalid table id to invalid table name
  fix delete_datafiles issue.
  [td-225] remove an assert
  [TD_543] fix coverity scan, cid:267787
  [td-547]
  [TD_543] fix coverity scan, cid:267773
  [TD_543] fix coverity scan, cid:267767
  TD-545
  [td-225]
  [TD_543] fix coverity scan, cid:267764
  TD-546
  ...
This commit is contained in:
Shuaiqiang Chang 2020-06-09 12:05:36 +08:00
commit db6f4514bc
158 changed files with 3427 additions and 2010 deletions

3
.gitignore vendored
View File

@ -64,4 +64,5 @@ CMakeError.log
/out/isenseconfig/WSL-Clang-Debug /out/isenseconfig/WSL-Clang-Debug
/out/isenseconfig/WSL-GCC-Debug /out/isenseconfig/WSL-GCC-Debug
/test/cfg /test/cfg
/src/.vs /src/.vs
*.o

View File

@ -111,7 +111,7 @@ matrix:
description: TDengine description: TDengine
# Where email notification of build analysis results will be sent # Where email notification of build analysis results will be sent
notification_email: sdsang@taosdata.com notification_email: sdsang@taosdata.com, slguan@taosdata.com
# Commands to prepare for build_command # Commands to prepare for build_command
# ** likely specific to your build ** # ** likely specific to your build **
@ -178,7 +178,7 @@ matrix:
cd ${TRAVIS_BUILD_DIR} cd ${TRAVIS_BUILD_DIR}
lcov -d . --capture --rc lcov_branch_coverage=1 -o coverage.info lcov -d . --capture --rc lcov_branch_coverage=1 -o coverage.info
lcov --remove coverage.info '*tests*' '*deps*' -o coverage.info lcov --remove coverage.info '*/tests/*' '*/test/*' '*/deps/*' -o coverage.info
lcov -l --rc lcov_branch_coverage=1 coverage.info || travis_terminate $? lcov -l --rc lcov_branch_coverage=1 coverage.info || travis_terminate $?
gem install coveralls-lcov gem install coveralls-lcov

View File

@ -162,18 +162,18 @@ done
# output the version info to the buildinfo file. # output the version info to the buildinfo file.
build_time=$(date +"%F %R") build_time=$(date +"%F %R")
echo "char version[64] = \"${version}\";" > ${versioninfo} echo "char version[12] = \"${version}\";" > ${versioninfo}
echo "char compatible_version[64] = \"${compatible_version}\";" >> ${versioninfo} echo "char compatible_version[12] = \"${compatible_version}\";" >> ${versioninfo}
echo "char gitinfo[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo} echo "char gitinfo[48] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo}
if [ "$verMode" != "cluster" ]; then if [ "$verMode" != "cluster" ]; then
echo "char gitinfoOfInternal[128] = \"\";" >> ${versioninfo} echo "char gitinfoOfInternal[48] = \"\";" >> ${versioninfo}
else else
enterprise_dir="${top_dir}/../enterprise" enterprise_dir="${top_dir}/../enterprise"
cd ${enterprise_dir} cd ${enterprise_dir}
echo "char gitinfoOfInternal[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo} echo "char gitinfoOfInternal[48] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo}
cd ${curr_dir} cd ${curr_dir}
fi fi
echo "char buildinfo[512] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo} echo "char buildinfo[64] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo}
echo "" >> ${versioninfo} echo "" >> ${versioninfo}
tmp_version=$(echo $version | tr -s "." "_") tmp_version=$(echo $version | tr -s "." "_")
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then

View File

@ -191,14 +191,14 @@ typedef struct SDataBlockList { // todo remove
} SDataBlockList; } SDataBlockList;
typedef struct SQueryInfo { typedef struct SQueryInfo {
int16_t command; // the command may be different for each subclause, so keep it seperately. int16_t command; // the command may be different for each subclause, so keep it seperately.
uint32_t type; // query/insert/import type uint32_t type; // query/insert/import type
char slidingTimeUnit; char slidingTimeUnit;
STimeWindow window; STimeWindow window;
int64_t intervalTime; // aggregation time interval int64_t intervalTime; // aggregation time interval
int64_t slidingTime; // sliding window in mseconds int64_t slidingTime; // sliding window in mseconds
SSqlGroupbyExpr groupbyExpr; // group by tags info SSqlGroupbyExpr groupbyExpr; // group by tags info
SArray * colList; // SArray<SColumn*> SArray * colList; // SArray<SColumn*>
SFieldInfo fieldsInfo; SFieldInfo fieldsInfo;
@ -207,11 +207,11 @@ typedef struct SQueryInfo {
SLimitVal slimit; SLimitVal slimit;
STagCond tagCond; STagCond tagCond;
SOrderVal order; SOrderVal order;
int16_t fillType; // interpolate type int16_t fillType; // final result fill type
int16_t numOfTables; int16_t numOfTables;
STableMetaInfo **pTableMetaInfo; STableMetaInfo **pTableMetaInfo;
struct STSBuf * tsBuf; struct STSBuf * tsBuf;
int64_t * fillVal; // default value for interpolation int64_t * fillVal; // default value for fill
char * msg; // pointer to the pCmd->payload to keep error message temporarily char * msg; // pointer to the pCmd->payload to keep error message temporarily
int64_t clauseLimit; // limit for current sub clause int64_t clauseLimit; // limit for current sub clause
@ -222,15 +222,15 @@ typedef struct SQueryInfo {
typedef struct { typedef struct {
int command; int command;
uint8_t msgType; uint8_t msgType;
bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta
bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta int8_t dataSourceType; // load data from file or not
int8_t dataSourceType; // load data from file or not
union { union {
int32_t count; int32_t count;
int32_t numOfTablesInSubmit; int32_t numOfTablesInSubmit;
}; };
int32_t insertType;
int32_t clauseIndex; // index of multiple subclause query int32_t clauseIndex; // index of multiple subclause query
int8_t parseFinished; int8_t parseFinished;
short numOfCols; short numOfCols;
@ -239,14 +239,12 @@ typedef struct {
int32_t payloadLen; int32_t payloadLen;
SQueryInfo **pQueryInfo; SQueryInfo **pQueryInfo;
int32_t numOfClause; int32_t numOfClause;
char * curSql; // current sql, resume position of sql after parsing paused
void * pTableList; // referred table involved in sql
int32_t batchSize; // for parameter ('?') binding and batch processing
int32_t numOfParams;
SDataBlockList *pDataBlocks; // submit data blocks after parsing sql SDataBlockList *pDataBlocks; // submit data blocks after parsing sql
char * curSql; // current sql, resume position of sql after parsing paused
void * pTableList; // referred table involved in sql
// for parameter ('?') binding and batch processing
int32_t batchSize;
int32_t numOfParams;
} SSqlCmd; } SSqlCmd;
typedef struct SResRec { typedef struct SResRec {
@ -316,7 +314,6 @@ typedef struct SSqlObj {
SRpcIpSet ipList; SRpcIpSet ipList;
char freed : 4; char freed : 4;
char listed : 4; char listed : 4;
uint32_t insertType;
tsem_t rspSem; tsem_t rspSem;
SSqlCmd cmd; SSqlCmd cmd;
SSqlRes res; SSqlRes res;
@ -361,7 +358,7 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion);
void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet); void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet);
int tscProcessSql(SSqlObj *pSql); int tscProcessSql(SSqlObj *pSql);
int tscRenewMeterMeta(SSqlObj *pSql, char *tableId); int tscRenewTableMeta(SSqlObj *pSql, char *tableId);
void tscQueueAsyncRes(SSqlObj *pSql); void tscQueueAsyncRes(SSqlObj *pSql);
void tscQueueAsyncError(void(*fp), void *param, int32_t code); void tscQueueAsyncError(void(*fp), void *param, int32_t code);
@ -404,6 +401,7 @@ TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port,
void *param, void **taos); void *param, void **taos);
void waitForQueryRsp(void *param, TAOS_RES *tres, int code) ; void waitForQueryRsp(void *param, TAOS_RES *tres, int code) ;
int doAsyncParseSql(SSqlObj* pSql);
void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, void (*fp)(), void *param, const char *sqlstr, size_t sqlLen); void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, void (*fp)(), void *param, const char *sqlstr, size_t sqlLen);
void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql); void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql);

View File

@ -309,7 +309,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNI
TAOS *tscon = (TAOS *)con; TAOS *tscon = (TAOS *)con;
if (tscon == NULL) { if (tscon == NULL) {
jniError("jobj:%p, connection is closed", jobj); jniError("jobj:%p, connection is closed", jobj);
return (jint)TSDB_CODE_INVALID_CONNECTION; return (jint)TSDB_CODE_TSC_INVALID_CONNECTION;
} }
if ((void *)tres == NULL) { if ((void *)tres == NULL) {

View File

@ -40,40 +40,39 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows); static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows);
static void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows); static void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows);
void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const char* sqlstr, size_t sqlLen) { int doAsyncParseSql(SSqlObj* pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res; SSqlRes* pRes = &pSql->res;
int32_t code = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE);
pSql->signature = pSql; if (code != TSDB_CODE_SUCCESS) {
pSql->param = param;
pSql->pTscObj = pObj;
pSql->maxRetry = TSDB_MAX_REPLICA_NUM;
pSql->fp = fp;
sem_init(&pSql->rspSem, 0, 0);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
tscError("failed to malloc payload"); tscError("failed to malloc payload");
tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_TSC_OUT_OF_MEMORY);
return; return code;
}
// todo check for OOM problem
pSql->sqlstr = calloc(1, sqlLen + 1);
if (pSql->sqlstr == NULL) {
tscError("%p failed to malloc sql string buffer", pSql);
tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY);
free(pCmd->payload);
return;
} }
pRes->qhandle = 0; pRes->qhandle = 0;
pRes->numOfRows = 1; pRes->numOfRows = 1;
strtolower(pSql->sqlstr, sqlstr);
tscDump("%p SQL: %s", pSql, pSql->sqlstr); tscDump("%p SQL: %s", pSql, pSql->sqlstr);
return tsParseSql(pSql, true);
}
void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const char* sqlstr, size_t sqlLen) {
pSql->signature = pSql;
pSql->param = param;
pSql->pTscObj = pObj;
pSql->maxRetry = TSDB_MAX_REPLICA_NUM;
pSql->fp = fp;
pSql->sqlstr = calloc(1, sqlLen + 1);
if (pSql->sqlstr == NULL) {
tscError("%p failed to malloc sql string buffer", pSql);
tscQueueAsyncError(pSql->fp, pSql->param, TSDB_CODE_TSC_OUT_OF_MEMORY);
return;
}
strtolower(pSql->sqlstr, sqlstr);
int32_t code = tsParseSql(pSql, true); int32_t code = doAsyncParseSql(pSql);
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return;
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
pSql->res.code = code; pSql->res.code = code;
@ -89,16 +88,16 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
tscError("bug!!! pObj:%p", pObj); tscError("bug!!! pObj:%p", pObj);
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED);
return; return;
} }
int32_t sqlLen = strlen(sqlstr); int32_t sqlLen = strlen(sqlstr);
if (sqlLen > tsMaxSQLStringLen) { if (sqlLen > tsMaxSQLStringLen) {
tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); tscError("sql string exceeds max length:%d", tsMaxSQLStringLen);
terrno = TSDB_CODE_INVALID_SQL; terrno = TSDB_CODE_TSC_INVALID_SQL;
tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_SQL); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_SQL);
return; return;
} }
@ -107,8 +106,8 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
tscError("failed to malloc sqlObj"); tscError("failed to malloc sqlObj");
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY);
return; return;
} }
@ -203,7 +202,7 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi
SSqlObj *pSql = (SSqlObj *)taosa; SSqlObj *pSql = (SSqlObj *)taosa;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
tscError("sql object is NULL"); tscError("sql object is NULL");
tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED);
return; return;
} }
@ -212,7 +211,7 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi
if (pRes->qhandle == 0) { if (pRes->qhandle == 0) {
tscError("qhandle is NULL"); tscError("qhandle is NULL");
tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_QHANDLE); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE);
return; return;
} }
@ -260,7 +259,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW),
SSqlObj *pSql = (SSqlObj *)taosa; SSqlObj *pSql = (SSqlObj *)taosa;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
tscError("sql object is NULL"); tscError("sql object is NULL");
tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED);
return; return;
} }
@ -269,7 +268,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW),
if (pRes->qhandle == 0) { if (pRes->qhandle == 0) {
tscError("qhandle is NULL"); tscError("qhandle is NULL");
tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_QHANDLE); tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE);
return; return;
} }
@ -443,15 +442,17 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
} }
if (pSql->pStream == NULL) { if (pSql->pStream == NULL) {
// check if it is a sub-query of super table query first, if true, enter another routine
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
if ((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) == TSDB_QUERY_TYPE_STABLE_SUBQUERY) { // check if it is a sub-query of super table query first, if true, enter another routine
if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_SUBQUERY)) {
tscTrace("%p update table meta in local cache, continue to process sql and send corresponding subquery", pSql);
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if (pTableMetaInfo->pTableMeta == NULL){ if (pTableMetaInfo->pTableMeta == NULL){
code = tscGetTableMeta(pSql, pTableMetaInfo); code = tscGetTableMeta(pSql, pTableMetaInfo);
assert(code == TSDB_CODE_SUCCESS); assert(code == TSDB_CODE_SUCCESS);
} }
assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0) && pTableMetaInfo->vgroupIndex >= 0 && pSql->param != NULL); assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0) && pTableMetaInfo->vgroupIndex >= 0 && pSql->param != NULL);
@ -461,37 +462,42 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex && assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex &&
tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0); tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0);
tscTrace("%p get metricMeta during super table query successfully", pSql); // NOTE: the vgroupInfo for the queried super table must be existed here.
assert(pTableMetaInfo->vgroupList != NULL);
code = tscGetSTableVgroupInfo(pSql, 0); if ((code = tscProcessSql(pSql)) == TSDB_CODE_SUCCESS) {
pRes->code = code; return;
}
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; } else { // continue to process normal async query
} else { // normal async query continues
if (pCmd->parseFinished) { if (pCmd->parseFinished) {
tscTrace("%p re-send data to vnode in table Meta callback since sql parsed completed", pSql); tscTrace("%p update table meta in local cache, continue to process sql and send corresponding query", pSql);
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
code = tscGetTableMeta(pSql, pTableMetaInfo); code = tscGetTableMeta(pSql, pTableMetaInfo);
assert(code == TSDB_CODE_SUCCESS); assert(code == TSDB_CODE_SUCCESS);
if (pTableMetaInfo->pTableMeta) { // if failed to process sql, go to error handler
// todo update the submit message according to the new table meta if ((code = tscProcessSql(pSql)) == TSDB_CODE_SUCCESS) {
// 1. table uid, 2. ip address return;
code = tscSendMsgToServer(pSql);
if (code == TSDB_CODE_SUCCESS) return;
} }
// // todo update the submit message according to the new table meta
// // 1. table uid, 2. ip address
// code = tscSendMsgToServer(pSql);
// if (code == TSDB_CODE_SUCCESS) return;
// }
} else { } else {
tscTrace("%p continue parse sql after get table meta", pSql);
code = tsParseSql(pSql, false); code = tsParseSql(pSql, false);
if ((pQueryInfo->type & TSDB_QUERY_TYPE_STMT_INSERT) == TSDB_QUERY_TYPE_STMT_INSERT) { if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STMT_INSERT)) {
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
code = tscGetTableMeta(pSql, pTableMetaInfo); code = tscGetTableMeta(pSql, pTableMetaInfo);
assert(code == TSDB_CODE_SUCCESS && pTableMetaInfo->pTableMeta != NULL); assert(code == TSDB_CODE_SUCCESS && pTableMetaInfo->pTableMeta != NULL);
(*pSql->fp)(pSql->param, pSql, code); (*pSql->fp)(pSql->param, pSql, code);
return; return;
} }
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return;
} }
} }
@ -500,13 +506,13 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
code = tscGetTableMeta(pSql, pTableMetaInfo); code = tscGetTableMeta(pSql, pTableMetaInfo);
pRes->code = code; pRes->code = code;
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return;
if (code == TSDB_CODE_SUCCESS && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { if (code == TSDB_CODE_SUCCESS && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
code = tscGetSTableVgroupInfo(pSql, pCmd->clauseIndex); code = tscGetSTableVgroupInfo(pSql, pCmd->clauseIndex);
pRes->code = code; pRes->code = code;
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return;
} }
} }
@ -518,15 +524,11 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
if (pSql->pStream) { if (pSql->pStream) {
tscTrace("%p stream:%p meta is updated, start new query, command:%d", pSql, pSql->pStream, pSql->cmd.command); tscTrace("%p stream:%p meta is updated, start new query, command:%d", pSql, pSql->pStream, pSql->cmd.command);
/* if (!pSql->cmd.parseFinished) {
* NOTE: tsParseSql(pSql, false);
* transfer the sql function for super table query before get meter/metric meta, sem_post(&pSql->rspSem);
* since in callback functions, only tscProcessSql(pStream->pSql) is executed! }
*/ return;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
tscTansformSQLFuncForSTableQuery(pQueryInfo);
tscIncStreamExecutionCount(pSql->pStream);
} else { } else {
tscTrace("%p get tableMeta successfully", pSql); tscTrace("%p get tableMeta successfully", pSql);
} }

View File

@ -156,7 +156,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) {
if (!isValidDataType(dataType, dataBytes)) { if (!isValidDataType(dataType, dataBytes)) {
tscError("Illegal data type %d or data type length %d", dataType, dataBytes); tscError("Illegal data type %d or data type length %d", dataType, dataBytes);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY || if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY ||
@ -325,7 +325,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
*bytes = (int16_t)dataBytes; *bytes = (int16_t)dataBytes;
*interBytes = dataBytes + sizeof(SLastrowInfo); *interBytes = dataBytes + sizeof(SLastrowInfo);
} else { } else {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -1293,7 +1293,7 @@ static void max_function_f(SQLFunctionCtx *pCtx, int32_t index) {
minMax_function_f(pCtx, index, 0); minMax_function_f(pCtx, index, 0);
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult == DATA_SET_FLAG) { if (pResInfo->hasResult == DATA_SET_FLAG && pResInfo->superTableQ) {
char *flag = pCtx->aOutputBuf + pCtx->inputBytes; char *flag = pCtx->aOutputBuf + pCtx->inputBytes;
*flag = DATA_SET_FLAG; *flag = DATA_SET_FLAG;
} }
@ -1309,7 +1309,7 @@ static void min_function_f(SQLFunctionCtx *pCtx, int32_t index) {
minMax_function_f(pCtx, index, 1); minMax_function_f(pCtx, index, 1);
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult == DATA_SET_FLAG) { if (pResInfo->hasResult == DATA_SET_FLAG && pResInfo->superTableQ) {
char *flag = pCtx->aOutputBuf + pCtx->inputBytes; char *flag = pCtx->aOutputBuf + pCtx->inputBytes;
*flag = DATA_SET_FLAG; *flag = DATA_SET_FLAG;
} }

View File

@ -345,12 +345,12 @@ static void tscProcessServStatus(SSqlObj *pSql) {
STscObj* pObj = pSql->pTscObj; STscObj* pObj = pSql->pTscObj;
if (pObj->pHb != NULL) { if (pObj->pHb != NULL) {
if (pObj->pHb->res.code == TSDB_CODE_NETWORK_UNAVAIL) { if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
pSql->res.code = TSDB_CODE_NETWORK_UNAVAIL; pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
return; return;
} }
} else { } else {
if (pSql->res.code == TSDB_CODE_NETWORK_UNAVAIL) { if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
return; return;
} }
} }
@ -414,7 +414,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
} else if (pCmd->command == TSDB_SQL_SERV_STATUS) { } else if (pCmd->command == TSDB_SQL_SERV_STATUS) {
tscProcessServStatus(pSql); tscProcessServStatus(pSql);
} else { } else {
pSql->res.code = TSDB_CODE_INVALID_SQL; pSql->res.code = TSDB_CODE_TSC_INVALID_SQL;
tscError("%p not support command:%d", pSql, pCmd->command); tscError("%p not support command:%d", pSql, pCmd->command);
} }

View File

@ -134,7 +134,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1
} }
if (getTimestampInUsFromStr(valueToken.z, valueToken.n, &interval) != TSDB_CODE_SUCCESS) { if (getTimestampInUsFromStr(valueToken.z, valueToken.n, &interval) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (timePrec == TSDB_TIME_PRECISION_MILLI) { if (timePrec == TSDB_TIME_PRECISION_MILLI) {
@ -423,7 +423,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
} }
strcpy(error, "client out of memory"); strcpy(error, "client out of memory");
*code = TSDB_CODE_CLI_OUT_OF_MEMORY; *code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return -1; return -1;
} }
@ -431,7 +431,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL &&
type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || (sToken.n == 0) || (type == TK_RP)) { type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || (sToken.n == 0) || (type == TK_RP)) {
tscInvalidSQLErrMsg(error, "invalid data or symbol", sToken.z); tscInvalidSQLErrMsg(error, "invalid data or symbol", sToken.z);
*code = TSDB_CODE_INVALID_SQL; *code = TSDB_CODE_TSC_INVALID_SQL;
return -1; return -1;
} }
@ -463,13 +463,13 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX);
int32_t ret = tsParseOneColumnData(pSchema, &sToken, start, error, str, isPrimaryKey, timePrec); int32_t ret = tsParseOneColumnData(pSchema, &sToken, start, error, str, isPrimaryKey, timePrec);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
*code = TSDB_CODE_INVALID_SQL; *code = TSDB_CODE_TSC_INVALID_SQL;
return -1; // NOTE: here 0 mean error! return -1; // NOTE: here 0 mean error!
} }
if (isPrimaryKey && tsCheckTimestamp(pDataBlocks, start) != TSDB_CODE_SUCCESS) { if (isPrimaryKey && tsCheckTimestamp(pDataBlocks, start) != TSDB_CODE_SUCCESS) {
tscInvalidSQLErrMsg(error, "client time/server time can not be mixed up", sToken.z); tscInvalidSQLErrMsg(error, "client time/server time can not be mixed up", sToken.z);
*code = TSDB_CODE_INVALID_TIME_STAMP; *code = TSDB_CODE_TSC_INVALID_TIME_STAMP;
return -1; return -1;
} }
} }
@ -526,7 +526,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe
if (spd->hasVal[0] == false) { if (spd->hasVal[0] == false) {
strcpy(error, "primary timestamp column can not be null"); strcpy(error, "primary timestamp column can not be null");
*code = TSDB_CODE_INVALID_SQL; *code = TSDB_CODE_TSC_INVALID_SQL;
return -1; return -1;
} }
@ -560,7 +560,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe
*str += index; *str += index;
if (sToken.n == 0 || sToken.type != TK_RP) { if (sToken.n == 0 || sToken.type != TK_RP) {
tscInvalidSQLErrMsg(error, ") expected", *str); tscInvalidSQLErrMsg(error, ") expected", *str);
*code = TSDB_CODE_INVALID_SQL; *code = TSDB_CODE_TSC_INVALID_SQL;
return -1; return -1;
} }
@ -569,7 +569,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe
if (numOfRows <= 0) { if (numOfRows <= 0) {
strcpy(error, "no any data points"); strcpy(error, "no any data points");
*code = TSDB_CODE_INVALID_SQL; *code = TSDB_CODE_TSC_INVALID_SQL;
return -1; return -1;
} else { } else {
return numOfRows; return numOfRows;
@ -611,7 +611,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3
// do nothing, if allocate more memory failed // do nothing, if allocate more memory failed
pDataBlock->nAllocSize = nAllocSizeOld; pDataBlock->nAllocSize = nAllocSizeOld;
*numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize; *numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize;
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
} }
@ -687,13 +687,13 @@ static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableList, char **st
int32_t maxNumOfRows; int32_t maxNumOfRows;
ret = tscAllocateMemIfNeed(dataBuf, tinfo.rowSize, &maxNumOfRows); ret = tscAllocateMemIfNeed(dataBuf, tinfo.rowSize, &maxNumOfRows);
if (TSDB_CODE_SUCCESS != ret) { if (TSDB_CODE_SUCCESS != ret) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
int32_t code = TSDB_CODE_INVALID_SQL; int32_t code = TSDB_CODE_TSC_INVALID_SQL;
char * tmpTokenBuf = calloc(1, 4096); // used for deleting Escape character: \\, \', \" char * tmpTokenBuf = calloc(1, 4096); // used for deleting Escape character: \\, \', \"
if (NULL == tmpTokenBuf) { if (NULL == tmpTokenBuf) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
int32_t numOfRows = tsParseValues(str, dataBuf, pTableMeta, maxNumOfRows, spd, pCmd->payload, &code, tmpTokenBuf); int32_t numOfRows = tsParseValues(str, dataBuf, pTableMeta, maxNumOfRows, spd, pCmd->payload, &code, tmpTokenBuf);
@ -772,7 +772,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
} }
if (numOfColList == 0 && cstart != NULL) { if (numOfColList == 0 && cstart != NULL) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX);
@ -954,7 +954,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
createTable = true; createTable = true;
code = tscGetMeterMetaEx(pSql, pTableMetaInfo, true); code = tscGetMeterMetaEx(pSql, pTableMetaInfo, true);
if (TSDB_CODE_ACTION_IN_PROGRESS == code) { if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) {
return code; return code;
} }
@ -967,7 +967,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
code = tscGetMeterMetaEx(pSql, pTableMetaInfo, false); code = tscGetMeterMetaEx(pSql, pTableMetaInfo, false);
if (pCmd->curSql == NULL) { if (pCmd->curSql == NULL) {
assert(code == TSDB_CODE_ACTION_IN_PROGRESS); assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS);
} }
} }
@ -981,7 +981,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
} }
if (*sqlstr == NULL) { if (*sqlstr == NULL) {
code = TSDB_CODE_INVALID_SQL; code = TSDB_CODE_TSC_INVALID_SQL;
} }
return code; return code;
@ -1046,7 +1046,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
pSql->cmd.pDataBlocks = tscCreateBlockArrayList(); pSql->cmd.pDataBlocks = tscCreateBlockArrayList();
if (NULL == pCmd->pTableList || NULL == pSql->cmd.pDataBlocks) { if (NULL == pCmd->pTableList || NULL == pSql->cmd.pDataBlocks) {
code = TSDB_CODE_CLI_OUT_OF_MEMORY; code = TSDB_CODE_TSC_OUT_OF_MEMORY;
goto _error_clean; goto _error_clean;
} }
} else { } else {
@ -1075,7 +1075,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
* Otherwise, create the first submit block and submit to virtual node. * Otherwise, create the first submit block and submit to virtual node.
*/ */
if (totalNum == 0) { if (totalNum == 0) {
code = TSDB_CODE_INVALID_SQL; code = TSDB_CODE_TSC_INVALID_SQL;
goto _error_clean; goto _error_clean;
} else { } else {
break; break;
@ -1103,7 +1103,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
* And during the getMeterMetaCallback function, the sql string will be parsed from the * And during the getMeterMetaCallback function, the sql string will be parsed from the
* interrupted position. * interrupted position.
*/ */
if (TSDB_CODE_ACTION_IN_PROGRESS == code) { if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) {
tscTrace("%p waiting for get table meta during insert, then resume from offset: %" PRId64 " , %s", pSql, tscTrace("%p waiting for get table meta during insert, then resume from offset: %" PRId64 " , %s", pSql,
pos, pCmd->curSql); pos, pCmd->curSql);
return code; return code;
@ -1297,7 +1297,7 @@ _clean:
int tsParseInsertSql(SSqlObj *pSql) { int tsParseInsertSql(SSqlObj *pSql) {
if (!pSql->pTscObj->writeAuth) { if (!pSql->pTscObj->writeAuth) {
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_TSC_NO_WRITE_AUTH;
} }
int32_t index = 0; int32_t index = 0;
@ -1314,7 +1314,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo); tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo);
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT);
TSDB_QUERY_SET_TYPE(pQueryInfo->type, pSql->insertType); TSDB_QUERY_SET_TYPE(pQueryInfo->type, pCmd->insertType);
sToken = tStrGetToken(pSql->sqlstr, &index, false, 0, NULL); sToken = tStrGetToken(pSql->sqlstr, &index, false, 0, NULL);
if (sToken.type != TK_INTO) { if (sToken.type != TK_INTO) {
@ -1342,7 +1342,7 @@ int tsParseSql(SSqlObj *pSql, bool initialParse) {
* Set the fp before parse the sql string, in case of getTableMeta failed, in which * Set the fp before parse the sql string, in case of getTableMeta failed, in which
* the error handle callback function can rightfully restore the user-defined callback function (fp). * the error handle callback function can rightfully restore the user-defined callback function (fp).
*/ */
if (initialParse && (pSql->insertType != TSDB_QUERY_TYPE_STMT_INSERT)) { if (initialParse && (pSql->cmd.insertType != TSDB_QUERY_TYPE_STMT_INSERT)) {
pSql->fetchFp = pSql->fp; pSql->fetchFp = pSql->fp;
pSql->fp = (void(*)())tscHandleMultivnodeInsert; pSql->fp = (void(*)())tscHandleMultivnodeInsert;
} }
@ -1354,9 +1354,7 @@ int tsParseSql(SSqlObj *pSql, bool initialParse) {
return ret; return ret;
} }
SSqlInfo SQLInfo = {0}; SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
tSQLParse(&SQLInfo, pSql->sqlstr);
ret = tscToSQLCmd(pSql, &SQLInfo); ret = tscToSQLCmd(pSql, &SQLInfo);
SQLInfoDestroy(&SQLInfo); SQLInfoDestroy(&SQLInfo);
} }

View File

@ -24,7 +24,6 @@
#include "tscSubquery.h" #include "tscSubquery.h"
int tsParseInsertSql(SSqlObj *pSql); int tsParseInsertSql(SSqlObj *pSql);
int taos_query_imp(STscObj* pObj, SSqlObj* pSql);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// functions for normal statement preparation // functions for normal statement preparation
@ -62,7 +61,7 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_
size *= 2; size *= 2;
void* tmp = realloc(stmt->parts, sizeof(SNormalStmtPart) * size); void* tmp = realloc(stmt->parts, sizeof(SNormalStmtPart) * size);
if (tmp == NULL) { if (tmp == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
stmt->sizeParts = size; stmt->sizeParts = size;
stmt->parts = (SNormalStmtPart*)tmp; stmt->parts = (SNormalStmtPart*)tmp;
@ -133,7 +132,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
var->pz = (char*)malloc((*tb->length) + 1); var->pz = (char*)malloc((*tb->length) + 1);
if (var->pz == NULL) { if (var->pz == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
memcpy(var->pz, tb->buffer, (*tb->length)); memcpy(var->pz, tb->buffer, (*tb->length));
var->pz[*tb->length] = 0; var->pz[*tb->length] = 0;
@ -142,7 +141,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
default: default:
tscTrace("param %d: type mismatch or invalid", i); tscTrace("param %d: type mismatch or invalid", i);
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
} }
@ -187,7 +186,7 @@ static int normalStmtPrepare(STscStmt* stmt) {
if (normal->numParams > 0) { if (normal->numParams > 0) {
normal->params = calloc(normal->numParams, sizeof(tVariant)); normal->params = calloc(normal->numParams, sizeof(tVariant));
if (normal->params == NULL) { if (normal->params == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
} }
@ -273,7 +272,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
} }
if (bind->buffer_type != param->type) { if (bind->buffer_type != param->type) {
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
short size = 0; short size = 0;
@ -300,7 +299,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
if ((*bind->length) > param->bytes) { if ((*bind->length) > param->bytes) {
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
size = (short)*bind->length; size = (short)*bind->length;
STR_WITH_SIZE_TO_VARSTR(data + param->offset, bind->buffer, size); STR_WITH_SIZE_TO_VARSTR(data + param->offset, bind->buffer, size);
@ -309,14 +308,14 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
size_t output = 0; size_t output = 0;
if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) { if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) {
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
varDataSetLen(data + param->offset, output); varDataSetLen(data + param->offset, output);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
default: default:
assert(false); assert(false);
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
memcpy(data + param->offset, bind->buffer, size); memcpy(data + param->offset, bind->buffer, size);
@ -344,7 +343,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
const double factor = 1.5; const double factor = 1.5;
void* tmp = realloc(pBlock->pData, (uint32_t)(totalDataSize * factor)); void* tmp = realloc(pBlock->pData, (uint32_t)(totalDataSize * factor));
if (tmp == NULL) { if (tmp == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pBlock->pData = (char*)tmp; pBlock->pData = (char*)tmp;
pBlock->nAllocSize = (uint32_t)(totalDataSize * factor); pBlock->nAllocSize = (uint32_t)(totalDataSize * factor);
@ -416,7 +415,7 @@ static int insertStmtReset(STscStmt* pStmt) {
static int insertStmtExecute(STscStmt* stmt) { static int insertStmtExecute(STscStmt* stmt) {
SSqlCmd* pCmd = &stmt->pSql->cmd; SSqlCmd* pCmd = &stmt->pSql->cmd;
if (pCmd->batchSize == 0) { if (pCmd->batchSize == 0) {
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
if ((pCmd->batchSize % 2) == 1) { if ((pCmd->batchSize % 2) == 1) {
++pCmd->batchSize; ++pCmd->batchSize;
@ -452,7 +451,7 @@ static int insertStmtExecute(STscStmt* stmt) {
pRes->qhandle = 0; pRes->qhandle = 0;
pSql->insertType = 0; pSql->cmd.insertType = 0;
pSql->fetchFp = waitForQueryRsp; pSql->fetchFp = waitForQueryRsp;
pSql->fp = (void(*)())tscHandleMultivnodeInsert; pSql->fp = (void(*)())tscHandleMultivnodeInsert;
@ -470,14 +469,14 @@ static int insertStmtExecute(STscStmt* stmt) {
TAOS_STMT* taos_stmt_init(TAOS* taos) { TAOS_STMT* taos_stmt_init(TAOS* taos) {
STscObj* pObj = (STscObj*)taos; STscObj* pObj = (STscObj*)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
tscError("connection disconnected"); tscError("connection disconnected");
return NULL; return NULL;
} }
STscStmt* pStmt = calloc(1, sizeof(STscStmt)); STscStmt* pStmt = calloc(1, sizeof(STscStmt));
if (pStmt == NULL) { if (pStmt == NULL) {
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("failed to allocate memory for statement"); tscError("failed to allocate memory for statement");
return NULL; return NULL;
} }
@ -486,7 +485,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
free(pStmt); free(pStmt);
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("failed to allocate memory for statement"); tscError("failed to allocate memory for statement");
return NULL; return NULL;
} }
@ -504,8 +503,8 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
STscStmt* pStmt = (STscStmt*)stmt; STscStmt* pStmt = (STscStmt*)stmt;
if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_TSC_DISCONNECTED;
} }
SSqlObj* pSql = pStmt->pSql; SSqlObj* pSql = pStmt->pSql;
@ -516,11 +515,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
pSql->param = (void*) pSql; pSql->param = (void*) pSql;
pSql->fp = waitForQueryRsp; pSql->fp = waitForQueryRsp;
pSql->insertType = TSDB_QUERY_TYPE_STMT_INSERT; pSql->cmd.insertType = TSDB_QUERY_TYPE_STMT_INSERT;
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
tscError("%p failed to malloc payload buffer", pSql); tscError("%p failed to malloc payload buffer", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1);
@ -528,7 +527,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
if (pSql->sqlstr == NULL) { if (pSql->sqlstr == NULL) {
tscError("%p failed to malloc sql string buffer", pSql); tscError("%p failed to malloc sql string buffer", pSql);
free(pCmd->payload); free(pCmd->payload);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pRes->qhandle = 0; pRes->qhandle = 0;
@ -544,7 +543,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
pSql->cmd.batchSize = 0; pSql->cmd.batchSize = 0;
int32_t code = tsParseSql(pSql, true); int32_t code = tsParseSql(pSql, true);
if (code == TSDB_CODE_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
// wait for the callback function to post the semaphore // wait for the callback function to post the semaphore
tsem_wait(&pSql->rspSem); tsem_wait(&pSql->rspSem);
return pSql->res.code; return pSql->res.code;
@ -589,7 +588,7 @@ int taos_stmt_add_batch(TAOS_STMT* stmt) {
if (pStmt->isInsert) { if (pStmt->isInsert) {
return insertStmtAddBatch(pStmt); return insertStmtAddBatch(pStmt);
} }
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_COM_OPS_NOT_SUPPORT;
} }
int taos_stmt_reset(TAOS_STMT* stmt) { int taos_stmt_reset(TAOS_STMT* stmt) {
@ -608,7 +607,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
} else { } else {
char* sql = normalStmtBuildSql(pStmt); char* sql = normalStmtBuildSql(pStmt);
if (sql == NULL) { if (sql == NULL) {
ret = TSDB_CODE_CLI_OUT_OF_MEMORY; ret = TSDB_CODE_TSC_OUT_OF_MEMORY;
} else { } else {
tfree(pStmt->pSql->sqlstr); tfree(pStmt->pSql->sqlstr);
pStmt->pSql->sqlstr = sql; pStmt->pSql->sqlstr = sql;

View File

@ -41,7 +41,7 @@
#define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_TBNAME_COLUMN_INDEX)) #define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_TBNAME_COLUMN_INDEX))
#define TBNAME_LIST_SEP "," #define TBNAME_LIST_SEP ","
typedef struct SColumnList { typedef struct SColumnList { // todo refactor
int32_t num; int32_t num;
SColumnIndex ids[TSDB_MAX_COLUMNS]; SColumnIndex ids[TSDB_MAX_COLUMNS];
} SColumnList; } SColumnList;
@ -179,7 +179,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SSQLToken* pPwd) {
// todo handle memory leak in error handle function // todo handle memory leak in error handle function
int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) { if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) {
return TSDB_CODE_APP_ERROR; return TSDB_CODE_TSC_APP_ERROR;
} }
SSqlCmd* pCmd = &(pSql->cmd); SSqlCmd* pCmd = &(pSql->cmd);
@ -264,7 +264,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case TSDB_SQL_SHOW: { case TSDB_SQL_SHOW: {
if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) { if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
break; break;
@ -286,7 +286,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) { if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
break; break;
@ -314,7 +314,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken* pPwd = &pInfo->pDCLInfo->user.passwd; SSQLToken* pPwd = &pInfo->pDCLInfo->user.passwd;
if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pName->n > TSDB_USER_LEN) { if (pName->n > TSDB_USER_LEN) {
@ -411,12 +411,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pCmd->command == TSDB_SQL_CREATE_USER) { if (pCmd->command == TSDB_SQL_CREATE_USER) {
if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else { } else {
if (pUser->type == TSDB_ALTER_USER_PASSWD) { if (pUser->type == TSDB_ALTER_USER_PASSWD) {
if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
assert(pPwd->type == TSDB_DATA_TYPE_NULL); assert(pPwd->type == TSDB_DATA_TYPE_NULL);
@ -517,6 +517,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
} }
pCmd->parseFinished = 1;
return TSDB_CODE_SUCCESS; // do not build query message here return TSDB_CODE_SUCCESS; // do not build query message here
} }
@ -542,6 +543,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "not support sql expression"); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "not support sql expression");
} }
pSql->cmd.parseFinished = true;
return tscBuildMsg[pCmd->command](pSql, pInfo); return tscBuildMsg[pCmd->command](pSql, pInfo);
} }
@ -577,7 +579,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
// interval is not null // interval is not null
SSQLToken* t = &pQuerySql->interval; SSQLToken* t = &pQuerySql->interval;
if (getTimestampInUsFromStr(t->z, t->n, &pQueryInfo->intervalTime) != TSDB_CODE_SUCCESS) { if (getTimestampInUsFromStr(t->z, t->n, &pQueryInfo->intervalTime) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// if the unit of time window value is millisecond, change the value from microsecond // if the unit of time window value is millisecond, change the value from microsecond
@ -596,7 +598,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
// for top/bottom + interval query, we do not add additional timestamp column in the front // for top/bottom + interval query, we do not add additional timestamp column in the front
if (isTopBottomQuery(pQueryInfo)) { if (isTopBottomQuery(pQueryInfo)) {
if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -635,7 +637,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
} }
if (tableIndex == COLUMN_INDEX_INITIAL_VAL) { if (tableIndex == COLUMN_INDEX_INITIAL_VAL) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX};
@ -651,7 +653,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
} }
if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -1040,7 +1042,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL
/* db name is not specified, the tableName dose not include db name */ /* db name is not specified, the tableName dose not include db name */
if (pDB != NULL) { if (pDB != NULL) {
if (pDB->n > TSDB_DB_NAME_LEN) { if (pDB->n > TSDB_DB_NAME_LEN) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
memcpy(&fullName[totalLen], pDB->z, pDB->n); memcpy(&fullName[totalLen], pDB->z, pDB->n);
@ -1054,12 +1056,12 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL
/* here we only check the table name length limitation */ /* here we only check the table name length limitation */
if (tableName->n > TSDB_TABLE_NAME_LEN) { if (tableName->n > TSDB_TABLE_NAME_LEN) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else { // pDB == NULL, the db prefix name is specified in tableName } else { // pDB == NULL, the db prefix name is specified in tableName
/* the length limitation includes tablename + dbname + sep */ /* the length limitation includes tablename + dbname + sep */
if (tableName->n > TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN + tListLen(TS_PATH_DELIMITER)) { if (tableName->n > TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN + tListLen(TS_PATH_DELIMITER)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -1075,7 +1077,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL
fullName[totalLen] = 0; fullName[totalLen] = 0;
} }
return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_INVALID_SQL; return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_TSC_INVALID_SQL;
} }
static void extractColumnNameFromString(tSQLExprItem* pItem) { static void extractColumnNameFromString(tSQLExprItem* pItem) {
@ -1122,12 +1124,12 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
// select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2 // select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2
if (addProjectionExprAndResultField(pQueryInfo, pItem) != TSDB_CODE_SUCCESS) { if (addProjectionExprAndResultField(pQueryInfo, pItem) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else if (pItem->pNode->nSQLOptr >= TK_COUNT && pItem->pNode->nSQLOptr <= TK_TBID) { } else if (pItem->pNode->nSQLOptr >= TK_COUNT && pItem->pNode->nSQLOptr <= TK_TBID) {
// sql function in selection clause, append sql function info in pSqlCmd structure sequentially // sql function in selection clause, append sql function info in pSqlCmd structure sequentially
if (addExprAndResultField(pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) { if (addExprAndResultField(pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else if (pItem->pNode->nSQLOptr >= TK_PLUS && pItem->pNode->nSQLOptr <= TK_REM) { } else if (pItem->pNode->nSQLOptr >= TK_PLUS && pItem->pNode->nSQLOptr <= TK_REM) {
@ -1154,7 +1156,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
} }
if (buildArithmeticExprString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) { if (buildArithmeticExprString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// expr string is set as the parameter of function // expr string is set as the parameter of function
@ -1230,7 +1232,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
} }
if (pQueryInfo->fieldsInfo.numOfOutput > TSDB_MAX_COLUMNS) { if (pQueryInfo->fieldsInfo.numOfOutput > TSDB_MAX_COLUMNS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -1246,7 +1248,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
tscTansformSQLFuncForSTableQuery(pQueryInfo); tscTansformSQLFuncForSTableQuery(pQueryInfo);
if (hasUnsupportFunctionsForSTableQuery(pQueryInfo)) { if (hasUnsupportFunctionsForSTableQuery(pQueryInfo)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -1414,7 +1416,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI
addProjectQueryCol(pQueryInfo, startPos, &index, pItem); addProjectQueryCol(pQueryInfo, startPos, &index, pItem);
} }
} else { } else {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -1483,7 +1485,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
int16_t functionID = 0; int16_t functionID = 0;
if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SSqlExpr* pExpr = NULL; SSqlExpr* pExpr = NULL;
@ -1517,12 +1519,14 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
// count tag is equalled to count(tbname) // count tag is equalled to count(tbname)
if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { bool isTag = false;
if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta) || index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
index.columnIndex = TSDB_TBNAME_COLUMN_INDEX; index.columnIndex = TSDB_TBNAME_COLUMN_INDEX;
isTag = true;
} }
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize; int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false); pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, isTag);
} }
} else { // count(*) is equalled to count(primary_timestamp_key) } else { // count(*) is equalled to count(primary_timestamp_key)
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
@ -1543,10 +1547,13 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
tscColumnListInsert(pQueryInfo->colList, &(ids.ids[i])); tscColumnListInsert(pQueryInfo->colList, &(ids.ids[i]));
} }
} }
SColumnIndex tsCol = {.tableIndex = index.tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; // the time stamp may be always needed
tscColumnListInsert(pQueryInfo->colList, &tsCol); if (index.tableIndex > 0 && index.tableIndex < tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) {
SColumnIndex tsCol = {.tableIndex = index.tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX};
tscColumnListInsert(pQueryInfo->colList, &tsCol);
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TK_SUM: case TK_SUM:
@ -1596,12 +1603,12 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
int16_t functionID = 0; int16_t functionID = 0;
if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (getResultDataInfo(pSchema->type, pSchema->bytes, functionID, 0, &resultType, &resultSize, if (getResultDataInfo(pSchema->type, pSchema->bytes, functionID, 0, &resultType, &resultSize,
&intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) { &intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// set the first column ts for diff query // set the first column ts for diff query
@ -1626,14 +1633,14 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
/* set the leastsquares parameters */ /* set the leastsquares parameters */
char val[8] = {0}; char val[8] = {0};
if (tVariantDump(&pParamElem[1].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { if (tVariantDump(&pParamElem[1].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES, 0); addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES, 0);
memset(val, 0, tListLen(val)); memset(val, 0, tListLen(val));
if (tVariantDump(&pParamElem[2].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { if (tVariantDump(&pParamElem[2].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0); addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0);
@ -1698,7 +1705,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
for (int32_t j = 0; j < tscGetNumOfColumns(pTableMetaInfo->pTableMeta); ++j) { for (int32_t j = 0; j < tscGetNumOfColumns(pTableMetaInfo->pTableMeta); ++j) {
index.columnIndex = j; index.columnIndex = j;
if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex++, &index) != 0) { if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex++, &index) != 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -1716,7 +1723,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
} }
if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i, &index) != 0) { if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i, &index) != 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
} }
@ -1733,7 +1740,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
SColumnIndex index = {.tableIndex = j, .columnIndex = i}; SColumnIndex index = {.tableIndex = j, .columnIndex = i};
if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i + j, &index) != if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i + j, &index) !=
0) { 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -1809,7 +1816,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
*/ */
int16_t functionId = 0; int16_t functionId = 0;
if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) { if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, resultSize, false); pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, resultSize, false);
@ -1824,7 +1831,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
int16_t functionId = 0; int16_t functionId = 0;
if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) { if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// set the first column ts for top/bottom query // set the first column ts for top/bottom query
@ -1930,7 +1937,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
} }
default: default:
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -2030,7 +2037,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColum
if (COLUMN_INDEX_VALIDE(*pIndex)) { if (COLUMN_INDEX_VALIDE(*pIndex)) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -2057,7 +2064,7 @@ int32_t getTableIndexImpl(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColum
} }
if (pIndex->tableIndex < 0) { if (pIndex->tableIndex < 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -2068,7 +2075,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn
extractTableNameFromToken(pToken, &tableToken); extractTableNameFromToken(pToken, &tableToken);
if (getTableIndexImpl(&tableToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { if (getTableIndexImpl(&tableToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -2076,13 +2083,13 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn
int32_t getColumnIndexByName(const SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) { int32_t getColumnIndexByName(const SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) {
if (pQueryInfo->pTableMetaInfo == NULL || pQueryInfo->numOfTables == 0) { if (pQueryInfo->pTableMetaInfo == NULL || pQueryInfo->numOfTables == 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SSQLToken tmpToken = *pToken; SSQLToken tmpToken = *pToken;
if (getTableIndexByName(&tmpToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { if (getTableIndexByName(&tmpToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return doGetColumnIndexByName(&tmpToken, pQueryInfo, pIndex); return doGetColumnIndexByName(&tmpToken, pQueryInfo, pIndex);
@ -2255,7 +2262,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) {
SSQLToken* idStr = &(pInfo->pDCLInfo->ip); SSQLToken* idStr = &(pInfo->pDCLInfo->ip);
if (idStr->n > TSDB_KILL_MSG_LEN) { if (idStr->n > TSDB_KILL_MSG_LEN) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
strncpy(pCmd->payload, idStr->z, idStr->n); strncpy(pCmd->payload, idStr->z, idStr->n);
@ -2302,7 +2309,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if (pTableMetaInfo->pTableMeta == NULL || !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { if (pTableMetaInfo->pTableMeta == NULL || !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
assert(tscGetNumOfTags(pTableMetaInfo->pTableMeta) >= 0); assert(tscGetNumOfTags(pTableMetaInfo->pTableMeta) >= 0);
@ -2324,7 +2331,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) {
(functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE)) { (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE)) {
if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, pExpr->param[0].i64Key, &type, &bytes, if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, pExpr->param[0].i64Key, &type, &bytes,
&interBytes, 0, true) != TSDB_CODE_SUCCESS) { &interBytes, 0, true) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
tscSqlExprUpdate(pQueryInfo, k, functionId, pExpr->colInfo.colIndex, TSDB_DATA_TYPE_BINARY, bytes); tscSqlExprUpdate(pQueryInfo, k, functionId, pExpr->colInfo.colIndex, TSDB_DATA_TYPE_BINARY, bytes);
@ -2748,7 +2755,7 @@ static bool isExprDirectParentOfLeaftNode(tSQLExpr* pExpr) {
static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** output) { static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** output) {
if (!isExprDirectParentOfLeaftNode(pExpr)) { if (!isExprDirectParentOfLeaftNode(pExpr)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
tSQLExpr* pLeft = pExpr->pLeft; tSQLExpr* pLeft = pExpr->pLeft;
@ -2761,7 +2768,7 @@ static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char**
tSQLExprNodeToString(pLeft, output); tSQLExprNodeToString(pLeft, output);
if (optrToString(pExpr, output) != TSDB_CODE_SUCCESS) { if (optrToString(pExpr, output) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
tSQLExprNodeToString(pRight, output); tSQLExprNodeToString(pRight, output);
@ -2827,7 +2834,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
break; break;
} }
default: default:
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
*exprString += 1; *exprString += 1;
@ -2838,7 +2845,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
tSQLExprList* pList = pExpr->pParam; tSQLExprList* pList = pExpr->pParam;
if (pList->nExpr <= 0) { if (pList->nExpr <= 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pList->nExpr > 0) { if (pList->nExpr > 0) {
@ -2854,7 +2861,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
} }
if (pSub->val.nLen <= 0 || pSub->val.nLen > TSDB_TABLE_NAME_LEN) { if (pSub->val.nLen <= 0 || pSub->val.nLen > TSDB_TABLE_NAME_LEN) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -2902,7 +2909,7 @@ static int32_t extractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnIndex* pIn
// TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2" // TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2"
pColFilter = addColumnFilterInfo(pColumn); pColFilter = addColumnFilterInfo(pColumn);
} else { // error; } else { // error;
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pColFilter->filterstr = pColFilter->filterstr =
@ -2977,7 +2984,7 @@ static int32_t getTablenameCond(SQueryInfo* pQueryInfo, tSQLExpr* pTableCond, SS
tSQLExpr* pRight = pTableCond->pRight; tSQLExpr* pRight = pTableCond->pRight;
if (!isTablenameToken(&pLeft->colInfo)) { if (!isTablenameToken(&pLeft->colInfo)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
@ -3010,7 +3017,7 @@ static int32_t getColumnQueryCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, i
} else { // handle leaf node } else { // handle leaf node
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return extractColumnFilterInfo(pQueryInfo, &index, pExpr, relOptr); return extractColumnFilterInfo(pQueryInfo, &index, pExpr, relOptr);
@ -3034,7 +3041,7 @@ static int32_t getJoinCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) {
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
@ -3046,7 +3053,7 @@ static int32_t getJoinCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) {
index = (SColumnIndex)COLUMN_INDEX_INITIALIZER; index = (SColumnIndex)COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pExpr->pRight->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&pExpr->pRight->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
@ -3072,7 +3079,7 @@ int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString) {
} else { } else {
int32_t ret = tSQLExprNodeToString(pLeft, exprString); int32_t ret = tSQLExprNodeToString(pLeft, exprString);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -3083,7 +3090,7 @@ int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString) {
} else { } else {
int32_t ret = tSQLExprNodeToString(pRight, exprString); int32_t ret = tSQLExprNodeToString(pRight, exprString);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -3097,12 +3104,12 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL
if (*type == NON_ARITHMEIC_EXPR) { if (*type == NON_ARITHMEIC_EXPR) {
*type = NORMAL_ARITHMETIC; *type = NORMAL_ARITHMETIC;
} else if (*type == AGG_ARIGHTMEIC) { } else if (*type == AGG_ARIGHTMEIC) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pExpr->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&pExpr->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// if column is timestamp, bool, binary, nchar, not support arithmetic, so return invalid sql // if column is timestamp, bool, binary, nchar, not support arithmetic, so return invalid sql
@ -3111,17 +3118,17 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL
if ((pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) || (pSchema->type == TSDB_DATA_TYPE_BOOL) || if ((pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) || (pSchema->type == TSDB_DATA_TYPE_BOOL) ||
(pSchema->type == TSDB_DATA_TYPE_BINARY) || (pSchema->type == TSDB_DATA_TYPE_NCHAR)) { (pSchema->type == TSDB_DATA_TYPE_BINARY) || (pSchema->type == TSDB_DATA_TYPE_NCHAR)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pList->ids[pList->num++] = index; pList->ids[pList->num++] = index;
} else if (pExpr->nSQLOptr == TK_FLOAT && (isnan(pExpr->val.dKey) || isinf(pExpr->val.dKey))) { } else if (pExpr->nSQLOptr == TK_FLOAT && (isnan(pExpr->val.dKey) || isinf(pExpr->val.dKey))) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) { } else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) {
if (*type == NON_ARITHMEIC_EXPR) { if (*type == NON_ARITHMEIC_EXPR) {
*type = AGG_ARIGHTMEIC; *type = AGG_ARIGHTMEIC;
} else if (*type == NORMAL_ARITHMETIC) { } else if (*type == NORMAL_ARITHMETIC) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t outputIndex = tscSqlExprNumOfExprs(pQueryInfo); int32_t outputIndex = tscSqlExprNumOfExprs(pQueryInfo);
@ -3130,7 +3137,7 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL
// sql function in selection clause, append sql function info in pSqlCmd structure sequentially // sql function in selection clause, append sql function info in pSqlCmd structure sequentially
if (addExprAndResultField(pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) { if (addExprAndResultField(pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -3334,7 +3341,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S
if (index.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) { // query on time range if (index.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) { // query on time range
if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) { if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// set join query condition // set join query condition
@ -3396,7 +3403,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S
} else { } else {
if (pRight->nSQLOptr == TK_ID) { // join on tag columns for stable query if (pRight->nSQLOptr == TK_ID) { // join on tag columns for stable query
if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) { if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pCondExpr->pJoinExpr != NULL) { if (pCondExpr->pJoinExpr != NULL) {
@ -3441,7 +3448,7 @@ int32_t getQueryCondExpr(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pC
tSQLExpr* pRight = (*pExpr)->pRight; tSQLExpr* pRight = (*pExpr)->pRight;
if (!isValidExpr(pLeft, pRight, (*pExpr)->nSQLOptr)) { if (!isValidExpr(pLeft, pRight, (*pExpr)->nSQLOptr)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t leftType = -1; int32_t leftType = -1;
@ -3679,7 +3686,7 @@ static int32_t getTimeRangeFromExpr(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) {
} else { } else {
SColumnIndex index = COLUMN_INDEX_INITIALIZER; SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
@ -3907,7 +3914,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t
* where ts in ('2015-12-12 4:8:12') * where ts in ('2015-12-12 4:8:12')
*/ */
if (pRight->nSQLOptr == TK_SET || optr == TK_IN) { if (pRight->nSQLOptr == TK_SET || optr == TK_IN) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int64_t val = 0; int64_t val = 0;
@ -3920,14 +3927,14 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t
if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO) == TSDB_CODE_SUCCESS) { if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO) == TSDB_CODE_SUCCESS) {
parsed = true; parsed = true;
} else { } else {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else { } else {
SSQLToken token = {.z = pRight->val.pz, .n = pRight->val.nLen, .type = TK_ID}; SSQLToken token = {.z = pRight->val.pz, .n = pRight->val.nLen, .type = TK_ID};
int32_t len = tSQLGetToken(pRight->val.pz, &token.type); int32_t len = tSQLGetToken(pRight->val.pz, &token.type);
if ((token.type != TK_INTEGER && token.type != TK_FLOAT) || len != pRight->val.nLen) { if ((token.type != TK_INTEGER && token.type != TK_FLOAT) || len != pRight->val.nLen) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
} else if (pRight->nSQLOptr == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) { } else if (pRight->nSQLOptr == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) {
@ -4035,7 +4042,7 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) {
if (pQueryInfo->fillVal == NULL) { if (pQueryInfo->fillVal == NULL) {
pQueryInfo->fillVal = calloc(size, sizeof(int64_t)); pQueryInfo->fillVal = calloc(size, sizeof(int64_t));
if (pQueryInfo->fillVal == NULL) { if (pQueryInfo->fillVal == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
} }
@ -4346,7 +4353,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (!validateOneTags(pCmd, &pFieldList->p[0])) { if (!validateOneTags(pCmd, &pFieldList->p[0])) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
@ -4369,7 +4376,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken name = {.z = pItem->pVar.pz, .n = pItem->pVar.nLen, .type = TK_STRING}; SSQLToken name = {.z = pItem->pVar.pz, .n = pItem->pVar.nLen, .type = TK_STRING};
if (getColumnIndexByName(&name, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&name, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) { if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) {
@ -4386,7 +4393,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
tVariantList* pVarList = pAlterSQL->varList; tVariantList* pVarList = pAlterSQL->varList;
if (pVarList->nExpr > 2) { if (pVarList->nExpr > 2) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
tVariantListItem* pSrcItem = &pAlterSQL->varList->a[0]; tVariantListItem* pSrcItem = &pAlterSQL->varList->a[0];
@ -4405,12 +4412,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSQLToken srcToken = {.z = pSrcItem->pVar.pz, .n = pSrcItem->pVar.nLen, .type = TK_STRING}; SSQLToken srcToken = {.z = pSrcItem->pVar.pz, .n = pSrcItem->pVar.nLen, .type = TK_STRING};
if (getColumnIndexByName(&srcToken, pQueryInfo, &srcIndex) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&srcToken, pQueryInfo, &srcIndex) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SSQLToken destToken = {.z = pDstItem->pVar.pz, .n = pDstItem->pVar.nLen, .type = TK_STRING}; SSQLToken destToken = {.z = pDstItem->pVar.pz, .n = pDstItem->pVar.nLen, .type = TK_STRING};
if (getColumnIndexByName(&destToken, pQueryInfo, &destIndex) == TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&destToken, pQueryInfo, &destIndex) == TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
char name[TSDB_COL_NAME_LEN + 1] = {0}; char name[TSDB_COL_NAME_LEN + 1] = {0};
@ -4433,7 +4440,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER;
SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen}; SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen};
if (getColumnIndexByName(&name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) { if (getColumnIndexByName(&name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (columnIndex.columnIndex < tscGetNumOfColumns(pTableMeta)) { if (columnIndex.columnIndex < tscGetNumOfColumns(pTableMeta)) {
@ -4456,7 +4463,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t size = sizeof(SUpdateTableTagValMsg) + pTagsSchema->bytes + TSDB_EXTRA_PAYLOAD_SIZE; int32_t size = sizeof(SUpdateTableTagValMsg) + pTagsSchema->bytes + TSDB_EXTRA_PAYLOAD_SIZE;
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for alter table msg", pSql); tscError("%p failed to malloc for alter table msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) (pCmd->payload + tsRpcHeadSize); SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) (pCmd->payload + tsRpcHeadSize);
@ -4490,7 +4497,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (!validateOneColumn(pCmd, &pFieldList->p[0])) { if (!validateOneColumn(pCmd, &pFieldList->p[0])) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]);
@ -4579,7 +4586,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SQueryInfo* pQueryInfo) {
invalidSqlErrMsg(pQueryInfo->msg, msg1); invalidSqlErrMsg(pQueryInfo->msg, msg1);
} }
return isProjectionFunction == true ? TSDB_CODE_INVALID_SQL : TSDB_CODE_SUCCESS; return isProjectionFunction == true ? TSDB_CODE_TSC_INVALID_SQL : TSDB_CODE_SUCCESS;
} }
typedef struct SDNodeDynConfOption { typedef struct SDNodeDynConfOption {
@ -4589,7 +4596,7 @@ typedef struct SDNodeDynConfOption {
int32_t validateDNodeConfig(tDCLSQL* pOptions) { int32_t validateDNodeConfig(tDCLSQL* pOptions) {
if (pOptions->nTokens < 2 || pOptions->nTokens > 3) { if (pOptions->nTokens < 2 || pOptions->nTokens > 3) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 17; const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 17;
@ -4615,7 +4622,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
SSQLToken* pValToken = &pOptions->a[2]; SSQLToken* pValToken = &pOptions->a[2];
int32_t val = strtol(pValToken->z, NULL, 10); int32_t val = strtol(pValToken->z, NULL, 10);
if (val != 0 && val != 1) { if (val != 0 && val != 1) {
return TSDB_CODE_INVALID_SQL; // options value is invalid return TSDB_CODE_TSC_INVALID_SQL; // options value is invalid
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
@ -4624,7 +4631,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
int32_t val = strtol(pValToken->z, NULL, 10); int32_t val = strtol(pValToken->z, NULL, 10);
if (val < 131 || val > 199) { if (val < 131 || val > 199) {
/* options value is out of valid range */ /* options value is out of valid range */
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
for (int32_t i = 2; i < DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1; ++i) { for (int32_t i = 2; i < DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1; ++i) {
@ -4637,12 +4644,12 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
} }
} }
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t validateLocalConfig(tDCLSQL* pOptions) { int32_t validateLocalConfig(tDCLSQL* pOptions) {
if (pOptions->nTokens < 1 || pOptions->nTokens > 2) { if (pOptions->nTokens < 1 || pOptions->nTokens > 2) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12},
@ -4664,7 +4671,7 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) {
int32_t val = strtol(pValToken->z, NULL, 10); int32_t val = strtol(pValToken->z, NULL, 10);
if (val < 131 || val > 199) { if (val < 131 || val > 199) {
// options value is out of valid range // options value is out of valid range
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) { for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) {
@ -4675,20 +4682,20 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) {
} }
} }
} }
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t validateColumnName(char* name) { int32_t validateColumnName(char* name) {
bool ret = isKeyWord(name, strlen(name)); bool ret = isKeyWord(name, strlen(name));
if (ret) { if (ret) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SSQLToken token = {.z = name}; SSQLToken token = {.z = name};
token.n = tSQLGetToken(name, &token.type); token.n = tSQLGetToken(name, &token.type);
if (token.type != TK_STRING && token.type != TK_ID) { if (token.type != TK_STRING && token.type != TK_ID) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (token.type == TK_STRING) { if (token.type == TK_STRING) {
@ -4697,13 +4704,13 @@ int32_t validateColumnName(char* name) {
int32_t k = tSQLGetToken(token.z, &token.type); int32_t k = tSQLGetToken(token.z, &token.type);
if (k != token.n) { if (k != token.n) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return validateColumnName(token.z); return validateColumnName(token.z);
} else { } else {
if (isNumber(&token)) { if (isNumber(&token)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -4901,15 +4908,15 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
setCreateDBOption(pMsg, pCreateDbSql); setCreateDBOption(pMsg, pCreateDbSql);
if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (setTimePrecision(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { if (setTimePrecision(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) { if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -5340,7 +5347,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
} }
if (checkUpdateTagPrjFunctions(pQueryInfo) != TSDB_CODE_SUCCESS) { if (checkUpdateTagPrjFunctions(pQueryInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
/* /*
@ -5348,7 +5355,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
* divide the subset of final result. * divide the subset of final result.
*/ */
if (doAddGroupbyColumnsOnDemand(pQueryInfo) != TSDB_CODE_SUCCESS) { if (doAddGroupbyColumnsOnDemand(pQueryInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// projection query on super table does not compatible with "group by" syntax // projection query on super table does not compatible with "group by" syntax
@ -5540,7 +5547,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
if (!validateTableColumnInfo(pFieldList, pCmd) || if (!validateTableColumnInfo(pFieldList, pCmd) ||
(pTagList != NULL && !validateTagParams(pTagList, pFieldList, pCmd))) { (pTagList != NULL && !validateTagParams(pTagList, pFieldList, pCmd))) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t col = 0; int32_t col = 0;
@ -5689,22 +5696,22 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo); bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo);
if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pQuerySql->pWhere != NULL) { // query condition in stream computing if (pQuerySql->pWhere != NULL) { // query condition in stream computing
if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) { if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
// set interval value // set interval value
if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} else { } else {
if ((pQueryInfo->intervalTime > 0) && if ((pQueryInfo->intervalTime > 0) &&
(validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) { (validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
@ -5718,13 +5725,13 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
} }
if (tsRewriteFieldNameIfNecessary(pQueryInfo) != TSDB_CODE_SUCCESS) { if (tsRewriteFieldNameIfNecessary(pQueryInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
if (validateSqlFunctionInStreamSql(pQueryInfo) != TSDB_CODE_SUCCESS) { if (validateSqlFunctionInStreamSql(pQueryInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
/* /*
@ -5845,26 +5852,26 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
// parse the group by clause in the first place // parse the group by clause in the first place
if (parseGroupbyClause(pQueryInfo, pQuerySql->pGroupby, pCmd) != TSDB_CODE_SUCCESS) { if (parseGroupbyClause(pQueryInfo, pQuerySql->pGroupby, pCmd) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// set interval value // set interval value
if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} else { } else {
if ((pQueryInfo->intervalTime > 0) && if ((pQueryInfo->intervalTime > 0) &&
(validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) { (validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
// set order by info // set order by info
if (parseOrderbyClause(pQueryInfo, pQuerySql, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) { if (parseOrderbyClause(pQueryInfo, pQuerySql, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// set where info // set where info
@ -5872,7 +5879,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
if (pQuerySql->pWhere != NULL) { if (pQuerySql->pWhere != NULL) {
if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) { if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pQuerySql->pWhere = NULL; pQuerySql->pWhere = NULL;
@ -6021,7 +6028,7 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray*
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} else { } else {
@ -6040,9 +6047,9 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray*
if ((*pExpr)->_node.optr == TSDB_BINARY_OP_DIVIDE) { if ((*pExpr)->_node.optr == TSDB_BINARY_OP_DIVIDE) {
if (pRight->nodeType == TSQL_NODE_VALUE) { if (pRight->nodeType == TSQL_NODE_VALUE) {
if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64Key == 0) { if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64Key == 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} else if (pRight->pVal->nType == TSDB_DATA_TYPE_FLOAT && pRight->pVal->dKey == 0) { } else if (pRight->pVal->nType == TSDB_DATA_TYPE_FLOAT && pRight->pVal->dKey == 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
} }

View File

@ -161,7 +161,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
tscError("%p pMemBuffer is NULL", pMemBuffer); tscError("%p pMemBuffer is NULL", pMemBuffer);
pRes->code = TSDB_CODE_APP_ERROR; pRes->code = TSDB_CODE_TSC_APP_ERROR;
return; return;
} }
@ -169,7 +169,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
tscError("%p no local buffer or intermediate result format model", pSql); tscError("%p no local buffer or intermediate result format model", pSql);
pRes->code = TSDB_CODE_APP_ERROR; pRes->code = TSDB_CODE_TSC_APP_ERROR;
return; return;
} }
@ -196,7 +196,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
pMemBuffer[0]->pageSize); pMemBuffer[0]->pageSize);
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
pRes->code = TSDB_CODE_APP_ERROR; pRes->code = TSDB_CODE_TSC_APP_ERROR;
return; return;
} }
@ -207,7 +207,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
tscError("%p failed to create local merge structure, out of memory", pSql); tscError("%p failed to create local merge structure, out of memory", pSql);
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return; return;
} }
@ -229,7 +229,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
SLocalDataSource *ds = (SLocalDataSource *)malloc(sizeof(SLocalDataSource) + pMemBuffer[0]->pageSize); SLocalDataSource *ds = (SLocalDataSource *)malloc(sizeof(SLocalDataSource) + pMemBuffer[0]->pageSize);
if (ds == NULL) { if (ds == NULL) {
tscError("%p failed to create merge structure", pSql); tscError("%p failed to create merge structure", pSql);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return; return;
} }
@ -327,7 +327,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
// tfree(pReducer->pBufForInterpo); // tfree(pReducer->pBufForInterpo);
tfree(pReducer->prevRowOfInput); tfree(pReducer->prevRowOfInput);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return; return;
} }
@ -561,7 +561,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
int32_t *orderIdx = (int32_t *)calloc(numOfGroupByCols, sizeof(int32_t)); int32_t *orderIdx = (int32_t *)calloc(numOfGroupByCols, sizeof(int32_t));
if (orderIdx == NULL) { if (orderIdx == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
if (numOfGroupByCols > 0) { if (numOfGroupByCols > 0) {
@ -582,7 +582,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
tfree(orderIdx); tfree(orderIdx);
if (*pOrderDesc == NULL) { if (*pOrderDesc == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} else { } else {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -647,7 +647,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
(*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pSql->numOfSubs); (*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pSql->numOfSubs);
if (*pMemBuffer == NULL) { if (*pMemBuffer == NULL) {
tscError("%p failed to allocate memory", pSql); tscError("%p failed to allocate memory", pSql);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pRes->code; return pRes->code;
} }
@ -656,7 +656,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size); pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size);
if (pSchema == NULL) { if (pSchema == NULL) {
tscError("%p failed to allocate memory", pSql); tscError("%p failed to allocate memory", pSql);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pRes->code; return pRes->code;
} }
@ -684,7 +684,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
} }
if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) { if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) {
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pRes->code; return pRes->code;
} }
@ -1185,7 +1185,9 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer, tFilePage
int32_t ret = 0; // merge all result by default int32_t ret = 0; // merge all result by default
int16_t functionId = pLocalReducer->pCtx[0].functionId; int16_t functionId = pLocalReducer->pCtx[0].functionId;
if (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_ARITHM) { // column projection query
// todo opt performance
if ((/*functionId == TSDB_FUNC_PRJ || */functionId == TSDB_FUNC_ARITHM) || (tscIsProjectionQueryOnSTable(pQueryInfo, 0))) { // column projection query
ret = 1; // disable merge procedure ret = 1; // disable merge procedure
} else { } else {
tOrderDescriptor *pDesc = pLocalReducer->pDesc; tOrderDescriptor *pDesc = pLocalReducer->pDesc;

View File

@ -179,7 +179,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
char *pMsg = rpcMallocCont(pCmd->payloadLen); char *pMsg = rpcMallocCont(pCmd->payloadLen);
if (NULL == pMsg) { if (NULL == pMsg) {
tscError("%p msg:%s malloc fail", pSql, taosMsg[pSql->cmd.msgType]); tscError("%p msg:%s malloc fail", pSql, taosMsg[pSql->cmd.msgType]);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
if (pSql->cmd.command < TSDB_SQL_MGMT) { if (pSql->cmd.command < TSDB_SQL_MGMT) {
@ -234,32 +234,21 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
} }
if (rpcMsg->pCont == NULL) { if (rpcMsg->pCont == NULL) {
rpcMsg->code = TSDB_CODE_NETWORK_UNAVAIL; rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
} else { } else {
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
if (rpcMsg->code == TSDB_CODE_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_INVALID_VGROUP_ID || if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
rpcMsg->code == TSDB_CODE_NETWORK_UNAVAIL) { rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
/*
* not_active_table: 1. the virtual node may fail to create table, since the procedure of create table is asynchronized,
* the virtual node may have not create table till now, so try again by using the new metermeta.
* 2. this requested table may have been removed by other client, so we need to renew the
* metermeta here.
*
* not_active_vnode: current vnode is move to other node due to node balance procedure or virtual node have been
* removed. So, renew metermeta and try again.
* not_active_session: db has been move to other node, the vnode does not exist on this dnode anymore.
*/
if (pCmd->command == TSDB_SQL_CONNECT) { if (pCmd->command == TSDB_SQL_CONNECT) {
rpcMsg->code = TSDB_CODE_NETWORK_UNAVAIL; rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
rpcFreeCont(rpcMsg->pCont); rpcFreeCont(rpcMsg->pCont);
return; return;
} else if (pCmd->command == TSDB_SQL_HB) { } else if (pCmd->command == TSDB_SQL_HB) {
rpcMsg->code = TSDB_CODE_NOT_READY; rpcMsg->code = TSDB_CODE_RPC_NOT_READY;
rpcFreeCont(rpcMsg->pCont); rpcFreeCont(rpcMsg->pCont);
return; return;
} else if (pCmd->command == TSDB_SQL_META) { } else if (pCmd->command == TSDB_SQL_META) {
// rpcFreeCont(rpcMsg->pCont); // get table meta query will not retry, do nothing
// return;
} else { } else {
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry); tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry);
@ -267,13 +256,14 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
if (pSql->retry > pSql->maxRetry) { if (pSql->retry > pSql->maxRetry) {
tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry); tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry);
} else { } else {
rpcMsg->code = tscRenewMeterMeta(pSql, pTableMetaInfo->name); rpcMsg->code = tscRenewTableMeta(pSql, pTableMetaInfo->name);
if (pTableMetaInfo->pTableMeta) {
tscSendMsgToServer(pSql); // if there is an error occurring, proceed to the following error handling procedure.
// todo add test cases
if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
rpcFreeCont(rpcMsg->pCont);
return;
} }
rpcFreeCont(rpcMsg->pCont);
return;
} }
} }
} }
@ -281,8 +271,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
pRes->rspLen = 0; pRes->rspLen = 0;
if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) {
pRes->code = (rpcMsg->code != TSDB_CODE_SUCCESS) ? rpcMsg->code : TSDB_CODE_NETWORK_UNAVAIL; pRes->code = (rpcMsg->code != TSDB_CODE_SUCCESS) ? rpcMsg->code : TSDB_CODE_RPC_NETWORK_UNAVAIL;
} else { } else {
tscTrace("%p query is cancelled, code:%d", pSql, tstrerror(pRes->code)); tscTrace("%p query is cancelled, code:%d", pSql, tstrerror(pRes->code));
} }
@ -292,7 +282,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
pSql->retry = 0; pSql->retry = 0;
} }
if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) {
assert(rpcMsg->msgType == pCmd->msgType + 1); assert(rpcMsg->msgType == pCmd->msgType + 1);
pRes->code = rpcMsg->code; pRes->code = rpcMsg->code;
pRes->rspType = rpcMsg->msgType; pRes->rspType = rpcMsg->msgType;
@ -301,7 +291,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
if (pRes->rspLen > 0 && rpcMsg->pCont) { if (pRes->rspLen > 0 && rpcMsg->pCont) {
char *tmp = (char *)realloc(pRes->pRsp, pRes->rspLen); char *tmp = (char *)realloc(pRes->pRsp, pRes->rspLen);
if (tmp == NULL) { if (tmp == NULL) {
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
} else { } else {
pRes->pRsp = tmp; pRes->pRsp = tmp;
memcpy(pRes->pRsp, rpcMsg->pCont, pRes->rspLen); memcpy(pRes->pRsp, rpcMsg->pCont, pRes->rspLen);
@ -330,10 +320,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
} }
} }
if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) {
rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql);
}
if (rpcMsg->code != TSDB_CODE_ACTION_IN_PROGRESS) {
if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? pRes->numOfRows: pRes->code; rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? pRes->numOfRows: pRes->code;
bool shouldFree = tscShouldBeFreed(pSql); bool shouldFree = tscShouldBeFreed(pSql);
@ -401,7 +392,7 @@ int tscProcessSql(SSqlObj *pSql) {
tscTrace("%p SQL cmd:%s will be processed, name:%s, type:%d", pSql, sqlCmd[pCmd->command], name, type); tscTrace("%p SQL cmd:%s will be processed, name:%s, type:%d", pSql, sqlCmd[pCmd->command], name, type);
if (pCmd->command < TSDB_SQL_MGMT) { // the pTableMetaInfo cannot be NULL if (pCmd->command < TSDB_SQL_MGMT) { // the pTableMetaInfo cannot be NULL
if (pTableMetaInfo == NULL) { if (pTableMetaInfo == NULL) {
pSql->res.code = TSDB_CODE_OTHERS; pSql->res.code = TSDB_CODE_TSC_APP_ERROR;
return pSql->res.code; return pSql->res.code;
} }
} else if (pCmd->command < TSDB_SQL_LOCAL) { } else if (pCmd->command < TSDB_SQL_LOCAL) {
@ -430,9 +421,9 @@ void tscKillSTableQuery(SSqlObj *pSql) {
/* /*
* here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause * here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause
* sub-queries not correctly released and master sql object of metric query reaches an abnormal state. * sub-queries not correctly released and master sql object of super table query reaches an abnormal state.
*/ */
pSql->pSubs[i]->res.code = TSDB_CODE_QUERY_CANCELLED; pSql->pSubs[i]->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
//taosStopRpcConn(pSql->pSubs[i]->thandle); //taosStopRpcConn(pSql->pSubs[i]->thandle);
} }
@ -564,7 +555,7 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char
pQueryMsg->numOfTables = htonl(1); // set the number of tables pQueryMsg->numOfTables = htonl(1); // set the number of tables
pMsg += sizeof(STableIdInfo); pMsg += sizeof(STableIdInfo);
} else { } else { // it is a subquery of the super table query, this IP info is acquired from vgroupInfo
int32_t index = pTableMetaInfo->vgroupIndex; int32_t index = pTableMetaInfo->vgroupIndex;
int32_t numOfVgroups = taosArrayGetSize(pTableMetaInfo->pVgroupTables); int32_t numOfVgroups = taosArrayGetSize(pTableMetaInfo->pVgroupTables);
assert(index >= 0 && index < numOfVgroups); assert(index >= 0 && index < numOfVgroups);
@ -605,7 +596,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return -1; return -1; // todo add test for this
} }
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
@ -677,7 +668,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex, pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex,
pColSchema->name); pColSchema->name);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
pQueryMsg->colList[i].colId = htons(pColSchema->colId); pQueryMsg->colList[i].colId = htons(pColSchema->colId);
@ -795,7 +786,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns, pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns,
pCol->colIndex, pColSchema->name); pCol->colIndex, pColSchema->name);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
SColumnInfo* pTagCol = (SColumnInfo*) pMsg; SColumnInfo* pTagCol = (SColumnInfo*) pMsg;
@ -885,7 +876,7 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pCmd->payloadLen = sizeof(SCMCreateDnodeMsg); pCmd->payloadLen = sizeof(SCMCreateDnodeMsg);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload; SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload;
@ -901,7 +892,7 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pCmd->payloadLen = sizeof(SCMCreateAcctMsg); pCmd->payloadLen = sizeof(SCMCreateAcctMsg);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMCreateAcctMsg *pAlterMsg = (SCMCreateAcctMsg *)pCmd->payload; SCMCreateAcctMsg *pAlterMsg = (SCMCreateAcctMsg *)pCmd->payload;
@ -947,7 +938,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMCreateUserMsg *pAlterMsg = (SCMCreateUserMsg*)pCmd->payload; SCMCreateUserMsg *pAlterMsg = (SCMCreateUserMsg*)pCmd->payload;
@ -986,7 +977,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload; SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload;
@ -1005,7 +996,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMDropTableMsg *pDropTableMsg = (SCMDropTableMsg*)pCmd->payload; SCMDropTableMsg *pDropTableMsg = (SCMDropTableMsg*)pCmd->payload;
@ -1022,7 +1013,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pCmd->payloadLen = sizeof(SCMDropDnodeMsg); pCmd->payloadLen = sizeof(SCMDropDnodeMsg);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload; SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload;
@ -1040,7 +1031,7 @@ int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload;
@ -1057,7 +1048,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload;
@ -1073,7 +1064,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMUseDbMsg *pUseDbMsg = (SCMUseDbMsg*)pCmd->payload; SCMUseDbMsg *pUseDbMsg = (SCMUseDbMsg*)pCmd->payload;
@ -1092,7 +1083,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMShowMsg *pShowMsg = (SCMShowMsg*)pCmd->payload; SCMShowMsg *pShowMsg = (SCMShowMsg*)pCmd->payload;
@ -1176,7 +1167,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
size = tscEstimateCreateTableMsgLength(pSql, pInfo); size = tscEstimateCreateTableMsgLength(pSql, pInfo);
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);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
@ -1321,7 +1312,7 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
@ -1431,7 +1422,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
SCMConnectMsg *pConnect = (SCMConnectMsg*)pCmd->payload; SCMConnectMsg *pConnect = (SCMConnectMsg*)pCmd->payload;
@ -1456,7 +1447,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (len > 0) { if (len > 0) {
tmpData = calloc(1, len); tmpData = calloc(1, len);
if (NULL == tmpData) { if (NULL == tmpData) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
// STagData is in binary format, strncpy is not available // STagData is in binary format, strncpy is not available
@ -1778,17 +1769,17 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
if (pMetaMsg->sid < 0 || pMetaMsg->vgroup.numOfIps < 0) { if (pMetaMsg->sid < 0 || pMetaMsg->vgroup.numOfIps < 0) {
tscError("invalid meter vgId:%d, sid%d", pMetaMsg->vgroup.numOfIps, pMetaMsg->sid); tscError("invalid meter vgId:%d, sid%d", pMetaMsg->vgroup.numOfIps, pMetaMsg->sid);
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
if (pMetaMsg->numOfTags > TSDB_MAX_TAGS || pMetaMsg->numOfTags < 0) { if (pMetaMsg->numOfTags > TSDB_MAX_TAGS || pMetaMsg->numOfTags < 0) {
tscError("invalid numOfTags:%d", pMetaMsg->numOfTags); tscError("invalid numOfTags:%d", pMetaMsg->numOfTags);
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) { if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) {
tscError("invalid numOfColumns:%d", pMetaMsg->numOfColumns); tscError("invalid numOfColumns:%d", pMetaMsg->numOfColumns);
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
for (int i = 0; i < pMetaMsg->vgroup.numOfIps; ++i) { for (int i = 0; i < pMetaMsg->vgroup.numOfIps; ++i) {
@ -1818,10 +1809,10 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
// todo handle out of memory case // todo handle out of memory case
if (pTableMetaInfo->pTableMeta == NULL) { if (pTableMetaInfo->pTableMeta == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
tscTrace("%p recv table meta: %"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name); tscTrace("%p recv table meta, uid:%"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name);
free(pTableMeta); free(pTableMeta);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -1839,9 +1830,9 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
ieType = *rsp; ieType = *rsp;
if (ieType != TSDB_IE_TYPE_META) { if (ieType != TSDB_IE_TYPE_META) {
tscError("invalid ie type:%d", ieType); tscError("invalid ie type:%d", ieType);
pSql->res.code = TSDB_CODE_INVALID_IE; pSql->res.code = TSDB_CODE_TSC_INVALID_IE;
pSql->res.numOfTotal = 0; pSql->res.numOfTotal = 0;
return TSDB_CODE_OTHERS; return TSDB_CODE_TSC_APP_ERROR;
} }
rsp++; rsp++;
@ -1861,32 +1852,32 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
if (pMeta->sid <= 0 || pMeta->vgId < 0) { if (pMeta->sid <= 0 || pMeta->vgId < 0) {
tscError("invalid meter vgId:%d, sid%d", pMeta->vgId, pMeta->sid); tscError("invalid meter vgId:%d, sid%d", pMeta->vgId, pMeta->sid);
pSql->res.code = TSDB_CODE_INVALID_VALUE; pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
pSql->res.numOfTotal = i; pSql->res.numOfTotal = i;
return TSDB_CODE_OTHERS; return TSDB_CODE_TSC_APP_ERROR;
} }
// pMeta->numOfColumns = htons(pMeta->numOfColumns); // pMeta->numOfColumns = htons(pMeta->numOfColumns);
// //
// if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) { // if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) {
// tscError("invalid tag value count:%d", pMeta->numOfTags); // tscError("invalid tag value count:%d", pMeta->numOfTags);
// pSql->res.code = TSDB_CODE_INVALID_VALUE; // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
// pSql->res.numOfTotal = i; // pSql->res.numOfTotal = i;
// return TSDB_CODE_OTHERS; // return TSDB_CODE_TSC_APP_ERROR;
// } // }
// //
// if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) { // if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) {
// tscError("invalid numOfTags:%d", pMeta->numOfTags); // tscError("invalid numOfTags:%d", pMeta->numOfTags);
// pSql->res.code = TSDB_CODE_INVALID_VALUE; // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
// pSql->res.numOfTotal = i; // pSql->res.numOfTotal = i;
// return TSDB_CODE_OTHERS; // return TSDB_CODE_TSC_APP_ERROR;
// } // }
// //
// if (pMeta->numOfColumns > TSDB_MAX_COLUMNS || pMeta->numOfColumns < 0) { // if (pMeta->numOfColumns > TSDB_MAX_COLUMNS || pMeta->numOfColumns < 0) {
// tscError("invalid numOfColumns:%d", pMeta->numOfColumns); // tscError("invalid numOfColumns:%d", pMeta->numOfColumns);
// pSql->res.code = TSDB_CODE_INVALID_VALUE; // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE;
// pSql->res.numOfTotal = i; // pSql->res.numOfTotal = i;
// return TSDB_CODE_OTHERS; // return TSDB_CODE_TSC_APP_ERROR;
// } // }
// //
// for (int j = 0; j < TSDB_REPLICA_MAX_NUM; ++j) { // for (int j = 0; j < TSDB_REPLICA_MAX_NUM; ++j) {
@ -1951,7 +1942,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
if (metricMetaList == NULL || sizes == NULL) { if (metricMetaList == NULL || sizes == NULL) {
tfree(metricMetaList); tfree(metricMetaList);
tfree(sizes); tfree(sizes);
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pSql->res.code; return pSql->res.code;
} }
@ -1970,7 +1961,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
char *pBuf = calloc(1, size); char *pBuf = calloc(1, size);
if (pBuf == NULL) { if (pBuf == NULL) {
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
goto _error_clean; goto _error_clean;
} }
@ -2030,7 +2021,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
// failed to put into cache // failed to put into cache
if (pTableMetaInfo->pMetricMeta == NULL) { if (pTableMetaInfo->pMetricMeta == NULL) {
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
goto _error_clean; goto _error_clean;
} }
} }
@ -2324,7 +2315,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); SSqlObj *pNew = calloc(1, sizeof(SSqlObj));
if (NULL == pNew) { if (NULL == pNew) {
tscError("%p malloc failed for new sqlobj to get table meta", pSql); tscError("%p malloc failed for new sqlobj to get table meta", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pNew->pTscObj = pSql->pTscObj; pNew->pTscObj = pSql->pTscObj;
@ -2341,7 +2332,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
tscError("%p malloc failed for payload to get table meta", pSql); tscError("%p malloc failed for payload to get table meta", pSql);
free(pNew); free(pNew);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
STableMetaInfo *pNewMeterMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo); STableMetaInfo *pNewMeterMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo);
@ -2357,7 +2348,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
int32_t code = tscProcessSql(pNew); int32_t code = tscProcessSql(pNew);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = TSDB_CODE_ACTION_IN_PROGRESS; code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify upper application that current process need to be terminated
} }
return code; return code;
@ -2388,56 +2379,26 @@ int tscGetMeterMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool create
return tscGetTableMeta(pSql, pTableMetaInfo); return tscGetTableMeta(pSql, pTableMetaInfo);
} }
/*
* in handling the renew metermeta problem during insertion,
*
* If the meter is created on demand during insertion, the routine usually waits for a short
* period to re-issue the getMeterMeta msg, in which makes a greater change that vnode has
* successfully created the corresponding table.
*/
static void tscWaitingForCreateTable(SSqlCmd *pCmd) {
if (pCmd->command == TSDB_SQL_INSERT) {
taosMsleep(50); // todo: global config
}
}
/** /**
* in renew metermeta, do not retrieve metadata in cache. * retrieve table meta from mnode, and update the local table meta cache.
* @param pSql sql object * @param pSql sql object
* @param tableId meter id * @param tableId table full name
* @return status code * @return status code
*/ */
int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) { int tscRenewTableMeta(SSqlObj *pSql, char *tableId) {
int code = 0;
// handle table meta renew process
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
/* STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
* 1. only update the metermeta in force model metricmeta is not updated if (pTableMetaInfo->pTableMeta) {
* 2. if get metermeta failed, still get the metermeta tscTrace("%p update table meta, old meta numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql,
*/ tscGetNumOfTags(pTableMeta), tscGetNumOfColumns(pTableMeta), pTableMeta->uid, pTableMeta);
if (pTableMetaInfo->pTableMeta == NULL || !tscQueryOnSTable(pCmd)) {
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
if (pTableMetaInfo->pTableMeta) {
tscTrace("%p update table meta, old: numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql,
tscGetNumOfTags(pTableMeta), tscGetNumOfColumns(pTableMeta), pTableMeta->uid, pTableMeta);
}
tscWaitingForCreateTable(pCmd);
taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true);
code = getTableMetaFromMgmt(pSql, pTableMetaInfo); // todo ??
} else {
tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql,
tscGetNumOfTags(pTableMetaInfo->pTableMeta), pCmd->numOfCols, pTableMetaInfo->pTableMeta->uid,
pTableMetaInfo->pTableMeta);
} }
return code; taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true);
return getTableMetaFromMgmt(pSql, pTableMetaInfo);
} }
static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) { static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) {
@ -2454,7 +2415,7 @@ static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) {
} }
int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
int code = TSDB_CODE_NETWORK_UNAVAIL; int code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
if (allVgroupInfoRetrieved(pCmd, clauseIndex)) { if (allVgroupInfoRetrieved(pCmd, clauseIndex)) {
@ -2491,7 +2452,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
pNew->param = pSql; pNew->param = pSql;
code = tscProcessSql(pNew); code = tscProcessSql(pNew);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = TSDB_CODE_ACTION_IN_PROGRESS; code = TSDB_CODE_TSC_ACTION_IN_PROGRESS;
} }
return code; return code;

View File

@ -57,12 +57,12 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
taos_init(); taos_init();
if (!validUserName(user)) { if (!validUserName(user)) {
terrno = TSDB_CODE_INVALID_ACCT; terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH;
return NULL; return NULL;
} }
if (!validPassword(pass)) { if (!validPassword(pass)) {
terrno = TSDB_CODE_INVALID_PASS; terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH;
return NULL; return NULL;
} }
@ -73,13 +73,13 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
void *pDnodeConn = NULL; void *pDnodeConn = NULL;
if (tscInitRpc(user, pass, &pDnodeConn) != 0) { if (tscInitRpc(user, pass, &pDnodeConn) != 0) {
terrno = TSDB_CODE_NETWORK_UNAVAIL; terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL;
return NULL; return NULL;
} }
STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj));
if (NULL == pObj) { if (NULL == pObj) {
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
rpcClose(pDnodeConn); rpcClose(pDnodeConn);
return NULL; return NULL;
} }
@ -93,7 +93,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
int32_t len = strlen(db); int32_t len = strlen(db);
/* db name is too long */ /* db name is too long */
if (len > TSDB_DB_NAME_LEN) { if (len > TSDB_DB_NAME_LEN) {
terrno = TSDB_CODE_INVALID_DB; terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH;
rpcClose(pDnodeConn); rpcClose(pDnodeConn);
free(pObj); free(pObj);
return NULL; return NULL;
@ -110,7 +110,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
if (NULL == pSql) { if (NULL == pSql) {
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
rpcClose(pDnodeConn); rpcClose(pDnodeConn);
free(pObj); free(pObj);
return NULL; return NULL;
@ -131,7 +131,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
pSql->cmd.command = TSDB_SQL_CONNECT; pSql->cmd.command = TSDB_SQL_CONNECT;
if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
rpcClose(pDnodeConn); rpcClose(pDnodeConn);
free(pSql); free(pSql);
free(pObj); free(pObj);
@ -212,48 +212,6 @@ void taos_close(TAOS *taos) {
} }
} }
int taos_query_imp(STscObj *pObj, SSqlObj *pSql) {
SSqlRes *pRes = &pSql->res;
SSqlCmd *pCmd = &pSql->cmd;
pRes->numOfRows = 1;
pRes->numOfTotal = 0;
pRes->numOfClauseTotal = 0;
pCmd->curSql = NULL;
if (NULL != pCmd->pTableList) {
taosHashCleanup(pCmd->pTableList);
pCmd->pTableList = NULL;
}
tscDump("%p pObj:%p, SQL: %s", pSql, pObj, pSql->sqlstr);
pRes->code = (uint8_t)tsParseSql(pSql, false);
/*
* set the qhandle to 0 before return in order to erase the qhandle value assigned in the previous successful query.
* If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscProcessSql()
* to free connection, which may cause segment fault, when the parse phrase is not even successfully executed.
*/
pRes->qhandle = 0;
if (pRes->code == TSDB_CODE_SUCCESS) {
tscDoQuery(pSql);
}
if (pRes->code == TSDB_CODE_SUCCESS) {
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj);
} else {
tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj);
}
if (pRes->code != TSDB_CODE_SUCCESS) {
tscPartiallyFreeSqlObj(pSql);
}
return pRes->code;
}
void waitForQueryRsp(void *param, TAOS_RES *tres, int code) { void waitForQueryRsp(void *param, TAOS_RES *tres, int code) {
assert(tres != NULL); assert(tres != NULL);
@ -264,14 +222,14 @@ void waitForQueryRsp(void *param, TAOS_RES *tres, int code) {
TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return NULL; return NULL;
} }
int32_t sqlLen = strlen(sqlstr); int32_t sqlLen = strlen(sqlstr);
if (sqlLen > tsMaxSQLStringLen) { if (sqlLen > tsMaxSQLStringLen) {
tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); tscError("sql string exceeds max length:%d", tsMaxSQLStringLen);
terrno = TSDB_CODE_INVALID_SQL; terrno = TSDB_CODE_TSC_INVALID_SQL;
return NULL; return NULL;
} }
@ -280,7 +238,7 @@ TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) {
SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
tscError("failed to malloc sqlObj"); tscError("failed to malloc sqlObj");
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
return NULL; return NULL;
} }
@ -419,7 +377,7 @@ static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) {
TAOS_ROW taos_fetch_row(TAOS_RES *res) { TAOS_ROW taos_fetch_row(TAOS_RES *res) {
SSqlObj *pSql = (SSqlObj *)res; SSqlObj *pSql = (SSqlObj *)res;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return NULL; return NULL;
} }
@ -462,7 +420,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
int nRows = 0; int nRows = 0;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
*rows = NULL; *rows = NULL;
return 0; return 0;
} }
@ -505,8 +463,8 @@ int taos_select_db(TAOS *taos, const char *db) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_TSC_DISCONNECTED;
} }
snprintf(sql, tListLen(sql), "use %s", db); snprintf(sql, tListLen(sql), "use %s", db);
@ -587,7 +545,7 @@ int taos_errno(TAOS_RES *tres) {
* why the sql is invalid * why the sql is invalid
*/ */
static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) { static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) {
if (code != TSDB_CODE_INVALID_SQL) { if (code != TSDB_CODE_TSC_INVALID_SQL) {
return false; return false;
} }
@ -649,7 +607,7 @@ void taos_stop_query(TAOS_RES *res) {
if (pSql->signature != pSql) return; if (pSql->signature != pSql) return;
tscTrace("%p start to cancel query", res); tscTrace("%p start to cancel query", res);
pSql->res.code = TSDB_CODE_QUERY_CANCELLED; pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
@ -734,8 +692,8 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
int taos_validate_sql(TAOS *taos, const char *sql) { int taos_validate_sql(TAOS *taos, const char *sql) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_TSC_DISCONNECTED;
} }
SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
@ -752,13 +710,13 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
int32_t sqlLen = strlen(sql); int32_t sqlLen = strlen(sql);
if (sqlLen > tsMaxSQLStringLen) { if (sqlLen > tsMaxSQLStringLen) {
tscError("%p sql too long", pSql); tscError("%p sql too long", pSql);
pRes->code = TSDB_CODE_INVALID_SQL; pRes->code = TSDB_CODE_TSC_INVALID_SQL;
return pRes->code; return pRes->code;
} }
pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1);
if (pSql->sqlstr == NULL) { if (pSql->sqlstr == NULL) {
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("%p failed to malloc sql string buffer", pSql); tscError("%p failed to malloc sql string buffer", pSql);
tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
return pRes->code; return pRes->code;
@ -790,7 +748,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
pCmd->command = TSDB_SQL_MULTI_META; pCmd->command = TSDB_SQL_MULTI_META;
pCmd->count = 0; pCmd->count = 0;
int code = TSDB_CODE_INVALID_TABLE_ID; int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
char *str = (char *)tblNameList; char *str = (char *)tblNameList;
SQueryInfo *pQueryInfo = NULL; SQueryInfo *pQueryInfo = NULL;
@ -824,7 +782,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
// Check if the table name available or not // Check if the table name available or not
if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) { if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_INVALID_TABLE_ID; code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
sprintf(pCmd->payload, "table name is invalid"); sprintf(pCmd->payload, "table name is invalid");
return code; return code;
} }
@ -834,7 +792,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
} }
if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) { if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) {
code = TSDB_CODE_INVALID_TABLE_ID; code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
sprintf(pCmd->payload, "tables over the max number"); sprintf(pCmd->payload, "tables over the max number");
return code; return code;
} }
@ -842,7 +800,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) { if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) {
char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen); char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen);
if (pNewMem == NULL) { if (pNewMem == NULL) {
code = TSDB_CODE_CLI_OUT_OF_MEMORY; code = TSDB_CODE_TSC_OUT_OF_MEMORY;
sprintf(pCmd->payload, "failed to allocate memory"); sprintf(pCmd->payload, "failed to allocate memory");
return code; return code;
} }
@ -866,8 +824,8 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_TSC_DISCONNECTED;
} }
SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
@ -884,13 +842,13 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
int32_t tblListLen = strlen(tableNameList); int32_t tblListLen = strlen(tableNameList);
if (tblListLen > MAX_TABLE_NAME_LENGTH) { if (tblListLen > MAX_TABLE_NAME_LENGTH) {
tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH); tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH);
pRes->code = TSDB_CODE_INVALID_SQL; pRes->code = TSDB_CODE_TSC_INVALID_SQL;
return pRes->code; return pRes->code;
} }
char *str = calloc(1, tblListLen + 1); char *str = calloc(1, tblListLen + 1);
if (str == NULL) { if (str == NULL) {
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("%p failed to malloc sql string buffer", pSql); tscError("%p failed to malloc sql string buffer", pSql);
return pRes->code; return pRes->code;
} }

View File

@ -19,6 +19,7 @@
#include "tscLog.h" #include "tscLog.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tsched.h" #include "tsched.h"
#include "tcache.h"
#include "tsclient.h" #include "tsclient.h"
#include "ttime.h" #include "ttime.h"
#include "ttimer.h" #include "ttimer.h"
@ -77,30 +78,23 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
int code = tscGetTableMeta(pSql, pTableMetaInfo); int code = tscGetTableMeta(pSql, pTableMetaInfo);
pSql->res.code = code; pSql->res.code = code;
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
if (code == 0 && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { if (code == 0 && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
code = tscGetSTableVgroupInfo(pSql, 0); code = tscGetSTableVgroupInfo(pSql, 0);
pSql->res.code = code; pSql->res.code = code;
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
} }
tscTansformSQLFuncForSTableQuery(pQueryInfo);
// failed to get meter/metric meta, retry in 10sec. // failed to get meter/metric meta, retry in 10sec.
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision); int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
tscError("%p stream:%p,get metermeta failed, retry in %" PRId64 "ms", pStream->pSql, pStream, retryDelayTime); tscError("%p stream:%p,get metermeta failed, retry in %" PRId64 "ms", pStream->pSql, pStream, retryDelayTime);
tscSetRetryTimer(pStream, pSql, retryDelayTime); tscSetRetryTimer(pStream, pSql, retryDelayTime);
return;
} else {
tscTansformSQLFuncForSTableQuery(pQueryInfo);
tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pTableMetaInfo->name);
tscDoQuery(pStream->pSql);
tscIncStreamExecutionCount(pStream);
} }
tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pTableMetaInfo->name);
tscProcessSql(pStream->pSql);
tscIncStreamExecutionCount(pStream);
} }
static void tscProcessStreamTimer(void *handle, void *tmrId) { static void tscProcessStreamTimer(void *handle, void *tmrId) {
@ -147,7 +141,8 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
retryDelay); retryDelay);
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
tscClearTableMetaInfo(pTableMetaInfo, true); taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), true);
tfree(pTableMetaInfo->vgroupList);
tscSetRetryTimer(pStream, pStream->pSql, retryDelay); tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
return; return;
@ -259,7 +254,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
pStream->numOfRes); pStream->numOfRes);
// release the metric/meter meta information reference, so data in cache can be updated // release the metric/meter meta information reference, so data in cache can be updated
tscClearTableMetaInfo(pTableMetaInfo, false);
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false);
tfree(pTableMetaInfo->vgroupList);
tscSetNextLaunchTimer(pStream, pSql); tscSetNextLaunchTimer(pStream, pSql);
} }
} }
@ -480,57 +477,40 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL);
return NULL; return NULL;
} }
pSql->signature = pSql; pSql->signature = pSql;
pSql->param = pSql;
pSql->pTscObj = pObj; pSql->pTscObj = pObj;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
int ret = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE);
if (TSDB_CODE_SUCCESS != ret) {
setErrorInfo(pSql, ret, NULL);
free(pSql);
return NULL;
}
pSql->sqlstr = strdup(sqlstr);
if (pSql->sqlstr == NULL) {
setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL);
tfree(pSql);
return NULL;
}
tsem_init(&pSql->rspSem, 0, 0);
SSqlInfo SQLInfo = {0};
tSQLParse(&SQLInfo, pSql->sqlstr);
tscResetSqlCmdObj(&pSql->cmd);
ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
if (TSDB_CODE_SUCCESS != ret) {
setErrorInfo(pSql, ret, NULL);
tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_CLI_OUT_OF_MEMORY);
tscFreeSqlObj(pSql);
return NULL;
}
pRes->code = tscToSQLCmd(pSql, &SQLInfo);
SQLInfoDestroy(&SQLInfo);
if (pRes->code != TSDB_CODE_SUCCESS) {
setErrorInfo(pSql, pRes->code, pCmd->payload);
SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream));
if (pStream == NULL) {
tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code); tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code);
tscFreeSqlObj(pSql); tscFreeSqlObj(pSql);
return NULL; return NULL;
} }
pSql->pStream = pStream;
SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream)); pSql->sqlstr = calloc(1, strlen(sqlstr) + 1);
if (pStream == NULL) { if (pSql->sqlstr == NULL) {
setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); tscError("%p failed to malloc sql string buffer", pSql);
tscFreeSqlObj(pSql);
return NULL;;
}
strtolower(pSql->sqlstr, sqlstr);
tsem_init(&pSql->rspSem, 0, 0);
int32_t code = doAsyncParseSql(pSql);
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
sem_wait(&pSql->rspSem);
}
if (pRes->code != TSDB_CODE_SUCCESS) {
setErrorInfo(pSql, pRes->code, pCmd->payload);
tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code); tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code);
tscFreeSqlObj(pSql); tscFreeSqlObj(pSql);
@ -550,13 +530,13 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
pStream->ctime = taosGetTimestamp(pStream->precision); pStream->ctime = taosGetTimestamp(pStream->precision);
pStream->etime = pQueryInfo->window.ekey; pStream->etime = pQueryInfo->window.ekey;
pSql->pStream = pStream;
tscAddIntoStreamList(pStream); tscAddIntoStreamList(pStream);
tscSetSlidingWindowInfo(pSql, pStream); tscSetSlidingWindowInfo(pSql, pStream);
pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, stime); pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, stime);
int64_t starttime = tscGetLaunchTimestamp(pStream); int64_t starttime = tscGetLaunchTimestamp(pStream);
pCmd->command = TSDB_SQL_SELECT;
taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer); taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer);
tscTrace("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql, tscTrace("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,

View File

@ -124,7 +124,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char*
strtolower(pSql->sqlstr, pSql->sqlstr); strtolower(pSql->sqlstr, pSql->sqlstr);
code = tsParseSql(pSql, false); code = tsParseSql(pSql, false);
if (code == TSDB_CODE_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
// wait for the callback function to post the semaphore // wait for the callback function to post the semaphore
sem_wait(&pSql->rspSem); sem_wait(&pSql->rspSem);
code = pSql->res.code; code = pSql->res.code;
@ -148,7 +148,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char*
pSub->topic[sizeof(pSub->topic) - 1] = 0; pSub->topic[sizeof(pSub->topic) - 1] = 0;
pSub->progress = taosArrayInit(32, sizeof(SSubscriptionProgress)); pSub->progress = taosArrayInit(32, sizeof(SSubscriptionProgress));
if (pSub->progress == NULL) { if (pSub->progress == NULL) {
THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); THROW(TSDB_CODE_TSC_OUT_OF_MEMORY);
} }
CLEANUP_EXECUTE(); CLEANUP_EXECUTE();
@ -301,7 +301,9 @@ void tscSaveSubscriptionProgress(void* sub) {
char path[256]; char path[256];
sprintf(path, "%s/subscribe", tsDataDir); sprintf(path, "%s/subscribe", tsDataDir);
if (access(path, 0) != 0) { if (access(path, 0) != 0) {
mkdir(path, 0777); if (mkdir(path, 0777) != 0 && errno != EEXIST) {
tscError("failed to create subscribe dir: %s", path);
}
} }
sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic); sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic);
@ -324,7 +326,7 @@ void tscSaveSubscriptionProgress(void* sub) {
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) {
STscObj* pObj = (STscObj*)taos; STscObj* pObj = (STscObj*)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
tscError("connection disconnected"); tscError("connection disconnected");
return NULL; return NULL;
} }

View File

@ -348,7 +348,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
//prepare the subqueries object failed, abort //prepare the subqueries object failed, abort
if (!success) { if (!success) {
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql, tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql,
pSql->numOfSubs, pSql->res.code); pSql->numOfSubs, pSql->res.code);
freeJoinSubqueryObj(pSql); freeJoinSubqueryObj(pSql);
@ -698,7 +698,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
if (pBuf == NULL) { if (pBuf == NULL) {
tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows); tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows);
pSupporter->pState->code = TSDB_CODE_APP_ERROR; // todo set the informative code pSupporter->pState->code = TSDB_CODE_TSC_APP_ERROR; // todo set the informative code
quitAllSubquery(pParentSql, pSupporter); quitAllSubquery(pParentSql, pSupporter);
return; return;
} }
@ -1019,13 +1019,13 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
if (pSql->pSubs == NULL) { if (pSql->pSubs == NULL) {
pSql->pSubs = calloc(pSupporter->pState->numOfTotal, POINTER_BYTES); pSql->pSubs = calloc(pSupporter->pState->numOfTotal, POINTER_BYTES);
if (pSql->pSubs == NULL) { if (pSql->pSubs == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
} }
SSqlObj *pNew = createSubqueryObj(pSql, tableIndex, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL); SSqlObj *pNew = createSubqueryObj(pSql, tableIndex, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL);
if (pNew == NULL) { if (pNew == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pSql->pSubs[pSql->numOfSubs++] = pNew; pSql->pSubs[pSql->numOfSubs++] = pNew;
@ -1163,7 +1163,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
if (pSupporter == NULL) { // failed to create support struct, abort current query if (pSupporter == NULL) { // failed to create support struct, abort current query
tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i);
pState->numOfCompleted = pQueryInfo->numOfTables - i - 1; pState->numOfCompleted = pQueryInfo->numOfTables - i - 1;
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pSql->res.code; return pSql->res.code;
} }
@ -1171,7 +1171,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
int32_t code = tscLaunchJoinSubquery(pSql, i, pSupporter); int32_t code = tscLaunchJoinSubquery(pSql, i, pSupporter);
if (code != TSDB_CODE_SUCCESS) { // failed to create subquery object, quit query if (code != TSDB_CODE_SUCCESS) { // failed to create subquery object, quit query
tscDestroyJoinSupporter(pSupporter); tscDestroyJoinSupporter(pSupporter);
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
break; break;
} }
@ -1209,7 +1209,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
// pRes->code check only serves in launching metric sub-queries // pRes->code check only serves in launching metric sub-queries
if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) {
pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function. pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function.
return pRes->code; return pRes->code;
} }
@ -1230,7 +1230,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
int32_t ret = tscLocalReducerEnvCreate(pSql, &pMemoryBuf, &pDesc, &pModel, nBufferSize); int32_t ret = tscLocalReducerEnvCreate(pSql, &pMemoryBuf, &pDesc, &pModel, nBufferSize);
if (ret != 0) { if (ret != 0) {
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscQueueAsyncRes(pSql); tscQueueAsyncRes(pSql);
return ret; return ret;
} }
@ -1291,14 +1291,14 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
if (i < pSql->numOfSubs) { if (i < pSql->numOfSubs) {
tscError("%p failed to prepare subquery structure and launch subqueries", pSql); tscError("%p failed to prepare subquery structure and launch subqueries", pSql);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs); tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs);
doCleanupSubqueries(pSql, i, pState); doCleanupSubqueries(pSql, i, pState);
return pRes->code; // free all allocated resource return pRes->code; // free all allocated resource
} }
if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) {
tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs); tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs);
doCleanupSubqueries(pSql, i, pState); doCleanupSubqueries(pSql, i, pState);
return pRes->code; return pRes->code;
@ -1369,7 +1369,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
/* /*
* kill current sub-query connection, which may retrieve data from vnodes; * kill current sub-query connection, which may retrieve data from vnodes;
* Here we get: pPObj->res.code == TSDB_CODE_QUERY_CANCELLED * Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED
*/ */
pSql->res.numOfRows = 0; pSql->res.numOfRows = 0;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts
@ -1401,7 +1401,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
tscError("%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry", tscError("%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry",
trsupport->pParentSqlObj, pSql); trsupport->pParentSqlObj, pSql);
pState->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
return; return;
} }
@ -1475,7 +1475,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) { if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) {
tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql, tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql,
tsAvailTmpDirGB, tsMinimalTmpDirGB); tsAvailTmpDirGB, tsMinimalTmpDirGB);
tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_CLI_NO_DISKSPACE); tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE);
return; return;
} }
@ -1484,7 +1484,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer,
pQueryInfo->groupbyExpr.orderType); pQueryInfo->groupbyExpr.orderType);
if (ret != 0) { // set no disk space error info, and abort retry if (ret != 0) { // set no disk space error info, and abort retry
return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_CLI_NO_DISKSPACE); return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE);
} }
// keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion // keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion
@ -1563,7 +1563,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) {
tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64, tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64,
pPObj, pSql, tsMaxNumOfOrderedResults, num); pPObj, pSql, tsMaxNumOfOrderedResults, num);
tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_SORTED_RES_TOO_MANY); tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_SORTED_RES_TOO_MANY);
return; return;
} }
@ -1578,14 +1578,14 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) { if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) {
tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql, tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql,
tsAvailTmpDirGB, tsMinimalTmpDirGB); tsAvailTmpDirGB, tsMinimalTmpDirGB);
tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE);
return; return;
} }
int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data, int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data,
pRes->numOfRows, pQueryInfo->groupbyExpr.orderType); pRes->numOfRows, pQueryInfo->groupbyExpr.orderType);
if (ret < 0) { // set no disk space error info, and abort retry if (ret < 0) { // set no disk space error info, and abort retry
tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE);
} else if (pRes->completed) { } else if (pRes->completed) {
tscAllDataRetrievedFromDnode(trsupport, pSql); tscAllDataRetrievedFromDnode(trsupport, pSql);
@ -1672,7 +1672,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
tscError("%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d", tscError("%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d",
trsupport->pParentSqlObj, pSql, pVgroup->vgId, trsupport->subqueryIndex); trsupport->pParentSqlObj, pSql, pVgroup->vgId, trsupport->subqueryIndex);
pState->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
} else { } else {
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
@ -1783,7 +1783,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
if (i < pSql->numOfSubs) { if (i < pSql->numOfSubs) {
tscError("%p failed to prepare subObj structure and launch sub-insertion", pSql); tscError("%p failed to prepare subObj structure and launch sub-insertion", pSql);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pRes->code; // free all allocated resource return pRes->code; // free all allocated resource
} }

View File

@ -80,9 +80,8 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn) {
} }
void taos_init_imp() { void taos_init_imp() {
char temp[128]; char temp[128];
struct stat dirstat;
errno = TSDB_CODE_SUCCESS; errno = TSDB_CODE_SUCCESS;
srand(taosGetTimestampSec()); srand(taosGetTimestampSec());
deltaToUtcInitOnce(); deltaToUtcInitOnce();
@ -94,7 +93,9 @@ void taos_init_imp() {
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
// For log directory // For log directory
if (stat(tsLogDir, &dirstat) < 0) mkdir(tsLogDir, 0755); if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) {
printf("failed to create log dir:%s\n", tsLogDir);
}
sprintf(temp, "%s/taoslog", tsLogDir); sprintf(temp, "%s/taoslog", tsLogDir);
if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) { if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) {
@ -200,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;

View File

@ -79,8 +79,14 @@ bool tscQueryOnSTable(SSqlCmd* pCmd) {
bool tscQueryTags(SQueryInfo* pQueryInfo) { bool tscQueryTags(SQueryInfo* pQueryInfo) {
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId; SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
int32_t functId = pExpr->functionId;
// "select count(tbname)" query
if (functId == TSDB_FUNC_COUNT && pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
continue;
}
if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG) { if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG) {
return false; return false;
} }
@ -183,7 +189,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
/* /*
* In following cases, return false for non ordered project query on super table * In following cases, return false for non ordered project query on super table
* 1. failed to get metermeta from server; 2. not a super table; 3. limitation is 0; * 1. failed to get tableMeta from server; 2. not a super table; 3. limitation is 0;
* 4. show queries, instead of a select query * 4. show queries, instead of a select query
*/ */
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
@ -192,11 +198,6 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
return false; return false;
} }
// only query on tag, a project query
if (tscQueryTags(pQueryInfo)) {
return true;
}
for (int32_t i = 0; i < numOfExprs; ++i) { for (int32_t i = 0; i < numOfExprs; ++i) {
int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId; int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG &&
@ -208,6 +209,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
return true; return true;
} }
// not order by timestamp projection query on super table
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
if (!tscIsProjectionQueryOnSTable(pQueryInfo, tableIndex)) { if (!tscIsProjectionQueryOnSTable(pQueryInfo, tableIndex)) {
return false; return false;
@ -299,7 +301,7 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
tfree(pRes->buffer); tfree(pRes->buffer);
tfree(pRes->length); tfree(pRes->length);
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pRes->code; return pRes->code;
} }
} }
@ -574,7 +576,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks)); STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks));
if (dataBuf == NULL) { if (dataBuf == NULL) {
tscError("failed to allocated memory, reason:%s", strerror(errno)); tscError("failed to allocated memory, reason:%s", strerror(errno));
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
dataBuf->nAllocSize = (uint32_t)initialSize; dataBuf->nAllocSize = (uint32_t)initialSize;
@ -709,7 +711,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
tscDestroyBlockArrayList(pVnodeDataBlockList); tscDestroyBlockArrayList(pVnodeDataBlockList);
tfree(dataBuf->pData); tfree(dataBuf->pData);
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
} }
@ -780,12 +782,12 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) {
assert(pCmd->allocSize == 0); assert(pCmd->allocSize == 0);
pCmd->payload = (char*)calloc(1, size); pCmd->payload = (char*)calloc(1, size);
if (pCmd->payload == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; if (pCmd->payload == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY;
pCmd->allocSize = size; pCmd->allocSize = size;
} else { } else {
if (pCmd->allocSize < size) { if (pCmd->allocSize < size) {
char* b = realloc(pCmd->payload, size); char* b = realloc(pCmd->payload, size);
if (b == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; if (b == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY;
pCmd->payload = b; pCmd->payload = b;
pCmd->allocSize = size; pCmd->allocSize = size;
} }
@ -984,7 +986,6 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol
pExpr->uid = pTableMetaInfo->pTableMeta->uid; pExpr->uid = pTableMetaInfo->pTableMeta->uid;
} }
return pExpr; return pExpr;
} }
@ -1152,7 +1153,7 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO
for (int32_t j = 0; j < numOfFilters; ++j) { for (int32_t j = 0; j < numOfFilters; ++j) {
if (pFilter[j].filterstr) { if (pFilter[j].filterstr) {
size_t len = (size_t) pFilter[j].len + 1; size_t len = (size_t) pFilter[j].len + 1 * TSDB_NCHAR_SIZE;
pFilter[j].pz = (int64_t) calloc(1, len); pFilter[j].pz = (int64_t) calloc(1, len);
memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t)len); memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t)len);
@ -1245,14 +1246,14 @@ static int32_t validateQuoteToken(SSQLToken* pToken) {
} }
if (k != pToken->n || pToken->type != TK_ID) { if (k != pToken->n || pToken->type != TK_ID) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tscValidateName(SSQLToken* pToken) { int32_t tscValidateName(SSQLToken* pToken) {
if (pToken->type != TK_STRING && pToken->type != TK_ID) { if (pToken->type != TK_STRING && pToken->type != TK_ID) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
@ -1269,14 +1270,14 @@ int32_t tscValidateName(SSQLToken* pToken) {
} else { } else {
sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
if (sep == NULL) { if (sep == NULL) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
return tscValidateName(pToken); return tscValidateName(pToken);
} }
} else { } else {
if (isNumber(pToken)) { if (isNumber(pToken)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
} }
} else { // two part } else { // two part
@ -1289,15 +1290,15 @@ int32_t tscValidateName(SSQLToken* pToken) {
pToken->n = tSQLGetToken(pToken->z, &pToken->type); pToken->n = tSQLGetToken(pToken->z, &pToken->type);
if (pToken->z[pToken->n] != TS_PATH_DELIMITER[0]) { if (pToken->z[pToken->n] != TS_PATH_DELIMITER[0]) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pToken->type != TK_STRING && pToken->type != TK_ID) { if (pToken->type != TK_STRING && pToken->type != TK_ID) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
int32_t firstPartLen = pToken->n; int32_t firstPartLen = pToken->n;
@ -1306,11 +1307,11 @@ int32_t tscValidateName(SSQLToken* pToken) {
pToken->n = oldLen - (sep - pStr) - 1; pToken->n = oldLen - (sep - pStr) - 1;
int32_t len = tSQLGetToken(pToken->z, &pToken->type); int32_t len = tSQLGetToken(pToken->z, &pToken->type);
if (len != pToken->n || (pToken->type != TK_STRING && pToken->type != TK_ID)) { if (len != pToken->n || (pToken->type != TK_STRING && pToken->type != TK_ID)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
// re-build the whole name string // re-build the whole name string
@ -1579,7 +1580,7 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
size_t s = pCmd->numOfClause + 1; size_t s = pCmd->numOfClause + 1;
char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES); char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES);
if (tmp == NULL) { if (tmp == NULL) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pCmd->pQueryInfo = (SQueryInfo**)tmp; pCmd->pQueryInfo = (SQueryInfo**)tmp;
@ -1947,8 +1948,8 @@ int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) {
bool tscIsUpdateQuery(SSqlObj* pSql) { bool tscIsUpdateQuery(SSqlObj* pSql) {
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
terrno = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_TSC_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_TSC_DISCONNECTED;
} }
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
@ -1965,7 +1966,7 @@ int32_t tscInvalidSQLErrMsg(char* msg, const char* additionalInfo, const char* s
if (sql == NULL) { if (sql == NULL) {
assert(additionalInfo != NULL); assert(additionalInfo != NULL);
sprintf(msg, msgFormat1, additionalInfo); sprintf(msg, msgFormat1, additionalInfo);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
char buf[64] = {0}; // only extract part of sql string char buf[64] = {0}; // only extract part of sql string
@ -1977,7 +1978,7 @@ int32_t tscInvalidSQLErrMsg(char* msg, const char* additionalInfo, const char* s
sprintf(msg, msgFormat3, buf); // no additional information for invalid sql error sprintf(msg, msgFormat3, buf); // no additional information for invalid sql error
} }
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) { bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) {
@ -2146,7 +2147,7 @@ void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t column
void* malloc_throw(size_t size) { void* malloc_throw(size_t size) {
void* p = malloc(size); void* p = malloc(size);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); THROW(TSDB_CODE_TSC_OUT_OF_MEMORY);
} }
return p; return p;
} }
@ -2154,7 +2155,7 @@ void* malloc_throw(size_t size) {
void* calloc_throw(size_t nmemb, size_t size) { void* calloc_throw(size_t nmemb, size_t size) {
void* p = calloc(nmemb, size); void* p = calloc(nmemb, size);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); THROW(TSDB_CODE_TSC_OUT_OF_MEMORY);
} }
return p; return p;
} }
@ -2162,7 +2163,7 @@ void* calloc_throw(size_t nmemb, size_t size) {
char* strdup_throw(const char* str) { char* strdup_throw(const char* str) {
char* p = strdup(str); char* p = strdup(str);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); THROW(TSDB_CODE_TSC_OUT_OF_MEMORY);
} }
return p; return p;
} }
@ -2173,7 +2174,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) {
if (first && first[0] != 0) { if (first && first[0] != 0) {
if (strlen(first) >= TSDB_EP_LEN) { if (strlen(first) >= TSDB_EP_LEN) {
terrno = TSDB_CODE_INVALID_FQDN; terrno = TSDB_CODE_TSC_INVALID_FQDN;
return -1; return -1;
} }
taosGetFqdnPortFromEp(first, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]); taosGetFqdnPortFromEp(first, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]);
@ -2182,7 +2183,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) {
if (second && second[0] != 0) { if (second && second[0] != 0) {
if (strlen(second) >= TSDB_EP_LEN) { if (strlen(second) >= TSDB_EP_LEN) {
terrno = TSDB_CODE_INVALID_FQDN; terrno = TSDB_CODE_TSC_INVALID_FQDN;
return -1; return -1;
} }
taosGetFqdnPortFromEp(second, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]); taosGetFqdnPortFromEp(second, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]);
@ -2190,7 +2191,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) {
} }
if ( tscMgmtIpSet.numOfIps == 0) { if ( tscMgmtIpSet.numOfIps == 0) {
terrno = TSDB_CODE_INVALID_FQDN; terrno = TSDB_CODE_TSC_INVALID_FQDN;
return -1; return -1;
} }

View File

@ -145,6 +145,7 @@ void tdFreeDataRow(SDataRow row);
void tdInitDataRow(SDataRow row, STSchema *pSchema); void tdInitDataRow(SDataRow row, STSchema *pSchema);
SDataRow tdDataRowDup(SDataRow row); SDataRow tdDataRowDup(SDataRow row);
// offset here not include dataRow header length
static FORCE_INLINE int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_t offset) { static FORCE_INLINE int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_t offset) {
ASSERT(value != NULL); ASSERT(value != NULL);
int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE; int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE;

View File

@ -234,7 +234,7 @@ bool taosCfgDynamicOptions(char *msg) {
int32_t vint = 0; int32_t vint = 0;
paGetToken(msg, &option, &olen); paGetToken(msg, &option, &olen);
if (olen == 0) return TSDB_CODE_INVALID_MSG_CONTENT; if (olen == 0) return TSDB_CODE_COM_INVALID_CFG_MSG;
paGetToken(option + olen + 1, &value, &vlen); paGetToken(option + olen + 1, &value, &vlen);
if (vlen == 0) if (vlen == 0)

View File

@ -3724,9 +3724,9 @@
} }
}, },
"websocket-extensions": { "websocket-extensions": {
"version": "0.1.3", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz", "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.4.tgz",
"integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==", "integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==",
"dev": true "dev": true
}, },
"whatwg-encoding": { "whatwg-encoding": {

View File

@ -2839,8 +2839,9 @@ websocket-driver@>=0.5.1:
websocket-extensions ">=0.1.1" websocket-extensions ">=0.1.1"
websocket-extensions@>=0.1.1: websocket-extensions@>=0.1.1:
version "0.1.3" version "0.1.4"
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29" resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==
whatwg-encoding@^1.0.1: whatwg-encoding@^1.0.1:
version "1.0.3" version "1.0.3"

View File

@ -413,5 +413,5 @@ if __name__ == '__main__':
print(data) print(data)
cinter.freeresult(result) cinter.freeResult(result)
cinter.close(conn) cinter.close(conn)

View File

@ -93,7 +93,6 @@ class TDengineCursor(object):
if self._connection is None: if self._connection is None:
return False return False
self._connection.clear_result_set()
self._reset_result() self._reset_result()
self._connection = None self._connection = None
@ -109,7 +108,6 @@ class TDengineCursor(object):
# TODO : change the exception raised here # TODO : change the exception raised here
raise ProgrammingError("Cursor is not connected") raise ProgrammingError("Cursor is not connected")
self._connection.clear_result_set()
self._reset_result() self._reset_result()
stmt = operation stmt = operation
@ -139,7 +137,7 @@ class TDengineCursor(object):
else: else:
raise ProgrammingError( raise ProgrammingError(
CTaosInterface.errStr( CTaosInterface.errStr(
self._result )) self._result ), errno)
def executemany(self, operation, seq_of_parameters): def executemany(self, operation, seq_of_parameters):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
@ -202,7 +200,6 @@ class TDengineCursor(object):
for i in range(len(self._fields)): for i in range(len(self._fields)):
buffer[i].extend(block[i]) buffer[i].extend(block[i])
self._connection.clear_result_set()
return list(map(tuple, zip(*buffer))) return list(map(tuple, zip(*buffer)))
@ -222,6 +219,8 @@ class TDengineCursor(object):
""" """
self._description = None self._description = None
self._rowcount = -1 self._rowcount = -1
if self._result is not None:
CTaosInterface.freeResult(self._result)
self._result = None self._result = None
self._fields = None self._fields = None
self._block = None self._block = None

View File

@ -413,5 +413,5 @@ if __name__ == '__main__':
print(data) print(data)
cinter.freeresult(result) cinter.freeResult(result)
cinter.close(conn) cinter.close(conn)

View File

@ -95,7 +95,6 @@ class TDengineCursor(object):
if self._connection is None: if self._connection is None:
return False return False
self._connection.clear_result_set()
self._reset_result() self._reset_result()
self._connection = None self._connection = None
@ -111,7 +110,6 @@ class TDengineCursor(object):
# TODO : change the exception raised here # TODO : change the exception raised here
raise ProgrammingError("Cursor is not connected") raise ProgrammingError("Cursor is not connected")
self._connection.clear_result_set()
self._reset_result() self._reset_result()
stmt = operation stmt = operation
@ -141,7 +139,7 @@ class TDengineCursor(object):
else: else:
raise ProgrammingError( raise ProgrammingError(
CTaosInterface.errStr( CTaosInterface.errStr(
self._result )) self._result), errno)
def executemany(self, operation, seq_of_parameters): def executemany(self, operation, seq_of_parameters):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
@ -204,8 +202,6 @@ class TDengineCursor(object):
for i in range(len(self._fields)): for i in range(len(self._fields)):
buffer[i].extend(block[i]) buffer[i].extend(block[i])
self._connection.clear_result_set()
return list(map(tuple, zip(*buffer))) return list(map(tuple, zip(*buffer)))
def nextset(self): def nextset(self):
@ -224,6 +220,8 @@ class TDengineCursor(object):
""" """
self._description = None self._description = None
self._rowcount = -1 self._rowcount = -1
if self._result is not None:
CTaosInterface.freeResult(self._result)
self._result = None self._result = None
self._fields = None self._fields = None
self._block = None self._block = None
@ -240,3 +238,4 @@ class TDengineCursor(object):
(ele['name'], ele['type'], None, None, None, None, False)) (ele['name'], ele['type'], None, None, None, None, False))
return self._result return self._result

View File

@ -413,5 +413,5 @@ if __name__ == '__main__':
print(data) print(data)
cinter.freeresult(result) cinter.freeResult(result)
cinter.close(conn) cinter.close(conn)

View File

@ -86,7 +86,6 @@ class TDengineCursor(object):
if self._connection is None: if self._connection is None:
return False return False
self._connection.clear_result_set()
self._reset_result() self._reset_result()
self._connection = None self._connection = None
@ -102,7 +101,6 @@ class TDengineCursor(object):
# TODO : change the exception raised here # TODO : change the exception raised here
raise ProgrammingError("Cursor is not connected") raise ProgrammingError("Cursor is not connected")
self._connection.clear_result_set()
self._reset_result() self._reset_result()
stmt = operation stmt = operation
@ -119,7 +117,7 @@ class TDengineCursor(object):
self._fields = CTaosInterface.useResult(self._result) self._fields = CTaosInterface.useResult(self._result)
return self._handle_result() return self._handle_result()
else: else:
raise ProgrammingError(CTaosInterface.errStr(self._result)) raise ProgrammingError(CTaosInterface.errStr(self._result), errno)
def executemany(self, operation, seq_of_parameters): def executemany(self, operation, seq_of_parameters):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
@ -149,7 +147,6 @@ class TDengineCursor(object):
for i in range(len(self._fields)): for i in range(len(self._fields)):
buffer[i].extend(block[i]) buffer[i].extend(block[i])
self._connection.clear_result_set()
return list(map(tuple, zip(*buffer))) return list(map(tuple, zip(*buffer)))
@ -171,6 +168,8 @@ class TDengineCursor(object):
""" """
self._description = None self._description = None
self._rowcount = -1 self._rowcount = -1
if self._result is not None:
CTaosInterface.freeResult(self._result)
self._result = None self._result = None
self._fields = None self._fields = None
self._block = None self._block = None

View File

@ -413,5 +413,5 @@ if __name__ == '__main__':
print(data) print(data)
cinter.freeresult(result) cinter.freeResult(result)
cinter.close(conn) cinter.close(conn)

View File

@ -86,7 +86,6 @@ class TDengineCursor(object):
if self._connection is None: if self._connection is None:
return False return False
self._connection.clear_result_set()
self._reset_result() self._reset_result()
self._connection = None self._connection = None
@ -102,7 +101,6 @@ class TDengineCursor(object):
# TODO : change the exception raised here # TODO : change the exception raised here
raise ProgrammingError("Cursor is not connected") raise ProgrammingError("Cursor is not connected")
self._connection.clear_result_set()
self._reset_result() self._reset_result()
stmt = operation stmt = operation
@ -119,7 +117,7 @@ class TDengineCursor(object):
self._fields = CTaosInterface.useResult(self._result ) self._fields = CTaosInterface.useResult(self._result )
return self._handle_result() return self._handle_result()
else: else:
raise ProgrammingError(CTaosInterface.errStr(self._result )) raise ProgrammingError(CTaosInterface.errStr(self._result ), errno)
def executemany(self, operation, seq_of_parameters): def executemany(self, operation, seq_of_parameters):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters. """Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
@ -149,7 +147,6 @@ class TDengineCursor(object):
for i in range(len(self._fields)): for i in range(len(self._fields)):
buffer[i].extend(block[i]) buffer[i].extend(block[i])
self._connection.clear_result_set()
return list(map(tuple, zip(*buffer))) return list(map(tuple, zip(*buffer)))
@ -171,6 +168,8 @@ class TDengineCursor(object):
""" """
self._description = None self._description = None
self._rowcount = -1 self._rowcount = -1
if self._result is not None:
CTaosInterface.freeResult(self._result)
self._result = None self._result = None
self._fields = None self._fields = None
self._block = None self._block = None

View File

@ -38,6 +38,7 @@ typedef struct {
int vgId; int vgId;
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN]; char pass[TSDB_PASSWORD_LEN];
char db[TSDB_DB_NAME_LEN];
FCqWrite cqWrite; FCqWrite cqWrite;
void *ahandle; void *ahandle;
int num; // number of continuous streams int num; // number of continuous streams
@ -48,7 +49,8 @@ typedef struct {
} SCqContext; } SCqContext;
typedef struct SCqObj { typedef struct SCqObj {
int tid; // table ID uint64_t uid;
int32_t tid; // table ID
int rowSize; // bytes of a row int rowSize; // bytes of a row
char * sqlStr; // SQL string char * sqlStr; // SQL string
STSchema * pSchema; // pointer to schema array STSchema * pSchema; // pointer to schema array
@ -73,6 +75,14 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) {
strcpy(pContext->user, pCfg->user); strcpy(pContext->user, pCfg->user);
strcpy(pContext->pass, pCfg->pass); strcpy(pContext->pass, pCfg->pass);
const char* db = pCfg->db;
for (const char* p = db; *p != 0; p++) {
if (*p == '.') {
db = p + 1;
break;
}
}
strcpy(pContext->db, db);
pContext->vgId = pCfg->vgId; pContext->vgId = pCfg->vgId;
pContext->cqWrite = pCfg->cqWrite; pContext->cqWrite = pCfg->cqWrite;
pContext->ahandle = ahandle; pContext->ahandle = ahandle;
@ -153,17 +163,19 @@ void cqStop(void *handle) {
pthread_mutex_unlock(&pContext->mutex); pthread_mutex_unlock(&pContext->mutex);
} }
void *cqCreate(void *handle, int tid, char *sqlStr, STSchema *pSchema) { void *cqCreate(void *handle, uint64_t uid, int tid, char *sqlStr, STSchema *pSchema) {
SCqContext *pContext = handle; SCqContext *pContext = handle;
SCqObj *pObj = calloc(sizeof(SCqObj), 1); SCqObj *pObj = calloc(sizeof(SCqObj), 1);
if (pObj == NULL) return NULL; if (pObj == NULL) return NULL;
pObj->uid = uid;
pObj->tid = tid; pObj->tid = tid;
pObj->sqlStr = malloc(strlen(sqlStr)+1); pObj->sqlStr = malloc(strlen(sqlStr)+1);
strcpy(pObj->sqlStr, sqlStr); strcpy(pObj->sqlStr, sqlStr);
pObj->pSchema = tdDupSchema(pSchema); pObj->pSchema = tdDupSchema(pSchema);
pObj->rowSize = schemaTLen(pSchema);
cTrace("vgId:%d, id:%d CQ:%s is created", pContext->vgId, pObj->tid, pObj->sqlStr); cTrace("vgId:%d, id:%d CQ:%s is created", pContext->vgId, pObj->tid, pObj->sqlStr);
@ -207,16 +219,16 @@ void cqDrop(void *handle) {
} }
static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
if (pContext->dbConn == NULL) { if (pContext->dbConn == NULL) {
pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, NULL, 0); pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, pContext->db, 0);
if (pContext->dbConn == NULL) { if (pContext->dbConn == NULL) {
cError("vgId:%d, failed to connect to TDengine(%s)", pContext->vgId, tstrerror(terrno)); cError("vgId:%d, failed to connect to TDengine(%s)", pContext->vgId, tstrerror(terrno));
return;
} }
return;
} }
int64_t lastKey = 0; int64_t lastKey = 0;
pObj->pContext = pContext;
pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, lastKey, pObj, NULL); pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, lastKey, pObj, NULL);
if (pObj->pStream) { if (pObj->pStream) {
pContext->num++; pContext->num++;
@ -229,29 +241,49 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
SCqObj *pObj = (SCqObj *)param; SCqObj *pObj = (SCqObj *)param;
SCqContext *pContext = pObj->pContext; SCqContext *pContext = pObj->pContext;
STSchema *pSchema = pObj->pSchema;
if (pObj->pStream == NULL) return; if (pObj->pStream == NULL) return;
cTrace("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr); cTrace("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr);
// construct data int size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + pObj->rowSize;
int size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + pObj->rowSize;
char *buffer = calloc(size, 1); char *buffer = calloc(size, 1);
SWalHead *pHead = (SWalHead *)buffer; SWalHead *pHead = (SWalHead *)buffer;
pHead->msgType = TSDB_MSG_TYPE_SUBMIT; SSubmitMsg *pMsg = (SSubmitMsg *) (buffer + sizeof(SWalHead));
pHead->len = size - sizeof(SWalHead);
SSubmitMsg *pSubmit = (SSubmitMsg *) (buffer + sizeof(SWalHead));
// to do: fill in the SSubmitMsg structure
pSubmit->numOfBlocks = 1;
SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg)); SSubmitBlk *pBlk = (SSubmitBlk *) (buffer + sizeof(SWalHead) + sizeof(SSubmitMsg));
// to do: fill in the SSubmitBlk strucuture
pBlk->tid = pObj->tid;
SDataRow trow = (SDataRow)pBlk->data;
tdInitDataRow(trow, pSchema);
for (int32_t i = 0; i < pSchema->numOfCols; i++) {
STColumn *c = pSchema->columns + i;
char* val = (char*)row[i];
if (IS_VAR_DATA_TYPE(c->type)) {
val -= sizeof(VarDataLenT);
}
tdAppendColVal(trow, val, c->type, c->bytes, c->offset);
}
pBlk->len = htonl(dataRowLen(trow));
pBlk->uid = htobe64(pObj->uid);
pBlk->tid = htonl(pObj->tid);
pBlk->numOfRows = htons(1);
pBlk->sversion = htonl(pSchema->version);
pBlk->padding = 0;
pHead->len = sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + dataRowLen(trow);
pMsg->header.vgId = htonl(pContext->vgId);
pMsg->header.contLen = htonl(pHead->len);
pMsg->length = pMsg->header.contLen;
pMsg->numOfBlocks = htonl(1);
pHead->msgType = TSDB_MSG_TYPE_SUBMIT;
pHead->version = 0;
// write into vnode write queue // write into vnode write queue
pContext->cqWrite(pContext->ahandle, pHead, TAOS_QTYPE_CQ); pContext->cqWrite(pContext->ahandle, pHead, TAOS_QTYPE_CQ);
free(buffer);
} }

View File

@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
tdDestroyTSchemaBuilder(&schemaBuilder); tdDestroyTSchemaBuilder(&schemaBuilder);
for (int sid =1; sid<10; ++sid) { for (int sid =1; sid<10; ++sid) {
cqCreate(pCq, sid, "select avg(speed) from demo.t1 sliding(1s) interval(5s)", pSchema); cqCreate(pCq, sid, sid, "select avg(speed) from demo.t1 sliding(1s) interval(5s)", pSchema);
} }
tdFreeSchema(pSchema); tdFreeSchema(pSchema);

View File

@ -22,6 +22,7 @@ extern "C" {
int32_t dnodeInitModules(); int32_t dnodeInitModules();
void dnodeStartModules(); void dnodeStartModules();
void dnodeStartStream();
void dnodeCleanupModules(); void dnodeCleanupModules();
void dnodeProcessModuleStatus(uint32_t moduleStatus); void dnodeProcessModuleStatus(uint32_t moduleStatus);

View File

@ -79,7 +79,7 @@ void dnodeCleanupMnodePeer() {
int32_t dnodeAllocateMnodePqueue() { int32_t dnodeAllocateMnodePqueue() {
tsMPeerQueue = taosOpenQueue(); tsMPeerQueue = taosOpenQueue();
if (tsMPeerQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (tsMPeerQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY;
taosAddIntoQset(tsMPeerQset, tsMPeerQueue, NULL); taosAddIntoQset(tsMPeerQset, tsMPeerQueue, NULL);
@ -125,7 +125,7 @@ static void dnodeFreeMnodePeerMsg(SMnodeMsg *pPeer) {
} }
static void dnodeSendRpcMnodePeerRsp(SMnodeMsg *pPeer, int32_t code) { static void dnodeSendRpcMnodePeerRsp(SMnodeMsg *pPeer, int32_t code) {
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pPeer->rpcMsg.handle, .handle = pPeer->rpcMsg.handle,

View File

@ -84,7 +84,7 @@ void dnodeCleanupMnodeRead() {
int32_t dnodeAllocateMnodeRqueue() { int32_t dnodeAllocateMnodeRqueue() {
tsMReadQueue = taosOpenQueue(); tsMReadQueue = taosOpenQueue();
if (tsMReadQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (tsMReadQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY;
taosAddIntoQset(tsMReadQset, tsMReadQueue, NULL); taosAddIntoQset(tsMReadQset, tsMReadQueue, NULL);
@ -130,8 +130,8 @@ static void dnodeFreeMnodeReadMsg(SMnodeMsg *pRead) {
} }
static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) { static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) {
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) {
// may be a auto create req, should put into write queue // may be a auto create req, should put into write queue
dnodeReprocessMnodeWriteMsg(pRead); dnodeReprocessMnodeWriteMsg(pRead);
return; return;

View File

@ -81,7 +81,7 @@ void dnodeCleanupMnodeWrite() {
int32_t dnodeAllocateMnodeWqueue() { int32_t dnodeAllocateMnodeWqueue() {
tsMWriteQueue = taosOpenQueue(); tsMWriteQueue = taosOpenQueue();
if (tsMWriteQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (tsMWriteQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY;
taosAddIntoQset(tsMWriteQset, tsMWriteQueue, NULL); taosAddIntoQset(tsMWriteQset, tsMWriteQueue, NULL);
@ -128,8 +128,8 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) {
void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) { void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) {
SMnodeMsg *pWrite = pRaw; SMnodeMsg *pWrite = pRaw;
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) {
dnodeReprocessMnodeWriteMsg(pWrite); dnodeReprocessMnodeWriteMsg(pWrite);
return; return;
} }

View File

@ -124,6 +124,7 @@ int32_t dnodeInitSystem() {
dnodeStartModules(); dnodeStartModules();
dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_RUNING); dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_RUNING);
dnodeStartStream();
dPrint("TDengine is initialized successfully"); dPrint("TDengine is initialized successfully");

View File

@ -180,7 +180,7 @@ void dnodeDispatchToMgmtQueue(SRpcMsg *pMsg) {
SRpcMsg rsp; SRpcMsg rsp;
rsp.handle = pMsg->handle; rsp.handle = pMsg->handle;
rsp.pCont = NULL; rsp.pCont = NULL;
rsp.code = TSDB_CODE_SERV_OUT_OF_MEMORY; rsp.code = TSDB_CODE_DND_OUT_OF_MEMORY;
rpcSendResponse(&rsp); rpcSendResponse(&rsp);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
} }
@ -202,7 +202,7 @@ static void *dnodeProcessMgmtQueue(void *param) {
if (dnodeProcessMgmtMsgFp[pMsg->msgType]) { if (dnodeProcessMgmtMsgFp[pMsg->msgType]) {
rsp.code = (*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg); rsp.code = (*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg);
} else { } else {
rsp.code = TSDB_CODE_MSG_NOT_PROCESSED; rsp.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
} }
rsp.handle = pMsg->handle; rsp.handle = pMsg->handle;
@ -219,7 +219,7 @@ static void *dnodeProcessMgmtQueue(void *param) {
static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) { static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
DIR *dir = opendir(tsVnodeDir); DIR *dir = opendir(tsVnodeDir);
if (dir == NULL) { if (dir == NULL) {
return TSDB_CODE_NO_WRITE_ACCESS; return TSDB_CODE_DND_NO_WRITE_ACCESS;
} }
*numOfVnodes = 0; *numOfVnodes = 0;
@ -260,11 +260,27 @@ static int32_t dnodeOpenVnodes() {
} }
free(vnodeList); free(vnodeList);
dPrint("there are total vnodes:%d, openned:%d failed:%d", numOfVnodes, numOfVnodes-failed, failed); dPrint("there are total vnodes:%d, openned:%d failed:%d", numOfVnodes, numOfVnodes-failed, failed);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void dnodeStartStream() {
int32_t vnodeList[TSDB_MAX_VNODES];
int32_t numOfVnodes = 0;
int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes);
if (status != TSDB_CODE_SUCCESS) {
dPrint("Get dnode list failed");
return;
}
for (int32_t i = 0; i < numOfVnodes; ++i) {
vnodeStartStream(vnodeList[i]);
}
dPrint("streams started");
}
static void dnodeCloseVnodes() { static void dnodeCloseVnodes() {
int32_t *vnodeList = (int32_t *)malloc(sizeof(int32_t) * TSDB_MAX_VNODES); int32_t *vnodeList = (int32_t *)malloc(sizeof(int32_t) * TSDB_MAX_VNODES);
int32_t numOfVnodes; int32_t numOfVnodes;

View File

@ -89,7 +89,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
rspMsg.contLen = 0; rspMsg.contLen = 0;
if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) {
rspMsg.code = TSDB_CODE_NOT_READY; rspMsg.code = TSDB_CODE_RPC_NOT_READY;
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
dTrace("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); dTrace("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]);
@ -97,7 +97,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
} }
if (pMsg->pCont == NULL) { if (pMsg->pCont == NULL) {
rspMsg.code = TSDB_CODE_INVALID_MSG_LEN; rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN;
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
return; return;
} }
@ -106,13 +106,14 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
(*dnodeProcessReqMsgFp[pMsg->msgType])(pMsg); (*dnodeProcessReqMsgFp[pMsg->msgType])(pMsg);
} else { } else {
dTrace("RPC %p, message:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); dTrace("RPC %p, message:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]);
rspMsg.code = TSDB_CODE_MSG_NOT_PROCESSED; rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
} }
} }
int32_t dnodeInitClient() { int32_t dnodeInitClient() {
char secret[TSDB_KEY_LEN] = "secret";
SRpcInit rpcInit; SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.label = "DND-C"; rpcInit.label = "DND-C";
@ -123,7 +124,7 @@ int32_t dnodeInitClient() {
rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.idleTime = tsShellActivityTimer * 1000;
rpcInit.user = "t"; rpcInit.user = "t";
rpcInit.ckey = "key"; rpcInit.ckey = "key";
rpcInit.secret = "secret"; rpcInit.secret = secret;
tsDnodeClientRpc = rpcOpen(&rpcInit); tsDnodeClientRpc = rpcOpen(&rpcInit);
if (tsDnodeClientRpc == NULL) { if (tsDnodeClientRpc == NULL) {

View File

@ -115,7 +115,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) {
dError("RPC %p, shell msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); dError("RPC %p, shell msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]);
rpcMsg.code = TSDB_CODE_NOT_READY; rpcMsg.code = TSDB_CODE_RPC_NOT_READY;
rpcSendResponse(&rpcMsg); rpcSendResponse(&rpcMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
return; return;
@ -131,7 +131,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
(*dnodeProcessShellMsgFp[pMsg->msgType])(pMsg); (*dnodeProcessShellMsgFp[pMsg->msgType])(pMsg);
} else { } else {
dError("RPC %p, shell msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]); dError("RPC %p, shell msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]);
rpcMsg.code = TSDB_CODE_MSG_NOT_PROCESSED; rpcMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
rpcSendResponse(&rpcMsg); rpcSendResponse(&rpcMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
return; return;
@ -140,7 +140,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) {
static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) { static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey); int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey);
if (code != TSDB_CODE_NOT_READY) return code; if (code != TSDB_CODE_RPC_NOT_READY) return code;
SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg)); SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg));
strcpy(pMsg->user, user); strcpy(pMsg->user, user);

View File

@ -92,6 +92,7 @@ int32_t main(int32_t argc, char *argv[]) {
// Initialize the system // Initialize the system
if (dnodeInitSystem() < 0) { if (dnodeInitSystem() < 0) {
syslog(LOG_ERR, "Error initialize TDengine system"); syslog(LOG_ERR, "Error initialize TDengine system");
dPrint("Failed to start TDengine, please check the log at:%s", tsLogDir);
closelog(); closelog();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

View File

@ -134,7 +134,7 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) {
.handle = pMsg->handle, .handle = pMsg->handle,
.pCont = NULL, .pCont = NULL,
.contLen = 0, .contLen = 0,
.code = TSDB_CODE_INVALID_VGROUP_ID, .code = TSDB_CODE_VND_INVALID_VGROUP_ID,
.msgType = 0 .msgType = 0
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
@ -189,16 +189,17 @@ static void dnodeContinueExecuteQuery(void* pVnode, void* qhandle, SReadMsg *pMs
} }
void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) { void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) {
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_VND_ACTION_IN_PROGRESS) return;
if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { if (code == TSDB_CODE_VND_ACTION_NEED_REPROCESSED) {
dnodeContinueExecuteQuery(pVnode, pRead->rspRet.qhandle, pRead); dnodeContinueExecuteQuery(pVnode, pRead->rspRet.qhandle, pRead);
code = TSDB_CODE_SUCCESS;
} }
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pRead->rpcMsg.handle, .handle = pRead->rpcMsg.handle,
.pCont = pRead->rspRet.rsp, .pCont = pRead->rspRet.rsp,
.contLen = pRead->rspRet.len, .contLen = pRead->rspRet.len,
.code = pRead->rspRet.code, .code = code,
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
@ -216,7 +217,7 @@ static void *dnodeProcessReadQueue(void *param) {
break; break;
} }
dTrace("%p, msg:%s will be processed", pReadMsg->rpcMsg.ahandle, taosMsg[pReadMsg->rpcMsg.msgType]); dTrace("%p, msg:%s will be processed in vread queue", pReadMsg->rpcMsg.ahandle, taosMsg[pReadMsg->rpcMsg.msgType]);
int32_t code = vnodeProcessRead(pVnode, pReadMsg->rpcMsg.msgType, pReadMsg->pCont, pReadMsg->contLen, &pReadMsg->rspRet); int32_t code = vnodeProcessRead(pVnode, pReadMsg->rpcMsg.msgType, pReadMsg->pCont, pReadMsg->contLen, &pReadMsg->rspRet);
dnodeSendRpcReadRsp(pVnode, pReadMsg, code); dnodeSendRpcReadRsp(pVnode, pReadMsg, code);
taosFreeQitem(pReadMsg); taosFreeQitem(pReadMsg);

View File

@ -115,7 +115,7 @@ void dnodeDispatchToVnodeWriteQueue(SRpcMsg *pMsg) {
.handle = pMsg->handle, .handle = pMsg->handle,
.pCont = NULL, .pCont = NULL,
.contLen = 0, .contLen = 0,
.code = TSDB_CODE_INVALID_VGROUP_ID, .code = TSDB_CODE_VND_INVALID_VGROUP_ID,
.msgType = 0 .msgType = 0
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
@ -216,7 +216,7 @@ static void *dnodeProcessWriteQueue(void *param) {
pHead->msgType = pWrite->rpcMsg.msgType; pHead->msgType = pWrite->rpcMsg.msgType;
pHead->version = 0; pHead->version = 0;
pHead->len = pWrite->contLen; pHead->len = pWrite->contLen;
dTrace("%p, msg:%s will be processed", pWrite->rpcMsg.ahandle, taosMsg[pWrite->rpcMsg.msgType]); dTrace("%p, msg:%s will be processed in vwrite queue", pWrite->rpcMsg.ahandle, taosMsg[pWrite->rpcMsg.msgType]);
} else { } else {
pHead = (SWalHead *)item; pHead = (SWalHead *)item;
} }

View File

@ -221,6 +221,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_COUNTRY_LEN 20 #define TSDB_COUNTRY_LEN 20
#define TSDB_LOCALE_LEN 64 #define TSDB_LOCALE_LEN 64
#define TSDB_TIMEZONE_LEN 64 #define TSDB_TIMEZONE_LEN 64
#define TSDB_LABEL_LEN 8
#define TSDB_FQDN_LEN 128 #define TSDB_FQDN_LEN 128
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6) #define TSDB_EP_LEN (TSDB_FQDN_LEN+6)

View File

@ -46,135 +46,174 @@ static STaosError errors[] = {
#endif #endif
// rpc // rpc
TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_IN_PROGRESS, 0, 0x0001, "action in progress") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ACTION_IN_PROGRESS, 0, 0x0001, "action in progress")
TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_NEED_REPROCESSED, 0, 0x0003, "action need to be reprocessed") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_REQUIRED, 0, 0x0002, "auth required")
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, 0, 0x0004, "message not processed") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_FAILURE, 0, 0x0003, "auth failure")
TAOS_DEFINE_ERROR(TSDB_CODE_ALREADY_PROCESSED, 0, 0x0005, "message already processed") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_REDIRECT, 0, 0x0004, "redirect")
TAOS_DEFINE_ERROR(TSDB_CODE_REDIRECT, 0, 0x0006, "redirect") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NOT_READY, 0, 0x0005, "not ready") // peer is not ready to process data
TAOS_DEFINE_ERROR(TSDB_CODE_LAST_SESSION_NOT_FINISHED, 0, 0x0007, "last session not finished") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ALREADY_PROCESSED, 0, 0x0006, "message already processed")
TAOS_DEFINE_ERROR(TSDB_CODE_MAX_SESSIONS, 0, 0x0008, "max sessions") // too many sessions TAOS_DEFINE_ERROR(TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED,0, 0x0007, "last session not finished")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SESSION_ID, 0, 0x0009, "invalid session id") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MISMATCHED_LINK_ID, 0, 0x0008, "mismatched meter id")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TRAN_ID, 0, 0x000A, "invalid transaction id") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TOO_SLOW, 0, 0x0009, "too slow")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_TYPE, 0, 0x000B, "invalid message type") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MAX_SESSIONS, 0, 0x000A, "max sessions") // too many sessions
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_LEN, 0, 0x000C, "invalid message length") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_UNAVAIL, 0, 0x000B, "network unavailable")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_CONTENT, 0, 0x000D, "invalid message content") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_APP_ERROR, 0, 0x000C, "rpc app error")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_VERSION, 0, 0x000E, "invalid message version") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_UNEXPECTED_RESPONSE, 0, 0x000D, "unexpected response")
TAOS_DEFINE_ERROR(TSDB_CODE_UNEXPECTED_RESPONSE, 0, 0x000F, "unexpected response") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_VALUE, 0, 0x000E, "invalid value")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_RESPONSE_TYPE, 0, 0x0010, "invalid response type") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TRAN_ID, 0, 0x000F, "invalid transaction id")
TAOS_DEFINE_ERROR(TSDB_CODE_MISMATCHED_METER_ID, 0, 0x0011, "mismatched meter id") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_SESSION_ID, 0, 0x0010, "invalid session id")
TAOS_DEFINE_ERROR(TSDB_CODE_DISCONNECTED, 0, 0x0012, "disconnected") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_MSG_TYPE, 0, 0x0011, "invalid message type")
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_READY, 0, 0x0013, "not ready") // peer is not ready to process data TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_RESPONSE_TYPE, 0, 0x0012, "invalid response type")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_SLOW, 0, 0x0014, "too slow") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TIME_STAMP, 0, 0x0013, "invalid timestamp")
TAOS_DEFINE_ERROR(TSDB_CODE_OTHERS, 0, 0x0015, "others")
TAOS_DEFINE_ERROR(TSDB_CODE_APP_ERROR, 0, 0x0016, "app error")
TAOS_DEFINE_ERROR(TSDB_CODE_ALREADY_THERE, 0, 0x0017, "already there")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_RESOURCE, 0, 0x0018, "no resource")
TAOS_DEFINE_ERROR(TSDB_CODE_OPS_NOT_SUPPORT, 0, 0x0019, "operations not support")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_OPTION, 0, 0x001A, "invalid option")
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_CONFIGURED, 0, 0x001B, "not configured")
TAOS_DEFINE_ERROR(TSDB_CODE_NETWORK_UNAVAIL, 0, 0x001C, "network unavailable")
TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_REQUIRED, 0, 0x001D, "auth required")
// db //common & util
TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 0x0100, "db not selected") TAOS_DEFINE_ERROR(TSDB_CODE_COM_OPS_NOT_SUPPORT, 0, 0x0100, "operations not support")
TAOS_DEFINE_ERROR(TSDB_CODE_DB_ALREADY_EXIST, 0, 0x0101, "database aleady exist") TAOS_DEFINE_ERROR(TSDB_CODE_COM_MEMORY_CORRUPTED, 0, 0x0101, "memory corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_DB, 0, 0x0102, "invalid database") TAOS_DEFINE_ERROR(TSDB_CODE_COM_OUT_OF_MEMORY, 0, 0x0102, "out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_MONITOR_DB_FORBIDDEN, 0, 0x0103, "monitor db forbidden") TAOS_DEFINE_ERROR(TSDB_CODE_COM_INVALID_CFG_MSG, 0, 0x0103, "invalid config message")
// user //client
TAOS_DEFINE_ERROR(TSDB_CODE_USER_ALREADY_EXIST, 0, 0x0180, "user already exist") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_SQL, 0, 0x0200, "invalid sql")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER, 0, 0x0181, "invalid user") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_QHANDLE, 0, 0x0201, "client invalid qhandle")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS, 0, 0x0182, "invalid password") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TIME_STAMP, 0, 0x0202, "client time/server time can not be mixed up")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER_FORMAT, 0, 0x0183, "invalid user format") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_VALUE, 0, 0x0203, "clientinvalid value")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS_FORMAT, 0, 0x0184, "invalid password format") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_VERSION, 0, 0x0204, "client invalid version")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_USER_FROM_CONN, 0, 0x0185, "can not get user from conn") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_IE, 0, 0x0205, "client invalid ie")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_FQDN, 0, 0x0206, "client invalid fqdn")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_USER_LENGTH, 0, 0x0207, "client invalid username length")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_PASS_LENGTH, 0, 0x0208, "client invalid password length")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_DB_LENGTH, 0, 0x0209, "client invalid database length")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH, 0, 0x020A, "client invalid table length")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_CONNECTION, 0, 0x020B, "client invalid connection")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_OUT_OF_MEMORY, 0, 0x020C, "client out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_DISKSPACE, 0, 0x020D, "client no disk space")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CACHE_ERASED, 0, 0x020E, "client query cache erased")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CANCELLED, 0, 0x020F, "client query cancelled")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SORTED_RES_TOO_MANY, 0, 0x0210, "client sorted res too many") // too many result for ordered super table projection query
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_APP_ERROR, 0, 0x0211, "client app error")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_ACTION_IN_PROGRESS, 0, 0x0212, "client action in progress")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DISCONNECTED, 0, 0x0213, "client disconnected")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_WRITE_AUTH, 0, 0x0214, "client no write auth")
// table // mnode
TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ALREADY_EXIST, 0, 0x0200, "table already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, 0, 0x0300, "mnode message not processed")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE_ID, 0, 0x0201, "invalid table id") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_IN_PROGRESS, 0, 0x0301, "mnode action in progress")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE_TYPE, 0, 0x0202, "invalid table type") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, 0, 0x0302, "mnode action need to be reprocessed")
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUPER_TABLE, 0, 0x0203, "no super table") // operation only available for super table TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, 0, 0x0303, "mnode no rights")
TAOS_DEFINE_ERROR(TSDB_CODE_TAG_ALREAY_EXIST, 0, 0x0204, "tag already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, 0, 0x0304, "mnode app error")
TAOS_DEFINE_ERROR(TSDB_CODE_TAG_NOT_EXIST, 0, 0x0205, "tag not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONNECTION, 0, 0x0305, "mnode invalid message connection")
TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_ALREAY_EXIST, 0, 0x0206, "field already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_VERSION, 0, 0x0306, "mnode invalid message version")
TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_NOT_EXIST, 0, 0x0207, "field not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_LEN, 0, 0x0307, "mnode invalid message length")
TAOS_DEFINE_ERROR(TSDB_CODE_COL_NAME_TOO_LONG, 0, 0x0208, "column name too long") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_TYPE, 0, 0x0308, "mnode invalid message type")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TAGS, 0, 0x0209, "too many tags") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_SHELL_CONNS, 0, 0x0309, "mnode too many shell conns")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_OUT_OF_MEMORY, 0, 0x030A, "mnode out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SHOWOBJ, 0, 0x030B, "mnode invalid show handle")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_QUERY_ID, 0, 0x030C, "mnode invalid query id")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STREAM_ID, 0, 0x030D, "mnode invalid stream id")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONN_ID, 0, 0x030E, "mnode invalid connection")
// dnode & mnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "mnode object already there")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 0x0280, "no enough dnodes") TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "mnode sdb error")
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 0x0281, "dnode already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 0x0282, "dnode not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 0x0283, "no master")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 0x0284, "no remove master")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 0x0285, "invalid query id")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 0x0286, "invalid stream id")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 0x0287, "invalid connection")
TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 0x0288, "sdb error")
TAOS_DEFINE_ERROR(TSDB_CODE_TIMESTAMP_OUT_OF_RANGE, 0, 0x0289, "timestamp is out of range")
// acct TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "mnode dnode already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 0x0300, "accounts already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnode not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 0x0301, "invalid account") TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, 0, 0x0332, "mnode vgroup not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 0x0302, "invalid account parameter") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_REMOVE_MASTER, 0, 0x0333, "mnode cant not remove master")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 0x0303, "too many accounts") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, 0, 0x0334, "mnode no enough dnodes")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 0x0304, "too many users")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 0x0305, "too many tables") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 0x0306, "too many databases") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 0x0307, "not enough time series") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_PARA, 0, 0x0342, "mnode invalid account parameter")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, 0, 0x0343, "mnode invalid acct option")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_ACCTS, 0, 0x0344, "mnode too many accounts")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, 0, 0x0350, "mnode user already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER, 0, 0x0351, "mnode invalid user")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER_FORMAT, 0, 0x0352, "mnode invalid user format")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_PASS_FORMAT, 0, 0x0353, "mnode invalid password format")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, 0, 0x0354, "mnode can not get user from conn")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, 0, 0x0355, "mnode too many users")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TABLE_ALREADY_EXIST, 0, 0x0360, "mnode table already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, 0, 0x0361, "mnode invalid table id")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_NAME, 0, 0x0362, "mnode invalid table name")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0363, "mnode invalid table type")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0364, "mnode too many tags")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TABLES, 0, 0x0365, "mnode too many tables")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0366, "mnode not enough time series")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0367, "mnode no super table") // operation only available for super table
TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0368, "mnode column name too long")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, 0, 0x0369, "mnode tag already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, 0, 0x036A, "mnode tag not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, 0, 0x036B, "mnode field already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, 0, 0x036C, "mnode field not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_SELECTED, 0, 0x0380, "mnode db not selected")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, 0, 0x0381, "mnode database aleady exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION, 0, 0x0382, "mnode invalid db option")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB, 0, 0x0383, "mnode invalid database")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MONITOR_DB_FORBIDDEN, 0, 0x0384, "mnode monitor db forbidden")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DATABASES, 0, 0x0385, "mnode too many databases")
// dnode
TAOS_DEFINE_ERROR(TSDB_CODE_DND_MSG_NOT_PROCESSED, 0, 0x0400, "dnode message not processed")
TAOS_DEFINE_ERROR(TSDB_CODE_DND_OUT_OF_MEMORY, 0, 0x0401, "dnode out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_DND_NO_WRITE_ACCESS, 0, 0x0402, "dnode no disk write access")
TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, 0, 0x0403, "dnode invalid message length")
TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_FILE_FORMAT, 0, 0x0404, "dnode invalid file format")
// vnode
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_IN_PROGRESS, 0, 0x0500, "vnode action in progress")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_MSG_NOT_PROCESSED, 0, 0x0501, "vnode message not processed")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_NEED_REPROCESSED, 0, 0x0502, "vnode action need to be reprocessed")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, 0, 0x0503, "vnode invalid vgroup id")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INIT_FAILED, 0, 0x0504, "vnode init failed")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISKSPACE, 0, 0x0505, "vnode no diskspace")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "vnode no disk permissions")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error")
// tsdb
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_TYPE, 0, 0x0601, "tsdb invalid table schema version")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_SCHEMA_VERSION, 0, 0x0602, "tsdb invalid table schema version")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_ALREADY_EXIST, 0, 0x0603, "tsdb table already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CONFIG, 0, 0x0604, "tsdb invalid configuration")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INIT_FAILED, 0, 0x0605, "tsdb init failed")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISKSPACE, 0, 0x0606, "tsdb no diskspace")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISK_PERMISSIONS, 0, 0x0607, "tsdb no disk permissions")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_CORRUPTED, 0, 0x0608, "tsdb file corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_OUT_OF_MEMORY, 0, 0x0609, "tsdb out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE, 0, 0x060A, "tsdb tag version is out of date")
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE, 0, 0x060B, "tsdb timestamp is out of range")
// query
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, 0, 0x0700, "query invalid handle")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_MSG, 0, 0x0701, "query invalid message") // failed to validate the sql expression msg by vnode
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NO_DISKSPACE, 0, 0x0702, "query no diskspace")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_OUT_OF_MEMORY, 0, 0x0703, "query out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_APP_ERROR, 0, 0x0704, "query app error")
// grant // grant
TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 0x0380, "auth failure") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "grant expired")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 0x0381, "no rights") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0801, "grant dnode limited")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 0x0382, "no write access") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0802, "grant account limited")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 0x0383, "no read access") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 0x0803, "grant timeseries limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0384, "grant expired") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 0x0804, "grant db limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0385, "grant dnode limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 0x0805, "grant user limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0386, "grant account limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 0x0806, "grant conn limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 0x0387, "grant timeseries limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 0x0807, "grant stream limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 0x0388, "grant db limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 0x0808, "grant speed limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 0x0389, "grant user limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x0809, "grant storage limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 0x038A, "grant conn limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x080A, "grant query time limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 0x038B, "grant stream limited") TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x080B, "grant cpu limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 0x038C, "grant speed limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x038D, "grant storage limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x038E, "grant query time limited")
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x038F, "grant cpu limited")
// server // sync
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 0x0400, "invalid vgroup id") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x0900, "sync invalid configuration")
TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 0x0402, "vgroup init failed")
TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 0x0403, "server no diskspace")
TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 0x0404, "server out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 0x0405, "no disk permissions")
TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 0x0406, "file corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 0x0407, "memory corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUCH_FILE_OR_DIR, 0, 0x0408, "no such file or directory")
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_SHELL_CONNS, 0, 0x0409, "too many shell conns")
// client
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 0x0481, "invalid client version")
TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 0x0482, "client out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 0x0483, "client no disk space")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 0x0484, "invalid timestamp")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 0x0485, "invalid sql")
TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 0x0486, "query cache erased")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 0x0487, "invalid query message") // failed to validate the sql expression msg by vnode
TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 0x0488, "sorted res too many") // too many result for ordered super table projection query
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 0x0489, "invalid handle")
TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 0x048A, "query cancelled")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 0x048B, "invalid ie")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 0x048C, "invalid value")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FQDN, 0, 0x048D, "invalid FQDN")
// others
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 0x0500, "invalid file format")
// TSDB
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONFIG, 0, 0x0580, "invalid TSDB configuration")
TAOS_DEFINE_ERROR(TSDB_CODE_TAG_VER_OUT_OF_DATE, 0, 0x0581, "tag version is out of date")
TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_SCHEMA_VERSION, 0, 0x0582, "invalid table schema version from client")
// wal
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "wal app error")
#ifdef TAOS_ERROR_C #ifdef TAOS_ERROR_C
}; };

View File

@ -27,6 +27,7 @@ typedef struct {
int vgId; int vgId;
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN]; char pass[TSDB_PASSWORD_LEN];
char db[TSDB_DB_NAME_LEN + 1];
FCqWrite cqWrite; FCqWrite cqWrite;
} SCqCfg; } SCqCfg;
@ -41,7 +42,7 @@ void cqStart(void *handle);
void cqStop(void *handle); void cqStop(void *handle);
// cqCreate is called by TSDB to start an instance of CQ // cqCreate is called by TSDB to start an instance of CQ
void *cqCreate(void *handle, int sid, char *sqlStr, STSchema *pSchema); void *cqCreate(void *handle, uint64_t uid, int sid, char *sqlStr, STSchema *pSchema);
// cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate // cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate
void cqDrop(void *handle); void cqDrop(void *handle);

View File

@ -43,7 +43,7 @@ typedef struct {
void *cqH; void *cqH;
int (*notifyStatus)(void *, int status); int (*notifyStatus)(void *, int status);
int (*eventCallBack)(void *); int (*eventCallBack)(void *);
void *(*cqCreateFunc)(void *handle, int sid, char *sqlStr, STSchema *pSchema); void *(*cqCreateFunc)(void *handle, uint64_t uid, int sid, char *sqlStr, STSchema *pSchema);
void (*cqDropFunc)(void *handle); void (*cqDropFunc)(void *handle);
void *(*configFunc)(int32_t vgId, int32_t sid); void *(*configFunc)(int32_t vgId, int32_t sid);
} STsdbAppH; } STsdbAppH;
@ -118,6 +118,7 @@ int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId);
int tsdbAlterTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbAlterTable(TsdbRepoT *repo, STableCfg *pCfg);
int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg); int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg);
TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid); TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid);
void tsdbStartStream(TsdbRepoT *repo);
uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size); uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size);

View File

@ -30,7 +30,6 @@ typedef enum _VN_STATUS {
typedef struct { typedef struct {
int len; int len;
int code;
void *rsp; void *rsp;
void *qhandle; //used by query and retrieve msg void *qhandle; //used by query and retrieve msg
} SRspRet; } SRspRet;
@ -38,6 +37,7 @@ typedef struct {
int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg);
int32_t vnodeDrop(int32_t vgId); int32_t vnodeDrop(int32_t vgId);
int32_t vnodeOpen(int32_t vgId, char *rootDir); int32_t vnodeOpen(int32_t vgId, char *rootDir);
int32_t vnodeStartStream(int32_t vgId);
int32_t vnodeAlter(void *pVnode, SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeAlter(void *pVnode, SMDCreateVnodeMsg *pVnodeCfg);
int32_t vnodeClose(int32_t vgId); int32_t vnodeClose(int32_t vgId);

View File

@ -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);
@ -858,11 +846,11 @@ void shellGetGrantInfo(void *con) {
char sql[] = "show grants"; char sql[] = "show grants";
TAOS_RES* pSql = taos_query(con, sql); result = taos_query(con, sql);
int code = taos_errno(pSql);
int code = taos_errno(result);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
if (code == TSDB_CODE_OPS_NOT_SUPPORT) { if (code == TSDB_CODE_COM_OPS_NOT_SUPPORT) {
fprintf(stdout, "Server is Community Edition, version is %s\n\n", taos_get_server_info(con)); fprintf(stdout, "Server is Community Edition, version is %s\n\n", taos_get_server_info(con));
} else { } else {
fprintf(stderr, "Failed to check Server Edition, Reason:%d:%s\n\n", taos_errno(con), taos_errstr(con)); fprintf(stderr, "Failed to check Server Edition, Reason:%d:%s\n\n", taos_errno(con), taos_errstr(con));

View File

@ -148,7 +148,11 @@ static void shellSourceFile(TAOS *con, char *fptr) {
} }
char *fname = full_path.we_wordv[0]; char *fname = full_path.we_wordv[0];
if (fname == NULL) {
fprintf(stderr, "ERROR: invalid filename\n");
return;
}
if (access(fname, F_OK) != 0) { if (access(fname, F_OK) != 0) {
fprintf(stderr, "ERROR: file %s is not exist\n", fptr); fprintf(stderr, "ERROR: file %s is not exist\n", fptr);
@ -169,6 +173,7 @@ static void shellSourceFile(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

@ -16,21 +16,19 @@
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "tsclient.h" #include "tsclient.h"
#include "tutil.h"
TAOS_RES* con;
pthread_t pid; pthread_t pid;
// TODO: IMPLEMENT INTERRUPT HANDLER. // TODO: IMPLEMENT INTERRUPT HANDLER.
void interruptHandler(int signum) { void interruptHandler(int signum) {
#ifdef LINUX #ifdef LINUX
taos_stop_query(con); taos_stop_query(result);
if (con != NULL) { if (result != NULL) {
/* /*
* we need to free result in async model, in order to avoid free * we need to free result in async model, in order to avoid free
* results while the master thread is waiting for server response. * results while the master thread is waiting for server response.
*/ */
tscQueueAsyncFreeResult(con); tscQueueAsyncFreeResult(result);
} }
result = NULL; result = NULL;
@ -88,7 +86,7 @@ int main(int argc, char* argv[]) {
shellParseArgument(argc, argv, &args); shellParseArgument(argc, argv, &args);
/* Initialize the shell */ /* Initialize the shell */
con = shellInit(&args); TAOS* con = shellInit(&args);
if (con == NULL) { if (con == NULL) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -109,5 +107,4 @@ int main(int argc, char* argv[]) {
pthread_create(&pid, NULL, shellLoopQuery, con); pthread_create(&pid, NULL, shellLoopQuery, con);
pthread_join(pid, NULL); pthread_join(pid, NULL);
} }
return 0;
} }

View File

@ -43,6 +43,7 @@ extern char configDir[];
#define MAX_DATA_SIZE 1024 #define MAX_DATA_SIZE 1024
#define MAX_NUM_DATATYPE 8 #define MAX_NUM_DATATYPE 8
#define OPT_ABORT 1 /* abort */ #define OPT_ABORT 1 /* abort */
#define STRING_LEN 512
/* The options we understand. */ /* The options we understand. */
static struct argp_option options[] = { static struct argp_option options[] = {
@ -380,10 +381,11 @@ int main(int argc, char *argv[]) {
bool insert_only = arguments.insert_only; bool insert_only = arguments.insert_only;
char **data_type = arguments.datatype; char **data_type = arguments.datatype;
int count_data_type = 0; int count_data_type = 0;
char dataString[512]; char dataString[STRING_LEN];
bool do_aggreFunc = true; bool do_aggreFunc = true;
memset(dataString, 0, 512); memset(dataString, 0, STRING_LEN);
int len = 0;
if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0) { if (strcasecmp(data_type[0], "BINARY") == 0 || strcasecmp(data_type[0], "BOOL") == 0) {
do_aggreFunc = false; do_aggreFunc = false;
@ -392,8 +394,8 @@ int main(int argc, char *argv[]) {
if (strcasecmp(data_type[count_data_type], "") == 0) { if (strcasecmp(data_type[count_data_type], "") == 0) {
break; break;
} }
strcat(dataString, data_type[count_data_type]);
strcat(dataString, " "); len += snprintf(dataString + len, STRING_LEN - len, "%s ", data_type[count_data_type]);
} }
FILE *fp = fopen(arguments.output_file, "a"); FILE *fp = fopen(arguments.output_file, "a");
@ -473,32 +475,29 @@ int main(int argc, char *argv[]) {
sprintf(command, "create database %s;", db_name); sprintf(command, "create database %s;", db_name);
taos_query(taos, command); taos_query(taos, command);
char cols[512] = "\0"; char cols[STRING_LEN] = "\0";
int colIndex = 0; int colIndex = 0;
len = 0;
for (; colIndex < ncols_per_record - 1; colIndex++) { for (; colIndex < ncols_per_record - 1; colIndex++) {
if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) {
sprintf(command, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]); len += snprintf(cols + len, STRING_LEN - len, ",f%d %s", colIndex + 1, data_type[colIndex % count_data_type]);
strcat(cols, command);
} else { } else {
sprintf(command, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d)", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary);
strcat(cols, command);
} }
} }
if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) { if (strcasecmp(data_type[colIndex % count_data_type], "BINARY") != 0) {
sprintf(command, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]); len += snprintf(cols + len, STRING_LEN - len, ",f%d %s)", colIndex + 1, data_type[colIndex % count_data_type]);
} else { } else {
sprintf(command, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary); len += snprintf(cols + len, STRING_LEN - len, ",f%d %s(%d))", colIndex + 1, data_type[colIndex % count_data_type], len_of_binary);
} }
strcat(cols, command);
if (!use_metric) { if (!use_metric) {
/* Create all the tables; */ /* Create all the tables; */
printf("Creating %d table(s)......\n", ntables); printf("Creating %d table(s)......\n", ntables);
for (int i = 0; i < ntables; i++) { for (int i = 0; i < ntables; i++) {
sprintf(command, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); snprintf(command, BUFFER_SIZE, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols);
queryDB(taos, command); queryDB(taos, command);
} }
@ -508,7 +507,7 @@ int main(int argc, char *argv[]) {
} else { } else {
/* Create metric table */ /* Create metric table */
printf("Creating meters super table...\n"); printf("Creating meters super table...\n");
sprintf(command, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); snprintf(command, BUFFER_SIZE, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols);
queryDB(taos, command); queryDB(taos, command);
printf("meters created!\n"); printf("meters created!\n");
@ -522,10 +521,10 @@ int main(int argc, char *argv[]) {
j = i % 10; j = i % 10;
} }
if (j % 2 == 0) { if (j % 2 == 0) {
sprintf(command, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j,"shanghai"); snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "shanghai");
} else { } else {
sprintf(command, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j,"beijing"); snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "beijing");
} }
queryDB(taos, command); queryDB(taos, command);
} }

View File

@ -117,8 +117,8 @@ typedef struct {
} SDbInfo; } SDbInfo;
typedef struct { typedef struct {
char name[TSDB_TABLE_NAME_LEN + 1]; char name[TSDB_TABLE_NAME_LEN];
char metric[TSDB_TABLE_NAME_LEN + 1]; char metric[TSDB_TABLE_NAME_LEN];
} STableRecord; } STableRecord;
typedef struct { typedef struct {
@ -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) {
@ -871,7 +870,7 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) {
int fd = -1; int fd = -1;
STableRecord tableRecord; STableRecord tableRecord;
strcpy(tableRecord.metric, metric); tstrncpy(tableRecord.metric, metric, TSDB_TABLE_NAME_LEN);
sprintf(command, "select tbname from %s", metric); sprintf(command, "select tbname from %s", metric);
result = taos_query(taos, command); result = taos_query(taos, command);

View File

@ -27,7 +27,7 @@
void * tsAcctSdb = NULL; void * tsAcctSdb = NULL;
static int32_t tsAcctUpdateSize; static int32_t tsAcctUpdateSize;
static void mnodeCreateRootAcct(); static int32_t mnodeCreateRootAcct();
static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj; SAcctObj *pAcct = pOper->pObj;
@ -70,7 +70,7 @@ static int32_t mnodeActionActionEncode(SSdbOper *pOper) {
static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { static int32_t mnodeAcctActionDecode(SSdbOper *pOper) {
SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj));
if (pAcct == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pAcct, pOper->rowData, tsAcctUpdateSize); memcpy(pAcct, pOper->rowData, tsAcctUpdateSize);
pOper->pObj = pAcct; pOper->pObj = pAcct;
@ -79,7 +79,11 @@ static int32_t mnodeAcctActionDecode(SSdbOper *pOper) {
static int32_t mnodeAcctActionRestored() { static int32_t mnodeAcctActionRestored() {
if (dnodeIsFirstDeploy()) { if (dnodeIsFirstDeploy()) {
mnodeCreateRootAcct(); int32_t code = mnodeCreateRootAcct();
if (code != TSDB_CODE_SUCCESS) {
mError("failed to create root account, reason:%s", tstrerror(code));
return code;
}
} }
acctInit(); acctInit();
@ -161,9 +165,9 @@ void mnodeDropUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
mnodeDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} }
static void mnodeCreateRootAcct() { static int32_t mnodeCreateRootAcct() {
int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb); int32_t numOfAccts = sdbGetNumOfRows(tsAcctSdb);
if (numOfAccts != 0) return; if (numOfAccts != 0) return TSDB_CODE_SUCCESS;
SAcctObj *pAcct = malloc(sizeof(SAcctObj)); SAcctObj *pAcct = malloc(sizeof(SAcctObj));
memset(pAcct, 0, sizeof(SAcctObj)); memset(pAcct, 0, sizeof(SAcctObj));
@ -190,7 +194,8 @@ static void mnodeCreateRootAcct() {
.table = tsAcctSdb, .table = tsAcctSdb,
.pObj = pAcct, .pObj = pAcct,
}; };
sdbInsertRow(&oper);
return sdbInsertRow(&oper);
} }
#ifndef _ACCT #ifndef _ACCT

View File

@ -56,7 +56,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
if (pSelDnode == NULL) { if (pSelDnode == NULL) {
mError("failed to alloc vnode to vgroup"); mError("failed to alloc vnode to vgroup");
return TSDB_CODE_NO_ENOUGH_DNODES; return TSDB_CODE_MND_NO_ENOUGH_DNODES;
} }
pVgroup->vnodeGid[0].dnodeId = pSelDnode->dnodeId; pVgroup->vnodeGid[0].dnodeId = pSelDnode->dnodeId;

View File

@ -71,7 +71,7 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) {
} }
else { else {
mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct); mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_MND_INVALID_ACCT;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -111,7 +111,7 @@ static int32_t mnodeDbActionEncode(SSdbOper *pOper) {
static int32_t mnodeDbActionDecode(SSdbOper *pOper) { static int32_t mnodeDbActionDecode(SSdbOper *pOper) {
SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj));
if (pDb == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pDb, pOper->rowData, tsDbUpdateSize); memcpy(pDb, pOper->rowData, tsDbUpdateSize);
pOper->pObj = pDb; pOper->pObj = pDb;
@ -189,102 +189,102 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
mError("invalid db option cacheBlockSize:%d valid range: [%d, %d]", pCfg->cacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE, mError("invalid db option cacheBlockSize:%d valid range: [%d, %d]", pCfg->cacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE,
TSDB_MAX_CACHE_BLOCK_SIZE); TSDB_MAX_CACHE_BLOCK_SIZE);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) { if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) {
mError("invalid db option totalBlocks:%d valid range: [%d, %d]", pCfg->totalBlocks, TSDB_MIN_TOTAL_BLOCKS, mError("invalid db option totalBlocks:%d valid range: [%d, %d]", pCfg->totalBlocks, TSDB_MIN_TOTAL_BLOCKS,
TSDB_MAX_TOTAL_BLOCKS); TSDB_MAX_TOTAL_BLOCKS);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->maxTables < TSDB_MIN_TABLES || pCfg->maxTables > TSDB_MAX_TABLES) { if (pCfg->maxTables < TSDB_MIN_TABLES || pCfg->maxTables > TSDB_MAX_TABLES) {
mError("invalid db option maxTables:%d valid range: [%d, %d]", pCfg->maxTables, TSDB_MIN_TABLES, TSDB_MAX_TABLES); mError("invalid db option maxTables:%d valid range: [%d, %d]", pCfg->maxTables, TSDB_MIN_TABLES, TSDB_MAX_TABLES);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) { if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) {
mError("invalid db option daysPerFile:%d valid range: [%d, %d]", pCfg->daysPerFile, TSDB_MIN_DAYS_PER_FILE, mError("invalid db option daysPerFile:%d valid range: [%d, %d]", pCfg->daysPerFile, TSDB_MIN_DAYS_PER_FILE,
TSDB_MAX_DAYS_PER_FILE); TSDB_MAX_DAYS_PER_FILE);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) { if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) {
mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, TSDB_MAX_KEEP); mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, TSDB_MAX_KEEP);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->daysToKeep < pCfg->daysPerFile) { if (pCfg->daysToKeep < pCfg->daysPerFile) {
mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile); mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > pCfg->daysToKeep) { if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > pCfg->daysToKeep) {
mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, pCfg->daysToKeep); mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, pCfg->daysToKeep);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) { if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) {
mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, TSDB_MIN_KEEP, pCfg->daysToKeep2); mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, TSDB_MIN_KEEP, pCfg->daysToKeep2);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) { if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) {
mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock, mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock,
TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK); TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) { if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) {
mError("invalid db option minRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->minRowsPerFileBlock, mError("invalid db option minRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->minRowsPerFileBlock,
TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK); TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) { if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) {
mError("invalid db option minRowsPerFileBlock:%d should smaller than maxRowsPerFileBlock:%d", mError("invalid db option minRowsPerFileBlock:%d should smaller than maxRowsPerFileBlock:%d",
pCfg->minRowsPerFileBlock, pCfg->maxRowsPerFileBlock); pCfg->minRowsPerFileBlock, pCfg->maxRowsPerFileBlock);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) { if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) {
mError("invalid db option commitTime:%d valid range: [%d, %d]", pCfg->commitTime, TSDB_MIN_COMMIT_TIME, mError("invalid db option commitTime:%d valid range: [%d, %d]", pCfg->commitTime, TSDB_MIN_COMMIT_TIME,
TSDB_MAX_COMMIT_TIME); TSDB_MAX_COMMIT_TIME);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) { if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) {
mError("invalid db option timePrecision:%d valid value: [%d, %d]", pCfg->precision, TSDB_MIN_PRECISION, mError("invalid db option timePrecision:%d valid value: [%d, %d]", pCfg->precision, TSDB_MIN_PRECISION,
TSDB_MAX_PRECISION); TSDB_MAX_PRECISION);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) { if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) {
mError("invalid db option compression:%d valid range: [%d, %d]", pCfg->compression, TSDB_MIN_COMP_LEVEL, mError("invalid db option compression:%d valid range: [%d, %d]", pCfg->compression, TSDB_MIN_COMP_LEVEL,
TSDB_MAX_COMP_LEVEL); TSDB_MAX_COMP_LEVEL);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) { if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) {
mError("invalid db option walLevel:%d, valid range: [%d, %d]", pCfg->walLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL); mError("invalid db option walLevel:%d, valid range: [%d, %d]", pCfg->walLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->replications < TSDB_MIN_REPLICA_NUM || pCfg->replications > TSDB_MAX_REPLICA_NUM) { if (pCfg->replications < TSDB_MIN_REPLICA_NUM || pCfg->replications > TSDB_MAX_REPLICA_NUM) {
mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_REPLICA_NUM, mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_REPLICA_NUM,
TSDB_MAX_REPLICA_NUM); TSDB_MAX_REPLICA_NUM);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL) { if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL) {
mError("invalid db option walLevel:%d must be greater than 0", pCfg->walLevel); mError("invalid db option walLevel:%d must be greater than 0", pCfg->walLevel);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
#ifndef _SYNC #ifndef _SYNC
if (pCfg->replications != 1) { if (pCfg->replications != 1) {
mError("invalid db option replications:%d can only be 1 in this version", pCfg->replications); mError("invalid db option replications:%d can only be 1 in this version", pCfg->replications);
return TSDB_CODE_INVALID_OPTION; return TSDB_CODE_MND_INVALID_DB_OPTION;
} }
#endif #endif
@ -320,7 +320,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
mError("db:%s, is already exist, ignore exist not set", pCreate->db); mError("db:%s, is already exist, ignore exist not set", pCreate->db);
return TSDB_CODE_DB_ALREADY_EXIST; return TSDB_CODE_MND_DB_ALREADY_EXIST;
} }
} }
@ -366,7 +366,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
code = sdbInsertRow(&oper); code = sdbInsertRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tfree(pDb); tfree(pDb);
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
return code; return code;
@ -743,7 +743,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) {
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
return code; return code;
@ -766,7 +766,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_GRANT_EXPIRED; code = TSDB_CODE_GRANT_EXPIRED;
} else if (!pMsg->pUser->writeAuth) { } else if (!pMsg->pUser->writeAuth) {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_MND_NO_RIGHTS;
} else { } else {
code = mnodeCreateDb(pMsg->pUser->pAcct, pCreate); code = mnodeCreateDb(pMsg->pUser->pAcct, pCreate);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
@ -800,7 +800,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) { if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) {
mError("db:%s, can't alter cache option", pDb->name); mError("db:%s, can't alter cache option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (totalBlocks > 0 && totalBlocks != pDb->cfg.totalBlocks) { if (totalBlocks > 0 && totalBlocks != pDb->cfg.totalBlocks) {
@ -813,13 +813,13 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
newCfg.maxTables = maxTables; newCfg.maxTables = maxTables;
if (newCfg.maxTables < pDb->cfg.maxTables) { if (newCfg.maxTables < pDb->cfg.maxTables) {
mError("db:%s, tables:%d should larger than origin:%d", pDb->name, newCfg.maxTables, pDb->cfg.maxTables); mError("db:%s, tables:%d should larger than origin:%d", pDb->name, newCfg.maxTables, pDb->cfg.maxTables);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
} }
if (daysPerFile > 0 && daysPerFile != pDb->cfg.daysPerFile) { if (daysPerFile > 0 && daysPerFile != pDb->cfg.daysPerFile) {
mError("db:%s, can't alter days option", pDb->name); mError("db:%s, can't alter days option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) { if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) {
@ -839,22 +839,22 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
if (minRows > 0 && minRows != pDb->cfg.minRowsPerFileBlock) { if (minRows > 0 && minRows != pDb->cfg.minRowsPerFileBlock) {
mError("db:%s, can't alter minRows option", pDb->name); mError("db:%s, can't alter minRows option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (maxRows > 0 && maxRows != pDb->cfg.maxRowsPerFileBlock) { if (maxRows > 0 && maxRows != pDb->cfg.maxRowsPerFileBlock) {
mError("db:%s, can't alter maxRows option", pDb->name); mError("db:%s, can't alter maxRows option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (commitTime > 0 && commitTime != pDb->cfg.commitTime) { if (commitTime > 0 && commitTime != pDb->cfg.commitTime) {
mError("db:%s, can't alter commitTime option", pDb->name); mError("db:%s, can't alter commitTime option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (precision > 0 && precision != pDb->cfg.precision) { if (precision > 0 && precision != pDb->cfg.precision) {
mError("db:%s, can't alter precision option", pDb->name); mError("db:%s, can't alter precision option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (compression >= 0 && compression != pDb->cfg.compression) { if (compression >= 0 && compression != pDb->cfg.compression) {
@ -864,7 +864,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
if (walLevel > 0 && walLevel != pDb->cfg.walLevel) { if (walLevel > 0 && walLevel != pDb->cfg.walLevel) {
mError("db:%s, can't alter walLevel option", pDb->name); mError("db:%s, can't alter walLevel option", pDb->name);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (replications > 0 && replications != pDb->cfg.replications) { if (replications > 0 && replications != pDb->cfg.replications) {
@ -873,17 +873,17 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
if (pDb->cfg.walLevel < TSDB_MIN_WAL_LEVEL) { if (pDb->cfg.walLevel < TSDB_MIN_WAL_LEVEL) {
mError("db:%s, walLevel:%d must be greater than 0", pDb->name, pDb->cfg.walLevel); mError("db:%s, walLevel:%d must be greater than 0", pDb->name, pDb->cfg.walLevel);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
if (replications > mnodeGetDnodesNum()) { if (replications > mnodeGetDnodesNum()) {
mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications); mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications);
terrno = TSDB_CODE_NO_ENOUGH_DNODES; terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
} }
if (pDb->cfg.replications - replications >= 2) { if (pDb->cfg.replications - replications >= 2) {
mError("db:%s, replica number can't change from 3 to 1", pDb->name, replications); mError("db:%s, replica number can't change from 3 to 1", pDb->name, replications);
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
} }
} }
@ -914,7 +914,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
} }
@ -942,7 +942,7 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db);
if (pMsg->pDb == NULL) { if (pMsg->pDb == NULL) {
mError("db:%s, failed to alter, invalid db", pAlter->db); mError("db:%s, failed to alter, invalid db", pAlter->db);
return TSDB_CODE_INVALID_DB; return TSDB_CODE_MND_INVALID_DB;
} }
int32_t code = mnodeAlterDb(pMsg->pDb, pAlter); int32_t code = mnodeAlterDb(pMsg->pDb, pAlter);
@ -966,7 +966,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
}; };
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != 0) { if (code != 0) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
return code; return code;
@ -983,13 +983,13 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
mError("db:%s, failed to drop, invalid db", pDrop->db); mError("db:%s, failed to drop, invalid db", pDrop->db);
return TSDB_CODE_INVALID_DB; return TSDB_CODE_MND_INVALID_DB;
} }
} }
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("db:%s, can't drop monitor database", pDrop->db); mError("db:%s, can't drop monitor database", pDrop->db);
return TSDB_CODE_MONITOR_DB_FORBIDDEN; return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN;
} }
int32_t code = mnodeSetDbDropping(pMsg->pDb); int32_t code = mnodeSetDbDropping(pMsg->pDb);

View File

@ -107,7 +107,7 @@ static int32_t mnodeDnodeActionEncode(SSdbOper *pOper) {
static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) { static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) {
SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj));
if (pDnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pDnode, pOper->rowData, tsDnodeUpdateSize); memcpy(pDnode, pOper->rowData, tsDnodeUpdateSize);
pOper->pObj = pDnode; pOper->pObj = pDnode;
@ -249,7 +249,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
} }
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep); SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep);
@ -286,7 +286,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
uint32_t version = htonl(pStatus->version); uint32_t version = htonl(pStatus->version);
if (version != tsVersion) { if (version != tsVersion) {
mError("status msg version:%d not equal with mnode:%d", version, tsVersion); mError("status msg version:%d not equal with mnode:%d", version, tsVersion);
return TSDB_CODE_INVALID_MSG_VERSION; return TSDB_CODE_MND_INVALID_MSG_VERSION;
} }
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
@ -294,13 +294,13 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
pDnode = mnodeGetDnodeByEp(pStatus->dnodeEp); pDnode = mnodeGetDnodeByEp(pStatus->dnodeEp);
if (pDnode == NULL) { if (pDnode == NULL) {
mTrace("dnode %s not created", pStatus->dnodeEp); mTrace("dnode %s not created", pStatus->dnodeEp);
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_MND_DNODE_NOT_EXIST;
} }
} else { } else {
pDnode = mnodeGetDnode(pStatus->dnodeId); pDnode = mnodeGetDnode(pStatus->dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp); mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_MND_DNODE_NOT_EXIST;
} }
} }
@ -347,7 +347,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess); int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess);
SDMStatusRsp *pRsp = rpcMallocCont(contLen); SDMStatusRsp *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
mnodeGetMnodeInfos(&pRsp->mnodes); mnodeGetMnodeInfos(&pRsp->mnodes);
@ -376,7 +376,7 @@ static int32_t mnodeCreateDnode(char *ep) {
if (pDnode != NULL) { if (pDnode != NULL) {
mnodeDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort); mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort);
return TSDB_CODE_DNODE_ALREADY_EXIST; return TSDB_CODE_MND_DNODE_ALREADY_EXIST;
} }
pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj));
@ -398,7 +398,7 @@ static int32_t mnodeCreateDnode(char *ep) {
int dnodeId = pDnode->dnodeId; int dnodeId = pDnode->dnodeId;
tfree(pDnode); tfree(pDnode);
mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code)); mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code));
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code)); mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code));
@ -414,7 +414,7 @@ int32_t mnodeDropDnode(SDnodeObj *pDnode) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code));
@ -425,13 +425,13 @@ static int32_t mnodeDropDnodeByEp(char *ep) {
SDnodeObj *pDnode = mnodeGetDnodeByEp(ep); SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("dnode:%s, is not exist", ep); mError("dnode:%s, is not exist", ep);
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_MND_DNODE_NOT_EXIST;
} }
mnodeDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) { if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) {
mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep); mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep);
return TSDB_CODE_NO_REMOVE_MASTER; return TSDB_CODE_MND_NO_REMOVE_MASTER;
} }
mPrint("dnode:%d, start to drop it", pDnode->dnodeId); mPrint("dnode:%d, start to drop it", pDnode->dnodeId);
@ -446,7 +446,7 @@ static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont; SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} else { } else {
int32_t code = mnodeCreateDnode(pCreate->ep); int32_t code = mnodeCreateDnode(pCreate->ep);
@ -466,7 +466,7 @@ static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) {
SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont; SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont;
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} else { } else {
int32_t code = mnodeDropDnodeByEp(pDrop->ep); int32_t code = mnodeDropDnodeByEp(pDrop->ep);
@ -486,7 +486,7 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
if (strcmp(pUser->pAcct->user, "root") != 0) { if (strcmp(pUser->pAcct->user, "root") != 0) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
int32_t cols = 0; int32_t cols = 0;
@ -615,7 +615,7 @@ static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -725,7 +725,7 @@ static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -812,7 +812,7 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;

View File

@ -41,7 +41,7 @@ void mnodeCreateMsg(SMnodeMsg *pMsg, SRpcMsg *rpcMsg) {
int32_t mnodeInitMsg(SMnodeMsg *pMsg) { int32_t mnodeInitMsg(SMnodeMsg *pMsg) {
pMsg->pUser = mnodeGetUserFromConn(pMsg->rpcMsg.handle); pMsg->pUser = mnodeGetUserFromConn(pMsg->rpcMsg.handle);
if (pMsg->pUser == NULL) { if (pMsg->pUser == NULL) {
return TSDB_CODE_INVALID_USER; return TSDB_CODE_MND_INVALID_USER;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;

View File

@ -88,9 +88,9 @@ int32_t mnodeStartSystem() {
} }
mPrint("starting to initialize mnode ..."); mPrint("starting to initialize mnode ...");
struct stat dirstat; if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) {
if (stat(tsMnodeDir, &dirstat) < 0) { mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno));
mkdir(tsMnodeDir, 0755); return -1;
} }
dnodeAllocateMnodeWqueue(); dnodeAllocateMnodeWqueue();

View File

@ -63,7 +63,7 @@ static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) {
static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) { static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) {
SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pMnode = pOper->pObj;
SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST;
pDnode->isMgmt = true; pDnode->isMgmt = true;
mnodeDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
@ -75,7 +75,7 @@ static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) {
SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pMnode = pOper->pObj;
SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId);
if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST;
pDnode->isMgmt = false; pDnode->isMgmt = false;
mnodeDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
@ -103,7 +103,7 @@ static int32_t mnodeMnodeActionEncode(SSdbOper *pOper) {
static int32_t mnodeMnodeActionDecode(SSdbOper *pOper) { static int32_t mnodeMnodeActionDecode(SSdbOper *pOper) {
SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj));
if (pMnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pMnode, pOper->rowData, tsMnodeUpdateSize); memcpy(pMnode, pOper->rowData, tsMnodeUpdateSize);
pOper->pObj = pMnode; pOper->pObj = pMnode;
@ -285,7 +285,7 @@ int32_t mnodeAddMnode(int32_t dnodeId) {
int32_t code = sdbInsertRow(&oper); int32_t code = sdbInsertRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tfree(pMnode); tfree(pMnode);
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
mnodeUpdateMnodeIpSet(); mnodeUpdateMnodeIpSet();
@ -307,7 +307,7 @@ void mnodeDropMnodeLocal(int32_t dnodeId) {
int32_t mnodeDropMnode(int32_t dnodeId) { int32_t mnodeDropMnode(int32_t dnodeId) {
SMnodeObj *pMnode = mnodeGetMnode(dnodeId); SMnodeObj *pMnode = mnodeGetMnode(dnodeId);
if (pMnode == NULL) { if (pMnode == NULL) {
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_MND_DNODE_NOT_EXIST;
} }
SSdbOper oper = { SSdbOper oper = {
@ -318,7 +318,7 @@ int32_t mnodeDropMnode(int32_t dnodeId) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
sdbDecRef(tsMnodeSdb, pMnode); sdbDecRef(tsMnodeSdb, pMnode);
@ -335,7 +335,7 @@ static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
if (strcmp(pUser->pAcct->user, "root") != 0) { if (strcmp(pUser->pAcct->user, "root") != 0) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
int32_t cols = 0; int32_t cols = 0;

View File

@ -48,7 +48,7 @@ void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)) {
int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) { int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) {
if (pMsg->rpcMsg.pCont == NULL) { if (pMsg->rpcMsg.pCont == NULL) {
mError("%p, msg:%s in mpeer queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mpeer queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_INVALID_MSG_LEN; return TSDB_CODE_MND_INVALID_MSG_LEN;
} }
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
@ -63,12 +63,12 @@ int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) {
mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i]));
} }
return TSDB_CODE_REDIRECT; return TSDB_CODE_RPC_REDIRECT;
} }
if (tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType] == NULL) { if (tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType] == NULL) {
mError("%p, msg:%s in mpeer queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mpeer queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_MSG_NOT_PROCESSED; return TSDB_CODE_MND_MSG_NOT_PROCESSED;
} }
return (*tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType])(pMsg); return (*tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType])(pMsg);

View File

@ -84,7 +84,7 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) {
if (connSize > tsMaxShellConns) { if (connSize > tsMaxShellConns) {
mError("failed to create conn for user:%s ip:%s:%u, conns:%d larger than maxShellConns:%d, ", user, taosIpStr(ip), mError("failed to create conn for user:%s ip:%s:%u, conns:%d larger than maxShellConns:%d, ", user, taosIpStr(ip),
port, connSize, tsMaxShellConns); port, connSize, tsMaxShellConns);
terrno = TSDB_CODE_TOO_MANY_SHELL_CONNS; terrno = TSDB_CODE_MND_TOO_MANY_SHELL_CONNS;
return NULL; return NULL;
} }
@ -168,7 +168,7 @@ static void *mnodeGetNextConn(SHashMutableIterator *pIter, SConnObj **pConn) {
static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mnodeGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS;
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -264,13 +264,13 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi
// not thread safe, need optimized // not thread safe, need optimized
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) { int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) {
pConn->numOfQueries = htonl(pHBMsg->numOfQueries); pConn->numOfQueries = htonl(pHBMsg->numOfQueries);
if (pConn->numOfQueries > 0) { if (pConn->numOfQueries > 0 && pConn->numOfQueries < 20) {
pConn->pQueries = calloc(sizeof(SQueryDesc), pConn->numOfQueries); pConn->pQueries = calloc(sizeof(SQueryDesc), pConn->numOfQueries);
memcpy(pConn->pQueries, pHBMsg->pData, pConn->numOfQueries * sizeof(SQueryDesc)); memcpy(pConn->pQueries, pHBMsg->pData, pConn->numOfQueries * sizeof(SQueryDesc));
} }
pConn->numOfStreams = htonl(pHBMsg->numOfStreams); pConn->numOfStreams = htonl(pHBMsg->numOfStreams);
if (pConn->numOfStreams > 0) { if (pConn->numOfStreams > 0 && pConn->numOfStreams < 20) {
pConn->pStreams = calloc(sizeof(SStreamDesc), pConn->numOfStreams); pConn->pStreams = calloc(sizeof(SStreamDesc), pConn->numOfStreams);
memcpy(pConn->pStreams, pHBMsg->pData + pConn->numOfQueries * sizeof(SQueryDesc), memcpy(pConn->pStreams, pHBMsg->pData + pConn->numOfQueries * sizeof(SQueryDesc),
pConn->numOfStreams * sizeof(SStreamDesc)); pConn->numOfStreams * sizeof(SStreamDesc));
@ -282,7 +282,7 @@ int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) {
static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mnodeGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS;
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -391,7 +391,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v
static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mnodeGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS;
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -519,7 +519,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v
static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
SUserObj *pUser = pMsg->pUser; SUserObj *pUser = pMsg->pUser;
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS;
SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
mPrint("kill query msg is received, queryId:%s", pKill->queryId); mPrint("kill query msg is received, queryId:%s", pKill->queryId);
@ -530,7 +530,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
if (queryIdStr == NULL || connIdStr == NULL) { if (queryIdStr == NULL || connIdStr == NULL) {
mPrint("failed to kill query, queryId:%s", pKill->queryId); mPrint("failed to kill query, queryId:%s", pKill->queryId);
return TSDB_CODE_INVALID_QUERY_ID; return TSDB_CODE_MND_INVALID_QUERY_ID;
} }
int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10); int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10);
@ -538,7 +538,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr); SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr);
if (pConn == NULL) { if (pConn == NULL) {
mError("connId:%s, failed to kill queryId:%d, conn not exist", connIdStr, queryId); mError("connId:%s, failed to kill queryId:%d, conn not exist", connIdStr, queryId);
return TSDB_CODE_INVALID_CONNECTION; return TSDB_CODE_MND_INVALID_CONN_ID;
} else { } else {
mPrint("connId:%s, queryId:%d is killed by user:%s", connIdStr, queryId, pUser->user); mPrint("connId:%s, queryId:%d is killed by user:%s", connIdStr, queryId, pUser->user);
pConn->queryId = queryId; pConn->queryId = queryId;
@ -549,7 +549,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) {
static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
SUserObj *pUser = pMsg->pUser; SUserObj *pUser = pMsg->pUser;
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS;
SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
mPrint("kill stream msg is received, streamId:%s", pKill->queryId); mPrint("kill stream msg is received, streamId:%s", pKill->queryId);
@ -560,7 +560,7 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
if (streamIdStr == NULL || connIdStr == NULL) { if (streamIdStr == NULL || connIdStr == NULL) {
mPrint("failed to kill stream, streamId:%s", pKill->queryId); mPrint("failed to kill stream, streamId:%s", pKill->queryId);
return TSDB_CODE_INVALID_STREAM_ID; return TSDB_CODE_MND_INVALID_STREAM_ID;
} }
int32_t streamId = (int32_t)strtol(streamIdStr, NULL, 10); int32_t streamId = (int32_t)strtol(streamIdStr, NULL, 10);
@ -568,7 +568,7 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr); SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr);
if (pConn == NULL) { if (pConn == NULL) {
mError("connId:%s, failed to kill streamId:%d, conn not exist", connIdStr, streamId); mError("connId:%s, failed to kill streamId:%d, conn not exist", connIdStr, streamId);
return TSDB_CODE_INVALID_CONNECTION; return TSDB_CODE_MND_INVALID_CONN_ID;
} else { } else {
mPrint("connId:%s, streamId:%d is killed by user:%s", connIdStr, streamId, pUser->user); mPrint("connId:%s, streamId:%d is killed by user:%s", connIdStr, streamId, pUser->user);
pConn->streamId = streamId; pConn->streamId = streamId;
@ -579,13 +579,13 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) {
static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) {
SUserObj *pUser = pMsg->pUser; SUserObj *pUser = pMsg->pUser;
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS; if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS;
SCMKillConnMsg *pKill = pMsg->rpcMsg.pCont; SCMKillConnMsg *pKill = pMsg->rpcMsg.pCont;
SConnObj * pConn = taosCacheAcquireByName(tsMnodeConnCache, pKill->queryId); SConnObj * pConn = taosCacheAcquireByName(tsMnodeConnCache, pKill->queryId);
if (pConn == NULL) { if (pConn == NULL) {
mError("connId:%s, failed to kill, conn not exist", pKill->queryId); mError("connId:%s, failed to kill, conn not exist", pKill->queryId);
return TSDB_CODE_INVALID_CONNECTION; return TSDB_CODE_MND_INVALID_CONN_ID;
} else { } else {
mPrint("connId:%s, is killed by user:%s", pKill->queryId, pUser->user); mPrint("connId:%s, is killed by user:%s", pKill->queryId, pUser->user);
pConn->killed = 1; pConn->killed = 1;

View File

@ -44,7 +44,7 @@ void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *pMsg)) {
int32_t mnodeProcessRead(SMnodeMsg *pMsg) { int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
if (pMsg->rpcMsg.pCont == NULL) { if (pMsg->rpcMsg.pCont == NULL) {
mError("%p, msg:%s in mread queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mread queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_INVALID_MSG_LEN; return TSDB_CODE_MND_INVALID_MSG_LEN;
} }
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
@ -59,12 +59,12 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i]));
} }
return TSDB_CODE_REDIRECT; return TSDB_CODE_RPC_REDIRECT;
} }
if (tsMnodeProcessReadMsgFp[pMsg->rpcMsg.msgType] == NULL) { if (tsMnodeProcessReadMsgFp[pMsg->rpcMsg.msgType] == NULL) {
mError("%p, msg:%s in mread queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mread queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_MSG_NOT_PROCESSED; return TSDB_CODE_MND_MSG_NOT_PROCESSED;
} }
int32_t code = mnodeInitMsg(pMsg); int32_t code = mnodeInitMsg(pMsg);

View File

@ -518,7 +518,7 @@ static int sdbWrite(void *param, void *data, int type) {
sdbError("table:%s, failed to restore %s record:%s from wal, version:%" PRId64 " too large, sdb version:%" PRId64, sdbError("table:%s, failed to restore %s record:%s from wal, version:%" PRId64 " too large, sdb version:%" PRId64,
pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version,
tsSdbObj.version); tsSdbObj.version);
return TSDB_CODE_OTHERS; return TSDB_CODE_MND_APP_ERROR;
} else { } else {
tsSdbObj.version = pHead->version; tsSdbObj.version = pHead->version;
} }
@ -561,7 +561,7 @@ static int sdbWrite(void *param, void *data, int type) {
SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable};
code = (*pTable->decodeFp)(&oper); code = (*pTable->decodeFp)(&oper);
return sdbUpdateHash(pTable, &oper); return sdbUpdateHash(pTable, &oper);
} else { return TSDB_CODE_INVALID_MSG_TYPE; } } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; }
} }
int32_t sdbInsertRow(SSdbOper *pOper) { int32_t sdbInsertRow(SSdbOper *pOper) {
@ -571,7 +571,7 @@ int32_t sdbInsertRow(SSdbOper *pOper) {
if (sdbGetRowFromObj(pTable, pOper->pObj)) { if (sdbGetRowFromObj(pTable, pOper->pObj)) {
sdbError("table:%s, failed to insert record:%s, already exist", pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj)); sdbError("table:%s, failed to insert record:%s, already exist", pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj));
sdbDecRef(pTable, pOper->pObj); sdbDecRef(pTable, pOper->pObj);
return TSDB_CODE_ALREADY_THERE; return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE;
} }
if (pTable->keyType == SDB_KEY_AUTO) { if (pTable->keyType == SDB_KEY_AUTO) {

View File

@ -110,12 +110,12 @@ static char *mnodeGetShowType(int32_t showType) {
static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
SCMShowMsg *pShowMsg = pMsg->rpcMsg.pCont; SCMShowMsg *pShowMsg = pMsg->rpcMsg.pCont;
if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) { if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) {
return TSDB_CODE_INVALID_MSG_TYPE; return TSDB_CODE_MND_INVALID_MSG_TYPE;
} }
if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) { if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) {
mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type)); mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type));
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_COM_OPS_NOT_SUPPORT;
} }
int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen); int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen);
@ -127,14 +127,14 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
pShow = mnodePutShowObj(pShow, showObjSize); pShow = mnodePutShowObj(pShow, showObjSize);
if (pShow == NULL) { if (pShow == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE; int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
SCMShowRsp *pShowRsp = rpcMallocCont(size); SCMShowRsp *pShowRsp = rpcMallocCont(size);
if (pShowRsp == NULL) { if (pShowRsp == NULL) {
mnodeReleaseShowObj(pShow, true); mnodeReleaseShowObj(pShow, true);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
pShowRsp->qhandle = htobe64((uint64_t) pShow); pShowRsp->qhandle = htobe64((uint64_t) pShow);
@ -169,7 +169,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
*/ */
if (!mnodeAccquireShowObj(pShow)) { if (!mnodeAccquireShowObj(pShow)) {
mError("%p, show is invalid", pShow); mError("%p, show is invalid", pShow);
return TSDB_CODE_INVALID_QHANDLE; return TSDB_CODE_MND_INVALID_SHOWOBJ;
} }
if (mnodeCheckShowFinished(pShow)) { if (mnodeCheckShowFinished(pShow)) {
@ -202,7 +202,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
rpcFreeCont(pRsp); rpcFreeCont(pRsp);
mnodeReleaseShowObj(pShow, false); mnodeReleaseShowObj(pShow, false);
assert(false); assert(false);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
pRsp->numOfRows = htonl(rowsRead); pRsp->numOfRows = htonl(rowsRead);
@ -224,7 +224,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) {
static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
SCMHeartBeatRsp *pHBRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp)); SCMHeartBeatRsp *pHBRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp));
if (pHBRsp == NULL) { if (pHBRsp == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
SCMHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont; SCMHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont;
@ -278,7 +278,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) != 0) { if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) != 0) {
mError("thandle:%p is already released while process connect msg", pMsg->rpcMsg.handle); mError("thandle:%p is already released while process connect msg", pMsg->rpcMsg.handle);
code = TSDB_CODE_INVALID_MSG_CONTENT; code = TSDB_CODE_MND_INVALID_CONNECTION;
goto connect_over; goto connect_over;
} }
@ -295,7 +295,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db);
SDbObj *pDb = mnodeGetDb(dbName); SDbObj *pDb = mnodeGetDb(dbName);
if (pDb == NULL) { if (pDb == NULL) {
code = TSDB_CODE_INVALID_DB; code = TSDB_CODE_MND_INVALID_DB;
goto connect_over; goto connect_over;
} }
mnodeDecDbRef(pDb); mnodeDecDbRef(pDb);
@ -303,7 +303,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp));
if (pConnectRsp == NULL) { if (pConnectRsp == NULL) {
code = TSDB_CODE_SERV_OUT_OF_MEMORY; code = TSDB_CODE_MND_OUT_OF_MEMORY;
goto connect_over; goto connect_over;
} }
@ -316,7 +316,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
} }
sprintf(pConnectRsp->acctId, "%x", pAcct->acctId); sprintf(pConnectRsp->acctId, "%x", pAcct->acctId);
strcpy(pConnectRsp->serverVersion, version); memcpy(pConnectRsp->serverVersion, version, TSDB_VERSION_LEN);
pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->writeAuth = pUser->writeAuth;
pConnectRsp->superAuth = pUser->superAuth; pConnectRsp->superAuth = pUser->superAuth;
@ -340,7 +340,7 @@ static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
if (pMsg->pDb == NULL) { if (pMsg->pDb == NULL) {
code = TSDB_CODE_INVALID_DB; code = TSDB_CODE_MND_INVALID_DB;
} }
return code; return code;

View File

@ -107,21 +107,21 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId); mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId);
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_MND_VGROUP_NOT_EXIST;
} }
mnodeDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
SDbObj *pDb = mnodeGetDb(pVgroup->dbName); SDbObj *pDb = mnodeGetDb(pVgroup->dbName);
if (pDb == NULL) { if (pDb == NULL) {
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName); mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
return TSDB_CODE_INVALID_DB; return TSDB_CODE_MND_INVALID_DB;
} }
mnodeDecDbRef(pDb); mnodeDecDbRef(pDb);
SAcctObj *pAcct = mnodeGetAcct(pDb->acct); SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
if (pAcct == NULL) { if (pAcct == NULL) {
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_MND_INVALID_ACCT;
} }
mnodeDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
@ -145,7 +145,7 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) { static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) {
SChildTableObj *pTable = pOper->pObj; SChildTableObj *pTable = pOper->pObj;
if (pTable->vgId == 0) { if (pTable->vgId == 0) {
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_MND_VGROUP_NOT_EXIST;
} }
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
@ -201,7 +201,7 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) {
assert(pTable != NULL && pOper->rowData != NULL); assert(pTable != NULL && pOper->rowData != NULL);
int32_t len = strlen(pTable->info.tableId); int32_t len = strlen(pTable->info.tableId);
if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_INVALID_TABLE_ID; if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID;
memcpy(pOper->rowData, pTable->info.tableId, len); memcpy(pOper->rowData, pTable->info.tableId, len);
memset(pOper->rowData + len, 0, 1); memset(pOper->rowData + len, 0, 1);
@ -229,12 +229,12 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) {
static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
assert(pOper->rowData != NULL); assert(pOper->rowData != NULL);
SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj));
if (pTable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
int32_t len = strlen(pOper->rowData); int32_t len = strlen(pOper->rowData);
if (len > TSDB_TABLE_ID_LEN) { if (len > TSDB_TABLE_ID_LEN) {
free(pTable); free(pTable);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_ID;
} }
pTable->info.tableId = strdup(pOper->rowData); pTable->info.tableId = strdup(pOper->rowData);
len++; len++;
@ -247,7 +247,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
pTable->schema = (SSchema *)malloc(schemaSize); pTable->schema = (SSchema *)malloc(schemaSize);
if (pTable->schema == NULL) { if (pTable->schema == NULL) {
mnodeDestroyChildTable(pTable); mnodeDestroyChildTable(pTable);
return TSDB_CODE_INVALID_TABLE_TYPE; return TSDB_CODE_MND_INVALID_TABLE_TYPE;
} }
memcpy(pTable->schema, pOper->rowData + len, schemaSize); memcpy(pTable->schema, pOper->rowData + len, schemaSize);
len += schemaSize; len += schemaSize;
@ -256,7 +256,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
pTable->sql = malloc(pTable->sqlLen); pTable->sql = malloc(pTable->sqlLen);
if (pTable->sql == NULL) { if (pTable->sql == NULL) {
mnodeDestroyChildTable(pTable); mnodeDestroyChildTable(pTable);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
memcpy(pTable->sql, pOper->rowData + len, pTable->sqlLen); memcpy(pTable->sql, pOper->rowData + len, pTable->sqlLen);
} }
@ -453,7 +453,7 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) {
assert(pOper->pObj != NULL && pOper->rowData != NULL); assert(pOper->pObj != NULL && pOper->rowData != NULL);
int32_t len = strlen(pStable->info.tableId); int32_t len = strlen(pStable->info.tableId);
if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_INVALID_TABLE_ID; if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID;
memcpy(pOper->rowData, pStable->info.tableId, len); memcpy(pOper->rowData, pStable->info.tableId, len);
memset(pOper->rowData + len, 0, 1); memset(pOper->rowData + len, 0, 1);
@ -474,12 +474,12 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) {
static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) {
assert(pOper->rowData != NULL); assert(pOper->rowData != NULL);
SSuperTableObj *pStable = (SSuperTableObj *) calloc(1, sizeof(SSuperTableObj)); SSuperTableObj *pStable = (SSuperTableObj *) calloc(1, sizeof(SSuperTableObj));
if (pStable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
int32_t len = strlen(pOper->rowData); int32_t len = strlen(pOper->rowData);
if (len > TSDB_TABLE_ID_LEN){ if (len > TSDB_TABLE_ID_LEN){
free(pStable); free(pStable);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_ID;
} }
pStable->info.tableId = strdup(pOper->rowData); pStable->info.tableId = strdup(pOper->rowData);
len++; len++;
@ -491,7 +491,7 @@ static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) {
pStable->schema = malloc(schemaSize); pStable->schema = malloc(schemaSize);
if (pStable->schema == NULL) { if (pStable->schema == NULL) {
mnodeDestroySuperTable(pStable); mnodeDestroySuperTable(pStable);
return TSDB_CODE_NOT_SUPER_TABLE; return TSDB_CODE_MND_NOT_SUPER_TABLE;
} }
memcpy(pStable->schema, pOper->rowData + len, schemaSize); memcpy(pStable->schema, pOper->rowData + len, schemaSize);
@ -668,7 +668,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to create, db not selected", pCreate->tableId); mError("table:%s, failed to create, db not selected", pCreate->tableId);
return TSDB_CODE_DB_NOT_SELECTED; return TSDB_CODE_MND_DB_NOT_SELECTED;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId);
@ -681,7 +681,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
mError("table:%s, failed to create, table already exist", pCreate->tableId); mError("table:%s, failed to create, table already exist", pCreate->tableId);
return TSDB_CODE_TABLE_ALREADY_EXIST; return TSDB_CODE_MND_TABLE_ALREADY_EXIST;
} }
} }
@ -699,12 +699,12 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to drop table, db not selected", pDrop->tableId); mError("table:%s, failed to drop table, db not selected", pDrop->tableId);
return TSDB_CODE_DB_NOT_SELECTED; return TSDB_CODE_MND_DB_NOT_SELECTED;
} }
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("table:%s, failed to drop table, in monitor database", pDrop->tableId); mError("table:%s, failed to drop table, in monitor database", pDrop->tableId);
return TSDB_CODE_MONITOR_DB_FORBIDDEN; return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->tableId);
@ -714,7 +714,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
mError("table:%s, failed to drop table, table not exist", pDrop->tableId); mError("table:%s, failed to drop table, table not exist", pDrop->tableId);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} }
} }
@ -735,14 +735,14 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to get table meta, db not selected", pInfo->tableId); mError("table:%s, failed to get table meta, db not selected", pInfo->tableId);
return TSDB_CODE_DB_NOT_SELECTED; return TSDB_CODE_MND_DB_NOT_SELECTED;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
if (!pInfo->createFlag) { if (!pInfo->createFlag) {
mError("table:%s, failed to get table meta, table not exist", pInfo->tableId); mError("table:%s, failed to get table meta, table not exist", pInfo->tableId);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} else { } else {
mTrace("table:%s, failed to get table meta, start auto create table ", pInfo->tableId); mTrace("table:%s, failed to get table meta, start auto create table ", pInfo->tableId);
return mnodeAutoCreateChildTable(pMsg); return mnodeAutoCreateChildTable(pMsg);
@ -761,7 +761,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
SSuperTableObj *pStable = calloc(1, sizeof(SSuperTableObj)); SSuperTableObj *pStable = calloc(1, sizeof(SSuperTableObj));
if (pStable == NULL) { if (pStable == NULL) {
mError("table:%s, failed to create, no enough memory", pCreate->tableId); mError("table:%s, failed to create, no enough memory", pCreate->tableId);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
pStable->info.tableId = strdup(pCreate->tableId); pStable->info.tableId = strdup(pCreate->tableId);
@ -779,7 +779,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if (pStable->schema == NULL) { if (pStable->schema == NULL) {
free(pStable); free(pStable);
mError("table:%s, failed to create, no schema input", pCreate->tableId); mError("table:%s, failed to create, no schema input", pCreate->tableId);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} }
memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
@ -804,7 +804,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mnodeDestroySuperTable(pStable); mnodeDestroySuperTable(pStable);
mError("table:%s, failed to create, sdb error", pCreate->tableId); mError("table:%s, failed to create, sdb error", pCreate->tableId);
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} else { } else {
mLPrint("table:%s, is created, tags:%d fields:%d", pStable->info.tableId, pStable->numOfTags, pStable->numOfColumns); mLPrint("table:%s, is created, tags:%d fields:%d", pStable->info.tableId, pStable->numOfTags, pStable->numOfColumns);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -862,18 +862,18 @@ static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char *
static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) { static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) {
if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) { if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) {
mError("stable:%s, add tag, too many tags", pStable->info.tableId); mError("stable:%s, add tag, too many tags", pStable->info.tableId);
return TSDB_CODE_TOO_MANY_TAGS; return TSDB_CODE_MND_TOO_MANY_TAGS;
} }
for (int32_t i = 0; i < ntags; i++) { for (int32_t i = 0; i < ntags; i++) {
if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_TAG_ALREAY_EXIST; return TSDB_CODE_MND_TAG_ALREAY_EXIST;
} }
if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_FIELD_ALREAY_EXIST; return TSDB_CODE_MND_FIELD_ALREAY_EXIST;
} }
} }
@ -898,7 +898,7 @@ static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[],
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("stable %s, succeed to add tag %s", pStable->info.tableId, schema[0].name); mPrint("stable %s, succeed to add tag %s", pStable->info.tableId, schema[0].name);
@ -909,7 +909,7 @@ static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
int32_t col = mnodeFindSuperTableTagIndex(pStable, tagName); int32_t col = mnodeFindSuperTableTagIndex(pStable, tagName);
if (col < 0) { if (col < 0) {
mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName); mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName);
return TSDB_CODE_TAG_NOT_EXIST; return TSDB_CODE_MND_TAG_NOT_EXIST;
} }
memmove(pStable->schema + pStable->numOfColumns + col, pStable->schema + pStable->numOfColumns + col + 1, memmove(pStable->schema + pStable->numOfColumns + col, pStable->schema + pStable->numOfColumns + col + 1,
@ -925,7 +925,7 @@ static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("stable %s, succeed to drop tag %s", pStable->info.tableId, tagName); mPrint("stable %s, succeed to drop tag %s", pStable->info.tableId, tagName);
@ -936,17 +936,17 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa
int32_t col = mnodeFindSuperTableTagIndex(pStable, oldTagName); int32_t col = mnodeFindSuperTableTagIndex(pStable, oldTagName);
if (col < 0) { if (col < 0) {
mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName); mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName);
return TSDB_CODE_TAG_NOT_EXIST; return TSDB_CODE_MND_TAG_NOT_EXIST;
} }
// int32_t rowSize = 0; // int32_t rowSize = 0;
uint32_t len = strlen(newTagName); uint32_t len = strlen(newTagName);
if (len >= TSDB_COL_NAME_LEN) { if (len >= TSDB_COL_NAME_LEN) {
return TSDB_CODE_COL_NAME_TOO_LONG; return TSDB_CODE_MND_COL_NAME_TOO_LONG;
} }
if (mnodeFindSuperTableTagIndex(pStable, newTagName) >= 0) { if (mnodeFindSuperTableTagIndex(pStable, newTagName) >= 0) {
return TSDB_CODE_TAG_ALREAY_EXIST; return TSDB_CODE_MND_TAG_ALREAY_EXIST;
} }
// update // update
@ -961,7 +961,7 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("stable %s, succeed to modify tag %s to %s", pStable->info.tableId, oldTagName, newTagName); mPrint("stable %s, succeed to modify tag %s to %s", pStable->info.tableId, oldTagName, newTagName);
@ -982,18 +982,18 @@ static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *col
static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) { static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) {
if (ncols <= 0) { if (ncols <= 0) {
mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId); mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_MND_APP_ERROR;
} }
for (int32_t i = 0; i < ncols; i++) { for (int32_t i = 0; i < ncols; i++) {
if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_FIELD_ALREAY_EXIST; return TSDB_CODE_MND_FIELD_ALREAY_EXIST;
} }
if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) { if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) {
mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name); mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name);
return TSDB_CODE_TAG_ALREAY_EXIST; return TSDB_CODE_MND_TAG_ALREAY_EXIST;
} }
} }
@ -1026,7 +1026,7 @@ static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SS
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("stable %s, succeed to add column", pStable->info.tableId); mPrint("stable %s, succeed to add column", pStable->info.tableId);
@ -1037,7 +1037,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c
int32_t col = mnodeFindSuperTableColumnIndex(pStable, colName); int32_t col = mnodeFindSuperTableColumnIndex(pStable, colName);
if (col <= 0) { if (col <= 0) {
mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName); mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName);
return TSDB_CODE_FIELD_NOT_EXIST; return TSDB_CODE_MND_FIELD_NOT_EXIST;
} }
memmove(pStable->schema + col, pStable->schema + col + 1, memmove(pStable->schema + col, pStable->schema + col + 1,
@ -1063,7 +1063,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("stable %s, succeed to delete column", pStable->info.tableId); mPrint("stable %s, succeed to delete column", pStable->info.tableId);
@ -1073,7 +1073,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c
// show super tables // show super tables
static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mnodeGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -1277,7 +1277,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen); SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
pRsp->numOfTables = 0; pRsp->numOfTables = 0;
@ -1340,7 +1340,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
if (pRsp->numOfTables != numOfTable) { if (pRsp->numOfTables != numOfTable) {
rpcFreeCont(pRsp); rpcFreeCont(pRsp);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} else { } else {
pRsp->numOfTables = htonl(pRsp->numOfTables); pRsp->numOfTables = htonl(pRsp->numOfTables);
pMsg->rpcRsp.rsp = pRsp; pMsg->rpcRsp.rsp = pRsp;
@ -1374,7 +1374,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO
SMDCreateTableMsg *pCreate = rpcMallocCont(contLen); SMDCreateTableMsg *pCreate = rpcMallocCont(contLen);
if (pCreate == NULL) { if (pCreate == NULL) {
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL; return NULL;
} }
@ -1431,7 +1431,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb
SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj));
if (pTable == NULL) { if (pTable == NULL) {
mError("table:%s, failed to alloc memory", pCreate->tableId); mError("table:%s, failed to alloc memory", pCreate->tableId);
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL; return NULL;
} }
@ -1452,7 +1452,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb
if (pSuperTable == NULL) { if (pSuperTable == NULL) {
mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name); mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name);
mnodeDestroyChildTable(pTable); mnodeDestroyChildTable(pTable);
terrno = TSDB_CODE_INVALID_TABLE_ID; terrno = TSDB_CODE_MND_INVALID_TABLE_NAME;
return NULL; return NULL;
} }
mnodeDecTableRef(pSuperTable); mnodeDecTableRef(pSuperTable);
@ -1472,7 +1472,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb
pTable->schema = (SSchema *) calloc(1, schemaSize); pTable->schema = (SSchema *) calloc(1, schemaSize);
if (pTable->schema == NULL) { if (pTable->schema == NULL) {
free(pTable); free(pTable);
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL; return NULL;
} }
memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
@ -1489,7 +1489,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb
pTable->sql = calloc(1, pTable->sqlLen); pTable->sql = calloc(1, pTable->sqlLen);
if (pTable->sql == NULL) { if (pTable->sql == NULL) {
free(pTable); free(pTable);
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL; return NULL;
} }
memcpy(pTable->sql, (char *) (pCreate->schema) + numOfCols * sizeof(SSchema), pTable->sqlLen); memcpy(pTable->sql, (char *) (pCreate->schema) + numOfCols * sizeof(SSchema), pTable->sqlLen);
@ -1506,7 +1506,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb
if (sdbInsertRow(&desc) != TSDB_CODE_SUCCESS) { if (sdbInsertRow(&desc) != TSDB_CODE_SUCCESS) {
free(pTable); free(pTable);
mError("table:%s, update sdb error", pCreate->tableId); mError("table:%s, update sdb error", pCreate->tableId);
terrno = TSDB_CODE_SDB_ERROR; terrno = TSDB_CODE_MND_SDB_ERROR;
return NULL; return NULL;
} }
@ -1567,7 +1567,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
dnodeSendMsgToDnode(&ipSet, &rpcMsg); dnodeSendMsgToDnode(&ipSet, &rpcMsg);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
@ -1575,13 +1575,13 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId);
if (pMsg->pVgroup == NULL) { if (pMsg->pVgroup == NULL) {
mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId); mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId);
return TSDB_CODE_OTHERS; return TSDB_CODE_MND_APP_ERROR;
} }
SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg)); SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg));
if (pDrop == NULL) { if (pDrop == NULL) {
mError("table:%s, failed to drop ctable, no enough memory", pTable->info.tableId); mError("table:%s, failed to drop ctable, no enough memory", pTable->info.tableId);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
strcpy(pDrop->tableId, pTable->info.tableId); strcpy(pDrop->tableId, pTable->info.tableId);
@ -1603,11 +1603,11 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
dnodeSendMsgToDnode(&ipSet, &rpcMsg); dnodeSendMsgToDnode(&ipSet, &rpcMsg);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
static int32_t mnodeModifyChildTableTagValue(SChildTableObj *pTable, char *tagName, char *nContent) { static int32_t mnodeModifyChildTableTagValue(SChildTableObj *pTable, char *tagName, char *nContent) {
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_COM_OPS_NOT_SUPPORT;
} }
static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) { static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) {
@ -1624,13 +1624,13 @@ static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *col
static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) { static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) {
if (ncols <= 0) { if (ncols <= 0) {
mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId); mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_MND_APP_ERROR;
} }
for (int32_t i = 0; i < ncols; i++) { for (int32_t i = 0; i < ncols; i++) {
if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) { if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) {
mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name); mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name);
return TSDB_CODE_FIELD_ALREAY_EXIST; return TSDB_CODE_MND_FIELD_ALREAY_EXIST;
} }
} }
@ -1661,7 +1661,7 @@ static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SS
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("table %s, succeed to add column", pTable->info.tableId); mPrint("table %s, succeed to add column", pTable->info.tableId);
@ -1672,7 +1672,7 @@ static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, c
int32_t col = mnodeFindNormalTableColumnIndex(pTable, colName); int32_t col = mnodeFindNormalTableColumnIndex(pTable, colName);
if (col <= 0) { if (col <= 0) {
mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName); mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName);
return TSDB_CODE_FIELD_NOT_EXIST; return TSDB_CODE_MND_FIELD_NOT_EXIST;
} }
memmove(pTable->schema + col, pTable->schema + col + 1, sizeof(SSchema) * (pTable->numOfColumns - col - 1)); memmove(pTable->schema + col, pTable->schema + col + 1, sizeof(SSchema) * (pTable->numOfColumns - col - 1));
@ -1693,7 +1693,7 @@ static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, c
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("table %s, succeed to drop column %s", pTable->info.tableId, colName); mPrint("table %s, succeed to drop column %s", pTable->info.tableId, colName);
@ -1739,8 +1739,8 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId);
if (pMsg->pVgroup == NULL) { if (pMsg->pVgroup == NULL) {
mError("table:%s, failed to get table meta, db not selected", pTable->info.tableId); mError("table:%s, failed to get table meta, vgroup not exist", pTable->info.tableId);
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_MND_VGROUP_NOT_EXIST;
} }
for (int32_t i = 0; i < pMsg->pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pMsg->pVgroup->numOfVnodes; ++i) {
@ -1766,7 +1766,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen); SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen);
if (pCreateMsg == NULL) { if (pCreateMsg == NULL) {
mError("table:%s, failed to create table while get meta info, no enough memory", pInfo->tableId); mError("table:%s, failed to create table while get meta info, no enough memory", pInfo->tableId);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId)); strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId));
@ -1783,14 +1783,14 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
pMsg->rpcMsg.pCont = pCreateMsg; pMsg->rpcMsg.pCont = pCreateMsg;
pMsg->rpcMsg.contLen = contLen; pMsg->rpcMsg.contLen = contLen;
return TSDB_CODE_ACTION_NEED_REPROCESSED; return TSDB_CODE_MND_ACTION_NEED_REPROCESSED;
} }
static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg) { static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg) {
STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16)); STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16));
if (pMeta == NULL) { if (pMeta == NULL) {
mError("table:%s, failed to get table meta, no enough memory", pMsg->pTable->tableId); mError("table:%s, failed to get table meta, no enough memory", pMsg->pTable->tableId);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
mnodeDoGetChildTableMeta(pMsg, pMeta); mnodeDoGetChildTableMeta(pMsg, pMeta);
@ -1909,7 +1909,7 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid); SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid);
if (pTable == NULL) { if (pTable == NULL) {
mError("dnode:%d, vgId:%d sid:%d, table not found", pCfg->dnodeId, pCfg->vgId, pCfg->sid); mError("dnode:%d, vgId:%d sid:%d, table not found", pCfg->dnodeId, pCfg->vgId, pCfg->sid);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_ID;
} }
SMDCreateTableMsg *pCreate = NULL; SMDCreateTableMsg *pCreate = NULL;
@ -1943,7 +1943,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
if (mnodeMsg->pVgroup == NULL) mnodeMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (mnodeMsg->pVgroup == NULL) mnodeMsg->pVgroup = mnodeGetVgroup(pTable->vgId);
if (mnodeMsg->pVgroup == NULL) { if (mnodeMsg->pVgroup == NULL) {
mError("table:%s, failed to get vgroup", pTable->info.tableId); mError("table:%s, failed to get vgroup", pTable->info.tableId);
dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_INVALID_VGROUP_ID); dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_VGROUP_NOT_EXIST);
return; return;
} }
@ -1956,7 +1956,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("table:%s, update ctables sdb error", pTable->info.tableId); mError("table:%s, update ctables sdb error", pTable->info.tableId);
dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_SDB_ERROR); dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_SDB_ERROR);
return; return;
} }
@ -2025,7 +2025,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice
SMultiTableMeta *pMultiMeta = rpcMallocCont(totalMallocLen); SMultiTableMeta *pMultiMeta = rpcMallocCont(totalMallocLen);
if (pMultiMeta == NULL) { if (pMultiMeta == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
pMultiMeta->contLen = sizeof(SMultiTableMeta); pMultiMeta->contLen = sizeof(SMultiTableMeta);
@ -2048,7 +2048,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
pMultiMeta = rpcReallocCont(pMultiMeta, totalMallocLen); pMultiMeta = rpcReallocCont(pMultiMeta, totalMallocLen);
if (pMultiMeta == NULL) { if (pMultiMeta == NULL) {
mnodeDecTableRef(pTable); mnodeDecTableRef(pTable);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} else { } else {
t--; t--;
mnodeDecTableRef(pTable); mnodeDecTableRef(pTable);
@ -2074,7 +2074,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mnodeGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
@ -2201,18 +2201,18 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId);
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("table:%s, failed to alter table, db not selected", pAlter->tableId); mError("table:%s, failed to alter table, db not selected", pAlter->tableId);
return TSDB_CODE_DB_NOT_SELECTED; return TSDB_CODE_MND_DB_NOT_SELECTED;
} }
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("table:%s, failed to alter table, its log db", pAlter->tableId); mError("table:%s, failed to alter table, its log db", pAlter->tableId);
return TSDB_CODE_MONITOR_DB_FORBIDDEN; return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN;
} }
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId); mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} }
pAlter->type = htons(pAlter->type); pAlter->type = htons(pAlter->type);
@ -2221,14 +2221,14 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
if (pAlter->numOfCols > 2) { if (pAlter->numOfCols > 2) {
mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols); mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_MND_APP_ERROR;
} }
for (int32_t i = 0; i < pAlter->numOfCols; ++i) { for (int32_t i = 0; i < pAlter->numOfCols; ++i) {
pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes); pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes);
} }
int32_t code = TSDB_CODE_OPS_NOT_SUPPORT; int32_t code = TSDB_CODE_COM_OPS_NOT_SUPPORT;
if (pMsg->pTable->type == TSDB_SUPER_TABLE) { if (pMsg->pTable->type == TSDB_SUPER_TABLE) {
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable;
mTrace("table:%s, start to alter stable", pAlter->tableId); mTrace("table:%s, start to alter stable", pAlter->tableId);
@ -2263,7 +2263,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mnodeGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;

View File

@ -56,7 +56,7 @@ static int32_t mnodeUserActionInsert(SSdbOper *pOper) {
mnodeDecAcctRef(pAcct); mnodeDecAcctRef(pAcct);
} else { } else {
mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct); mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_MND_INVALID_ACCT;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -94,7 +94,7 @@ static int32_t mnodeUserActionEncode(SSdbOper *pOper) {
static int32_t mnodeUserActionDecode(SSdbOper *pOper) { static int32_t mnodeUserActionDecode(SSdbOper *pOper) {
SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj));
if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pUser, pOper->rowData, tsUserUpdateSize); memcpy(pUser, pOper->rowData, tsUserUpdateSize);
pOper->pObj = pUser; pOper->pObj = pUser;
@ -179,7 +179,7 @@ static int32_t mnodeUpdateUser(SUserObj *pUser) {
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
return code; return code;
@ -192,18 +192,18 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) {
} }
if (name[0] == 0) { if (name[0] == 0) {
return TSDB_CODE_INVALID_USER_FORMAT; return TSDB_CODE_MND_INVALID_USER_FORMAT;
} }
if (pass[0] == 0) { if (pass[0] == 0) {
return TSDB_CODE_INVALID_PASS_FORMAT; return TSDB_CODE_MND_INVALID_PASS_FORMAT;
} }
SUserObj *pUser = mnodeGetUser(name); SUserObj *pUser = mnodeGetUser(name);
if (pUser != NULL) { if (pUser != NULL) {
mTrace("user:%s, is already there", name); mTrace("user:%s, is already there", name);
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_USER_ALREADY_EXIST; return TSDB_CODE_MND_USER_ALREADY_EXIST;
} }
code = grantCheck(TSDB_GRANT_USER); code = grantCheck(TSDB_GRANT_USER);
@ -232,7 +232,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) {
code = sdbInsertRow(&oper); code = sdbInsertRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tfree(pUser); tfree(pUser);
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
return code; return code;
@ -247,7 +247,7 @@ static int32_t mnodeDropUser(SUserObj *pUser) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
return code; return code;
@ -256,7 +256,7 @@ static int32_t mnodeDropUser(SUserObj *pUser) {
static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mnodeGetUserFromConn(pConn); SUserObj *pUser = mnodeGetUserFromConn(pConn);
if (pUser == NULL) { if (pUser == NULL) {
return TSDB_CODE_NO_USER_FROM_CONN; return TSDB_CODE_MND_NO_USER_FROM_CONN;
} }
int32_t cols = 0; int32_t cols = 0;
@ -369,7 +369,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
} }
} else { } else {
mError("user:%s, no rights to create user", pOperUser->user); mError("user:%s, no rights to create user", pOperUser->user);
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_MND_NO_RIGHTS;
} }
return code; return code;
@ -382,12 +382,12 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
SCMAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; SCMAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
SUserObj *pUser = mnodeGetUser(pAlter->user); SUserObj *pUser = mnodeGetUser(pAlter->user);
if (pUser == NULL) { if (pUser == NULL) {
return TSDB_CODE_INVALID_USER; return TSDB_CODE_MND_INVALID_USER;
} }
if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) {
@ -413,7 +413,7 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} else { } else {
mError("user:%s, no rights to alter user", pOperUser->user); mError("user:%s, no rights to alter user", pOperUser->user);
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_MND_NO_RIGHTS;
} }
} else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { } else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) {
bool hasRight = false; bool hasRight = false;
@ -454,11 +454,11 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} else { } else {
mError("user:%s, no rights to alter user", pOperUser->user); mError("user:%s, no rights to alter user", pOperUser->user);
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_MND_NO_RIGHTS;
} }
} else { } else {
mError("user:%s, no rights to alter user", pOperUser->user); mError("user:%s, no rights to alter user", pOperUser->user);
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_MND_NO_RIGHTS;
} }
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
@ -472,13 +472,13 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) {
SCMDropUserMsg *pDrop = pMsg->rpcMsg.pCont; SCMDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
SUserObj *pUser = mnodeGetUser(pDrop->user); SUserObj *pUser = mnodeGetUser(pDrop->user);
if (pUser == NULL) { if (pUser == NULL) {
return TSDB_CODE_INVALID_USER; return TSDB_CODE_MND_INVALID_USER;
} }
if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 || if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 ||
(strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) {
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
bool hasRight = false; bool hasRight = false;
@ -502,7 +502,7 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) {
mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} }
} else { } else {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_MND_NO_RIGHTS;
} }
mnodeDecUserRef(pUser); mnodeDecUserRef(pUser);
@ -540,15 +540,15 @@ void mnodeDropAllUsers(SAcctObj *pAcct) {
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) { int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
*secret = 0; *secret = 0;
mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_NOT_READY)); mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_RPC_NOT_READY));
return TSDB_CODE_NOT_READY; return TSDB_CODE_RPC_NOT_READY;
} }
SUserObj *pUser = mnodeGetUser(user); SUserObj *pUser = mnodeGetUser(user);
if (pUser == NULL) { if (pUser == NULL) {
*secret = 0; *secret = 0;
mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_INVALID_USER)); mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_MND_INVALID_USER));
return TSDB_CODE_INVALID_USER; return TSDB_CODE_MND_INVALID_USER;
} else { } else {
*spi = 1; *spi = 1;
*encrypt = 0; *encrypt = 0;

View File

@ -68,7 +68,7 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) {
// refer to db // refer to db
SDbObj *pDb = mnodeGetDb(pVgroup->dbName); SDbObj *pDb = mnodeGetDb(pVgroup->dbName);
if (pDb == NULL) { if (pDb == NULL) {
return TSDB_CODE_INVALID_DB; return TSDB_CODE_MND_INVALID_DB;
} }
pVgroup->pDb = pDb; pVgroup->pDb = pDb;
@ -185,7 +185,7 @@ static int32_t mnodeVgroupActionEncode(SSdbOper *pOper) {
static int32_t mnodeVgroupActionDecode(SSdbOper *pOper) { static int32_t mnodeVgroupActionDecode(SSdbOper *pOper) {
SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj));
if (pVgroup == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pVgroup, pOper->rowData, tsVgUpdateSize); memcpy(pVgroup, pOper->rowData, tsVgUpdateSize);
pOper->pObj = pVgroup; pOper->pObj = pVgroup;
@ -307,7 +307,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
if (balanceAllocVnodes(pVgroup) != 0) { if (balanceAllocVnodes(pVgroup) != 0) {
mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes); mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes);
free(pVgroup); free(pVgroup);
return TSDB_CODE_NO_ENOUGH_DNODES; return TSDB_CODE_MND_NO_ENOUGH_DNODES;
} }
SSdbOper oper = { SSdbOper oper = {
@ -320,7 +320,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
int32_t code = sdbInsertRow(&oper); int32_t code = sdbInsertRow(&oper);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tfree(pVgroup); tfree(pVgroup);
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_MND_SDB_ERROR;
} }
mPrint("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); mPrint("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes);
@ -333,7 +333,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
pMsg->expected = pVgroup->numOfVnodes; pMsg->expected = pVgroup->numOfVnodes;
mnodeSendCreateVgroupMsg(pVgroup, pMsg); mnodeSendCreateVgroupMsg(pVgroup, pMsg);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) {
@ -358,7 +358,7 @@ void mnodeCleanupVgroups() {
int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SDbObj *pDb = mnodeGetDb(pShow->db); SDbObj *pDb = mnodeGetDb(pShow->db);
if (pDb == NULL) { if (pDb == NULL) {
return TSDB_CODE_DB_NOT_SELECTED; return TSDB_CODE_MND_DB_NOT_SELECTED;
} }
int32_t cols = 0; int32_t cols = 0;
@ -383,11 +383,11 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
pTable = mnodeGetTable(pShow->payload); pTable = mnodeGetTable(pShow->payload);
if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) {
mnodeDecTableRef(pTable); mnodeDecTableRef(pTable);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} }
mnodeDecTableRef(pTable); mnodeDecTableRef(pTable);
pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId); pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId);
if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID; if (NULL == pVgroup) return TSDB_CODE_MND_INVALID_TABLE_NAME;
mnodeDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica;
} else { } else {
@ -643,7 +643,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
}; };
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != 0) { if (code != 0) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
dnodeSendRpcMnodeWriteRsp(mnodeMsg, code); dnodeSendRpcMnodeWriteRsp(mnodeMsg, code);
@ -704,7 +704,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
}; };
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code != 0) { if (code != 0) {
code = TSDB_CODE_SDB_ERROR; code = TSDB_CODE_MND_SDB_ERROR;
} }
dnodeReprocessMnodeWriteMsg(mnodeMsg); dnodeReprocessMnodeWriteMsg(mnodeMsg);
@ -718,14 +718,14 @@ static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) {
SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnodeId); SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId); mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId);
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_MND_VGROUP_NOT_EXIST;
} }
mnodeDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId); SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId); mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId);
return TSDB_CODE_INVALID_VGROUP_ID; return TSDB_CODE_MND_VGROUP_NOT_EXIST;
} }
mnodeDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);

View File

@ -44,7 +44,7 @@ void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg))
int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
if (pMsg->rpcMsg.pCont == NULL) { if (pMsg->rpcMsg.pCont == NULL) {
mError("%p, msg:%s in mwrite queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mwrite queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_INVALID_MSG_LEN; return TSDB_CODE_MND_INVALID_MSG_LEN;
} }
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
@ -59,12 +59,12 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i]));
} }
return TSDB_CODE_REDIRECT; return TSDB_CODE_RPC_REDIRECT;
} }
if (tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType] == NULL) { if (tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType] == NULL) {
mError("%p, msg:%s in mwrite queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mwrite queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_MSG_NOT_PROCESSED; return TSDB_CODE_MND_MSG_NOT_PROCESSED;
} }
int32_t code = mnodeInitMsg(pMsg); int32_t code = mnodeInitMsg(pMsg);
@ -75,7 +75,7 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
if (!pMsg->pUser->writeAuth) { if (!pMsg->pUser->writeAuth) {
mError("%p, msg:%s in mwrite queue, not processed, no write auth", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); mError("%p, msg:%s in mwrite queue, not processed, no write auth", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
return TSDB_CODE_NO_RIGHTS; return TSDB_CODE_MND_NO_RIGHTS;
} }
return (*tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType])(pMsg); return (*tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType])(pMsg);

View File

@ -229,7 +229,7 @@ static void taosGetSystemLocale() { // get and set default locale
uError("can't get locale from system, set it to en_US.UTF-8"); uError("can't get locale from system, set it to en_US.UTF-8");
strcpy(tsLocale, "en_US.UTF-8"); strcpy(tsLocale, "en_US.UTF-8");
} else { } else {
strncpy(tsLocale, locale, tListLen(tsLocale)); tstrncpy(tsLocale, locale, tListLen(tsLocale));
uError("locale not configured, set to system default:%s", tsLocale); uError("locale not configured, set to system default:%s", tsLocale);
} }
} }
@ -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

View File

@ -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); }

View File

@ -443,9 +443,9 @@ void httpJsonPairStatus(JsonBuf* buf, int code) {
httpJsonPairIntVal(buf, "code", 4, code); httpJsonPairIntVal(buf, "code", 4, code);
if (code >= 0) { if (code >= 0) {
httpJsonItemToken(buf); httpJsonItemToken(buf);
if (code == TSDB_CODE_DB_NOT_SELECTED) { if (code == TSDB_CODE_MND_DB_NOT_SELECTED) {
httpJsonPair(buf, "desc", 4, "failed to create database", 23); httpJsonPair(buf, "desc", 4, "failed to create database", 23);
} else if (code == TSDB_CODE_INVALID_TABLE_ID) { } else if (code == TSDB_CODE_MND_INVALID_TABLE_NAME) {
httpJsonPair(buf, "desc", 4, "failed to create table", 22); httpJsonPair(buf, "desc", 4, "failed to create table", 22);
} else } else
httpJsonPair(buf, "desc", 4, (char*)tstrerror(code), (int)strlen(tstrerror(code))); httpJsonPair(buf, "desc", 4, (char*)tstrerror(code), (int)strlen(tstrerror(code)));

View File

@ -80,14 +80,14 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) {
HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos; HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos;
char * sql = httpGetCmdsString(pContext, singleCmd->sql); char * sql = httpGetCmdsString(pContext, singleCmd->sql);
if (code == TSDB_CODE_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%s:inprogress, sql:%s", httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%s:inprogress, sql:%s",
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql); pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql);
return; return;
} }
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);
@ -234,7 +234,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) {
HttpEncodeMethod *encode = pContext->encodeMethod; HttpEncodeMethod *encode = pContext->encodeMethod;
if (code == TSDB_CODE_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s:inprogress, sqlObj:%p", httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s:inprogress, sqlObj:%p",
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), (SSqlObj *)result); pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), (SSqlObj *)result);
return; return;
@ -242,7 +242,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) {
if (code < 0) { if (code < 0) {
SSqlObj *pObj = (SSqlObj *)result; SSqlObj *pObj = (SSqlObj *)result;
if (code == TSDB_CODE_INVALID_SQL) { if (code == TSDB_CODE_TSC_INVALID_SQL) {
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p, error:%s", httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p, error:%s",
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj, pObj->cmd.payload); pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj, pObj->cmd.payload);
httpSendTaosdInvalidSqlErrorResp(pContext, pObj->cmd.payload); httpSendTaosdInvalidSqlErrorResp(pContext, pObj->cmd.payload);

View File

@ -32,12 +32,12 @@ bool httpCheckUsedbSql(char *sql) {
void httpTimeToString(time_t t, char *buf, int buflen) { void httpTimeToString(time_t t, char *buf, int buflen) {
memset(buf, 0, (size_t)buflen); memset(buf, 0, (size_t)buflen);
char ts[30] = {0}; char ts[32] = {0};
struct tm *ptm; struct tm *ptm;
time_t tt = t / 1000; time_t tt = t / 1000;
ptm = localtime(&tt); ptm = localtime(&tt);
strftime(ts, 64, "%Y-%m-%d %H:%M:%S", ptm); strftime(ts, 31, "%Y-%m-%d %H:%M:%S", ptm);
sprintf(buf, "%s.%03ld", ts, t % 1000); sprintf(buf, "%s.%03ld", ts, t % 1000);
} }

View File

@ -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);

View File

@ -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;
} }
@ -313,7 +320,7 @@ bool tgGetPassFromUrl(HttpContext *pContext) {
return false; return false;
} }
strcpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos); tstrncpy(pContext->pass, pParser->path[TG_PASS_URL_POS].pos, TSDB_PASSWORD_LEN);
return true; return true;
} }

View File

@ -103,7 +103,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) {
if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) { if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) {
if (cmd->cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { if (cmd->cmdState == HTTP_CMD_STATE_NOT_RUN_YET) {
if (code == TSDB_CODE_DB_NOT_SELECTED || code == TSDB_CODE_INVALID_DB) { if (code == TSDB_CODE_MND_DB_NOT_SELECTED || code == TSDB_CODE_MND_INVALID_DB) {
cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED;
if (multiCmds->cmds[0].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { if (multiCmds->cmds[0].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) {
multiCmds->pos = (int16_t)-1; multiCmds->pos = (int16_t)-1;
@ -111,7 +111,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) {
pContext->ipstr); pContext->ipstr);
return false; return false;
} }
} else if (code == TSDB_CODE_INVALID_TABLE_ID) { } else if (code == TSDB_CODE_MND_INVALID_TABLE_NAME) {
cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED;
if (multiCmds->cmds[multiCmds->pos - 1].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { if (multiCmds->cmds[multiCmds->pos - 1].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) {
multiCmds->pos = (int16_t)(multiCmds->pos - 2); multiCmds->pos = (int16_t)(multiCmds->pos - 2);

View File

@ -207,7 +207,7 @@ static void monitorInitDatabase() {
} }
static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) {
if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) { if (-code == TSDB_CODE_MND_TABLE_ALREADY_EXIST || -code == TSDB_CODE_MND_DB_ALREADY_EXIST || code >= 0) {
monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) {
monitorPrint("dnode:%s is started", tsLocalEp); monitorPrint("dnode:%s is started", tsLocalEp);

View File

@ -322,7 +322,7 @@ enum {
#define NORMAL_ARITHMETIC 1 #define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2 #define AGG_ARIGHTMEIC 2
int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pSql); SSqlInfo qSQLParse(const char *str);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -373,7 +373,6 @@ static SWindowResult *doSetTimeWindowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin
SPosInfo pos = {-1, -1}; SPosInfo pos = {-1, -1};
createQueryResultInfo(pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &pos); createQueryResultInfo(pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &pos);
} }
pWindowResInfo->capacity = newCap; pWindowResInfo->capacity = newCap;
} }
@ -789,11 +788,10 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
sas->data = calloc(pQuery->numOfCols, POINTER_BYTES); sas->data = calloc(pQuery->numOfCols, POINTER_BYTES);
// here the pQuery->colList and sas->colList are identical // here the pQuery->colList and sas->colList are identical
int32_t numOfCols = taosArrayGetSize(pDataBlock);
for (int32_t i = 0; i < pQuery->numOfCols; ++i) { for (int32_t i = 0; i < pQuery->numOfCols; ++i) {
SColumnInfo *pColMsg = &pQuery->colList[i]; SColumnInfo *pColMsg = &pQuery->colList[i];
int32_t numOfCols = taosArrayGetSize(pDataBlock);
dataBlock = NULL; dataBlock = NULL;
for (int32_t k = 0; k < numOfCols; ++k) { //todo refactor for (int32_t k = 0; k < numOfCols; ++k) { //todo refactor
SColumnInfoData *p = taosArrayGet(pDataBlock, k); SColumnInfoData *p = taosArrayGet(pDataBlock, k);
@ -1437,7 +1435,7 @@ _clean:
tfree(pRuntimeEnv->resultInfo); tfree(pRuntimeEnv->resultInfo);
tfree(pRuntimeEnv->pCtx); tfree(pRuntimeEnv->pCtx);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY;
} }
static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
@ -1478,7 +1476,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
} }
static bool isQueryKilled(SQInfo *pQInfo) { static bool isQueryKilled(SQInfo *pQInfo) {
return (pQInfo->code == TSDB_CODE_QUERY_CANCELLED); return (pQInfo->code == TSDB_CODE_TSC_QUERY_CANCELLED);
#if 0 #if 0
/* /*
* check if the queried meter is going to be deleted. * check if the queried meter is going to be deleted.
@ -1494,7 +1492,7 @@ static bool isQueryKilled(SQInfo *pQInfo) {
#endif #endif
} }
static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_QUERY_CANCELLED; } static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; }
static bool isFixedOutputQuery(SQuery *pQuery) { static bool isFixedOutputQuery(SQuery *pQuery) {
if (pQuery->intervalTime != 0) { if (pQuery->intervalTime != 0) {
@ -1567,11 +1565,6 @@ static bool isFirstLastRowQuery(SQuery *pQuery) {
return false; return false;
} }
static UNUSED_FUNC bool notHasQueryTimeRange(SQuery *pQuery) {
return (pQuery->window.skey == 0 && pQuery->window.ekey == INT64_MAX && QUERY_IS_ASC_QUERY(pQuery)) ||
(pQuery->window.skey == INT64_MAX && pQuery->window.ekey == 0 && (!QUERY_IS_ASC_QUERY(pQuery)));
}
static bool needReverseScan(SQuery *pQuery) { static bool needReverseScan(SQuery *pQuery) {
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionId = pQuery->pSelectExpr[i].base.functionId; int32_t functionId = pQuery->pSelectExpr[i].base.functionId;
@ -1590,8 +1583,11 @@ static bool needReverseScan(SQuery *pQuery) {
static bool onlyQueryTags(SQuery* pQuery) { static bool onlyQueryTags(SQuery* pQuery) {
for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { for(int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionId = pQuery->pSelectExpr[i].base.functionId; SExprInfo* pExprInfo = &pQuery->pSelectExpr[i];
if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG) {
int32_t functionId = pExprInfo->base.functionId;
if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG &&
(!(functionId == TSDB_FUNC_COUNT && pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX))) {
return false; return false;
} }
} }
@ -1766,61 +1762,6 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool stableQuery) {
} }
} }
static UNUSED_FUNC void doSetInterpVal(SQLFunctionCtx *pCtx, TSKEY ts, int16_t type, int32_t index, char *data) {
assert(pCtx->param[index].pz == NULL);
int32_t len = 0;
size_t t = 0;
if (type == TSDB_DATA_TYPE_BINARY) {
t = strlen(data);
len = t + 1 + TSDB_KEYSIZE;
pCtx->param[index].pz = calloc(1, len);
} else if (type == TSDB_DATA_TYPE_NCHAR) {
t = wcslen((const wchar_t *)data);
len = (t + 1) * TSDB_NCHAR_SIZE + TSDB_KEYSIZE;
pCtx->param[index].pz = calloc(1, len);
} else {
len = TSDB_KEYSIZE * 2;
pCtx->param[index].pz = malloc(len);
}
pCtx->param[index].nType = TSDB_DATA_TYPE_BINARY;
char *z = pCtx->param[index].pz;
*(TSKEY *)z = ts;
z += TSDB_KEYSIZE;
switch (type) {
case TSDB_DATA_TYPE_FLOAT:
*(double *)z = GET_FLOAT_VAL(data);
break;
case TSDB_DATA_TYPE_DOUBLE:
*(double *)z = GET_DOUBLE_VAL(data);
break;
case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_TIMESTAMP:
*(int64_t *)z = GET_INT64_VAL(data);
break;
case TSDB_DATA_TYPE_BINARY:
strncpy(z, data, t);
break;
case TSDB_DATA_TYPE_NCHAR: {
wcsncpy((wchar_t *)z, (const wchar_t *)data, t);
} break;
default:
assert(0);
}
pCtx->param[index].nLen = len;
}
static int32_t getInitialPageNum(SQInfo *pQInfo) { static int32_t getInitialPageNum(SQInfo *pQInfo) {
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
int32_t INITIAL_RESULT_ROWS_VALUE = 16; int32_t INITIAL_RESULT_ROWS_VALUE = 16;
@ -2099,7 +2040,8 @@ static void ensureOutputBuffer(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pB
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t bytes = pQuery->pSelectExpr[i].bytes; int32_t bytes = pQuery->pSelectExpr[i].bytes;
assert(bytes > 0 && newSize > 0);
char *tmp = realloc(pQuery->sdata[i], bytes * newSize + sizeof(tFilePage)); char *tmp = realloc(pQuery->sdata[i], bytes * newSize + sizeof(tFilePage));
if (tmp == NULL) { // todo handle the oom if (tmp == NULL) { // todo handle the oom
assert(0); assert(0);
@ -4068,45 +4010,19 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool
initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, rows, 4096, type); initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, rows, 4096, type);
} }
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
/*
* in case of last_row query without query range, we set the query timestamp to be
* STable->lastKey. Otherwise, keep the initial query time range unchanged.
*/
// if (isFirstLastRowQuery(pQuery)) {
// if (!normalizeUnBoundLastRowQuery(pQInfo, &interpInfo)) {
// sem_post(&pQInfo->dataReady);
// pointInterpSupporterDestroy(&interpInfo);
// return TSDB_CODE_SUCCESS;
// }
// }
if (pQuery->fillType != TSDB_FILL_NONE && !isPointInterpoQuery(pQuery)) { if (pQuery->fillType != TSDB_FILL_NONE && !isPointInterpoQuery(pQuery)) {
SFillColInfo* pColInfo = taosCreateFillColInfo(pQuery); SFillColInfo* pColInfo = taosCreateFillColInfo(pQuery);
pRuntimeEnv->pFillInfo = taosInitFillInfo(pQuery->order.order, 0, 0, pQuery->rec.capacity, pQuery->numOfOutput, pRuntimeEnv->pFillInfo = taosInitFillInfo(pQuery->order.order, 0, 0, pQuery->rec.capacity, pQuery->numOfOutput,
pQuery->slidingTime, pQuery->fillType, pColInfo); pQuery->slidingTime, pQuery->fillType, pColInfo);
} }
// todo refactor
pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery); pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery);
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static UNUSED_FUNC bool isGroupbyEachTable(SSqlGroupbyExpr *pGroupbyExpr, STableGroupInfo *pSidset) {
if (pGroupbyExpr == NULL || pGroupbyExpr->numOfGroupCols == 0) {
return false;
}
for (int32_t i = 0; i < pGroupbyExpr->numOfGroupCols; ++i) {
SColIndex* pColIndex = taosArrayGet(pGroupbyExpr->columnInfo, i);
if (pColIndex->flag == TSDB_COL_TAG) {
return true;
}
}
return false;
}
static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
@ -4885,6 +4801,10 @@ static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pE
int32_t j = 0; int32_t j = 0;
if (TSDB_COL_IS_TAG(pExprMsg->colInfo.flag)) { if (TSDB_COL_IS_TAG(pExprMsg->colInfo.flag)) {
if (pExprMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
return -1;
}
while(j < pQueryMsg->numOfTags) { while(j < pQueryMsg->numOfTags) {
if (pExprMsg->colInfo.colId == pTagCols[j].colId) { if (pExprMsg->colInfo.colId == pTagCols[j].colId) {
return j; return j;
@ -4942,8 +4862,11 @@ static bool validateQuerySourceCols(SQueryTableMsg *pQueryMsg, SSqlFuncMsg** pEx
return false; return false;
} else if (numOfTotal == 0) { } else if (numOfTotal == 0) {
for(int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) { for(int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) {
if ((pExprMsg[i]->functionId == TSDB_FUNC_TAGPRJ) || SSqlFuncMsg* pFuncMsg = pExprMsg[i];
(pExprMsg[i]->functionId == TSDB_FUNC_TID_TAG && pExprMsg[i]->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX)) {
if ((pFuncMsg->functionId == TSDB_FUNC_TAGPRJ) ||
(pFuncMsg->functionId == TSDB_FUNC_TID_TAG && pFuncMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) ||
(pFuncMsg->functionId == TSDB_FUNC_COUNT && pFuncMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX)) {
continue; continue;
} }
@ -5009,7 +4932,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
// query msg safety check // query msg safety check
if (!validateQueryMsg(pQueryMsg)) { if (!validateQueryMsg(pQueryMsg)) {
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
char *pMsg = (char *)(pQueryMsg->colList) + sizeof(SColumnInfo) * pQueryMsg->numOfCols; char *pMsg = (char *)(pQueryMsg->colList) + sizeof(SColumnInfo) * pQueryMsg->numOfCols;
@ -5079,14 +5002,14 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
} }
} }
if (pExprMsg->functionId == TSDB_FUNC_TAG || pExprMsg->functionId == TSDB_FUNC_TAGPRJ || int16_t functionId = pExprMsg->functionId;
pExprMsg->functionId == TSDB_FUNC_TAG_DUMMY) { if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG_DUMMY) {
if (pExprMsg->colInfo.flag != TSDB_COL_TAG) { // ignore the column index check for arithmetic expression. if (pExprMsg->colInfo.flag != TSDB_COL_TAG) { // ignore the column index check for arithmetic expression.
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
} else { } else {
// if (!validateExprColumnInfo(pQueryMsg, pExprMsg)) { // if (!validateExprColumnInfo(pQueryMsg, pExprMsg)) {
// return TSDB_CODE_INVALID_QUERY_MSG; // return TSDB_CODE_QRY_INVALID_MSG;
// } // }
} }
@ -5096,7 +5019,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
if (!validateQuerySourceCols(pQueryMsg, *pExpr)) { if (!validateQuerySourceCols(pQueryMsg, *pExpr)) {
tfree(*pExpr); tfree(*pExpr);
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
pMsg = createTableIdList(pQueryMsg, pMsg, pTableIdList); pMsg = createTableIdList(pQueryMsg, pMsg, pTableIdList);
@ -5185,21 +5108,21 @@ static int32_t buildAirthmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable
if (pExprNode == NULL) { if (pExprNode == NULL) {
qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz); qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_QRY_APP_ERROR;
} }
pArithExprInfo->pExpr = pExprNode; pArithExprInfo->pExpr = pExprNode;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
SColumnInfo* pTagCols) { SColumnInfo* pTagCols) {
*pExprInfo = NULL; *pExprInfo = NULL;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SExprInfo *pExprs = (SExprInfo *)calloc(1, sizeof(SExprInfo) * pQueryMsg->numOfOutput); SExprInfo *pExprs = (SExprInfo *)calloc(pQueryMsg->numOfOutput, sizeof(SExprInfo));
if (pExprs == NULL) { if (pExprs == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY;
} }
bool isSuperTable = QUERY_IS_STABLE_QUERY(pQueryMsg->queryType); bool isSuperTable = QUERY_IS_STABLE_QUERY(pQueryMsg->queryType);
@ -5223,23 +5146,29 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo
type = TSDB_DATA_TYPE_DOUBLE; type = TSDB_DATA_TYPE_DOUBLE;
bytes = tDataTypeDesc[type].nSize; bytes = tDataTypeDesc[type].nSize;
} else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { // parse the normal column } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX && pExprs[i].base.functionId == TSDB_FUNC_TAGPRJ) { // parse the normal column
type = TSDB_DATA_TYPE_BINARY; type = TSDB_DATA_TYPE_BINARY;
bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
} else{ } else {
int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols);
assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags); assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX);
if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX) {
SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j];
type = pCol->type;
bytes = pCol->bytes;
} else {
type = TSDB_DATA_TYPE_BINARY;
bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
}
SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j];
type = pCol->type;
bytes = pCol->bytes;
} }
int32_t param = pExprs[i].base.arg[0].argValue.i64; int32_t param = pExprs[i].base.arg[0].argValue.i64;
if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].type, &pExprs[i].bytes, if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].type, &pExprs[i].bytes,
&pExprs[i].interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { &pExprs[i].interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) {
tfree(pExprs); tfree(pExprs);
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
if (pExprs[i].base.functionId == TSDB_FUNC_TAG_DUMMY || pExprs[i].base.functionId == TSDB_FUNC_TS_DUMMY) { if (pExprs[i].base.functionId == TSDB_FUNC_TAG_DUMMY || pExprs[i].base.functionId == TSDB_FUNC_TS_DUMMY) {
@ -5280,7 +5209,7 @@ static SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SCol
// using group by tag columns // using group by tag columns
SSqlGroupbyExpr *pGroupbyExpr = (SSqlGroupbyExpr *)calloc(1, sizeof(SSqlGroupbyExpr)); SSqlGroupbyExpr *pGroupbyExpr = (SSqlGroupbyExpr *)calloc(1, sizeof(SSqlGroupbyExpr));
if (pGroupbyExpr == NULL) { if (pGroupbyExpr == NULL) {
*code = TSDB_CODE_SERV_OUT_OF_MEMORY; *code = TSDB_CODE_QRY_OUT_OF_MEMORY;
return NULL; return NULL;
} }
@ -5328,7 +5257,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) {
if (lower == TSDB_RELATION_INVALID && upper == TSDB_RELATION_INVALID) { if (lower == TSDB_RELATION_INVALID && upper == TSDB_RELATION_INVALID) {
qError("QInfo:%p invalid filter info", pQInfo); qError("QInfo:%p invalid filter info", pQInfo);
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
int16_t type = pQuery->colList[i].type; int16_t type = pQuery->colList[i].type;
@ -5340,7 +5269,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) {
if (rangeFilterArray == NULL && filterArray == NULL) { if (rangeFilterArray == NULL && filterArray == NULL) {
qError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type); qError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type);
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
if ((lower == TSDB_RELATION_GREATER_EQUAL || lower == TSDB_RELATION_GREATER) && if ((lower == TSDB_RELATION_GREATER_EQUAL || lower == TSDB_RELATION_GREATER) &&
@ -5364,7 +5293,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) {
if (upper != TSDB_RELATION_INVALID) { if (upper != TSDB_RELATION_INVALID) {
qError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type); qError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type);
return TSDB_CODE_INVALID_QUERY_MSG; return TSDB_CODE_QRY_INVALID_MSG;
} }
} else { } else {
pSingleColFilter->fp = filterArray[upper]; pSingleColFilter->fp = filterArray[upper];
@ -5813,18 +5742,18 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
if (pQueryMsg->numOfTables <= 0) { if (pQueryMsg->numOfTables <= 0) {
qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables); qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables);
code = TSDB_CODE_INVALID_QUERY_MSG; code = TSDB_CODE_QRY_INVALID_MSG;
goto _over; goto _over;
} }
if (pTableIdList == NULL || taosArrayGetSize(pTableIdList) == 0) { if (pTableIdList == NULL || taosArrayGetSize(pTableIdList) == 0) {
qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg); qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg);
code = TSDB_CODE_INVALID_QUERY_MSG; code = TSDB_CODE_QRY_INVALID_MSG;
goto _over; goto _over;
} }
SExprInfo *pExprs = NULL; SExprInfo *pExprs = NULL;
if ((code = createSqlFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { if ((code = createQFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) {
goto _over; goto _over;
} }
@ -5882,7 +5811,7 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
(*pQInfo) = createQInfoImpl(pQueryMsg, pTableIdList, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo); (*pQInfo) = createQInfoImpl(pQueryMsg, pTableIdList, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo);
if ((*pQInfo) == NULL) { if ((*pQInfo) == NULL) {
code = TSDB_CODE_SERV_OUT_OF_MEMORY; code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _over; goto _over;
} }
@ -5891,10 +5820,11 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
_over: _over:
tfree(tagCond); tfree(tagCond);
tfree(tbnameCond); tfree(tbnameCond);
tfree(pGroupColIndex);
taosArrayDestroy(pTableIdList); taosArrayDestroy(pTableIdList);
//pQInfo already freed in initQInfo, but *pQInfo may not pointer to null;
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
//pQInfo already freed in initQInfo, but *pQInfo may not pointer to null;
*pQInfo = NULL; *pQInfo = NULL;
} }
@ -5926,6 +5856,7 @@ void qTableQuery(qinfo_t qinfo) {
qTrace("QInfo:%p query task is launched", pQInfo); qTrace("QInfo:%p query task is launched", pQInfo);
if (onlyQueryTags(pQInfo->runtimeEnv.pQuery)) { if (onlyQueryTags(pQInfo->runtimeEnv.pQuery)) {
assert(pQInfo->runtimeEnv.pQueryHandle == NULL);
buildTagQueryResult(pQInfo); // todo support the limit/offset buildTagQueryResult(pQInfo); // todo support the limit/offset
} else if (pQInfo->runtimeEnv.stableQuery) { } else if (pQInfo->runtimeEnv.stableQuery) {
stableQueryImpl(pQInfo); stableQueryImpl(pQInfo);
@ -5941,7 +5872,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo) {
SQInfo *pQInfo = (SQInfo *)qinfo; SQInfo *pQInfo = (SQInfo *)qinfo;
if (pQInfo == NULL || !isValidQInfo(pQInfo)) { if (pQInfo == NULL || !isValidQInfo(pQInfo)) {
return TSDB_CODE_INVALID_QHANDLE; return TSDB_CODE_QRY_INVALID_QHANDLE;
} }
SQuery *pQuery = pQInfo->runtimeEnv.pQuery; SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
@ -5980,7 +5911,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
SQInfo *pQInfo = (SQInfo *)qinfo; SQInfo *pQInfo = (SQInfo *)qinfo;
if (pQInfo == NULL || !isValidQInfo(pQInfo)) { if (pQInfo == NULL || !isValidQInfo(pQInfo)) {
return TSDB_CODE_INVALID_QHANDLE; return TSDB_CODE_QRY_INVALID_QHANDLE;
} }
SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
@ -6016,36 +5947,35 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
} }
return code; return code;
// if (numOfRows == 0 && (pRetrieve->qhandle == (uint64_t)pObj->qhandle) && (code != TSDB_CODE_ACTION_IN_PROGRESS)) {
// qTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code);
// vnodeDecRefCount(pObj->qhandle);
// pObj->qhandle = NULL;
// }
} }
static void buildTagQueryResult(SQInfo* pQInfo) { static void buildTagQueryResult(SQInfo* pQInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
SQuery * pQuery = pRuntimeEnv->pQuery; SQuery * pQuery = pRuntimeEnv->pQuery;
size_t num = taosArrayGetSize(pQInfo->groupInfo.pGroupList); size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList);
assert(num == 0 || num == 1); assert(numOfGroup == 0 || numOfGroup == 1);
if (num == 0) {
if (numOfGroup == 0) {
return; return;
} }
SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0);
num = taosArrayGetSize(pa);
size_t num = taosArrayGetSize(pa);
assert(num == pQInfo->groupInfo.numOfTables); assert(num == pQInfo->groupInfo.numOfTables);
int32_t count = 0;
int32_t functionId = pQuery->pSelectExpr[0].base.functionId; int32_t functionId = pQuery->pSelectExpr[0].base.functionId;
if (functionId == TSDB_FUNC_TID_TAG) { // return the tags & table Id if (functionId == TSDB_FUNC_TID_TAG) { // return the tags & table Id
assert(pQuery->numOfOutput == 1); assert(pQuery->numOfOutput == 1);
SExprInfo* pExprInfo = &pQuery->pSelectExpr[0]; SExprInfo* pExprInfo = &pQuery->pSelectExpr[0];
int32_t rsize = pExprInfo->bytes; int32_t rsize = pExprInfo->bytes;
count = 0;
for(int32_t i = 0; i < num; ++i) {
while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) {
int32_t i = pQInfo->tableIndex++;
SGroupItem *item = taosArrayGet(pa, i); SGroupItem *item = taosArrayGet(pa, i);
char *output = pQuery->sdata[0]->data + i * rsize; char *output = pQuery->sdata[0]->data + i * rsize;
@ -6085,30 +6015,38 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
} }
} }
} }
count += 1;
} }
pQInfo->tableIndex = pQInfo->groupInfo.numOfTables; qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, count);
qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, num);
} else if (functionId == TSDB_FUNC_COUNT) {// handle the "count(tbname)" query
*(int64_t*) pQuery->sdata[0]->data = num;
count = 1;
pQInfo->tableIndex = num; //set query completed
qTrace("QInfo:%p create count(tbname) query, res:%d rows:1", pQInfo, count);
} else { // return only the tags|table name etc. } else { // return only the tags|table name etc.
for(int32_t i = 0; i < num; ++i) { count = 0;
while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) {
int32_t i = pQInfo->tableIndex++;
SExprInfo* pExprInfo = pQuery->pSelectExpr; SExprInfo* pExprInfo = pQuery->pSelectExpr;
SGroupItem* item = taosArrayGet(pa, i); SGroupItem* item = taosArrayGet(pa, i);
for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { for(int32_t j = 0; j < pQuery->numOfOutput; ++j) {
// todo check the return value, refactor codes
if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
char* data = tsdbGetTableName(pQInfo->tsdb, &item->id); char* data = tsdbGetTableName(pQInfo->tsdb, &item->id);
char* dst = pQuery->sdata[j]->data + count * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE);
char* dst = pQuery->sdata[j]->data + i * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE);
memcpy(dst, data, varDataTLen(data)); memcpy(dst, data, varDataTLen(data));
} else {// todo refactor } else {// todo refactor
int16_t type = pExprInfo[j].type; int16_t type = pExprInfo[j].type;
int16_t bytes = pExprInfo[j].bytes; int16_t bytes = pExprInfo[j].bytes;
char* data = tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo[j].base.colInfo.colId, type, bytes); char* data = tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo[j].base.colInfo.colId, type, bytes);
char* dst = pQuery->sdata[j]->data + count * pExprInfo[j].bytes;
char* dst = pQuery->sdata[j]->data + i * pExprInfo[j].bytes;
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
if (data == NULL) { if (data == NULL) {
setVardataNull(dst, type); setVardataNull(dst, type);
@ -6124,13 +6062,13 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
} }
} }
} }
count += 1;
} }
pQInfo->tableIndex = pQInfo->groupInfo.numOfTables; qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, count);
qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, num);
} }
pQuery->rec.rows = num; pQuery->rec.rows = count;
setQueryStatus(pQuery, QUERY_COMPLETED); setQueryStatus(pQuery, QUERY_COMPLETED);
} }

View File

@ -1035,7 +1035,7 @@ void exprTreeToBinary(SBufferWriter* bw, tExprNode* expr) {
static void* exception_calloc(size_t nmemb, size_t size) { static void* exception_calloc(size_t nmemb, size_t size) {
void* p = calloc(nmemb, size); void* p = calloc(nmemb, size);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
} }
return p; return p;
} }
@ -1043,7 +1043,7 @@ static void* exception_calloc(size_t nmemb, size_t size) {
static void* exception_malloc(size_t size) { static void* exception_malloc(size_t size) {
void* p = malloc(size); void* p = malloc(size);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
} }
return p; return p;
} }
@ -1051,7 +1051,7 @@ static void* exception_malloc(size_t size) {
static UNUSED_FUNC char* exception_strdup(const char* str) { static UNUSED_FUNC char* exception_strdup(const char* str) {
char* p = strdup(str); char* p = strdup(str);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); THROW(TSDB_CODE_QRY_OUT_OF_MEMORY);
} }
return p; return p;
} }

View File

@ -26,16 +26,18 @@
#include "tstrbuild.h" #include "tstrbuild.h"
#include "queryLog.h" #include "queryLog.h"
int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { SSqlInfo qSQLParse(const char *pStr) {
void *pParser = ParseAlloc(malloc); void *pParser = ParseAlloc(malloc);
pSQLInfo->valid = true;
SSqlInfo sqlInfo = {0};
sqlInfo.valid = true;
int32_t i = 0; int32_t i = 0;
while (1) { while (1) {
SSQLToken t0 = {0}; SSQLToken t0 = {0};
if (pStr[i] == 0) { if (pStr[i] == 0) {
Parse(pParser, 0, t0, pSQLInfo); Parse(pParser, 0, t0, &sqlInfo);
goto abort_parse; goto abort_parse;
} }
@ -49,19 +51,19 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) {
break; break;
} }
case TK_SEMI: { case TK_SEMI: {
Parse(pParser, 0, t0, pSQLInfo); Parse(pParser, 0, t0, &sqlInfo);
goto abort_parse; goto abort_parse;
} }
case TK_QUESTION: case TK_QUESTION:
case TK_ILLEGAL: { case TK_ILLEGAL: {
snprintf(pSQLInfo->pzErrMsg, tListLen(pSQLInfo->pzErrMsg), "unrecognized token: \"%s\"", t0.z); snprintf(sqlInfo.pzErrMsg, tListLen(sqlInfo.pzErrMsg), "unrecognized token: \"%s\"", t0.z);
pSQLInfo->valid = false; sqlInfo.valid = false;
goto abort_parse; goto abort_parse;
} }
default: default:
Parse(pParser, t0.type, t0, pSQLInfo); Parse(pParser, t0.type, t0, &sqlInfo);
if (pSQLInfo->valid == false) { if (sqlInfo.valid == false) {
goto abort_parse; goto abort_parse;
} }
} }
@ -69,7 +71,7 @@ int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) {
abort_parse: abort_parse:
ParseFree(pParser, free); ParseFree(pParser, free);
return 0; return sqlInfo;
} }
tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken *pToken) { tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken *pToken) {

View File

@ -28,19 +28,19 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si
if (!FD_VALID(pResBuf->fd)) { if (!FD_VALID(pResBuf->fd)) {
qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno));
return TSDB_CODE_CLI_NO_DISKSPACE; return TSDB_CODE_QRY_NO_DISKSPACE;
} }
int32_t ret = ftruncate(pResBuf->fd, pResBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE); int32_t ret = ftruncate(pResBuf->fd, pResBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno));
return TSDB_CODE_CLI_NO_DISKSPACE; return TSDB_CODE_QRY_NO_DISKSPACE;
} }
pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0); pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0);
if (pResBuf->pBuf == MAP_FAILED) { if (pResBuf->pBuf == MAP_FAILED) {
qError("QInfo:%p failed to map temp file: %s. %s", handle, pResBuf->path, strerror(errno)); qError("QInfo:%p failed to map temp file: %s. %s", handle, pResBuf->path, strerror(errno));
return TSDB_CODE_CLI_OUT_OF_MEMORY; // todo change error code return TSDB_CODE_QRY_OUT_OF_MEMORY; // todo change error code
} }
qTrace("QInfo:%p create tmp file for output result, %s, %" PRId64 "bytes", handle, pResBuf->path, qTrace("QInfo:%p create tmp file for output result, %s, %" PRId64 "bytes", handle, pResBuf->path,
@ -68,7 +68,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf
if (ret != 0) { if (ret != 0) {
// dError("QInfo:%p failed to create intermediate result output file:%s. %s", pQInfo, pSupporter->extBufFile, // dError("QInfo:%p failed to create intermediate result output file:%s. %s", pQInfo, pSupporter->extBufFile,
// strerror(errno)); // strerror(errno));
return -TSDB_CODE_SERV_NO_DISKSPACE; return -TSDB_CODE_QRY_NO_DISKSPACE;
} }
pResultBuf->totalBufSize = pResultBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE; pResultBuf->totalBufSize = pResultBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE;
@ -76,7 +76,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf
if (pResultBuf->pBuf == MAP_FAILED) { if (pResultBuf->pBuf == MAP_FAILED) {
// dError("QInfo:%p failed to map temp file: %s. %s", pQInfo, pSupporter->extBufFile, strerror(errno)); // dError("QInfo:%p failed to map temp file: %s. %s", pQInfo, pSupporter->extBufFile, strerror(errno));
return -TSDB_CODE_SERV_OUT_OF_MEMORY; return -TSDB_CODE_QRY_OUT_OF_MEMORY;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;

View File

@ -311,7 +311,7 @@ void calc_fn_i32_i32_sub(void *left, void *right, int32_t numLeft, int32_t numRi
if (numLeft == numRight) { if (numLeft == numRight) {
for (; i >= 0 && i < numRight; i += step, pOutput += 1) { for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) { if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
setNull((char *)&(pOutput[i]), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize); setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize);
continue; continue;
} }
*pOutput = (double)pLeft[i] - pRight[i]; *pOutput = (double)pLeft[i] - pRight[i];

View File

@ -46,7 +46,7 @@ uint32_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* pa
*pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries); *pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries);
if ((*pTree) == NULL) { if ((*pTree) == NULL) {
qError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); qError("allocate memory for loser-tree failed. reason:%s", strerror(errno));
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY;
} }
(*pTree)->pNode = (SLoserTreeNode*)(((char*)(*pTree)) + sizeof(SLoserTreeInfo)); (*pTree)->pNode = (SLoserTreeNode*)(((char*)(*pTree)) + sizeof(SLoserTreeInfo));

View File

@ -99,47 +99,47 @@ TEST(testCase, db_table_name) {
EXPECT_EQ(testValidateName(t4), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t4), TSDB_CODE_SUCCESS);
char t5[] = "table.'def'"; char t5[] = "table.'def'";
EXPECT_EQ(testValidateName(t5), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t5), TSDB_CODE_TSC_INVALID_SQL);
char t6[] = "'table'.'def'"; char t6[] = "'table'.'def'";
EXPECT_EQ(testValidateName(t6), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t6), TSDB_CODE_TSC_INVALID_SQL);
char t7[] = "'_ab1234'.'def'"; char t7[] = "'_ab1234'.'def'";
EXPECT_EQ(testValidateName(t7), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t7), TSDB_CODE_SUCCESS);
printf("%s\n", t7); printf("%s\n", t7);
char t8[] = "'_ab&^%1234'.'def'"; char t8[] = "'_ab&^%1234'.'def'";
EXPECT_EQ(testValidateName(t8), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t8), TSDB_CODE_TSC_INVALID_SQL);
char t9[] = "'_123'.'gtest中文'"; char t9[] = "'_123'.'gtest中文'";
EXPECT_EQ(testValidateName(t9), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t9), TSDB_CODE_TSC_INVALID_SQL);
char t10[] = "abc.'gtest中文'"; char t10[] = "abc.'gtest中文'";
EXPECT_EQ(testValidateName(t10), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t10), TSDB_CODE_TSC_INVALID_SQL);
char t10_1[] = "abc.'中文gtest'"; char t10_1[] = "abc.'中文gtest'";
EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_TSC_INVALID_SQL);
char t11[] = "'192.168.0.1'.abc"; char t11[] = "'192.168.0.1'.abc";
EXPECT_EQ(testValidateName(t11), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t11), TSDB_CODE_TSC_INVALID_SQL);
char t12[] = "192.168.0.1.abc"; char t12[] = "192.168.0.1.abc";
EXPECT_EQ(testValidateName(t12), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t12), TSDB_CODE_TSC_INVALID_SQL);
char t13[] = "abc."; char t13[] = "abc.";
EXPECT_EQ(testValidateName(t13), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t13), TSDB_CODE_TSC_INVALID_SQL);
char t14[] = ".abc"; char t14[] = ".abc";
EXPECT_EQ(testValidateName(t14), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t14), TSDB_CODE_TSC_INVALID_SQL);
char t15[] = ".'abc'"; char t15[] = ".'abc'";
EXPECT_EQ(testValidateName(t15), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t15), TSDB_CODE_TSC_INVALID_SQL);
char t16[] = ".abc'"; char t16[] = ".abc'";
EXPECT_EQ(testValidateName(t16), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t16), TSDB_CODE_TSC_INVALID_SQL);
char t17[] = "123a.\"abc\""; char t17[] = "123a.\"abc\"";
EXPECT_EQ(testValidateName(t17), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t17), TSDB_CODE_TSC_INVALID_SQL);
printf("%s\n", t17); printf("%s\n", t17);
char t18[] = "a.\"abc\""; char t18[] = "a.\"abc\"";
@ -147,13 +147,13 @@ TEST(testCase, db_table_name) {
printf("%s\n", t18); printf("%s\n", t18);
char t19[] = "'_ab1234'.'def'.'ab123'"; char t19[] = "'_ab1234'.'def'.'ab123'";
EXPECT_EQ(testValidateName(t19), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t19), TSDB_CODE_TSC_INVALID_SQL);
char t20[] = "'_ab1234*&^'"; char t20[] = "'_ab1234*&^'";
EXPECT_EQ(testValidateName(t20), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t20), TSDB_CODE_TSC_INVALID_SQL);
char t21[] = "'1234_abc'"; char t21[] = "'1234_abc'";
EXPECT_EQ(testValidateName(t21), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t21), TSDB_CODE_TSC_INVALID_SQL);
// =======Containing capital letters================= // =======Containing capital letters=================
@ -167,10 +167,10 @@ TEST(testCase, db_table_name) {
EXPECT_EQ(testValidateName(t32), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t32), TSDB_CODE_SUCCESS);
char t33[] = "'ABC.def"; char t33[] = "'ABC.def";
EXPECT_EQ(testValidateName(t33), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t33), TSDB_CODE_TSC_INVALID_SQL);
char t33_0[] = "abc.DEF'"; char t33_0[] = "abc.DEF'";
EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_TSC_INVALID_SQL);
char t34[] = "'ABC.def'"; char t34[] = "'ABC.def'";
//int32_t tmp0 = testValidateName(t34); //int32_t tmp0 = testValidateName(t34);
@ -193,38 +193,38 @@ TEST(testCase, db_table_name) {
// do not use key words // do not use key words
char t39[] = "table.'DEF'"; char t39[] = "table.'DEF'";
EXPECT_EQ(testValidateName(t39), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t39), TSDB_CODE_TSC_INVALID_SQL);
char t40[] = "'table'.'DEF'"; char t40[] = "'table'.'DEF'";
EXPECT_EQ(testValidateName(t40), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t40), TSDB_CODE_TSC_INVALID_SQL);
char t41[] = "'_abXYZ1234'.'deFF'"; char t41[] = "'_abXYZ1234'.'deFF'";
EXPECT_EQ(testValidateName(t41), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t41), TSDB_CODE_SUCCESS);
char t42[] = "'_abDEF&^%1234'.'DIef'"; char t42[] = "'_abDEF&^%1234'.'DIef'";
EXPECT_EQ(testValidateName(t42), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t42), TSDB_CODE_TSC_INVALID_SQL);
char t43[] = "'_123'.'Gtest中文'"; char t43[] = "'_123'.'Gtest中文'";
EXPECT_EQ(testValidateName(t43), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t43), TSDB_CODE_TSC_INVALID_SQL);
char t44[] = "'aABC'.'Gtest中文'"; char t44[] = "'aABC'.'Gtest中文'";
EXPECT_EQ(testValidateName(t44), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t44), TSDB_CODE_TSC_INVALID_SQL);
char t45[] = "'ABC'."; char t45[] = "'ABC'.";
EXPECT_EQ(testValidateName(t45), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t45), TSDB_CODE_TSC_INVALID_SQL);
char t46[] = ".'ABC'"; char t46[] = ".'ABC'";
EXPECT_EQ(testValidateName(t46), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t46), TSDB_CODE_TSC_INVALID_SQL);
char t47[] = "a.\"aTWc\""; char t47[] = "a.\"aTWc\"";
EXPECT_EQ(testValidateName(t47), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t47), TSDB_CODE_SUCCESS);
// ================has space ================= // ================has space =================
char t60[] = " ABC "; char t60[] = " ABC ";
EXPECT_EQ(testValidateName(t60), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t60), TSDB_CODE_TSC_INVALID_SQL);
char t60_1[] = " ABC "; char t60_1[] = " ABC ";
EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_TSC_INVALID_SQL);
char t61[] = "' ABC '"; char t61[] = "' ABC '";
EXPECT_EQ(testValidateName(t61), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t61), TSDB_CODE_SUCCESS);
@ -233,96 +233,96 @@ TEST(testCase, db_table_name) {
EXPECT_EQ(testValidateName(t61_1), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t61_1), TSDB_CODE_SUCCESS);
char t62[] = " ABC . def "; char t62[] = " ABC . def ";
EXPECT_EQ(testValidateName(t62), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t62), TSDB_CODE_TSC_INVALID_SQL);
char t63[] = "' ABC . def "; char t63[] = "' ABC . def ";
EXPECT_EQ(testValidateName(t63), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t63), TSDB_CODE_TSC_INVALID_SQL);
char t63_0[] = " abc . DEF ' "; char t63_0[] = " abc . DEF ' ";
EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_TSC_INVALID_SQL);
char t64[] = " ' ABC . def ' "; char t64[] = " ' ABC . def ' ";
//int32_t tmp1 = testValidateName(t64); //int32_t tmp1 = testValidateName(t64);
EXPECT_EQ(testValidateName(t64), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t64), TSDB_CODE_TSC_INVALID_SQL);
char t65[] = " ' ABC '. def "; char t65[] = " ' ABC '. def ";
EXPECT_EQ(testValidateName(t65), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t65), TSDB_CODE_TSC_INVALID_SQL);
char t66[] = "' ABC '.' DEF '"; char t66[] = "' ABC '.' DEF '";
EXPECT_EQ(testValidateName(t66), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t66), TSDB_CODE_SUCCESS);
char t67[] = "abc . ' DEF '"; char t67[] = "abc . ' DEF '";
EXPECT_EQ(testValidateName(t67), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t67), TSDB_CODE_TSC_INVALID_SQL);
char t68[] = "' abc '.' DEF '"; char t68[] = "' abc '.' DEF '";
EXPECT_EQ(testValidateName(t68), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t68), TSDB_CODE_SUCCESS);
// do not use key words // do not use key words
char t69[] = "table.'DEF'"; char t69[] = "table.'DEF'";
EXPECT_EQ(testValidateName(t69), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t69), TSDB_CODE_TSC_INVALID_SQL);
char t70[] = "'table'.'DEF'"; char t70[] = "'table'.'DEF'";
EXPECT_EQ(testValidateName(t70), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t70), TSDB_CODE_TSC_INVALID_SQL);
char t71[] = "'_abXYZ1234 '.' deFF '"; char t71[] = "'_abXYZ1234 '.' deFF '";
EXPECT_EQ(testValidateName(t71), TSDB_CODE_SUCCESS); EXPECT_EQ(testValidateName(t71), TSDB_CODE_SUCCESS);
char t72[] = "'_abDEF&^%1234'.' DIef'"; char t72[] = "'_abDEF&^%1234'.' DIef'";
EXPECT_EQ(testValidateName(t72), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t72), TSDB_CODE_TSC_INVALID_SQL);
char t73[] = "'_123'.' Gtest中文'"; char t73[] = "'_123'.' Gtest中文'";
EXPECT_EQ(testValidateName(t73), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t73), TSDB_CODE_TSC_INVALID_SQL);
char t74[] = "' aABC'.'Gtest中文'"; char t74[] = "' aABC'.'Gtest中文'";
EXPECT_EQ(testValidateName(t74), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t74), TSDB_CODE_TSC_INVALID_SQL);
char t75[] = "' ABC '."; char t75[] = "' ABC '.";
EXPECT_EQ(testValidateName(t75), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t75), TSDB_CODE_TSC_INVALID_SQL);
char t76[] = ".' ABC'"; char t76[] = ".' ABC'";
EXPECT_EQ(testValidateName(t76), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t76), TSDB_CODE_TSC_INVALID_SQL);
char t77[] = " a . \"aTWc\" "; char t77[] = " a . \"aTWc\" ";
EXPECT_EQ(testValidateName(t77), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t77), TSDB_CODE_TSC_INVALID_SQL);
char t78[] = " a.\"aTWc \""; char t78[] = " a.\"aTWc \"";
EXPECT_EQ(testValidateName(t78), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t78), TSDB_CODE_TSC_INVALID_SQL);
// ===============muti string by space =================== // ===============muti string by space ===================
// There's no such case. // There's no such case.
//char t160[] = "A BC"; //char t160[] = "A BC";
//EXPECT_EQ(testValidateName(t160), TSDB_CODE_INVALID_SQL); //EXPECT_EQ(testValidateName(t160), TSDB_CODE_TSC_INVALID_SQL);
//printf("end:%s\n", t160); //printf("end:%s\n", t160);
// There's no such case. // There's no such case.
//char t161[] = "' A BC '"; //char t161[] = "' A BC '";
//EXPECT_EQ(testValidateName(t161), TSDB_CODE_INVALID_SQL); //EXPECT_EQ(testValidateName(t161), TSDB_CODE_TSC_INVALID_SQL);
char t162[] = " AB C . de f "; char t162[] = " AB C . de f ";
EXPECT_EQ(testValidateName(t162), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t162), TSDB_CODE_TSC_INVALID_SQL);
char t163[] = "' AB C . de f "; char t163[] = "' AB C . de f ";
EXPECT_EQ(testValidateName(t163), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t163), TSDB_CODE_TSC_INVALID_SQL);
char t163_0[] = " ab c . DE F ' "; char t163_0[] = " ab c . DE F ' ";
EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_TSC_INVALID_SQL);
char t164[] = " ' AB C . de f ' "; char t164[] = " ' AB C . de f ' ";
//int32_t tmp2 = testValidateName(t164); //int32_t tmp2 = testValidateName(t164);
EXPECT_EQ(testValidateName(t164), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t164), TSDB_CODE_TSC_INVALID_SQL);
char t165[] = " ' A BC '. de f "; char t165[] = " ' A BC '. de f ";
EXPECT_EQ(testValidateName(t165), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t165), TSDB_CODE_TSC_INVALID_SQL);
char t166[] = "' AB C '.' DE F '"; char t166[] = "' AB C '.' DE F '";
EXPECT_EQ(testValidateName(t166), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t166), TSDB_CODE_TSC_INVALID_SQL);
char t167[] = "ab c . ' D EF '"; char t167[] = "ab c . ' D EF '";
EXPECT_EQ(testValidateName(t167), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t167), TSDB_CODE_TSC_INVALID_SQL);
char t168[] = "' a bc '.' DE F '"; char t168[] = "' a bc '.' DE F '";
EXPECT_EQ(testValidateName(t168), TSDB_CODE_INVALID_SQL); EXPECT_EQ(testValidateName(t168), TSDB_CODE_TSC_INVALID_SQL);
} }

View File

@ -47,7 +47,7 @@ typedef struct {
uint16_t localPort; uint16_t localPort;
int8_t connType; int8_t connType;
int index; // for UDP server only, round robin for multiple threads int index; // for UDP server only, round robin for multiple threads
char label[12]; char label[TSDB_LABEL_LEN];
char user[TSDB_UNI_LEN]; // meter ID char user[TSDB_UNI_LEN]; // meter ID
char spi; // security parameter index char spi; // security parameter index
@ -58,6 +58,7 @@ typedef struct {
void (*cfp)(SRpcMsg *, SRpcIpSet *); void (*cfp)(SRpcMsg *, SRpcIpSet *);
int (*afp)(char *user, char *spi, char *encrypt, char *secret, char *ckey); int (*afp)(char *user, char *spi, char *encrypt, char *secret, char *ckey);
int refCount;
void *idPool; // handle to ID pool void *idPool; // handle to ID pool
void *tmrCtrl; // handle to timer void *tmrCtrl; // handle to timer
SHashObj *hash; // handle returned by hash utility SHashObj *hash; // handle returned by hash utility
@ -87,7 +88,7 @@ typedef struct {
} SRpcReqContext; } SRpcReqContext;
typedef struct SRpcConn { typedef struct SRpcConn {
char info[50];// debug info: label + pConn + ahandle char info[48];// debug info: label + pConn + ahandle
int sid; // session ID int sid; // session ID
uint32_t ownId; // own link ID uint32_t ownId; // own link ID
uint32_t peerId; // peer link ID uint32_t peerId; // peer link ID
@ -199,6 +200,8 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen);
static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen); static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen);
static void rpcLockConn(SRpcConn *pConn); static void rpcLockConn(SRpcConn *pConn);
static void rpcUnlockConn(SRpcConn *pConn); static void rpcUnlockConn(SRpcConn *pConn);
static void rpcAddRef(SRpcInfo *pRpc);
static void rpcDecRef(SRpcInfo *pRpc);
void *rpcOpen(const SRpcInit *pInit) { void *rpcOpen(const SRpcInit *pInit) {
SRpcInfo *pRpc; SRpcInfo *pRpc;
@ -224,6 +227,7 @@ void *rpcOpen(const SRpcInit *pInit) {
pRpc->spi = pInit->spi; pRpc->spi = pInit->spi;
pRpc->cfp = pInit->cfp; pRpc->cfp = pInit->cfp;
pRpc->afp = pInit->afp; pRpc->afp = pInit->afp;
pRpc->refCount = 1;
size_t size = sizeof(SRpcConn) * pRpc->sessions; size_t size = sizeof(SRpcConn) * pRpc->sessions;
pRpc->connList = (SRpcConn *)calloc(1, size); pRpc->connList = (SRpcConn *)calloc(1, size);
@ -293,15 +297,8 @@ void rpcClose(void *param) {
(*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle); (*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle);
(*taosCleanUpConn[pRpc->connType])(pRpc->udphandle); (*taosCleanUpConn[pRpc->connType])(pRpc->udphandle);
taosHashCleanup(pRpc->hash);
taosTmrCleanUp(pRpc->tmrCtrl);
taosIdPoolCleanUp(pRpc->idPool);
rpcCloseConnCache(pRpc->pCache);
tfree(pRpc->connList);
pthread_mutex_destroy(&pRpc->mutex);
tTrace("%s rpc is closed", pRpc->label); tTrace("%s rpc is closed", pRpc->label);
tfree(pRpc); rpcDecRef(pRpc);
} }
void *rpcMallocCont(int contLen) { void *rpcMallocCont(int contLen) {
@ -378,6 +375,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcConn *pConn = (SRpcConn *)pRsp->handle;
SRpcMsg rpcMsg = *pRsp; SRpcMsg rpcMsg = *pRsp;
SRpcMsg *pMsg = &rpcMsg; SRpcMsg *pMsg = &rpcMsg;
SRpcInfo *pRpc = pConn->pRpc;
if ( pMsg->pCont == NULL ) { if ( pMsg->pCont == NULL ) {
pMsg->pCont = rpcMallocCont(0); pMsg->pCont = rpcMallocCont(0);
@ -395,6 +393,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
if ( pConn->inType == 0 || pConn->user[0] == 0 ) { if ( pConn->inType == 0 || pConn->user[0] == 0 ) {
tTrace("%s, connection is already released, rsp wont be sent", pConn->info); tTrace("%s, connection is already released, rsp wont be sent", pConn->info);
rpcUnlockConn(pConn); rpcUnlockConn(pConn);
rpcDecRef(pRpc);
return; return;
} }
@ -418,9 +417,8 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
rpcFreeMsg(pConn->pRspMsg); rpcFreeMsg(pConn->pRspMsg);
pConn->pRspMsg = msg; pConn->pRspMsg = msg;
pConn->rspMsgLen = msgLen; pConn->rspMsgLen = msgLen;
if (pMsg->code == TSDB_CODE_ACTION_IN_PROGRESS) pConn->inTranId--; if (pMsg->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) pConn->inTranId--;
SRpcInfo *pRpc = pConn->pRpc;
taosTmrStopA(&pConn->pTimer); taosTmrStopA(&pConn->pTimer);
// set the idle timer to monitor the activity // set the idle timer to monitor the activity
@ -429,6 +427,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) {
pConn->secured = 1; // connection shall be secured pConn->secured = 1; // connection shall be secured
rpcUnlockConn(pConn); rpcUnlockConn(pConn);
rpcDecRef(pRpc); // decrease the referene count
return; return;
} }
@ -443,7 +442,7 @@ void rpcSendRedirectRsp(void *thandle, const SRpcIpSet *pIpSet) {
memcpy(rpcMsg.pCont, pIpSet, sizeof(SRpcIpSet)); memcpy(rpcMsg.pCont, pIpSet, sizeof(SRpcIpSet));
rpcMsg.code = TSDB_CODE_REDIRECT; rpcMsg.code = TSDB_CODE_RPC_REDIRECT;
rpcMsg.handle = thandle; rpcMsg.handle = thandle;
rpcSendResponse(&rpcMsg); rpcSendResponse(&rpcMsg);
@ -496,7 +495,7 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort,
uint32_t peerIp = taosGetIpFromFqdn(peerFqdn); uint32_t peerIp = taosGetIpFromFqdn(peerFqdn);
if (peerIp == -1) { if (peerIp == -1) {
tError("%s, failed to resolve FQDN:%s", pRpc->label, peerFqdn); tError("%s, failed to resolve FQDN:%s", pRpc->label, peerFqdn);
terrno = TSDB_CODE_APP_ERROR; terrno = TSDB_CODE_RPC_APP_ERROR;
return NULL; return NULL;
} }
@ -513,7 +512,7 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort,
void *shandle = (connType & RPC_CONN_TCP)? pRpc->tcphandle:pRpc->udphandle; void *shandle = (connType & RPC_CONN_TCP)? pRpc->tcphandle:pRpc->udphandle;
pConn->chandle = (*taosOpenConn[connType])(shandle, pConn, pConn->peerIp, pConn->peerPort); pConn->chandle = (*taosOpenConn[connType])(shandle, pConn, pConn->peerIp, pConn->peerPort);
if (pConn->chandle == NULL) { if (pConn->chandle == NULL) {
terrno = TSDB_CODE_NETWORK_UNAVAIL; terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL;
rpcCloseConn(pConn); rpcCloseConn(pConn);
pConn = NULL; pConn = NULL;
} }
@ -570,7 +569,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
int sid = taosAllocateId(pRpc->idPool); int sid = taosAllocateId(pRpc->idPool);
if (sid <= 0) { if (sid <= 0) {
tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions); tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions);
terrno = TSDB_CODE_MAX_SESSIONS; terrno = TSDB_CODE_RPC_MAX_SESSIONS;
} else { } else {
pConn = pRpc->connList + sid; pConn = pRpc->connList + sid;
memset(pConn, 0, sizeof(SRpcConn)); memset(pConn, 0, sizeof(SRpcConn));
@ -606,7 +605,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
int sid = taosAllocateId(pRpc->idPool); int sid = taosAllocateId(pRpc->idPool);
if (sid <= 0) { if (sid <= 0) {
tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions); tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions);
terrno = TSDB_CODE_MAX_SESSIONS; terrno = TSDB_CODE_RPC_MAX_SESSIONS;
} else { } else {
pConn = pRpc->connList + sid; pConn = pRpc->connList + sid;
memset(pConn, 0, sizeof(SRpcConn)); memset(pConn, 0, sizeof(SRpcConn));
@ -618,7 +617,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
pConn->linkUid = pHead->linkUid; pConn->linkUid = pHead->linkUid;
if (pRpc->afp) { if (pRpc->afp) {
if (pConn->user[0] == 0) { if (pConn->user[0] == 0) {
terrno = TSDB_CODE_AUTH_REQUIRED; terrno = TSDB_CODE_RPC_AUTH_REQUIRED;
} else { } else {
terrno = (*pRpc->afp)(pConn->user, &pConn->spi, &pConn->encrypt, pConn->secret, pConn->ckey); terrno = (*pRpc->afp)(pConn->user, &pConn->spi, &pConn->encrypt, pConn->secret, pConn->ckey);
} }
@ -656,13 +655,13 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, SRecvInfo *pRecv) {
if (pRpc->connType == TAOS_CONN_SERVER) { if (pRpc->connType == TAOS_CONN_SERVER) {
pConn = rpcAllocateServerConn(pRpc, pRecv); pConn = rpcAllocateServerConn(pRpc, pRecv);
} else { } else {
terrno = TSDB_CODE_UNEXPECTED_RESPONSE; terrno = TSDB_CODE_RPC_UNEXPECTED_RESPONSE;
} }
} }
if (pConn) { if (pConn) {
if (pConn->linkUid != pHead->linkUid) { if (pConn->linkUid != pHead->linkUid) {
terrno = TSDB_CODE_MISMATCHED_METER_ID; terrno = TSDB_CODE_RPC_MISMATCHED_LINK_ID;
pConn = NULL; pConn = NULL;
} }
} }
@ -700,7 +699,7 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) {
if (pConn->peerId != pHead->sourceId) { if (pConn->peerId != pHead->sourceId) {
tTrace("%s, source Id is changed, old:0x%08x new:0x%08x", pConn->info, tTrace("%s, source Id is changed, old:0x%08x new:0x%08x", pConn->info,
pConn->peerId, pHead->sourceId); pConn->peerId, pHead->sourceId);
return TSDB_CODE_INVALID_VALUE; return TSDB_CODE_RPC_INVALID_VALUE;
} }
} }
@ -708,7 +707,7 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) {
if (pConn->inType == pHead->msgType) { if (pConn->inType == pHead->msgType) {
if (pHead->code == 0) { if (pHead->code == 0) {
tTrace("%s, %s is retransmitted", pConn->info, taosMsg[pHead->msgType]); tTrace("%s, %s is retransmitted", pConn->info, taosMsg[pHead->msgType]);
rpcSendQuickRsp(pConn, TSDB_CODE_ACTION_IN_PROGRESS); rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS);
} else { } else {
// do nothing, it is heart beat from client // do nothing, it is heart beat from client
} }
@ -720,13 +719,13 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) {
} }
// do not reply any message // do not reply any message
return TSDB_CODE_ALREADY_PROCESSED; return TSDB_CODE_RPC_ALREADY_PROCESSED;
} }
if (pConn->inType != 0) { if (pConn->inType != 0) {
tTrace("%s, last session is not finished, inTranId:%d tranId:%d", pConn->info, tTrace("%s, last session is not finished, inTranId:%d tranId:%d", pConn->info,
pConn->inTranId, pHead->tranId); pConn->inTranId, pHead->tranId);
return TSDB_CODE_LAST_SESSION_NOT_FINISHED; return TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED;
} }
pConn->inTranId = pHead->tranId; pConn->inTranId = pHead->tranId;
@ -740,39 +739,39 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
pConn->peerId = pHead->sourceId; pConn->peerId = pHead->sourceId;
if (pConn->outType == 0 || pConn->pContext == NULL) { if (pConn->outType == 0 || pConn->pContext == NULL) {
return TSDB_CODE_UNEXPECTED_RESPONSE; return TSDB_CODE_RPC_UNEXPECTED_RESPONSE;
} }
if (pHead->tranId != pConn->outTranId) { if (pHead->tranId != pConn->outTranId) {
return TSDB_CODE_INVALID_TRAN_ID; return TSDB_CODE_RPC_INVALID_TRAN_ID;
} }
if (pHead->msgType != pConn->outType + 1) { if (pHead->msgType != pConn->outType + 1) {
return TSDB_CODE_INVALID_RESPONSE_TYPE; return TSDB_CODE_RPC_INVALID_RESPONSE_TYPE;
} }
taosTmrStopA(&pConn->pTimer); taosTmrStopA(&pConn->pTimer);
pConn->retry = 0; pConn->retry = 0;
if (pHead->code == TSDB_CODE_AUTH_REQUIRED && pRpc->spi) { if (pHead->code == TSDB_CODE_RPC_AUTH_REQUIRED && pRpc->spi) {
tTrace("%s, authentication shall be restarted", pConn->info); tTrace("%s, authentication shall be restarted", pConn->info);
pConn->secured = 0; pConn->secured = 0;
rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen); rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen);
pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl);
return TSDB_CODE_ALREADY_PROCESSED; return TSDB_CODE_RPC_ALREADY_PROCESSED;
} }
if (pHead->code == TSDB_CODE_ACTION_IN_PROGRESS) { if (pHead->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) {
if (pConn->tretry <= tsRpcMaxRetry) { if (pConn->tretry <= tsRpcMaxRetry) {
tTrace("%s, peer is still processing the transaction, retry:%d", pConn->info, pConn->tretry); tTrace("%s, peer is still processing the transaction, retry:%d", pConn->info, pConn->tretry);
pConn->tretry++; pConn->tretry++;
rpcSendReqHead(pConn); rpcSendReqHead(pConn);
pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl);
return TSDB_CODE_ALREADY_PROCESSED; return TSDB_CODE_RPC_ALREADY_PROCESSED;
} else { } else {
// peer still in processing, give up // peer still in processing, give up
tTrace("%s, server processing takes too long time, give up", pConn->info); tTrace("%s, server processing takes too long time, give up", pConn->info);
pHead->code = TSDB_CODE_TOO_SLOW; pHead->code = TSDB_CODE_RPC_TOO_SLOW;
} }
} }
@ -793,29 +792,29 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) {
if (pHead->msgType >= TSDB_MSG_TYPE_MAX || pHead->msgType <= 0) { if (pHead->msgType >= TSDB_MSG_TYPE_MAX || pHead->msgType <= 0) {
tTrace("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType); tTrace("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType);
terrno = TSDB_CODE_INVALID_MSG_TYPE; return NULL; terrno = TSDB_CODE_RPC_INVALID_MSG_TYPE; return NULL;
} }
if (sid < 0 || sid >= pRpc->sessions) { if (sid < 0 || sid >= pRpc->sessions) {
tTrace("%s sid:%d, sid is out of range, max sid:%d, %s discarded", pRpc->label, sid, tTrace("%s sid:%d, sid is out of range, max sid:%d, %s discarded", pRpc->label, sid,
pRpc->sessions, taosMsg[pHead->msgType]); pRpc->sessions, taosMsg[pHead->msgType]);
terrno = TSDB_CODE_INVALID_SESSION_ID; return NULL; terrno = TSDB_CODE_RPC_INVALID_SESSION_ID; return NULL;
} }
pConn = rpcGetConnObj(pRpc, sid, pRecv); pConn = rpcGetConnObj(pRpc, sid, pRecv);
if (pConn == NULL) { if (pConn == NULL) {
tTrace("%s %p, failed to get connection obj(%s)", pRpc->label, (void *)pHead->ahandle, tstrerror(terrno)); tTrace("%s %p, failed to get connection obj(%s)", pRpc->label, (void *)pHead->ahandle, tstrerror(terrno));
return NULL; return NULL;
} else { }
if (rpcIsReq(pHead->msgType)) {
pConn->ahandle = (void *)pHead->ahandle;
sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle);
}
}
rpcLockConn(pConn); rpcLockConn(pConn);
sid = pConn->sid;
if (rpcIsReq(pHead->msgType)) {
pConn->ahandle = (void *)pHead->ahandle;
sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle);
}
sid = pConn->sid;
pConn->chandle = pRecv->chandle; pConn->chandle = pRecv->chandle;
pConn->peerIp = pRecv->ip; pConn->peerIp = pRecv->ip;
pConn->peerPort = pRecv->port; pConn->peerPort = pRecv->port;
@ -848,14 +847,15 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) {
} }
static void rpcProcessBrokenLink(SRpcConn *pConn) { static void rpcProcessBrokenLink(SRpcConn *pConn) {
if (pConn == NULL) return;
SRpcInfo *pRpc = pConn->pRpc; SRpcInfo *pRpc = pConn->pRpc;
tTrace("%s, link is broken", pConn->info); tTrace("%s, link is broken", pConn->info);
// pConn->chandle = NULL;
rpcLockConn(pConn);
if (pConn->outType) { if (pConn->outType) {
SRpcReqContext *pContext = pConn->pContext; SRpcReqContext *pContext = pConn->pContext;
pContext->code = TSDB_CODE_NETWORK_UNAVAIL; pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl); taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl);
} }
@ -868,11 +868,12 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) {
rpcMsg.contLen = 0; rpcMsg.contLen = 0;
rpcMsg.handle = pConn; rpcMsg.handle = pConn;
rpcMsg.msgType = pConn->inType; rpcMsg.msgType = pConn->inType;
rpcMsg.code = TSDB_CODE_NETWORK_UNAVAIL; rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
(*(pRpc->cfp))(&rpcMsg); (*(pRpc->cfp))(&rpcMsg);
*/ */
} }
rpcUnlockConn(pConn);
rpcCloseConn(pConn); rpcCloseConn(pConn);
} }
@ -886,7 +887,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
// underlying UDP layer does not know it is server or client // underlying UDP layer does not know it is server or client
pRecv->connType = pRecv->connType | pRpc->connType; pRecv->connType = pRecv->connType | pRpc->connType;
if (pRecv->ip == 0 && pConn) { if (pRecv->ip == 0) {
rpcProcessBrokenLink(pConn); rpcProcessBrokenLink(pConn);
return NULL; return NULL;
} }
@ -901,7 +902,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
} }
int32_t code = terrno; int32_t code = terrno;
if (code != TSDB_CODE_ALREADY_PROCESSED) { if (code != TSDB_CODE_RPC_ALREADY_PROCESSED) {
if (code != 0) { // parsing error if (code != 0) { // parsing error
if (rpcIsReq(pHead->msgType)) { if (rpcIsReq(pHead->msgType)) {
rpcSendErrorMsgToPeer(pRecv, code); rpcSendErrorMsgToPeer(pRecv, code);
@ -951,6 +952,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) {
if ( rpcIsReq(pHead->msgType) ) { if ( rpcIsReq(pHead->msgType) ) {
rpcMsg.handle = pConn; rpcMsg.handle = pConn;
rpcAddRef(pRpc); // add the refCount for requests
pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl);
(*(pRpc->cfp))(&rpcMsg, NULL); (*(pRpc->cfp))(&rpcMsg, NULL);
} else { } else {
@ -960,28 +962,28 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) {
pConn->pContext = NULL; pConn->pContext = NULL;
// for UDP, port may be changed by server, the port in ipSet shall be used for cache // for UDP, port may be changed by server, the port in ipSet shall be used for cache
if (pHead->code != TSDB_CODE_TOO_SLOW) { if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) {
rpcAddConnIntoCache(pRpc->pCache, pConn, pConn->peerFqdn, pContext->ipSet.port[pContext->ipSet.inUse], pConn->connType); rpcAddConnIntoCache(pRpc->pCache, pConn, pConn->peerFqdn, pContext->ipSet.port[pContext->ipSet.inUse], pConn->connType);
} else { } else {
rpcCloseConn(pConn); rpcCloseConn(pConn);
} }
if (pHead->code == TSDB_CODE_REDIRECT) { if (pHead->code == TSDB_CODE_RPC_REDIRECT) {
pContext->redirect++; pContext->redirect++;
if (pContext->redirect > TSDB_MAX_REPLICA) { if (pContext->redirect > TSDB_MAX_REPLICA) {
pHead->code = TSDB_CODE_NETWORK_UNAVAIL; pHead->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
tWarn("%s, too many redirects, quit", pConn->info); tWarn("%s, too many redirects, quit", pConn->info);
} }
} }
if (pHead->code == TSDB_CODE_REDIRECT) { if (pHead->code == TSDB_CODE_RPC_REDIRECT) {
pContext->numOfTry = 0; pContext->numOfTry = 0;
memcpy(&pContext->ipSet, pHead->content, sizeof(pContext->ipSet)); memcpy(&pContext->ipSet, pHead->content, sizeof(pContext->ipSet));
tTrace("%s, redirect is received, numOfIps:%d", pConn->info, pContext->ipSet.numOfIps); tTrace("%s, redirect is received, numOfIps:%d", pConn->info, pContext->ipSet.numOfIps);
for (int i=0; i<pContext->ipSet.numOfIps; ++i) for (int i=0; i<pContext->ipSet.numOfIps; ++i)
pContext->ipSet.port[i] = htons(pContext->ipSet.port[i]); pContext->ipSet.port[i] = htons(pContext->ipSet.port[i]);
rpcSendReqToServer(pRpc, pContext); rpcSendReqToServer(pRpc, pContext);
} else if (pHead->code == TSDB_CODE_NOT_READY) { } else if (pHead->code == TSDB_CODE_RPC_NOT_READY) {
pContext->code = pHead->code; pContext->code = pHead->code;
rpcProcessConnError(pContext, NULL); rpcProcessConnError(pContext, NULL);
} else { } else {
@ -1058,7 +1060,7 @@ static void rpcSendErrorMsgToPeer(SRecvInfo *pRecv, int32_t code) {
pReplyHead->code = htonl(code); pReplyHead->code = htonl(code);
msgLen = sizeof(SRpcHead); msgLen = sizeof(SRpcHead);
if (code == TSDB_CODE_INVALID_TIME_STAMP) { if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP) {
// include a time stamp if client's time is not synchronized well // include a time stamp if client's time is not synchronized well
uint8_t *pContent = pReplyHead->content; uint8_t *pContent = pReplyHead->content;
timeStamp = htonl(taosGetTimestampSec()); timeStamp = htonl(taosGetTimestampSec());
@ -1200,7 +1202,7 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) {
rpcUnlockConn(pConn); rpcUnlockConn(pConn);
if (reportDisc && pConn->pContext) { if (reportDisc && pConn->pContext) {
pConn->pContext->code = TSDB_CODE_NETWORK_UNAVAIL; pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
rpcProcessConnError(pConn->pContext, NULL); rpcProcessConnError(pConn->pContext, NULL);
rpcCloseConn(pConn); rpcCloseConn(pConn);
} }
@ -1221,7 +1223,7 @@ static void rpcProcessIdleTimer(void *param, void *tmrId) {
rpcMsg.contLen = 0; rpcMsg.contLen = 0;
rpcMsg.handle = pConn; rpcMsg.handle = pConn;
rpcMsg.msgType = pConn->inType; rpcMsg.msgType = pConn->inType;
rpcMsg.code = TSDB_CODE_NETWORK_UNAVAIL; rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
(*(pRpc->cfp))(&rpcMsg); (*(pRpc->cfp))(&rpcMsg);
*/ */
} }
@ -1239,7 +1241,7 @@ static void rpcProcessProgressTimer(void *param, void *tmrId) {
if (pConn->inType && pConn->user[0]) { if (pConn->inType && pConn->user[0]) {
tTrace("%s, progress timer expired, send progress", pConn->info); tTrace("%s, progress timer expired, send progress", pConn->info);
rpcSendQuickRsp(pConn, TSDB_CODE_ACTION_IN_PROGRESS); rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS);
pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl);
} else { } else {
tTrace("%s, progress timer:%p not processed", pConn->info, tmrId); tTrace("%s, progress timer:%p not processed", pConn->info, tmrId);
@ -1379,12 +1381,12 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
if ( !rpcIsReq(pHead->msgType) ) { if ( !rpcIsReq(pHead->msgType) ) {
// for response, if code is auth failure, it shall bypass the auth process // for response, if code is auth failure, it shall bypass the auth process
code = htonl(pHead->code); code = htonl(pHead->code);
if (code==TSDB_CODE_INVALID_TIME_STAMP || code==TSDB_CODE_AUTH_FAILURE || code == TSDB_CODE_AUTH_REQUIRED || if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE ||
code==TSDB_CODE_INVALID_USER || code == TSDB_CODE_NOT_READY) { code == TSDB_CODE_RPC_AUTH_REQUIRED || code == TSDB_CODE_MND_INVALID_USER || code == TSDB_CODE_RPC_NOT_READY) {
pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen); pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen);
// tTrace("%s, dont check authentication since code is:0x%x", pConn->info, code); // tTrace("%s, dont check authentication since code is:0x%x", pConn->info, code);
return 0; return 0;
} }
} }
code = 0; code = 0;
@ -1397,11 +1399,11 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
delta -= (int32_t)taosGetTimestampSec(); delta -= (int32_t)taosGetTimestampSec();
if (abs(delta) > 900) { if (abs(delta) > 900) {
tWarn("%s, time diff:%d is too big, msg discarded", pConn->info, delta); tWarn("%s, time diff:%d is too big, msg discarded", pConn->info, delta);
code = TSDB_CODE_INVALID_TIME_STAMP; code = TSDB_CODE_RPC_INVALID_TIME_STAMP;
} else { } else {
if (rpcAuthenticateMsg(pHead, msgLen-TSDB_AUTH_LEN, pDigest->auth, pConn->secret) < 0) { if (rpcAuthenticateMsg(pHead, msgLen-TSDB_AUTH_LEN, pDigest->auth, pConn->secret) < 0) {
tTrace("%s, authentication failed, msg discarded", pConn->info); tTrace("%s, authentication failed, msg discarded", pConn->info);
code = TSDB_CODE_AUTH_FAILURE; code = TSDB_CODE_RPC_AUTH_FAILURE;
} else { } else {
pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen) - sizeof(SRpcDigest); pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen) - sizeof(SRpcDigest);
if ( !rpcIsReq(pHead->msgType) ) pConn->secured = 1; // link is secured for client if ( !rpcIsReq(pHead->msgType) ) pConn->secured = 1; // link is secured for client
@ -1410,7 +1412,7 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
} }
} else { } else {
tTrace("%s, auth spi:%d not matched with received:%d", pConn->info, pConn->spi, pHead->spi); tTrace("%s, auth spi:%d not matched with received:%d", pConn->info, pConn->spi, pHead->spi);
code = pHead->spi ? TSDB_CODE_AUTH_FAILURE : TSDB_CODE_AUTH_REQUIRED; code = pHead->spi ? TSDB_CODE_RPC_AUTH_FAILURE : TSDB_CODE_RPC_AUTH_REQUIRED;
} }
return code; return code;
@ -1433,3 +1435,23 @@ static void rpcUnlockConn(SRpcConn *pConn) {
} }
} }
static void rpcAddRef(SRpcInfo *pRpc)
{
atomic_add_fetch_8(&pRpc->refCount, 1);
}
static void rpcDecRef(SRpcInfo *pRpc)
{
if (atomic_sub_fetch_8(&pRpc->refCount, 1) == 0) {
taosHashCleanup(pRpc->hash);
taosTmrCleanUp(pRpc->tmrCtrl);
taosIdPoolCleanUp(pRpc->idPool);
rpcCloseConnCache(pRpc->pCache);
tfree(pRpc->connList);
pthread_mutex_destroy(&pRpc->mutex);
tTrace("%s rpc resources are released", pRpc->label);
tfree(pRpc);
}
}

View File

@ -16,6 +16,8 @@
#include "os.h" #include "os.h"
#include "tsocket.h" #include "tsocket.h"
#include "tutil.h" #include "tutil.h"
#include "taosdef.h"
#include "taoserror.h"
#include "rpcLog.h" #include "rpcLog.h"
#include "rpcHead.h" #include "rpcHead.h"
#include "rpcTcp.h" #include "rpcTcp.h"
@ -26,8 +28,9 @@
typedef struct SFdObj { typedef struct SFdObj {
void *signature; void *signature;
int fd; // TCP socket FD int fd; // TCP socket FD
void *thandle; // handle from upper layer, like TAOS int closedByApp; // 1: already closed by App
void *thandle; // handle from upper layer, like TAOS
uint32_t ip; uint32_t ip;
uint16_t port; uint16_t port;
struct SThreadObj *pThreadObj; struct SThreadObj *pThreadObj;
@ -44,7 +47,7 @@ typedef struct SThreadObj {
int pollFd; int pollFd;
int numOfFds; int numOfFds;
int threadId; int threadId;
char label[12]; char label[TSDB_LABEL_LEN];
void *shandle; // handle passed by upper layer during server initialization void *shandle; // handle passed by upper layer during server initialization
void *(*processData)(SRecvInfo *pPacket); void *(*processData)(SRecvInfo *pPacket);
} SThreadObj; } SThreadObj;
@ -53,7 +56,7 @@ typedef struct {
int fd; int fd;
uint32_t ip; uint32_t ip;
uint16_t port; uint16_t port;
char label[12]; char label[TSDB_LABEL_LEN];
int numOfThreads; int numOfThreads;
void * shandle; void * shandle;
SThreadObj *pThreadObj; SThreadObj *pThreadObj;
@ -64,13 +67,21 @@ static void *taosProcessTcpData(void *param);
static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd); static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd);
static void taosFreeFdObj(SFdObj *pFdObj); static void taosFreeFdObj(SFdObj *pFdObj);
static void taosReportBrokenLink(SFdObj *pFdObj); static void taosReportBrokenLink(SFdObj *pFdObj);
static void* taosAcceptTcpConnection(void *arg); static void *taosAcceptTcpConnection(void *arg);
void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) { void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) {
SServerObj *pServerObj; SServerObj *pServerObj;
SThreadObj *pThreadObj; SThreadObj *pThreadObj;
pServerObj = (SServerObj *)calloc(sizeof(SServerObj), 1); pServerObj = (SServerObj *)calloc(sizeof(SServerObj), 1);
if (pServerObj == NULL) {
tError("TCP:%s no enough memory", label);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL;
}
pServerObj->fd = -1;
pServerObj->thread = 0;
pServerObj->ip = ip; pServerObj->ip = ip;
pServerObj->port = port; pServerObj->port = port;
tstrncpy(pServerObj->label, label, sizeof(pServerObj->label)); tstrncpy(pServerObj->label, label, sizeof(pServerObj->label));
@ -79,17 +90,30 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
pServerObj->pThreadObj = (SThreadObj *)calloc(sizeof(SThreadObj), numOfThreads); pServerObj->pThreadObj = (SThreadObj *)calloc(sizeof(SThreadObj), numOfThreads);
if (pServerObj->pThreadObj == NULL) { if (pServerObj->pThreadObj == NULL) {
tError("TCP:%s no enough memory", label); tError("TCP:%s no enough memory", label);
terrno = TAOS_SYSTEM_ERROR(errno);
free(pServerObj); free(pServerObj);
return NULL; return NULL;
} }
int code = 0; int code = 0;
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
// initialize parameters in case it may encounter error later
pThreadObj = pServerObj->pThreadObj; pThreadObj = pServerObj->pThreadObj;
for (int i = 0; i < numOfThreads; ++i) { for (int i = 0; i < numOfThreads; ++i) {
pThreadObj->pollFd = -1;
pThreadObj->thread = 0;
pThreadObj->processData = fp; pThreadObj->processData = fp;
tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label));
pThreadObj->shandle = shandle; pThreadObj->shandle = shandle;
pThreadObj++;
}
// initialize mutex, thread, fd which may fail
pThreadObj = pServerObj->pThreadObj;
for (int i = 0; i < numOfThreads; ++i) {
code = pthread_mutex_init(&(pThreadObj->mutex), NULL); code = pthread_mutex_init(&(pThreadObj->mutex), NULL);
if (code < 0) { if (code < 0) {
tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno)); tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno));
@ -103,11 +127,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
break; break;
} }
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj));
pthread_attr_destroy(&thattr);
if (code != 0) { if (code != 0) {
tError("%s failed to create TCP process data thread(%s)", label, strerror(errno)); tError("%s failed to create TCP process data thread(%s)", label, strerror(errno));
break; break;
@ -117,48 +137,51 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
pThreadObj++; pThreadObj++;
} }
pServerObj->fd = taosOpenTcpServerSocket(pServerObj->ip, pServerObj->port);
if (pServerObj->fd < 0) code = -1;
if (code == 0) { if (code == 0) {
pthread_attr_t thattr; code = pthread_create(&pServerObj->thread, &thattr, taosAcceptTcpConnection, (void *)pServerObj);
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
code = pthread_create(&(pServerObj->thread), &thattr, (void *)taosAcceptTcpConnection, (void *)(pServerObj));
pthread_attr_destroy(&thattr);
if (code != 0) { if (code != 0) {
tError("%s failed to create TCP accept thread(%s)", label, strerror(errno)); tError("%s failed to create TCP accept thread(%s)", label, strerror(errno));
} }
} }
if (code != 0) { if (code != 0) {
free(pServerObj->pThreadObj); terrno = TAOS_SYSTEM_ERROR(errno);
free(pServerObj); taosCleanUpTcpServer(pServerObj);
pServerObj = NULL; pServerObj = NULL;
} else { } else {
tTrace("%s TCP server is initialized, ip:0x%x port:%hu numOfThreads:%d", label, ip, port, numOfThreads); tTrace("%s TCP server is initialized, ip:0x%x port:%hu numOfThreads:%d", label, ip, port, numOfThreads);
} }
pthread_attr_destroy(&thattr);
return (void *)pServerObj; return (void *)pServerObj;
} }
static void taosStopTcpThread(SThreadObj* pThreadObj) { static void taosStopTcpThread(SThreadObj* pThreadObj) {
pThreadObj->stop = true; pThreadObj->stop = true;
eventfd_t fd = -1;
// signal the thread to stop, try graceful method first, if (pThreadObj->thread && pThreadObj->pollFd >=0) {
// and use pthread_cancel when failed // signal the thread to stop, try graceful method first,
struct epoll_event event = { .events = EPOLLIN }; // and use pthread_cancel when failed
eventfd_t fd = eventfd(1, 0); struct epoll_event event = { .events = EPOLLIN };
if (fd == -1) { fd = eventfd(1, 0);
tError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); if (fd == -1) {
pthread_cancel(pThreadObj->thread); // failed to create eventfd, call pthread_cancel instead, which may result in data corruption:
} else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { tError("%s, failed to create eventfd(%s)", pThreadObj->label, strerror(errno));
tError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); pthread_cancel(pThreadObj->thread);
pthread_cancel(pThreadObj->thread); } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
// failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption:
tError("%s, failed to call epoll_ctl(%s)", pThreadObj->label, strerror(errno));
pthread_cancel(pThreadObj->thread);
}
} }
pthread_join(pThreadObj->thread, NULL); if (pThreadObj->thread) pthread_join(pThreadObj->thread, NULL);
close(pThreadObj->pollFd); if (pThreadObj->pollFd >=0) close(pThreadObj->pollFd);
if (fd != -1) { if (fd != -1) close(fd);
close(fd);
}
while (pThreadObj->pHead) { while (pThreadObj->pHead) {
SFdObj *pFdObj = pThreadObj->pHead; SFdObj *pFdObj = pThreadObj->pHead;
@ -173,9 +196,8 @@ void taosCleanUpTcpServer(void *handle) {
SThreadObj *pThreadObj; SThreadObj *pThreadObj;
if (pServerObj == NULL) return; if (pServerObj == NULL) return;
if(pServerObj->fd >=0) shutdown(pServerObj->fd, SHUT_RD);
shutdown(pServerObj->fd, SHUT_RD); if(pServerObj->thread) pthread_join(pServerObj->thread, NULL);
pthread_join(pServerObj->thread, NULL);
for (int i = 0; i < pServerObj->numOfThreads; ++i) { for (int i = 0; i < pServerObj->numOfThreads; ++i) {
pThreadObj = pServerObj->pThreadObj + i; pThreadObj = pServerObj->pThreadObj + i;
@ -189,7 +211,7 @@ void taosCleanUpTcpServer(void *handle) {
tfree(pServerObj); tfree(pServerObj);
} }
static void* taosAcceptTcpConnection(void *arg) { static void *taosAcceptTcpConnection(void *arg) {
int connFd = -1; int connFd = -1;
struct sockaddr_in caddr; struct sockaddr_in caddr;
int threadId = 0; int threadId = 0;
@ -197,10 +219,6 @@ static void* taosAcceptTcpConnection(void *arg) {
SServerObj *pServerObj; SServerObj *pServerObj;
pServerObj = (SServerObj *)arg; pServerObj = (SServerObj *)arg;
pServerObj->fd = taosOpenTcpServerSocket(pServerObj->ip, pServerObj->port);
if (pServerObj->fd < 0) return NULL;
tTrace("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port); tTrace("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port);
while (1) { while (1) {
@ -211,6 +229,7 @@ static void* taosAcceptTcpConnection(void *arg) {
tTrace("%s TCP server socket was shutdown, exiting...", pServerObj->label); tTrace("%s TCP server socket was shutdown, exiting...", pServerObj->label);
break; break;
} }
tError("%s TCP accept failure(%s)", pServerObj->label, strerror(errno)); tError("%s TCP accept failure(%s)", pServerObj->label, strerror(errno));
continue; continue;
} }
@ -254,6 +273,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *
if (pthread_mutex_init(&(pThreadObj->mutex), NULL) < 0) { if (pthread_mutex_init(&(pThreadObj->mutex), NULL) < 0) {
tError("%s failed to init TCP client mutex(%s)", label, strerror(errno)); tError("%s failed to init TCP client mutex(%s)", label, strerror(errno));
free(pThreadObj); free(pThreadObj);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL; return NULL;
} }
@ -261,6 +281,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *
if (pThreadObj->pollFd < 0) { if (pThreadObj->pollFd < 0) {
tError("%s failed to create TCP client epoll", label); tError("%s failed to create TCP client epoll", label);
free(pThreadObj); free(pThreadObj);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL; return NULL;
} }
@ -273,6 +294,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *
if (code != 0) { if (code != 0) {
close(pThreadObj->pollFd); close(pThreadObj->pollFd);
free(pThreadObj); free(pThreadObj);
terrno = TAOS_SYSTEM_ERROR(errno);
tError("%s failed to create TCP read data thread(%s)", label, strerror(errno)); tError("%s failed to create TCP read data thread(%s)", label, strerror(errno));
return NULL; return NULL;
} }
@ -287,7 +309,7 @@ void taosCleanUpTcpClient(void *chandle) {
if (pThreadObj == NULL) return; if (pThreadObj == NULL) return;
taosStopTcpThread(pThreadObj); taosStopTcpThread(pThreadObj);
tTrace (":%s, all connections are cleaned up", pThreadObj->label); tTrace ("%s, all connections are cleaned up", pThreadObj->label);
tfree(pThreadObj); tfree(pThreadObj);
} }
@ -318,7 +340,9 @@ void taosCloseTcpConnection(void *chandle) {
SFdObj *pFdObj = chandle; SFdObj *pFdObj = chandle;
if (pFdObj == NULL) return; if (pFdObj == NULL) return;
taosFreeFdObj(pFdObj); pFdObj->thandle = NULL;
pFdObj->closedByApp = 1;
shutdown(pFdObj->fd, SHUT_WR);
} }
int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle) { int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle) {
@ -334,7 +358,9 @@ static void taosReportBrokenLink(SFdObj *pFdObj) {
SThreadObj *pThreadObj = pFdObj->pThreadObj; SThreadObj *pThreadObj = pFdObj->pThreadObj;
// notify the upper layer, so it will clean the associated context // notify the upper layer, so it will clean the associated context
if (pFdObj->thandle) { if (pFdObj->closedByApp == 0) {
shutdown(pFdObj->fd, SHUT_WR);
SRecvInfo recvInfo; SRecvInfo recvInfo;
recvInfo.msg = NULL; recvInfo.msg = NULL;
recvInfo.msgLen = 0; recvInfo.msgLen = 0;
@ -345,9 +371,59 @@ static void taosReportBrokenLink(SFdObj *pFdObj) {
recvInfo.chandle = NULL; recvInfo.chandle = NULL;
recvInfo.connType = RPC_CONN_TCP; recvInfo.connType = RPC_CONN_TCP;
(*(pThreadObj->processData))(&recvInfo); (*(pThreadObj->processData))(&recvInfo);
} else { }
taosFreeFdObj(pFdObj);
taosFreeFdObj(pFdObj);
}
static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) {
SRpcHead rpcHead;
int32_t msgLen, leftLen, retLen, headLen;
char *buffer, *msg;
SThreadObj *pThreadObj = pFdObj->pThreadObj;
headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead));
if (headLen != sizeof(SRpcHead)) {
tTrace("%s %p, read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen);
return -1;
} }
msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen);
buffer = malloc(msgLen + tsRpcOverhead);
if ( NULL == buffer) {
tError("%s %p, TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen);
return -1;
}
msg = buffer + tsRpcOverhead;
leftLen = msgLen - headLen;
retLen = taosReadMsg(pFdObj->fd, msg + headLen, leftLen);
if (leftLen != retLen) {
tError("%s %p, read error, leftLen:%d retLen:%d",
pThreadObj->label, pFdObj->thandle, leftLen, retLen);
free(buffer);
return -1;
}
memcpy(msg, &rpcHead, sizeof(SRpcHead));
pInfo->msg = msg;
pInfo->msgLen = msgLen;
pInfo->ip = pFdObj->ip;
pInfo->port = pFdObj->port;
pInfo->shandle = pThreadObj->shandle;
pInfo->thandle = pFdObj->thandle;;
pInfo->chandle = pFdObj;
pInfo->connType = RPC_CONN_TCP;
if (pFdObj->closedByApp) {
free(buffer);
return -1;
}
return 0;
} }
#define maxEvents 10 #define maxEvents 10
@ -357,7 +433,6 @@ static void *taosProcessTcpData(void *param) {
SFdObj *pFdObj; SFdObj *pFdObj;
struct epoll_event events[maxEvents]; struct epoll_event events[maxEvents];
SRecvInfo recvInfo; SRecvInfo recvInfo;
SRpcHead rpcHead;
while (1) { while (1) {
int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, -1); int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, -1);
@ -376,51 +451,23 @@ static void *taosProcessTcpData(void *param) {
continue; continue;
} }
if (events[i].events & EPOLLRDHUP) {
tTrace("%s %p, FD RD hang up", pThreadObj->label, pFdObj->thandle);
taosReportBrokenLink(pFdObj);
continue;
}
if (events[i].events & EPOLLHUP) { if (events[i].events & EPOLLHUP) {
tTrace("%s %p, FD hang up", pThreadObj->label, pFdObj->thandle); tTrace("%s %p, FD hang up", pThreadObj->label, pFdObj->thandle);
taosReportBrokenLink(pFdObj); taosReportBrokenLink(pFdObj);
continue; continue;
} }
int32_t headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead)); if (taosReadTcpData(pFdObj, &recvInfo) < 0) {
if (headLen != sizeof(SRpcHead)) { shutdown(pFdObj->fd, SHUT_WR);
tTrace("%s %p, read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen);
taosReportBrokenLink(pFdObj);
continue; continue;
} }
int32_t msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen);
char *buffer = malloc(msgLen + tsRpcOverhead);
if ( NULL == buffer) {
tError("%s %p, TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen);
taosReportBrokenLink(pFdObj);
continue;
}
char *msg = buffer + tsRpcOverhead;
int32_t leftLen = msgLen - headLen;
int32_t retLen = taosReadMsg(pFdObj->fd, msg + headLen, leftLen);
if (leftLen != retLen) {
tError("%s %p, read error, leftLen:%d retLen:%d",
pThreadObj->label, pFdObj->thandle, leftLen, retLen);
taosReportBrokenLink(pFdObj);
tfree(buffer);
continue;
}
// tTrace("%s TCP data is received, ip:0x%x:%u len:%d", pThreadObj->label, pFdObj->ip, pFdObj->port, msgLen);
memcpy(msg, &rpcHead, sizeof(SRpcHead));
recvInfo.msg = msg;
recvInfo.msgLen = msgLen;
recvInfo.ip = pFdObj->ip;
recvInfo.port = pFdObj->port;
recvInfo.shandle = pThreadObj->shandle;
recvInfo.thandle = pFdObj->thandle;;
recvInfo.chandle = pFdObj;
recvInfo.connType = RPC_CONN_TCP;
pFdObj->thandle = (*(pThreadObj->processData))(&recvInfo); pFdObj->thandle = (*(pThreadObj->processData))(&recvInfo);
if (pFdObj->thandle == NULL) taosFreeFdObj(pFdObj); if (pFdObj->thandle == NULL) taosFreeFdObj(pFdObj);
} }
@ -433,16 +480,20 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd) {
struct epoll_event event; struct epoll_event event;
SFdObj *pFdObj = (SFdObj *)calloc(sizeof(SFdObj), 1); SFdObj *pFdObj = (SFdObj *)calloc(sizeof(SFdObj), 1);
if (pFdObj == NULL) return NULL; if (pFdObj == NULL) {
return NULL;
}
pFdObj->closedByApp = 0;
pFdObj->fd = fd; pFdObj->fd = fd;
pFdObj->pThreadObj = pThreadObj; pFdObj->pThreadObj = pThreadObj;
pFdObj->signature = pFdObj; pFdObj->signature = pFdObj;
event.events = EPOLLIN | EPOLLPRI | EPOLLWAKEUP; event.events = EPOLLIN | EPOLLRDHUP;
event.data.ptr = pFdObj; event.data.ptr = pFdObj;
if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
tfree(pFdObj); tfree(pFdObj);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL; return NULL;
} }
@ -475,13 +526,10 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
taosCloseSocket(pFdObj->fd); taosCloseSocket(pFdObj->fd);
pThreadObj->numOfFds--; pThreadObj->numOfFds--;
if (pThreadObj->numOfFds < 0) if (pThreadObj->numOfFds < 0)
tError("%s %p, TCP thread:%d, number of FDs is negative!!!", tError("%s %p, TCP thread:%d, number of FDs is negative!!!",
pThreadObj->label, pFdObj->thandle, pThreadObj->threadId); pThreadObj->label, pFdObj->thandle, pThreadObj->threadId);
// remove from the FdObject list
if (pFdObj->prev) { if (pFdObj->prev) {
(pFdObj->prev)->next = pFdObj->next; (pFdObj->prev)->next = pFdObj->next;
} else { } else {

View File

@ -18,6 +18,8 @@
#include "tsystem.h" #include "tsystem.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
#include "taosdef.h"
#include "taoserror.h"
#include "rpcLog.h" #include "rpcLog.h"
#include "rpcUdp.h" #include "rpcUdp.h"
#include "rpcHead.h" #include "rpcHead.h"
@ -33,7 +35,7 @@ typedef struct {
int fd; int fd;
uint16_t port; // peer port uint16_t port; // peer port
uint16_t localPort; // local port uint16_t localPort; // local port
char label[12]; // copy from udpConnSet; char label[TSDB_LABEL_LEN]; // copy from udpConnSet;
pthread_t thread; pthread_t thread;
void *hash; void *hash;
void *shandle; // handle passed by upper layer during server initialization void *shandle; // handle passed by upper layer during server initialization
@ -49,7 +51,7 @@ typedef struct {
uint16_t port; // local Port uint16_t port; // local Port
void *shandle; // handle passed by upper layer during server initialization void *shandle; // handle passed by upper layer during server initialization
int threads; int threads;
char label[12]; char label[TSDB_LABEL_LEN];
void *(*fp)(SRecvInfo *pPacket); void *(*fp)(SRecvInfo *pPacket);
SUdpConn udpConn[]; SUdpConn udpConn[];
} SUdpConnSet; } SUdpConnSet;
@ -64,6 +66,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
pSet = (SUdpConnSet *)malloc((size_t)size); pSet = (SUdpConnSet *)malloc((size_t)size);
if (pSet == NULL) { if (pSet == NULL) {
tError("%s failed to allocate UdpConn", label); tError("%s failed to allocate UdpConn", label);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL; return NULL;
} }
@ -72,30 +75,34 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
pSet->port = port; pSet->port = port;
pSet->shandle = shandle; pSet->shandle = shandle;
pSet->fp = fp; pSet->fp = fp;
pSet->threads = threads;
tstrncpy(pSet->label, label, sizeof(pSet->label)); tstrncpy(pSet->label, label, sizeof(pSet->label));
pthread_attr_t thAttr;
pthread_attr_init(&thAttr);
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
int i;
uint16_t ownPort; uint16_t ownPort;
for (int i = 0; i < threads; ++i) { for (i = 0; i < threads; ++i) {
pConn = pSet->udpConn + i; pConn = pSet->udpConn + i;
ownPort = (port ? port + i : 0); ownPort = (port ? port + i : 0);
pConn->fd = taosOpenUdpSocket(ip, ownPort); pConn->fd = taosOpenUdpSocket(ip, ownPort);
if (pConn->fd < 0) { if (pConn->fd < 0) {
tError("%s failed to open UDP socket %x:%hu", label, ip, port); tError("%s failed to open UDP socket %x:%hu", label, ip, port);
taosCleanUpUdpConnection(pSet); break;
return NULL;
} }
pConn->buffer = malloc(RPC_MAX_UDP_SIZE); pConn->buffer = malloc(RPC_MAX_UDP_SIZE);
if (NULL == pConn->buffer) { if (NULL == pConn->buffer) {
tError("%s failed to malloc recv buffer", label); tError("%s failed to malloc recv buffer", label);
taosCleanUpUdpConnection(pSet); break;
return NULL;
} }
struct sockaddr_in sin; struct sockaddr_in sin;
unsigned int addrlen = sizeof(sin); unsigned int addrlen = sizeof(sin);
if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 && sin.sin_family == AF_INET && if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 &&
addrlen == sizeof(sin)) { sin.sin_family == AF_INET && addrlen == sizeof(sin)) {
pConn->localPort = (uint16_t)ntohs(sin.sin_port); pConn->localPort = (uint16_t)ntohs(sin.sin_port);
} }
@ -106,23 +113,22 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
pConn->pSet = pSet; pConn->pSet = pSet;
pConn->signature = pConn; pConn->signature = pConn;
pthread_attr_t thAttr;
pthread_attr_init(&thAttr);
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
int code = pthread_create(&pConn->thread, &thAttr, taosRecvUdpData, pConn); int code = pthread_create(&pConn->thread, &thAttr, taosRecvUdpData, pConn);
pthread_attr_destroy(&thAttr);
if (code != 0) { if (code != 0) {
tError("%s failed to create thread to process UDP data, reason:%s", label, strerror(errno)); tError("%s failed to create thread to process UDP data(%s)", label, strerror(errno));
taosCloseSocket(pConn->fd); break;
taosCleanUpUdpConnection(pSet);
return NULL;
} }
++pSet->threads;
} }
tTrace("%s UDP connection is initialized, ip:%x port:%hu threads:%d", label, ip, port, threads); pthread_attr_destroy(&thAttr);
if (i != threads) {
terrno = TAOS_SYSTEM_ERROR(errno);
taosCleanUpUdpConnection(pSet);
return NULL;
}
tTrace("%s UDP connection is initialized, ip:%x:%hu threads:%d", label, ip, port, threads);
return pSet; return pSet;
} }
@ -135,16 +141,17 @@ void taosCleanUpUdpConnection(void *handle) {
for (int i = 0; i < pSet->threads; ++i) { for (int i = 0; i < pSet->threads; ++i) {
pConn = pSet->udpConn + i; pConn = pSet->udpConn + i;
pConn->signature = NULL; pConn->signature = NULL;
// shutdown to signal the thread to exit // shutdown to signal the thread to exit
shutdown(pConn->fd, SHUT_RD); if ( pConn->fd >=0) shutdown(pConn->fd, SHUT_RD);
} }
for (int i = 0; i < pSet->threads; ++i) { for (int i = 0; i < pSet->threads; ++i) {
pConn = pSet->udpConn + i; pConn = pSet->udpConn + i;
pthread_join(pConn->thread, NULL); if (pConn->thread) pthread_join(pConn->thread, NULL);
free(pConn->buffer); if (pConn->fd >=0) taosCloseSocket(pConn->fd);
taosCloseSocket(pConn->fd); tfree(pConn->buffer);
tTrace("chandle:%p is closed", pConn); tTrace("UDP chandle:%p is closed", pConn);
} }
tfree(pSet); tfree(pSet);
@ -158,7 +165,7 @@ void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t
SUdpConn *pConn = pSet->udpConn + pSet->index; SUdpConn *pConn = pSet->udpConn + pSet->index;
pConn->port = port; pConn->port = port;
tTrace("%s UDP connection is setup, ip:%x:%hu, local:%x:%d", pConn->label, ip, port, pSet->ip, pConn->localPort); tTrace("%s UDP connection is setup, ip:%x:%hu", pConn->label, ip, port);
return pConn; return pConn;
} }

View File

@ -92,16 +92,15 @@ STsdbCfg *tsdbGetCfg(const TsdbRepoT *repo) {
* @return a TSDB repository handle on success, NULL for failure * @return a TSDB repository handle on success, NULL for failure
*/ */
int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO */) { int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO */) {
if (mkdir(rootDir, 0755) != 0) { if (mkdir(rootDir, 0755) != 0) {
tsdbError("vgId:%d, failed to create rootDir! rootDir:%s, reason:%s", pCfg->tsdbId, rootDir, strerror(errno)); tsdbError("vgId:%d, failed to create rootDir! rootDir:%s, reason:%s", pCfg->tsdbId, rootDir, strerror(errno));
if (errno == EACCES) { if (errno == EACCES) {
return TSDB_CODE_NO_DISK_PERMISSIONS; return TSDB_CODE_TDB_NO_DISK_PERMISSIONS;
} else if (errno == ENOSPC) { } else if (errno == ENOSPC) {
return TSDB_CODE_SERV_NO_DISKSPACE; return TSDB_CODE_TDB_NO_DISKSPACE;
} else if (errno == EEXIST) { } else if (errno == EEXIST) {
} else { } else {
return TSDB_CODE_VG_INIT_FAILED; return TSDB_CODE_TDB_INIT_FAILED;
} }
} }
@ -315,7 +314,7 @@ int32_t tsdbConfigRepo(TsdbRepoT *repo, STsdbCfg *pCfg) {
STsdbRepo *pRepo = (STsdbRepo *)repo; STsdbRepo *pRepo = (STsdbRepo *)repo;
STsdbCfg * pRCfg = &pRepo->config; STsdbCfg * pRCfg = &pRepo->config;
if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return TSDB_CODE_INVALID_CONFIG; if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return TSDB_CODE_TDB_INVALID_CONFIG;
ASSERT(pRCfg->tsdbId == pCfg->tsdbId); ASSERT(pRCfg->tsdbId == pCfg->tsdbId);
ASSERT(pRCfg->cacheBlockSize == pCfg->cacheBlockSize); ASSERT(pRCfg->cacheBlockSize == pCfg->cacheBlockSize);
@ -416,13 +415,13 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) {
int16_t tversion = htons(pMsg->tversion); int16_t tversion = htons(pMsg->tversion);
STable *pTable = tsdbGetTableByUid(pMeta, htobe64(pMsg->uid)); STable *pTable = tsdbGetTableByUid(pMeta, htobe64(pMsg->uid));
if (pTable == NULL) return TSDB_CODE_INVALID_TABLE_ID; if (pTable == NULL) return TSDB_CODE_TDB_INVALID_TABLE_ID;
if (pTable->tableId.tid != htonl(pMsg->tid)) return TSDB_CODE_INVALID_TABLE_ID; if (pTable->tableId.tid != htonl(pMsg->tid)) return TSDB_CODE_TDB_INVALID_TABLE_ID;
if (pTable->type != TSDB_CHILD_TABLE) { if (pTable->type != TSDB_CHILD_TABLE) {
tsdbError("vgId:%d failed to update tag value of table %s since its type is %d", pRepo->config.tsdbId, tsdbError("vgId:%d failed to update tag value of table %s since its type is %d", pRepo->config.tsdbId,
varDataVal(pTable->name), pTable->type); varDataVal(pTable->name), pTable->type);
return TSDB_CODE_INVALID_TABLE_TYPE; return TSDB_CODE_TDB_INVALID_TABLE_TYPE;
} }
if (schemaVersion(tsdbGetTableTagSchema(pMeta, pTable)) < tversion) { if (schemaVersion(tsdbGetTableTagSchema(pMeta, pTable)) < tversion) {
@ -452,7 +451,7 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) {
"vgId:%d failed to update tag value of table %s since version out of date, client tag version:%d server tag " "vgId:%d failed to update tag value of table %s since version out of date, client tag version:%d server tag "
"version:%d", "version:%d",
pRepo->config.tsdbId, varDataVal(pTable->name), tversion, schemaVersion(pTable->tagSchema)); pRepo->config.tsdbId, varDataVal(pTable->name), tversion, schemaVersion(pTable->tagSchema));
return TSDB_CODE_TAG_VER_OUT_OF_DATE; return TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE;
} }
if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) { if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) {
tsdbRemoveTableFromIndex(pMeta, pTable); tsdbRemoveTableFromIndex(pMeta, pTable);
@ -474,6 +473,18 @@ TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid) {
return TSDB_GET_TABLE_LAST_KEY(pTable); return TSDB_GET_TABLE_LAST_KEY(pTable);
} }
void tsdbStartStream(TsdbRepoT *repo) {
STsdbRepo *pRepo = (STsdbRepo *)repo;
STsdbMeta *pMeta = pRepo->tsdbMeta;
for (int i = 0; i < pRepo->config.maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable && pTable->type == TSDB_STREAM_TABLE) {
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.uid, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable));
}
}
}
STableInfo *tsdbGetTableInfo(TsdbRepoT *pRepo, STableId tableId) { STableInfo *tsdbGetTableInfo(TsdbRepoT *pRepo, STableId tableId) {
// TODO // TODO
return NULL; return NULL;
@ -948,7 +959,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY
if (pTable == NULL) { if (pTable == NULL) {
tsdbError("vgId:%d, failed to get table for insert, uid:" PRIu64 ", tid:%d", pRepo->config.tsdbId, pBlock->uid, tsdbError("vgId:%d, failed to get table for insert, uid:" PRIu64 ", tid:%d", pRepo->config.tsdbId, pBlock->uid,
pBlock->tid); pBlock->tid);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_TDB_INVALID_TABLE_ID;
} }
// Check schema version // Check schema version
@ -980,7 +991,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY
if (tsdbGetTableSchemaByVersion(pMeta, pTable, tversion) == NULL) { if (tsdbGetTableSchemaByVersion(pMeta, pTable, tversion) == NULL) {
tsdbError("vgId:%d table:%s tid:%d invalid schema version %d from client", pRepo->config.tsdbId, tsdbError("vgId:%d table:%s tid:%d invalid schema version %d from client", pRepo->config.tsdbId,
varDataVal(pTable->name), pTable->tableId.tid, tversion); varDataVal(pTable->name), pTable->tableId.tid, tversion);
return TSDB_CODE_TABLE_SCHEMA_VERSION; return TSDB_CODE_TDB_TABLE_SCHEMA_VERSION;
} }
} }
@ -996,7 +1007,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY
tsdbError("vgId:%d, table:%s, tid:%d, talbe uid:%ld timestamp is out of range. now:" PRId64 ", maxKey:" PRId64 tsdbError("vgId:%d, table:%s, tid:%d, talbe uid:%ld timestamp is out of range. now:" PRId64 ", maxKey:" PRId64
", minKey:" PRId64, ", minKey:" PRId64,
pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, pTable->tableId.uid, now, minKey, maxKey); pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, pTable->tableId.uid, now, minKey, maxKey);
return TSDB_CODE_TIMESTAMP_OUT_OF_RANGE; return TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
} }
if (tdInsertRowToTable(pRepo, row, pTable) < 0) { if (tdInsertRowToTable(pRepo, row, pTable) < 0) {

View File

@ -74,14 +74,16 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) {
STable *tsdbDecodeTable(void *cont, int contLen) { STable *tsdbDecodeTable(void *cont, int contLen) {
STable *pTable = (STable *)calloc(1, sizeof(STable)); STable *pTable = (STable *)calloc(1, sizeof(STable));
if (pTable == NULL) return NULL; if (pTable == NULL) return NULL;
pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS);
if (pTable->schema == NULL) {
free(pTable);
return NULL;
}
void *ptr = cont; void *ptr = cont;
T_READ_MEMBER(ptr, int8_t, pTable->type); T_READ_MEMBER(ptr, int8_t, pTable->type);
if (pTable->type != TSDB_CHILD_TABLE) {
pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS);
if (pTable->schema == NULL) {
free(pTable);
return NULL;
}
}
int len = *(int *)ptr; int len = *(int *)ptr;
ptr = (char *)ptr + sizeof(int); ptr = (char *)ptr + sizeof(int);
pTable->name = calloc(1, len + VARSTR_HEADER_SIZE + 1); pTable->name = calloc(1, len + VARSTR_HEADER_SIZE + 1);
@ -150,7 +152,6 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
void tsdbOrgMeta(void *pHandle) { void tsdbOrgMeta(void *pHandle) {
STsdbMeta *pMeta = (STsdbMeta *)pHandle; STsdbMeta *pMeta = (STsdbMeta *)pHandle;
STsdbRepo *pRepo = (STsdbRepo *)pMeta->pRepo;
for (int i = 1; i < pMeta->maxTables; i++) { for (int i = 1; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i]; STable *pTable = pMeta->tables[i];
@ -158,13 +159,6 @@ void tsdbOrgMeta(void *pHandle) {
tsdbAddTableIntoIndex(pMeta, pTable); tsdbAddTableIntoIndex(pMeta, pTable);
} }
} }
for (int i = 0; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable && pTable->type == TSDB_STREAM_TABLE) {
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, i, pTable->sql, tsdbGetTableSchema(pMeta, pTable));
}
}
} }
/** /**
@ -323,7 +317,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
pTable = (STable *)calloc(1, sizeof(STable)); pTable = (STable *)calloc(1, sizeof(STable));
if (pTable == NULL) { if (pTable == NULL) {
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
goto _err; goto _err;
} }
@ -343,7 +337,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN); tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN);
pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1);
if (pTable->name == NULL) { if (pTable->name == NULL) {
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
goto _err; goto _err;
} }
STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->sname, tsize); STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->sname, tsize);
@ -352,7 +346,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, pColSchema->type, pColSchema->bytes, 1, 0, 0, pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, pColSchema->type, pColSchema->bytes, 1, 0, 0,
getTagIndexKey); // Allow duplicate key, no lock getTagIndexKey); // Allow duplicate key, no lock
if (pTable->pIndex == NULL) { if (pTable->pIndex == NULL) {
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
goto _err; goto _err;
} }
} else { } else {
@ -364,7 +358,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
tsize = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN); tsize = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN);
pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1);
if (pTable->name == NULL) { if (pTable->name == NULL) {
terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
goto _err; goto _err;
} }
STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->name, tsize); STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->name, tsize);
@ -399,7 +393,7 @@ static int tsdbUpdateTableTagSchema(STable *pTable, STSchema *newSchema) {
ASSERT(schemaVersion(pTable->tagSchema) < schemaVersion(newSchema)); ASSERT(schemaVersion(pTable->tagSchema) < schemaVersion(newSchema));
STSchema *pOldSchema = pTable->tagSchema; STSchema *pOldSchema = pTable->tagSchema;
STSchema *pNewSchema = tdDupSchema(newSchema); STSchema *pNewSchema = tdDupSchema(newSchema);
if (pNewSchema == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pNewSchema == NULL) return TSDB_CODE_TDB_OUT_OF_MEMORY;
pTable->tagSchema = pNewSchema; pTable->tagSchema = pNewSchema;
tdFreeSchema(pOldSchema); tdFreeSchema(pOldSchema);
@ -454,7 +448,7 @@ int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg) {
if (pTable != NULL) { if (pTable != NULL) {
tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name), tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name),
pTable->tableId.tid, pTable->tableId.uid); pTable->tableId.tid, pTable->tableId.uid);
return TSDB_CODE_TABLE_ALREADY_EXIST; return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
} }
STable *super = NULL; STable *super = NULL;
@ -628,7 +622,10 @@ static int tsdbFreeTable(STable *pTable) {
if (pTable->type == TSDB_CHILD_TABLE) { if (pTable->type == TSDB_CHILD_TABLE) {
kvRowFree(pTable->tagVal); kvRowFree(pTable->tagVal);
} else { } else {
for (int i = 0; i < pTable->numOfSchemas; i++) tdFreeSchema(pTable->schema[i]); if (pTable->schema) {
for (int i = 0; i < pTable->numOfSchemas; i++) tdFreeSchema(pTable->schema[i]);
free(pTable->schema);
}
} }
if (pTable->type == TSDB_STREAM_TABLE) { if (pTable->type == TSDB_STREAM_TABLE) {
@ -683,7 +680,7 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx) {
tsdbAddTableIntoIndex(pMeta, pTable); tsdbAddTableIntoIndex(pMeta, pTable);
} }
if (pTable->type == TSDB_STREAM_TABLE && addIdx) { if (pTable->type == TSDB_STREAM_TABLE && addIdx) {
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.uid, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable));
} }
pMeta->nTables++; pMeta->nTables++;

View File

@ -764,8 +764,8 @@ static bool tsdbShouldCreateNewLast(SRWHelper *pHelper) {
static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite, SCompBlock *pCompBlock, static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite, SCompBlock *pCompBlock,
bool isLast, bool isSuperBlock) { bool isLast, bool isSuperBlock) {
ASSERT(rowsToWrite > 0 && rowsToWrite <= pDataCols->numOfRows && ASSERT(rowsToWrite > 0 && rowsToWrite <= pDataCols->numOfRows && rowsToWrite <= pHelper->config.maxRowsPerFileBlock);
rowsToWrite <= pHelper->config.maxRowsPerFileBlock); ASSERT(isLast ? rowsToWrite < pHelper->config.minRowsPerFileBlock : true);
SCompData *pCompData = (SCompData *)(pHelper->pBuffer); SCompData *pCompData = (SCompData *)(pHelper->pBuffer);
int64_t offset = 0; int64_t offset = 0;
@ -905,14 +905,15 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
rowsWritten = MIN((defaultRowsToWrite - blockAtIdx(pHelper, blkIdx)->numOfRows), pDataCols->numOfRows); rowsWritten = MIN((defaultRowsToWrite - blockAtIdx(pHelper, blkIdx)->numOfRows), pDataCols->numOfRows);
if ((blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) && if ((blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) &&
(blockAtIdx(pHelper, blkIdx)->numOfRows + rowsWritten < pHelper->config.minRowsPerFileBlock) && (pHelper->files.nLastF.fd) > 0) { (blockAtIdx(pHelper, blkIdx)->numOfRows + rowsWritten < pHelper->config.minRowsPerFileBlock) &&
(pHelper->files.nLastF.fd) < 0) {
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.lastF), pDataCols, rowsWritten, &compBlock, true, false) < 0) if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.lastF), pDataCols, rowsWritten, &compBlock, true, false) < 0)
goto _err; goto _err;
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err; if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
} else { } else {
// Load // Load
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err; if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err;
ASSERT(pHelper->pDataCols[0]->numOfRows == blockAtIdx(pHelper, blkIdx)->numOfRows); ASSERT(pHelper->pDataCols[0]->numOfRows <= blockAtIdx(pHelper, blkIdx)->numOfRows);
// Merge // Merge
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, rowsWritten) < 0) goto _err; if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, rowsWritten) < 0) goto _err;
// Write // Write
@ -936,21 +937,21 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
// Key must overlap with the block // Key must overlap with the block
ASSERT(keyFirst <= blockAtIdx(pHelper, blkIdx)->keyLast); ASSERT(keyFirst <= blockAtIdx(pHelper, blkIdx)->keyLast);
TSKEY keyLimit = TSKEY keyLimit = (blkIdx == pIdx->numOfBlocks - 1) ? INT64_MAX : blockAtIdx(pHelper, blkIdx + 1)->keyFirst - 1;
(blkIdx == pIdx->numOfBlocks - 1) ? INT64_MAX : pHelper->pCompInfo->blocks[blkIdx + 1].keyFirst - 1;
// rows1: number of rows must merge in this block // rows1: number of rows must merge in this block
int rows1 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, blockAtIdx(pHelper, blkIdx)->keyLast); int rows1 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, blockAtIdx(pHelper, blkIdx)->keyLast);
// rows2: max nuber of rows the block can have more // rows2: max number of rows the block can have more
int rows2 = pHelper->config.maxRowsPerFileBlock - blockAtIdx(pHelper, blkIdx)->numOfRows; int rows2 = pHelper->config.maxRowsPerFileBlock - blockAtIdx(pHelper, blkIdx)->numOfRows;
// rows3: number of rows between this block and the next block // rows3: number of rows between this block and the next block
int rows3 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, keyLimit); int rows3 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, keyLimit);
ASSERT(rows3 >= rows1); ASSERT(rows3 >= rows1);
if ((rows2 >= rows1) && if ((rows2 >= rows1) && (blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) &&
(( blockAtIdx(pHelper, blkIdx)->last) || ((!blockAtIdx(pHelper, blkIdx)->last) ||
((rows1 + blockAtIdx(pHelper, blkIdx)->numOfRows < pHelper->config.minRowsPerFileBlock) && (pHelper->files.nLastF.fd < 0)))) { ((rows1 + blockAtIdx(pHelper, blkIdx)->numOfRows < pHelper->config.minRowsPerFileBlock) &&
(pHelper->files.nLastF.fd < 0)))) {
rowsWritten = rows1; rowsWritten = rows1;
bool isLast = false; bool isLast = false;
SFile *pFile = NULL; SFile *pFile = NULL;
@ -964,7 +965,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
if (tsdbWriteBlockToFile(pHelper, pFile, pDataCols, rows1, &compBlock, isLast, false) < 0) goto _err; if (tsdbWriteBlockToFile(pHelper, pFile, pDataCols, rows1, &compBlock, isLast, false) < 0) goto _err;
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err; if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
} else { // Load-Merge-Write } else { // Load-Merge-Write
// Load // Load
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err; if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err;
if (blockAtIdx(pHelper, blkIdx)->last) pHelper->hasOldLastBlock = false; if (blockAtIdx(pHelper, blkIdx)->last) pHelper->hasOldLastBlock = false;
@ -1106,16 +1107,16 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) { for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i; SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i;
if (pTCompBlock->numOfSubBlocks > 1) { if (pTCompBlock->numOfSubBlocks > 1) {
ptr = (void *)((char *)(pHelper->pCompInfo) + pTCompBlock->offset + pTCompBlock->len); ptr = POINTER_SHIFT(pHelper->pCompInfo, pTCompBlock->offset);
break; break;
} }
} }
if (ptr == NULL) ptr = (void *)((char *)(pHelper->pCompInfo) + pIdx->len - sizeof(TSCKSUM)); if (ptr == NULL) ptr = POINTER_SHIFT(pHelper->pCompInfo, pIdx->len-sizeof(TSCKSUM));
size_t tsize = pIdx->len - ((char *)ptr - (char *)(pHelper->pCompInfo)); size_t tsize = pIdx->len - ((char *)ptr - (char *)(pHelper->pCompInfo));
if (tsize > 0) { if (tsize > 0) {
memmove((void *)((char *)ptr + sizeof(SCompBlock) * 2), ptr, tsize); memmove(POINTER_SHIFT(ptr, sizeof(SCompBlock) * 2), ptr, tsize);
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) { for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i; SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i;
if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset += (sizeof(SCompBlock) * 2); if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset += (sizeof(SCompBlock) * 2);

View File

@ -1216,7 +1216,7 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void*
static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numOfBlocks, int32_t* numOfAllocBlocks) { static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numOfBlocks, int32_t* numOfAllocBlocks) {
char* tmp = realloc(pQueryHandle->pDataBlockInfo, sizeof(STableBlockInfo) * numOfBlocks); char* tmp = realloc(pQueryHandle->pDataBlockInfo, sizeof(STableBlockInfo) * numOfBlocks);
if (tmp == NULL) { if (tmp == NULL) {
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_TDB_OUT_OF_MEMORY;
} }
pQueryHandle->pDataBlockInfo = (STableBlockInfo*) tmp; pQueryHandle->pDataBlockInfo = (STableBlockInfo*) tmp;
@ -1233,7 +1233,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) { if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) {
cleanBlockOrderSupporter(&sup, 0); cleanBlockOrderSupporter(&sup, 0);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_TDB_OUT_OF_MEMORY;
} }
int32_t cnt = 0; int32_t cnt = 0;
@ -1251,7 +1251,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
char* buf = calloc(1, sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); char* buf = calloc(1, sizeof(STableBlockInfo) * pTableCheck->numOfBlocks);
if (buf == NULL) { if (buf == NULL) {
cleanBlockOrderSupporter(&sup, numOfQualTables); cleanBlockOrderSupporter(&sup, numOfQualTables);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_TDB_OUT_OF_MEMORY;
} }
sup.pDataBlockInfo[numOfQualTables] = (STableBlockInfo*)buf; sup.pDataBlockInfo[numOfQualTables] = (STableBlockInfo*)buf;
@ -1289,7 +1289,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
uint8_t ret = tLoserTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); uint8_t ret = tLoserTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
cleanBlockOrderSupporter(&sup, numOfTables); cleanBlockOrderSupporter(&sup, numOfTables);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_TDB_OUT_OF_MEMORY;
} }
int32_t numOfTotal = 0; int32_t numOfTotal = 0;
@ -2177,14 +2177,14 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag
STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
if (pTable == NULL) { if (pTable == NULL) {
tsdbError("%p failed to get stable, uid:%" PRIu64, tsdb, uid); tsdbError("%p failed to get stable, uid:%" PRIu64, tsdb, uid);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_TDB_INVALID_TABLE_ID;
} }
if (pTable->type != TSDB_SUPER_TABLE) { if (pTable->type != TSDB_SUPER_TABLE) {
tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", tid:%d, name:%s", tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", tid:%d, name:%s",
tsdb, uid, pTable->tableId.tid, pTable->name); tsdb, uid, pTable->tableId.tid, pTable->name);
return TSDB_CODE_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client return TSDB_CODE_COM_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client
} }
SArray* res = taosArrayInit(8, sizeof(STableId)); SArray* res = taosArrayInit(8, sizeof(STableId));
@ -2221,7 +2221,7 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag
tExprNode* tbnameExpr = expr; tExprNode* tbnameExpr = expr;
expr = calloc(1, sizeof(tExprNode)); expr = calloc(1, sizeof(tExprNode));
if (expr == NULL) { if (expr == NULL) {
THROW( TSDB_CODE_SERV_OUT_OF_MEMORY ); THROW( TSDB_CODE_TDB_OUT_OF_MEMORY );
} }
expr->nodeType = TSQL_NODE_EXPR; expr->nodeType = TSQL_NODE_EXPR;
expr->_node.optr = tagNameRelType; expr->_node.optr = tagNameRelType;
@ -2248,7 +2248,7 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag
int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, uint64_t uid, STableGroupInfo* pGroupInfo) { int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, uint64_t uid, STableGroupInfo* pGroupInfo) {
STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
if (pTable == NULL) { if (pTable == NULL) {
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_TDB_INVALID_TABLE_ID;
} }
//todo assert table type, add the table ref count //todo assert table type, add the table ref count

60
src/util/inc/tkvstore.h Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_KVSTORE_H_
#define _TD_KVSTORE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
typedef int (*iterFunc)(void *, void *cont, int contLen);
typedef void (*afterFunc)(void *);
typedef struct {
int64_t size;
int64_t tombSize;
int64_t nRecords;
int64_t nDels;
} SStoreInfo;
typedef struct {
char * fname;
int fd;
char * fsnap;
int sfd;
char * fnew;
int nfd;
SHashObj * map;
iterFunc iFunc;
afterFunc aFunc;
void * appH;
SStoreInfo info;
} SKVStore;
int tdCreateKVStore(char *fname);
int tdDestroyKVStore();
SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH);
void tdCloseKVStore(SKVStore *pStore);
int tdKVStoreStartCommit(SKVStore *pStore);
int tdUpdateRecordInKVStore(SKVStore *pStore, uint64_t uid, void *cont, int contLen);
int tdKVStoreEndCommit(SKVStore *pStore);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -26,7 +26,7 @@
size_t tbufSkip(SBufferReader* buf, size_t size) { size_t tbufSkip(SBufferReader* buf, size_t size) {
if( (buf->pos + size) > buf->size ) { if( (buf->pos + size) > buf->size ) {
THROW( TSDB_CODE_MEMORY_CORRUPTED ); THROW( TSDB_CODE_COM_MEMORY_CORRUPTED );
} }
size_t old = buf->pos; size_t old = buf->pos;
buf->pos += size; buf->pos += size;
@ -58,7 +58,7 @@ const char* tbufReadString( SBufferReader* buf, size_t* len ) {
const char* ret = buf->data + buf->pos; const char* ret = buf->data + buf->pos;
tbufSkip( buf, l + 1 ); tbufSkip( buf, l + 1 );
if( ret[l] != 0 ) { if( ret[l] != 0 ) {
THROW( TSDB_CODE_MEMORY_CORRUPTED ); THROW( TSDB_CODE_COM_MEMORY_CORRUPTED );
} }
if( len != NULL ) { if( len != NULL ) {
*len = l; *len = l;
@ -204,7 +204,7 @@ void tbufEnsureCapacity( SBufferWriter* buf, size_t size ) {
char* data = (*buf->allocator)( buf->data, nsize ); char* data = (*buf->allocator)( buf->data, nsize );
// TODO: the exception should be thrown by the allocator function // TODO: the exception should be thrown by the allocator function
if( data == NULL ) { if( data == NULL ) {
THROW( TSDB_CODE_SERV_OUT_OF_MEMORY ); THROW( TSDB_CODE_COM_OUT_OF_MEMORY );
} }
buf->data = data; buf->data = data;
buf->size = nsize; buf->size = nsize;

View File

@ -18,6 +18,7 @@ void generate_key(unsigned char* key);
void generate_sub_keys(unsigned char* main_key, key_set* key_sets); void generate_sub_keys(unsigned char* main_key, key_set* key_sets);
void process_message(unsigned char* message_piece, unsigned char* processed_piece, key_set* key_sets, int mode); void process_message(unsigned char* message_piece, unsigned char* processed_piece, key_set* key_sets, int mode);
#if 0
int64_t taosDesGenKey() { int64_t taosDesGenKey() {
unsigned int iseed = (unsigned int)time(NULL); unsigned int iseed = (unsigned int)time(NULL);
srand(iseed); srand(iseed);
@ -27,6 +28,7 @@ int64_t taosDesGenKey() {
return *((int64_t*)key); return *((int64_t*)key);
} }
#endif
char* taosDesImp(unsigned char* key, char* src, unsigned int len, int process_mode) { char* taosDesImp(unsigned char* key, char* src, unsigned int len, int process_mode) {
unsigned int number_of_blocks = len / 8; unsigned int number_of_blocks = len / 8;

292
src/util/src/tkvstore.c Normal file
View File

@ -0,0 +1,292 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "hash.h"
#include "os.h"
#include "taoserror.h"
#include "tchecksum.h"
#include "tcoding.h"
#include "tkvstore.h"
#include "tulog.h"
#define TD_KVSTORE_HEADER_SIZE 512
#define TD_KVSTORE_MAJOR_VERSION 1
#define TD_KVSTORE_MAINOR_VERSION 0
#define TD_KVSTORE_SNAP_SUFFIX ".snap"
#define TD_KVSTORE_NEW_SUFFIX ".new"
static int tdInitKVStoreHeader(int fd, char *fname);
static void * tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo);
// static void * tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo);
static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH);
static char * tdGetKVStoreSnapshotFname(char *fdata);
static char * tdGetKVStoreNewFname(char *fdata);
static void tdFreeKVStore(SKVStore *pStore);
static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo);
int tdCreateKVStore(char *fname) {
char *tname = strdup(fname);
if (tname == NULL) return TSDB_CODE_COM_OUT_OF_MEMORY;
int fd = open(fname, O_RDWR | O_CREAT, 0755);
if (fd < 0) {
uError("failed to open file %s since %s", fname, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
}
int code = tdInitKVStoreHeader(fd, fname);
if (code != TSDB_CODE_SUCCESS) return code;
if (fsync(fd) < 0) {
uError("failed to fsync file %s since %s", fname, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
}
if (close(fd) < 0) {
uError("failed to close file %s since %s", fname, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
}
return TSDB_CODE_SUCCESS;
}
SKVStore *tdOpenKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH) {
SKVStore *pStore = tdNewKVStore(fname, iFunc, aFunc, appH);
if (pStore == NULL) return NULL;
pStore->fd = open(pStore->fname, O_RDWR);
if (pStore->fd < 0) {
uError("failed to open file %s since %s", pStore->fname, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (access(pStore->fsnap, F_OK) == 0) {
uTrace("file %s exists, try to recover the KV store", pStore->fsnap);
pStore->sfd = open(pStore->fsnap, O_RDONLY);
if (pStore->sfd < 0) {
uError("failed to open file %s since %s", pStore->fsnap, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
// TODO: rewind the file
close(pStore->sfd);
pStore->sfd = -1;
remove(pStore->fsnap);
}
// TODO: Recover from the file
return pStore;
_err:
if (pStore->fd > 0) {
close(pStore->fd);
pStore->fd = -1;
}
if (pStore->sfd > 0) {
close(pStore->sfd);
pStore->sfd = -1;
}
tdFreeKVStore(pStore);
return NULL;
}
int tdKVStoreStartCommit(SKVStore *pStore) {
pStore->fd = open(pStore->fname, O_RDWR);
if (pStore->fd < 0) {
uError("failed to open file %s since %s", pStore->fname, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
pStore->sfd = open(pStore->fsnap, O_WRONLY | O_CREAT, 0755);
if (pStore->sfd < 0) {
uError("failed to open file %s since %s", pStore->fsnap, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (tsendfile(pStore->sfd, pStore->fd, NULL, TD_KVSTORE_HEADER_SIZE) < TD_KVSTORE_HEADER_SIZE) {
uError("failed to send file %d bytes since %s", TD_KVSTORE_HEADER_SIZE, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (fsync(pStore->sfd) < 0) {
uError("failed to fsync file %s since %s", pStore->fsnap, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (close(pStore->sfd) < 0) {
uError("failed to close file %s since %s", pStore->fsnap, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
pStore->sfd = -1;
return 0;
_err:
if (pStore->sfd > 0) {
close(pStore->sfd);
pStore->sfd = -1;
remove(pStore->fsnap);
}
if (pStore->fd > 0) {
close(pStore->fd);
pStore->fd = -1;
}
return -1;
}
int tdKVStoreEndCommit(SKVStore *pStore) {
ASSERT(pStore->fd > 0);
terrno = tdUpdateKVStoreHeader(pStore->fd, pStore->fname, &(pStore->info));
if (terrno != TSDB_CODE_SUCCESS) return -1;
if (fsync(pStore->fd) < 0) {
uError("failed to fsync file %s since %s", pStore->fname, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
if (close(pStore->fd) < 0) {
uError("failed to close file %s since %s", pStore->fname, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
remove(pStore->fsnap);
return 0;
}
static int tdUpdateKVStoreHeader(int fd, char *fname, SStoreInfo *pInfo) {
char buf[TD_KVSTORE_HEADER_SIZE] = "\0";
if (lseek(fd, 0, SEEK_SET) < 0) {
uError("failed to lseek file %s since %s", fname, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
}
tdEncodeStoreInfo(buf, pInfo);
taosCalcChecksumAppend(0, (uint8_t *)buf, TD_KVSTORE_HEADER_SIZE);
if (twrite(fd, buf, TD_KVSTORE_HEADER_SIZE) < TD_KVSTORE_HEADER_SIZE) {
uError("failed to write file %s %d bytes since %s", fname, TD_KVSTORE_HEADER_SIZE, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
}
return TSDB_CODE_SUCCESS;
}
static int tdInitKVStoreHeader(int fd, char *fname) {
SStoreInfo info = {TD_KVSTORE_HEADER_SIZE, 0, 0, 0};
return tdUpdateKVStoreHeader(fd, fname, &info);
}
static void *tdEncodeStoreInfo(void *buf, SStoreInfo *pInfo) {
buf = taosEncodeVariantI64(buf, pInfo->size);
buf = taosEncodeVariantI64(buf, pInfo->tombSize);
buf = taosEncodeVariantI64(buf, pInfo->nRecords);
buf = taosEncodeVariantI64(buf, pInfo->nDels);
return buf;
}
// static void *tdDecodeStoreInfo(void *buf, SStoreInfo *pInfo) {
// buf = taosDecodeVariantI64(buf, &(pInfo->size));
// buf = taosDecodeVariantI64(buf, &(pInfo->tombSize));
// buf = taosDecodeVariantI64(buf, &(pInfo->nRecords));
// buf = taosDecodeVariantI64(buf, &(pInfo->nDels));
// return buf;
// }
static SKVStore *tdNewKVStore(char *fname, iterFunc iFunc, afterFunc aFunc, void *appH) {
SKVStore *pStore = (SKVStore *)malloc(sizeof(SKVStore));
if (pStore == NULL) goto _err;
pStore->fname = strdup(fname);
if (pStore->map == NULL) goto _err;
pStore->fsnap = tdGetKVStoreSnapshotFname(fname);
if (pStore->fsnap == NULL) goto _err;
pStore->fnew = tdGetKVStoreNewFname(fname);
if (pStore->fnew == NULL) goto _err;
pStore->fd = -1;
pStore->sfd = -1;
pStore->nfd = -1;
pStore->iFunc = iFunc;
pStore->aFunc = aFunc;
pStore->appH = appH;
pStore->map = taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false);
if (pStore->map == NULL) {
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
goto _err;
}
return pStore;
_err:
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
tdFreeKVStore(pStore);
return NULL;
}
static void tdFreeKVStore(SKVStore *pStore) {
if (pStore) {
tfree(pStore->fname);
tfree(pStore->fsnap);
tfree(pStore->fnew);
taosHashCleanup(pStore->map);
free(pStore);
}
}
static char *tdGetKVStoreSnapshotFname(char *fdata) {
size_t size = strlen(fdata) + strlen(TD_KVSTORE_SNAP_SUFFIX) + 1;
char * fname = malloc(size);
if (fname == NULL) {
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
return NULL;
}
sprintf(fname, "%s%s", fdata, TD_KVSTORE_SNAP_SUFFIX);
return fname;
}
static char *tdGetKVStoreNewFname(char *fdata) {
size_t size = strlen(fdata) + strlen(TD_KVSTORE_NEW_SUFFIX) + 1;
char * fname = malloc(size);
if (fname == NULL) {
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
return NULL;
}
sprintf(fname, "%s%s", fdata, TD_KVSTORE_NEW_SUFFIX);
return fname;
}

View File

@ -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)) {

View File

@ -87,6 +87,10 @@ void *taosThreadToOpenNewNote(void *param)
umask(0); umask(0);
int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) {
return NULL;
}
taosLockNote(fd, pNote); taosLockNote(fd, pNote);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);

Some files were not shown because too many files have changed in this diff Show More