diff --git a/Jenkinsfile b/Jenkinsfile index 398ce0f8696f7aa0c9e22918b838094333aba197..2558df777b5698de59093316da0e18407a160d77 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,8 +83,7 @@ def pre_test(){ mkdir debug cd debug cmake .. > /dev/null - make > /dev/null - make install > /dev/null + make -j4> /dev/null ''' return 1 diff --git a/include/common/tname.h b/include/common/tname.h index 7578a7804cccae575ec35becd3da6f595150b9bf..e31bfd38a67dd5e01e6a3246e490d998bf50331f 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -16,7 +16,7 @@ #ifndef TDENGINE_TNAME_H #define TDENGINE_TNAME_H -#include "taosmsg.h" +//#include "taosmsg.h" #define TSDB_DB_NAME_T 1 #define TSDB_TABLE_NAME_T 2 @@ -27,7 +27,7 @@ typedef struct SName { uint8_t type; //db_name_t, table_name_t - char acctId[TSDB_ACCT_ID_LEN]; + int32_t acctId; char dbname[TSDB_DB_NAME_LEN]; char tname[TSDB_TABLE_NAME_LEN]; } SName; @@ -38,7 +38,7 @@ int32_t tNameLen(const SName* name); SName* tNameDup(const SName* name); -bool tIsValidName(const SName* name); +bool tNameIsValid(const SName* name); const char* tNameGetTableName(const SName* name); @@ -50,14 +50,10 @@ bool tNameIsEmpty(const SName* name); void tNameAssign(SName* dst, const SName* src); -int32_t tNameFromString(SName* dst, const char* str, uint32_t type); - -int32_t tNameSetAcctId(SName* dst, const char* acct); +int32_t tNameSetDbName(SName* dst, int32_t acctId, const char* dbName, size_t nameLen); -SSchema* tGetTbnameColumnSchema(); +int32_t tNameFromString(SName* dst, const char* str, uint32_t type); -#if 0 -int32_t tNameSetDbName(SName* dst, const char* acct, SToken* dbToken); -#endif +int32_t tNameSetAcctId(SName* dst, int32_t acctId); #endif // TDENGINE_TNAME_H diff --git a/include/libs/query/query.h b/include/libs/qcom/query.h similarity index 96% rename from include/libs/query/query.h rename to include/libs/qcom/query.h index f8c7d787ba1c44b23e9354b6c03e7296234959c0..254d572149b6c01a439cd9e23470ff90c5a65936 100644 --- a/include/libs/query/query.h +++ b/include/libs/qcom/query.h @@ -81,12 +81,14 @@ typedef struct STableMetaOutput { STableMeta *tbMeta; } STableMetaOutput; +bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); + extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize); +SSchema* tGetTbnameColumnSchema(); extern void msgInit(); - extern int32_t qDebugFlag; #define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0) diff --git a/include/util/mallocator.h b/include/util/mallocator.h index ffe242017efaa49d2d9b6c1b92e802dcdd97951e..49a93273532523418d475a902809a9e0ee93706a 100644 --- a/include/util/mallocator.h +++ b/include/util/mallocator.h @@ -22,23 +22,28 @@ extern "C" { #endif -typedef struct SMemAllocator SMemAllocator; -typedef struct SMemAllocatorFactory SMemAllocatorFactory; - -struct SMemAllocator { +// Memory allocator +#define TD_MEM_ALCT(TYPE) \ + struct { \ + void *(*malloc_)(struct TYPE *, uint64_t size); \ + void (*free_)(struct TYPE *, void *ptr); \ + } +#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_ +#define TD_MA_FREE_FUNC(TMA) (TMA)->free_ + +#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE)) +#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR)) + +typedef struct SMemAllocator { void *impl; - void *(*malloc)(SMemAllocator *, uint64_t size); - void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size); - void *(*realloc)(SMemAllocator *, void *ptr, uint64_t size); - void (*free)(SMemAllocator *, void *ptr); - uint64_t (*usage)(SMemAllocator *); -}; - -struct SMemAllocatorFactory { + TD_MEM_ALCT(SMemAllocator); +} SMemAllocator; + +typedef struct SMemAllocatorFactory { void *impl; - SMemAllocator *(*create)(SMemAllocatorFactory *); - void (*destroy)(SMemAllocatorFactory *, SMemAllocator *); -}; + SMemAllocator *(*create)(struct SMemAllocatorFactory *); + void (*destroy)(struct SMemAllocatorFactory *, SMemAllocator *); +} SMemAllocatorFactory; #ifdef __cplusplus } diff --git a/include/util/tdlist.h b/include/util/tdlist.h deleted file mode 100644 index d047a57770277ef32272b59576cdc8ab98b64e43..0000000000000000000000000000000000000000 --- a/include/util/tdlist.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * 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 . - */ - -#ifndef _TD_UTIL_TDLIST_H_ -#define _TD_UTIL_TDLIST_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -// Single linked list -#define TD_SLIST_NODE(TYPE) \ - struct { \ - struct TYPE *sl_next_; \ - } - -#define TD_SLIST(TYPE) \ - struct { \ - struct TYPE *sl_head_; \ - int sl_neles_; \ - } - -#define TD_SLIST_HEAD(sl) ((sl)->sl_head_) -#define TD_SLIST_NELES(sl) ((sl)->sl_neles_) -#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_) - -#define tSListInit(sl) \ - do { \ - (sl)->sl_head_ = NULL; \ - (sl)->sl_neles_ = 0; \ - } while (0) - -#define tSListPush(sl, sln) \ - do { \ - TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \ - TD_SLIST_HEAD(sl) = (sln); \ - TD_SLIST_NELES(sl) += 1; \ - } while (0) - -#define tSListPop(sl) \ - do { \ - TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \ - TD_SLIST_NELES(sl) -= 1; \ - } while (0) - -// Double linked list -#define TD_DLIST_NODE(TYPE) \ - struct { \ - struct TYPE *dl_prev_; \ - struct TYPE *dl_next_; \ - } - -#define TD_DLIST(TYPE) \ - struct { \ - struct TYPE *dl_head_; \ - struct TYPE *dl_tail_; \ - int dl_neles_; \ - } - -#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_) -#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_) -#define TD_DLIST_HEAD(dl) ((dl)->dl_head_) -#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_) -#define TD_DLIST_NELES(dl) ((dl)->dl_neles_) - -#define tDListInit(dl) \ - do { \ - TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \ - TD_DLIST_NELES(dl) = 0; \ - } while (0) - -#define tDListAppend(dl, dln) \ - do { \ - if (TD_DLIST_HEAD(dl) == NULL) { \ - TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ - TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \ - } else { \ - TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \ - TD_DLIST_NODE_NEXT(dln) = NULL; \ - TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \ - TD_DLIST_TAIL(dl) = (dln); \ - } \ - TD_DLIST_NELES(dl) += 1; \ - } while (0) - -#define tDListPrepend(dl, dln) \ - do { \ - if (TD_DLIST_HEAD(dl) == NULL) { \ - TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ - TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \ - } else { \ - TD_DLIST_NODE_PREV(dln) = NULL; \ - TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \ - TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \ - TD_DLIST_HEAD(dl) = (dln); \ - } \ - TD_DLIST_NELES(dl) += 1; \ - } while (0) - -#define tDListPop(dl, dln) \ - do { \ - if (TD_DLIST_HEAD(dl) == (dln)) { \ - TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \ - } \ - if (TD_DLIST_TAIL(dl) == (dln)) { \ - TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \ - } \ - if (TD_DLIST_NODE_PREV(dln) != NULL) { \ - TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \ - } \ - if (TD_DLIST_NODE_NEXT(dln) != NULL) { \ - TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \ - } \ - TD_DLIST_NELES(dl) -= 1; \ - TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ - } while (0) - -#if 0 -// List iterator -#define TD_LIST_FITER 0 -#define TD_LIST_BITER 1 -#define TD_LIST_ITER(S) \ - struct { \ - int it_dir_; \ - S * it_next_; \ - S * it_ptr_; \ - TD_DLIST(S) * it_list_; \ - } - -#define tlistIterInit(it, l, dir) \ - (it)->it_dir_ = (dir); \ - (it)->it_list_ = l; \ - if ((dir) == TD_LIST_FITER) { \ - (it)->it_next_ = (l)->dl_head_; \ - } else { \ - (it)->it_next_ = (l)->dl_tail_; \ - } - -#define tlistIterNext(it) \ - ({ \ - (it)->it_ptr_ = (it)->it_next_; \ - if ((it)->it_next_ != NULL) { \ - if ((it)->it_dir_ == TD_LIST_FITER) { \ - (it)->it_next_ = (it)->it_next_->next_; \ - } else { \ - (it)->it_next_ = (it)->it_next_->prev_; \ - } \ - } \ - (it)->it_ptr_; \ - }) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_UTIL_TDLIST_H_*/ \ No newline at end of file diff --git a/include/util/tlist.h b/include/util/tlist.h index e803e9660511b9acd79158e45085b64d27c4e856..06d0abc797befe3e9954e37513318207ec650090 100644 --- a/include/util/tlist.h +++ b/include/util/tlist.h @@ -19,19 +19,124 @@ extern "C" { #endif +// Single linked list ================ +#define TD_SLIST_NODE(TYPE) \ + struct { \ + struct TYPE *sl_next_; \ + } + +#define TD_SLIST(TYPE) \ + struct { \ + struct TYPE *sl_head_; \ + int sl_neles_; \ + } + +#define TD_SLIST_HEAD(sl) ((sl)->sl_head_) +#define TD_SLIST_NELES(sl) ((sl)->sl_neles_) +#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_) + +#define TD_SLIST_INIT(sl) \ + do { \ + (sl)->sl_head_ = NULL; \ + (sl)->sl_neles_ = 0; \ + } while (0) + +#define TD_SLIST_PUSH(sl, sln) \ + do { \ + TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \ + TD_SLIST_HEAD(sl) = (sln); \ + TD_SLIST_NELES(sl) += 1; \ + } while (0) + +#define TD_SLIST_POP(sl) \ + do { \ + TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \ + TD_SLIST_NELES(sl) -= 1; \ + } while (0) + +// Double linked list ================ +#define TD_DLIST_NODE(TYPE) \ + struct { \ + struct TYPE *dl_prev_; \ + struct TYPE *dl_next_; \ + } + +#define TD_DLIST(TYPE) \ + struct { \ + struct TYPE *dl_head_; \ + struct TYPE *dl_tail_; \ + int dl_neles_; \ + } + +#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_) +#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_) +#define TD_DLIST_HEAD(dl) ((dl)->dl_head_) +#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_) +#define TD_DLIST_NELES(dl) ((dl)->dl_neles_) + +#define TD_DLIST_INIT(dl) \ + do { \ + TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \ + TD_DLIST_NELES(dl) = 0; \ + } while (0) + +#define TD_DLIST_APPEND(dl, dln) \ + do { \ + if (TD_DLIST_HEAD(dl) == NULL) { \ + TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ + TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \ + } else { \ + TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \ + TD_DLIST_NODE_NEXT(dln) = NULL; \ + TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \ + TD_DLIST_TAIL(dl) = (dln); \ + } \ + TD_DLIST_NELES(dl) += 1; \ + } while (0) + +#define TD_DLIST_PREPEND(dl, dln) \ + do { \ + if (TD_DLIST_HEAD(dl) == NULL) { \ + TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ + TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \ + } else { \ + TD_DLIST_NODE_PREV(dln) = NULL; \ + TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \ + TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \ + TD_DLIST_HEAD(dl) = (dln); \ + } \ + TD_DLIST_NELES(dl) += 1; \ + } while (0) + +#define TD_DLIST_POP(dl, dln) \ + do { \ + if (TD_DLIST_HEAD(dl) == (dln)) { \ + TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \ + } \ + if (TD_DLIST_TAIL(dl) == (dln)) { \ + TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \ + } \ + if (TD_DLIST_NODE_PREV(dln) != NULL) { \ + TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \ + } \ + if (TD_DLIST_NODE_NEXT(dln) != NULL) { \ + TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \ + } \ + TD_DLIST_NELES(dl) -= 1; \ + TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ + } while (0) + +// General double linked list typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T; -typedef struct _list_node { - struct _list_node *next; - struct _list_node *prev; - char data[]; +typedef struct SListNode { + TD_DLIST_NODE(SListNode); + char data[]; } SListNode; typedef struct { - struct _list_node *head; - struct _list_node *tail; - int numOfEles; - int eleSize; + TD_DLIST(SListNode); + int eleSize; } SList; typedef struct { @@ -39,11 +144,11 @@ typedef struct { TD_LIST_DIRECTION_T direction; } SListIter; -#define listHead(l) (l)->head -#define listTail(l) (l)->tail -#define listNEles(l) (l)->numOfEles -#define listEleSize(l) (l)->eleSize -#define isListEmpty(l) ((l)->numOfEles == 0) +#define listHead(l) TD_DLIST_HEAD(l) +#define listTail(l) TD_DLIST_TAIL(l) +#define listNEles(l) TD_DLIST_NELES(l) +#define listEleSize(l) ((l)->eleSize) +#define isListEmpty(l) (TD_DLIST_NELES(l) == 0) #define listNodeFree(n) free(n) void tdListInit(SList *list, int eleSize); diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index 61b60e5ba631408ae181cb9b0a84820079371f61..c78bf02cbdf73ab0fa3fb7e34814945a870f8aac 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -2,14 +2,13 @@ aux_source_directory(src CLIENT_SRC) add_library(taos ${CLIENT_SRC}) target_include_directories( taos - PUBLIC "${CMAKE_SOURCE_DIR}/include/client" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PUBLIC "${CMAKE_SOURCE_DIR}/include/client" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( taos - PRIVATE common INTERFACE api - PRIVATE os util common transport parser catalog function query + PRIVATE os util common transport parser catalog function qcom ) ADD_SUBDIRECTORY(test) \ No newline at end of file diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 9ef1d67e744d86bf2b39f27cc2bb622508c180a7..4e7fff06b6bd60f015764745d8d093046e812fd6 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -76,11 +76,10 @@ typedef struct SAppInfo { typedef struct STscObj { char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; - char acctId[TSDB_ACCT_ID_LEN]; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; + int32_t acctId; uint32_t connId; uint64_t id; // ref ID returned by taosAddRef -// struct SSqlObj *sqlList; void *pTransporter; pthread_mutex_t mutex; // used to protect the operation on db int32_t numOfReqs; // number of sqlObj from this tscObj diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index c038799bb465da85315f05d11a764bbcd1350c82..b6200de824822170e2827b041b1c768c3e7a48c1 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -153,7 +153,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { void* output = NULL; int32_t outputLen = 0; code = qParseQuerySql(pRequest->sqlstr, sqlLen, pRequest->requestId, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE); - if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW) { + if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_CREATE_DB) { pRequest->type = type; pRequest->body.param = output; pRequest->body.paramLen = outputLen; @@ -430,7 +430,7 @@ void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 int32_t offset = 0; for (int32_t i = 0; i < numOfCols; ++i) { pResultInfo->length[i] = pResultInfo->fields[i].bytes; - pResultInfo->row[i] = pResultInfo->pData + offset * pResultInfo->numOfRows; + pResultInfo->row[i] = (char*) (pResultInfo->pData + offset * pResultInfo->numOfRows); pResultInfo->pCol[i] = pResultInfo->row[i]; offset += pResultInfo->fields[i].bytes; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 646964e31967dfd205aa4850b8d7d9283428aaaf..36fa013f27e0b31f7d0124a3f6e8feccd19d345a 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -14,6 +14,7 @@ */ #include +#include #include "clientInt.h" #include "clientLog.h" #include "os.h" @@ -2885,7 +2886,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg } int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) { - assert(tIsValidName(&pTableMetaInfo->name)); + assert(tNameIsValid(&pTableMetaInfo->name)); char name[TSDB_TABLE_FNAME_LEN] = {0}; tNameExtractFullName(&pTableMetaInfo->name, name); @@ -3138,7 +3139,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { // TODO refactor pthread_mutex_lock(&pTscObj->mutex); char temp[TSDB_TABLE_FNAME_LEN * 2] = {0}; - int32_t len = sprintf(temp, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db); + int32_t len = sprintf(temp, "%d%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db); assert(len <= sizeof(pTscObj->db)); tstrncpy(pTscObj->db, temp, sizeof(pTscObj->db)); @@ -3153,6 +3154,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { } pTscObj->connId = pConnect->connId; + pTscObj->acctId = pConnect->acctId; // update the appInstInfo pTscObj->pAppInfo->clusterId = pConnect->clusterId; @@ -3165,19 +3167,33 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { return 0; } -int32_t buildCreateUserMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER; - pMsgBody->msgLen = sizeof(SCreateUserMsg); +int32_t doBuildMsgSupp(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { pMsgBody->requestObjRefId = pRequest->self; - pMsgBody->pData = pRequest->body.param; - return 0; -} - -int32_t buildShowMsg(SRequestObj* pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_SHOW; pMsgBody->msgLen = pRequest->body.paramLen; - pMsgBody->requestObjRefId = pRequest->self; pMsgBody->pData = pRequest->body.param; + + switch(pRequest->type) { + case TSDB_SQL_CREATE_USER: + pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER; + break; + case TSDB_SQL_CREATE_DB: { + pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_DB; + + SCreateDbMsg* pCreateMsg = pRequest->body.param; + SName name = {0}; + int32_t ret = tNameSetDbName(&name, pRequest->pTscObj->acctId, pCreateMsg->db, strnlen(pCreateMsg->db, tListLen(pCreateMsg->db))); + if (ret != TSDB_CODE_SUCCESS) { + return -1; + } + + tNameGetFullDbName(&name, pCreateMsg->db); + + break; + } + case TSDB_SQL_SHOW: + pMsgBody->msgType = TSDB_MSG_TYPE_SHOW; + break; + } } STableMeta* createTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) { @@ -3283,6 +3299,9 @@ int32_t processRetrieveMnodeRsp(SRequestObj *pRequest, const char* pMsg, int32_t return 0; } +int32_t processCreateDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { + // todo rsp with the vnode id list +} void initMsgHandleFp() { #if 0 @@ -3363,11 +3382,14 @@ void initMsgHandleFp() { buildRequestMsgFp[TSDB_SQL_CONNECT] = buildConnectMsg; handleRequestRspFp[TSDB_SQL_CONNECT] = processConnectRsp; - buildRequestMsgFp[TSDB_SQL_CREATE_USER] = buildCreateUserMsg; + buildRequestMsgFp[TSDB_SQL_CREATE_USER] = doBuildMsgSupp; - buildRequestMsgFp[TSDB_SQL_SHOW] = buildShowMsg; + buildRequestMsgFp[TSDB_SQL_SHOW] = doBuildMsgSupp; handleRequestRspFp[TSDB_SQL_SHOW] = processShowRsp; buildRequestMsgFp[TSDB_SQL_RETRIEVE_MNODE] = buildRetrieveMnodeMsg; handleRequestRspFp[TSDB_SQL_RETRIEVE_MNODE]= processRetrieveMnodeRsp; + + buildRequestMsgFp[TSDB_SQL_CREATE_DB] = doBuildMsgSupp; + handleRequestRspFp[TSDB_SQL_CREATE_DB] = processCreateDbRsp; } \ No newline at end of file diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 46fd76234e13de5a392c6ab6b0edbf8e1d8d3869..944247e88e57901d57bdaf18a1025c53b08ad107 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -57,25 +57,38 @@ TEST(testCase, create_user_Test) { taos_close(pConn); } -//TEST(testCase, show_user_Test) { +//TEST(testCase, drop_user_Test) { // TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // -// TAOS_RES* pRes = taos_query(pConn, "show users"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); +// TAOS_RES* pRes = taos_query(pConn, "drop user abc"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); // } // +// taos_free_result(pRes); // taos_close(pConn); //} +TEST(testCase, show_user_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "show users"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_close(pConn); +} + TEST(testCase, show_db_Test) { TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); assert(pConn != NULL); @@ -94,3 +107,18 @@ TEST(testCase, show_db_Test) { taos_close(pConn); } + +TEST(testCase, create_db_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc"); + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_close(pConn); +} diff --git a/source/common/inc/commonInt.h b/source/common/inc/commonInt.h deleted file mode 100644 index 5b71f83faf477f217bc2183dc258edccf76913f7..0000000000000000000000000000000000000000 --- a/source/common/inc/commonInt.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * 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 . - */ - -#ifndef _TD_COMMON_INT_H_ -#define _TD_COMMON_INT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); - - - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_COMMON_INT_H_*/ diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 28f920a6a98b539ac82216f84af71ffc78abd0ff..fa303fe4e923317c276ccc025499593ca3a8b66a 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -4,9 +4,6 @@ #include "tname.h" #include "taosmsg.h" -#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS) -#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS) - #define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T) char* extractDBName(const char* tableId, char* name) { @@ -120,84 +117,11 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in #endif -static struct SSchema _s = { - .colId = TSDB_TBNAME_COLUMN_INDEX, - .type = TSDB_DATA_TYPE_BINARY, - .bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, - .name = "tbname", -}; - -SSchema* tGetTbnameColumnSchema() { - return &_s; -} - -static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) { - int32_t rowLen = 0; - - for (int32_t i = 0; i < numOfCols; ++i) { - // 1. valid types - if (!isValidDataType(pSchema[i].type)) { - return false; - } - - // 2. valid length for each type - if (pSchema[i].type == TSDB_DATA_TYPE_BINARY) { - if (pSchema[i].bytes > TSDB_MAX_BINARY_LEN) { - return false; - } - } else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { - if (pSchema[i].bytes > TSDB_MAX_NCHAR_LEN) { - return false; - } - } else { - if (pSchema[i].bytes != tDataTypes[pSchema[i].type].bytes) { - return false; - } - } - - // 3. valid column names - for (int32_t j = i + 1; j < numOfCols; ++j) { - if (strncasecmp(pSchema[i].name, pSchema[j].name, sizeof(pSchema[i].name) - 1) == 0) { - return false; - } - } - - rowLen += pSchema[i].bytes; - } - - return rowLen <= maxLen; -} - -bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) { - if (!VALIDNUMOFCOLS(numOfCols)) { - return false; - } - - if (!VALIDNUMOFTAGS(numOfTags)) { - return false; - } - - /* first column must be the timestamp, which is a primary key */ - if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) { - return false; - } - - if (!doValidateSchema(pSchema, numOfCols, TSDB_MAX_BYTES_PER_ROW)) { - return false; - } - - if (!doValidateSchema(&pSchema[numOfCols], numOfTags, TSDB_MAX_TAGS_LEN)) { - return false; - } - - return true; -} - int32_t tNameExtractFullName(const SName* name, char* dst) { assert(name != NULL && dst != NULL); // invalid full name format, abort - if (!tIsValidName(name)) { + if (!tNameIsValid(name)) { return -1; } @@ -230,7 +154,7 @@ int32_t tNameLen(const SName* name) { } } -bool tIsValidName(const SName* name) { +bool tNameIsValid(const SName* name) { assert(name != NULL); if (!VALID_NAME_TYPE(name->type)) { @@ -265,13 +189,13 @@ int32_t tNameGetDbName(const SName* name, char* dst) { int32_t tNameGetFullDbName(const SName* name, char* dst) { assert(name != NULL && dst != NULL); snprintf(dst, TSDB_ACCT_ID_LEN + TS_PATH_DELIMITER_LEN + TSDB_DB_NAME_LEN, // there is a over write risk - "%s.%s", name->acctId, name->dbname); + "%d.%s", name->acctId, name->dbname); return 0; } bool tNameIsEmpty(const SName* name) { assert(name != NULL); - return name->type == 0 || strlen(name->acctId) <= 0; + return name->type == 0 || name->acctId == 0; } const char* tNameGetTableName(const SName* name) { @@ -283,32 +207,23 @@ void tNameAssign(SName* dst, const SName* src) { memcpy(dst, src, sizeof(SName)); } -//int32_t tNameSetDbName(SName* dst, const char* acct, SStrToken* dbToken) { -// assert(dst != NULL && dbToken != NULL && acct != NULL); -// -// // too long account id or too long db name -// if (strlen(acct) >= tListLen(dst->acctId) || dbToken->n >= tListLen(dst->dbname)) { -// return -1; -// } -// -// dst->type = TSDB_DB_NAME_T; -// tstrncpy(dst->acctId, acct, tListLen(dst->acctId)); -// tstrncpy(dst->dbname, dbToken->z, dbToken->n + 1); -// return 0; -//} - -int32_t tNameSetAcctId(SName* dst, const char* acct) { - assert(dst != NULL && acct != NULL); +int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t nameLen) { + assert(dst != NULL && dbName != NULL && nameLen > 0); // too long account id or too long db name - if (strlen(acct) >= tListLen(dst->acctId)) { + if (nameLen >= tListLen(dst->dbname)) { return -1; } - tstrncpy(dst->acctId, acct, tListLen(dst->acctId)); + dst->type = TSDB_DB_NAME_T; + dst->acctId = acct; + tstrncpy(dst->dbname, dbName, nameLen + 1); + return 0; +} - assert(strlen(dst->acctId) > 0); - +int32_t tNameSetAcctId(SName* dst, int32_t acctId) { + assert(dst != NULL && acct != NULL); + dst->acctId = acctId; return 0; } @@ -325,14 +240,11 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { int32_t len = (int32_t)(p - str); // too long account id or too long db name - if ((len >= tListLen(dst->acctId)) || (len <= 0)) { - return -1; - } - - memcpy (dst->acctId, str, len); - dst->acctId[len] = 0; - - assert(strlen(dst->acctId) > 0); +// if ((len >= tListLen(dst->acctId)) || (len <= 0)) { +// return -1; +// } +// memcpy (dst->acctId, str, len); + dst->acctId = strtoll(str, NULL, 10); } if ((type & T_NAME_DB) == T_NAME_DB) { diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index e6a88c7629635ace1449d6269a55165bd52f3713..56e07aca10704f7d8cb79a92c2ad80e4b25fee02 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -19,7 +19,7 @@ #include "mallocator.h" #include "sync.h" #include "tcoding.h" -#include "tdlist.h" +#include "tlist.h" #include "tlockfree.h" #include "tmacro.h" #include "wal.h" diff --git a/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c b/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c index 99d4781df9ab286bbcfe5eff92e25fbd8b4c86e0..5999b08a7d83f5460eabe80038ba18fca9b5b99b 100644 --- a/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c +++ b/source/dnode/vnode/impl/src/vnodeArenaMAImpl.c @@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { pVMA->capacity = capacity; pVMA->ssize = ssize; pVMA->lsize = lsize; - tSListInit(&(pVMA->nlist)); + TD_SLIST_INIT(&(pVMA->nlist)); pVMA->pNode = vArenaNodeNew(capacity); if (pVMA->pNode == NULL) { @@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { return NULL; } - tSListPush(&(pVMA->nlist), pVMA->pNode); + TD_SLIST_PUSH(&(pVMA->nlist), pVMA->pNode); return pVMA; } @@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { if (pVMA) { while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) { SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist)); - tSListPop(&(pVMA->nlist)); + TD_SLIST_POP(&(pVMA->nlist)); vArenaNodeFree(pNode); } @@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { void vmaReset(SVMemAllocator *pVMA) { while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) { SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist)); - tSListPop(&(pVMA->nlist)); + TD_SLIST_POP(&(pVMA->nlist)); vArenaNodeFree(pNode); } @@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) { return NULL; } - tSListPush(&(pVMA->nlist), pNode); + TD_SLIST_PUSH(&(pVMA->nlist), pNode); } ptr = pNode->ptr; diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index 6c1ededfc968ef08ac8d334c4f213be87b5816d4..228df6c0a4ac383f4822516d4d465603ccd4a6f0 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -39,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) { return -1; } - tDListInit(&(pVnode->pBufPool->free)); - tDListInit(&(pVnode->pBufPool->incycle)); + TD_DLIST_INIT(&(pVnode->pBufPool->free)); + TD_DLIST_INIT(&(pVnode->pBufPool->incycle)); pVnode->pBufPool->inuse = NULL; @@ -54,7 +54,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { return -1; } - tDListAppend(&(pVnode->pBufPool->free), pVMA); + TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA); } pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)malloc(sizeof(SMemAllocatorFactory)); @@ -76,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) { while (true) { SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->incycle)); if (pVMA == NULL) break; - tDListPop(&(pVnode->pBufPool->incycle), pVMA); + TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA); vmaDestroy(pVMA); } while (true) { SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->free)); if (pVMA == NULL) break; - tDListPop(&(pVnode->pBufPool->free), pVMA); + TD_DLIST_POP(&(pVnode->pBufPool->free), pVMA); vmaDestroy(pVMA); } @@ -97,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) { pVnode->pBufPool->inuse = NULL; - tDListAppend(&(pVnode->pBufPool->incycle), pvma); + TD_DLIST_APPEND(&(pVnode->pBufPool->incycle), pvma); return 0; } @@ -106,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) { SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle)); ASSERT(pvma != NULL); - tDListPop(&(pBufPool->incycle), pvma); + TD_DLIST_POP(&(pBufPool->incycle), pvma); vmaReset(pvma); - tDListAppend(&(pBufPool->free), pvma); + TD_DLIST_APPEND(&(pBufPool->free), pvma); return 0; } @@ -121,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) { // TODO: add sem_wait and sem_post pBufPool->inuse = TD_DLIST_HEAD(&(pBufPool->free)); if (pBufPool->inuse) { - tDListPop(&(pBufPool->free), pBufPool->inuse); + TD_DLIST_POP(&(pBufPool->free), pBufPool->inuse); break; } else { // tsem_wait(&(pBufPool->hasFree)); @@ -168,11 +168,7 @@ static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF) { pWrapper->pVMA = pVnode->pBufPool->inuse; pMA->impl = pWrapper; - pMA->malloc = vmaMaloocCb; - pMA->calloc = NULL; - pMA->realloc = NULL; - pMA->free = NULL; - pMA->usage = NULL; + TD_MA_MALLOC_FUNC(pMA) = vmaMaloocCb; return pMA; } @@ -184,7 +180,7 @@ static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) { free(pMA); if (--pVMA->_ref.val == 0) { - tDListPop(&(pVnode->pBufPool->incycle), pVMA); - tDListAppend(&(pVnode->pBufPool->free), pVMA); + TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA); + TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA); } } \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeMgr.c b/source/dnode/vnode/impl/src/vnodeMgr.c index 964cbe77daaa1b89f74f2ba57f97e60864c2e1e0..fae96ae22c534df65703f8b0c4ac02073da53f16 100644 --- a/source/dnode/vnode/impl/src/vnodeMgr.c +++ b/source/dnode/vnode/impl/src/vnodeMgr.c @@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) { pthread_mutex_init(&(vnodeMgr.mutex), NULL); pthread_cond_init(&(vnodeMgr.hasTask), NULL); - tDListInit(&(vnodeMgr.queue)); + TD_DLIST_INIT(&(vnodeMgr.queue)); for (uint16_t i = 0; i < nthreads; i++) { pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL); @@ -77,7 +77,7 @@ void vnodeClear() { int vnodeScheduleTask(SVnodeTask* pTask) { pthread_mutex_lock(&(vnodeMgr.mutex)); - tDListAppend(&(vnodeMgr.queue), pTask); + TD_DLIST_APPEND(&(vnodeMgr.queue), pTask); pthread_cond_signal(&(vnodeMgr.hasTask)); @@ -101,7 +101,7 @@ static void* loop(void* arg) { pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex)); } } else { - tDListPop(&(vnodeMgr.queue), pTask); + TD_DLIST_POP(&(vnodeMgr.queue), pTask); break; } } diff --git a/source/dnode/vnode/tsdb/inc/tsdbDef.h b/source/dnode/vnode/tsdb/inc/tsdbDef.h index 7c593cb4c740385f8c1040e7019e80ef45952c45..b1375c9477e9d31f076e0d6b364aed3b48e89b44 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbDef.h +++ b/source/dnode/vnode/tsdb/inc/tsdbDef.h @@ -18,7 +18,7 @@ #include "mallocator.h" #include "taosmsg.h" -#include "tdlist.h" +#include "tlist.h" #include "thash.h" #include "tskiplist.h" diff --git a/source/dnode/vnode/tsdb/src/tsdbMemTable.c b/source/dnode/vnode/tsdb/src/tsdbMemTable.c index e3d1f8673ed878f30021502e3ea6736861743831..7b0df18f5add82c46e07ba3ca3b66f55791318c6 100644 --- a/source/dnode/vnode/tsdb/src/tsdbMemTable.c +++ b/source/dnode/vnode/tsdb/src/tsdbMemTable.c @@ -50,7 +50,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { pMA = (*pMAF->create)(pMAF); ASSERT(pMA != NULL); - pMemTable = (STsdbMemTable *)((*pMA->malloc)(pMA, sizeof(*pMemTable))); + pMemTable = (STsdbMemTable *)TD_MA_MALLOC(pMA, sizeof(*pMemTable)); if (pMemTable == NULL) { (*pMAF->destroy)(pMAF, pMA); return NULL; @@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { pMemTable->keyMax = TSKEY_MIN; pMemTable->nRow = 0; pMemTable->pMA = pMA; - tSListInit(&(pMemTable->list)); + TD_SLIST_INIT(&(pMemTable->list)); // TODO return pMemTable; @@ -71,7 +71,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) { SMemAllocator *pMA = pMemTable->pMA; - if (pMA->free) { + if (TD_MA_FREE_FUNC(pMA) != NULL) { // TODO ASSERT(0); } @@ -81,12 +81,12 @@ void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) { int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) { SMemAllocator *pMA = pMemTable->pMA; - STbData * pTbData = (STbData *)((*pMA->malloc)(pMA, sizeof(*pTbData))); + STbData * pTbData = (STbData *)TD_MA_MALLOC(pMA, sizeof(*pTbData)); if (pTbData == NULL) { // TODO } - tSListPush(&(pMemTable->list), pTbData); + TD_SLIST_PUSH(&(pMemTable->list), pTbData); return 0; } diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index 57a5023807507baa44261430056c6d6b885875f0..636cf0a9a84453458ec0d06b84231f926a4637b5 100644 --- a/source/libs/CMakeLists.txt +++ b/source/libs/CMakeLists.txt @@ -10,4 +10,4 @@ add_subdirectory(catalog) add_subdirectory(executor) add_subdirectory(planner) add_subdirectory(function) -add_subdirectory(query) +add_subdirectory(qcom) diff --git a/source/libs/catalog/CMakeLists.txt b/source/libs/catalog/CMakeLists.txt index e6311152d6763f7a3c600f12d5a9acd3339ef529..f47e105b8a9f26f26df65a102d9e55983f8c8699 100644 --- a/source/libs/catalog/CMakeLists.txt +++ b/source/libs/catalog/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( catalog - PRIVATE os util common transport query + PRIVATE os util transport qcom ) ADD_SUBDIRECTORY(test) \ No newline at end of file diff --git a/source/libs/catalog/test/CMakeLists.txt b/source/libs/catalog/test/CMakeLists.txt index 176978cc7f6c0167ea9f5b5f3d2c5dbe3b28db92..3c7418bdccb14667d52d6739c544f209ccdb822e 100644 --- a/source/libs/catalog/test/CMakeLists.txt +++ b/source/libs/catalog/test/CMakeLists.txt @@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(catalogTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( catalogTest - PUBLIC os util common catalog transport gtest query taos + PUBLIC os util common catalog transport gtest qcom taos ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/libs/parser/CMakeLists.txt b/source/libs/parser/CMakeLists.txt index 5e635aa6a16a1c987cbdc6932597628003df36d8..6ab3020935d7630565c4a8d6d6d5756f5e08a88b 100644 --- a/source/libs/parser/CMakeLists.txt +++ b/source/libs/parser/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( parser - PRIVATE os util common catalog function transport query + PRIVATE os util catalog function transport qcom ) ADD_SUBDIRECTORY(test) diff --git a/source/libs/parser/inc/astGenerator.h b/source/libs/parser/inc/astGenerator.h index 954bc29e62e15559663c8bdc61a6e7107d824a13..6ae40b0d7163bc127fcd92a2bd04a557316fa87b 100644 --- a/source/libs/parser/inc/astGenerator.h +++ b/source/libs/parser/inc/astGenerator.h @@ -171,8 +171,8 @@ typedef struct SCreateDbInfo { int8_t update; int8_t cachelast; SArray *keep; - int8_t dbType; - int16_t partitions; +// int8_t dbType; +// int16_t partitions; } SCreateDbInfo; typedef struct SCreateFuncInfo { diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index 223d5a57686dbc280a0f97c37e3d96dc43af34e1..de7cdd58b85227c3a4dbb1742a0789fe01413802 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -5,5 +5,7 @@ #include "taosmsg.h" SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen); +SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen); +SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen); #endif // TDENGINE_ASTTOMSG_H diff --git a/source/libs/parser/inc/parserUtil.h b/source/libs/parser/inc/parserUtil.h index b402621903b37b5884cf387fe861e92a8ef9108c..c588a34a40771391fd39fe9688277aa4640cb0fc 100644 --- a/source/libs/parser/inc/parserUtil.h +++ b/source/libs/parser/inc/parserUtil.h @@ -46,6 +46,7 @@ SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index); int32_t parserValidateIdToken(SToken* pToken); int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf); +int32_t parserValidateNameToken(SToken* pToken); int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg); int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr); diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index d12278632ba815090e604c67b3b68df5a8c4f4ab..dda30c56fc6c9d647659f1fddcf2bcb69ce25c20 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -948,27 +948,24 @@ void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam) { void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) { pDBInfo->compressionLevel = -1; - pDBInfo->walLevel = -1; + pDBInfo->walLevel = -1; pDBInfo->fsyncPeriod = -1; - pDBInfo->commitTime = -1; + pDBInfo->commitTime = -1; pDBInfo->maxTablesPerVnode = -1; - pDBInfo->cacheBlockSize = -1; - pDBInfo->numOfBlocks = -1; + pDBInfo->cacheBlockSize = -1; + pDBInfo->numOfBlocks = -1; pDBInfo->maxRowsPerBlock = -1; pDBInfo->minRowsPerBlock = -1; - pDBInfo->daysPerFile = -1; + pDBInfo->daysPerFile = -1; pDBInfo->replica = -1; - pDBInfo->quorum = -1; - pDBInfo->keep = NULL; + pDBInfo->quorum = -1; + pDBInfo->keep = NULL; - pDBInfo->update = -1; + pDBInfo->update = -1; pDBInfo->cachelast = -1; - pDBInfo->dbType = -1; - pDBInfo->partitions = -1; - memset(&pDBInfo->precision, 0, sizeof(SToken)); } diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 6bfbd5ebedfa0d6cb190c4496ae0a06b1daf95a6..1b46faececee5dabb589d8fdae2bccc0ddf0aca1 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -1,23 +1,160 @@ #include "parserInt.h" +#include "parserUtil.h" SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateUserMsg *pMsg = (SCreateUserMsg *)calloc(1, sizeof(SCreateUserMsg)); + SCreateUserMsg* pMsg = (SCreateUserMsg*)calloc(1, sizeof(SCreateUserMsg)); if (pMsg == NULL) { -// tscError("0x%" PRIx64 " failed to malloc for query msg", id); + // tscError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; } - SUserInfo *pUser = &pInfo->pMiscInfo->user; + SUserInfo* pUser = &pInfo->pMiscInfo->user; strncpy(pMsg->user, pUser->user.z, pUser->user.n); pMsg->type = pUser->type; pMsg->superUser = (int8_t)pUser->type; if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { -// pMsg->privilege = (char)pCmd->count; + // pMsg->privilege = (char)pCmd->count; } else { strncpy(pMsg->pass, pUser->passwd.z, pUser->passwd.n); } return pMsg; -} \ No newline at end of file +} + +SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen) { + SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg)); + + pShowMsg->type = pShowInfo->showType; + + if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { + SToken* pPattern = &pShowInfo->pattern; + if (pPattern->type > 0) { // only show tables support wildcard query + strncpy(pShowMsg->payload, pPattern->z, pPattern->n); + pShowMsg->payloadLen = htons(pPattern->n); + } + } else { + SToken* pEpAddr = &pShowInfo->prefix; + assert(pEpAddr->n > 0 && pEpAddr->type > 0); + + strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n); + pShowMsg->payloadLen = htons(pEpAddr->n); + } + + return pShowMsg; +} + +static int32_t setKeepOption(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) { + const char* msg1 = "invalid number of keep options"; + const char* msg2 = "invalid keep value"; + const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2"; + + pMsg->daysToKeep0 = htonl(-1); + pMsg->daysToKeep1 = htonl(-1); + pMsg->daysToKeep2 = htonl(-1); + + SArray* pKeep = pCreateDb->keep; + if (pKeep != NULL) { + size_t s = taosArrayGetSize(pKeep); +#ifdef _STORAGE + if (s >= 4 ||s <= 0) { +#else + if (s != 1) { +#endif + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + +// tListI* p0 = taosArrayGet(pKeep, 0); +// tVariantListItem* p1 = (s > 1) ? taosArrayGet(pKeep, 1) : p0; +// tVariantListItem* p2 = (s > 2) ? taosArrayGet(pKeep, 2) : p1; +// +// if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) { +// return buildInvalidOperationMsg(pMsgBuf, msg2); +// } +// if (!(((int32_t)p0->pVar.i64 <= (int32_t)p1->pVar.i64) && ((int32_t)p1->pVar.i64 <= (int32_t)p2->pVar.i64))) { +// return buildInvalidOperationMsg(pMsgBuf, msg3); +// } +// +// pMsg->daysToKeep0 = htonl((int32_t)p0->pVar.i64); +// pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64); +// pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64); + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t setTimePrecision(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDbInfo, SMsgBuf* pMsgBuf) { + const char* msg = "invalid time precision"; + + pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default + + SToken* pToken = &pCreateDbInfo->precision; + if (pToken->n > 0) { + pToken->n = strdequote(pToken->z); + + if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 && + strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) { + // time precision for this db: million second + pMsg->precision = TSDB_TIME_PRECISION_MILLI; + } else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 && + strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) { + pMsg->precision = TSDB_TIME_PRECISION_MICRO; + } else if (strncmp(pToken->z, TSDB_TIME_PRECISION_NANO_STR, pToken->n) == 0 && + strlen(TSDB_TIME_PRECISION_NANO_STR) == pToken->n) { + pMsg->precision = TSDB_TIME_PRECISION_NANO; + } else { + return buildInvalidOperationMsg(pMsgBuf, msg); + } + } + + return TSDB_CODE_SUCCESS; +} + +static void doSetDbOptions(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDb) { + pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize); + pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks); + pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); + pMsg->commitTime = htonl((int32_t)pCreateDb->commitTime); + pMsg->minRowsPerFileBlock = htonl(pCreateDb->minRowsPerBlock); + pMsg->maxRowsPerFileBlock = htonl(pCreateDb->maxRowsPerBlock); + pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod); + pMsg->compression = pCreateDb->compressionLevel; + pMsg->walLevel = (char)pCreateDb->walLevel; + pMsg->replications = pCreateDb->replica; + pMsg->quorum = pCreateDb->quorum; + pMsg->ignoreExist = pCreateDb->ignoreExists; + pMsg->update = pCreateDb->update; + pMsg->cacheLastRow = pCreateDb->cachelast; +} + +int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbSql, SMsgBuf* pMsgBuf) { + doSetDbOptions(pCreateDbMsg, pCreateDbSql); + + if (setKeepOption(pCreateDbMsg, pCreateDbSql, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + if (setTimePrecision(pCreateDbMsg, pCreateDbSql, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + // todo configurable + pCreateDbMsg->numOfVgroups = htonl(2); + + return TSDB_CODE_SUCCESS; +} + +SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen) { + SCreateDbMsg* pCreateMsg = calloc(1, sizeof(SCreateDbMsg)); + + SMsgBuf msg = {.buf = msgBuf, .len = msgLen}; + if (setDbOptions(pCreateMsg, pCreateDbInfo, &msg) != TSDB_CODE_SUCCESS) { + tfree(pCreateMsg); + terrno = TSDB_CODE_TSC_INVALID_OPERATION; + + return NULL; + } + + return pCreateMsg; +} diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c index 2ee95732d02ac9eb7240f203735904fd4d69993c..135774cd3b6921130c183efabf1dcacc12c51120 100644 --- a/source/libs/parser/src/astValidate.c +++ b/source/libs/parser/src/astValidate.c @@ -759,11 +759,6 @@ int32_t validateIntervalNode(SQueryStmtInfo *pQueryInfo, SSqlNode* pSqlNode, SMs // It is a time window query pQueryInfo->info.timewindow = true; return TSDB_CODE_SUCCESS; - // disable it temporarily -// bool interpQuery = tscIsPointInterpQuery(pQueryInfo); -// if ((pSqlNode->interval.token == TK_EVERY && (!interpQuery)) || (pSqlNode->interval.token == TK_INTERVAL && interpQuery)) { -// return buildInvalidOperationMsg(pMsgBuf, msg4); -// } } int32_t validateSessionNode(SQueryStmtInfo *pQueryInfo, SSessionWindowVal* pSession, int32_t precision, SMsgBuf* pMsgBuf) { @@ -3707,14 +3702,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer return TSDB_CODE_SUCCESS; } - case TSDB_SQL_SHOW: { - if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - break; - } - case TSDB_SQL_CREATE_FUNCTION: case TSDB_SQL_DROP_FUNCTION: { code = handleUserDefinedFunc(pSql, pInfo); @@ -3725,35 +3712,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer break; } - case TSDB_SQL_ALTER_DB: - case TSDB_SQL_CREATE_DB: { - const char* msg1 = "invalid db name"; - const char* msg2 = "name too long"; - - SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); - if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - char buf[TSDB_DB_NAME_LEN] = {0}; - SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); - - if (tscValidateName(&token) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pSql), &token); - if (ret != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - break; - } - case TSDB_SQL_CREATE_DNODE: { const char* msg = "invalid host name (ip address)"; @@ -4133,25 +4091,83 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe } } - SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg)); - pShowMsg->type = pShowInfo->showType; + *output = buildShowMsg(pShowInfo, 0, pMsgBuf->buf, pMsgBuf->len); + *msgLen = sizeof(SShowMsg)/* + htons(pShowMsg->payloadLen)*/; + return TSDB_CODE_SUCCESS; +} + +// can only perform the parameters based on the macro definitation +static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) { + char msg[512] = {0}; - if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { - SToken* pPattern = &pShowInfo->pattern; - if (pPattern->type > 0) { // only show tables support wildcard query - strncpy(pShowMsg->payload, pPattern->z, pPattern->n); - pShowMsg->payloadLen = htons(pPattern->n); - } - } else { - SToken* pEpAddr = &pShowInfo->prefix; - assert(pEpAddr->n > 0 && pEpAddr->type > 0); + if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) { + snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel); + return buildInvalidOperationMsg(pMsgBuf, msg); + } - strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n); - pShowMsg->payloadLen = htons(pEpAddr->n); + if (pCreate->replications != -1 && + (pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) { + snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, + TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + int32_t blocks = ntohl(pCreate->totalBlocks); + if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) { + snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks, + TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->quorum != -1 && + (pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) { + snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum, + TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + int32_t val = htonl(pCreate->daysPerFile); + if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) { + snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, + TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->cacheBlockSize); + if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) { + snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val, + TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO && + pCreate->precision != TSDB_TIME_PRECISION_NANO) { + snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision, + TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->commitTime); + if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) { + snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, + TSDB_MIN_COMMIT_TIME, TSDB_MAX_COMMIT_TIME); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->fsyncPeriod); + if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) { + snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, + TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->compression != -1 && + (pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) { + snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, + TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); + return buildInvalidOperationMsg(pMsgBuf, msg); } - *output = pShowMsg; - *msgLen = sizeof(SShowMsg) + htons(pShowMsg->payloadLen); return TSDB_CODE_SUCCESS; } @@ -4216,6 +4232,36 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in code = setShowInfo(pInfo, output, outputLen, pMsgBuf); break; } + + case TSDB_SQL_ALTER_DB: + case TSDB_SQL_CREATE_DB: { + const char* msg1 = "invalid db name"; + const char* msg2 = "name too long"; + + SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); + if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + char buf[TSDB_DB_NAME_LEN] = {0}; + SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); + + if (parserValidateNameToken(&token) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pMsgBuf->buf, pMsgBuf->len); + if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + strncpy(pCreateMsg->db, token.z, token.n); + + *output = pCreateMsg; + *outputLen = sizeof(SCreateDbMsg); + break; + } + default: break; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 5e08859a66a94acadabb7b1b48b7827867031a94..e0ac7c295bc82d5fe9dff60519dd9ede7efe7447 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -77,7 +77,7 @@ static int32_t tnameComparFn(const void* p1, const void* p2) { SName* pn1 = (SName*)p1; SName* pn2 = (SName*)p2; - int32_t ret = strncmp(pn1->acctId, pn2->acctId, tListLen(pn1->acctId)); + int32_t ret = pn1->acctId - pn2->acctId; if (ret != 0) { return ret > 0? 1:-1; } else { diff --git a/source/libs/parser/src/parserUtil.c b/source/libs/parser/src/parserUtil.c index 3a61f5912b6fcf17377d7e98bc4e6cd4f0ef6c6b..b72bc06324d3a33e960b713c421e0af77a3dd86d 100644 --- a/source/libs/parser/src/parserUtil.c +++ b/source/libs/parser/src/parserUtil.c @@ -122,6 +122,25 @@ int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf) { return TSDB_CODE_SUCCESS; } +int32_t parserValidateNameToken(SToken* pToken) { + if (pToken == NULL || pToken->z == NULL || pToken->type != TK_ID) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + // it is a token quoted with escape char '`' + if (pToken->z[0] == TS_ESCAPE_CHAR && pToken->z[pToken->n - 1] == TS_ESCAPE_CHAR) { + return TSDB_CODE_SUCCESS; + } + + char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); + if (sep != NULL) { // It is a complex type, not allow + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + strntolower(pToken->z, pToken->z, pToken->n); + return TSDB_CODE_SUCCESS; +} + int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) { strncpy(pBuf->buf, msg, pBuf->len); return TSDB_CODE_TSC_INVALID_OPERATION; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 53a7ba48f84efb9864bb91aed8cc583d3309e2e8..d674462fc0f277fa5be0a7a5988f28eed15c1499 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -2519,7 +2519,7 @@ static void yy_reduce( { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 105: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy256); yymsp[1].minor.yy256.dbType = TSDB_DB_TYPE_DEFAULT;} +{setDefaultCreateDbOption(&yymsp[1].minor.yy256);} break; case 106: /* db_optr ::= db_optr cache */ { yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } @@ -2590,16 +2590,16 @@ static void yy_reduce( break; case 121: /* topic_optr ::= db_optr */ case 131: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==131); -{ yylhsminor.yy256 = yymsp[0].minor.yy256; yylhsminor.yy256.dbType = TSDB_DB_TYPE_TOPIC; } +{ yylhsminor.yy256 = yymsp[0].minor.yy256;} yymsp[0].minor.yy256 = yylhsminor.yy256; break; case 122: /* topic_optr ::= topic_optr partitions */ case 132: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==132); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy256 = yymsp[-1].minor.yy256; } yymsp[-1].minor.yy256 = yylhsminor.yy256; break; case 123: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy256); yymsp[1].minor.yy256.dbType = TSDB_DB_TYPE_DEFAULT;} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy256); } break; case 133: /* typename ::= ids */ { diff --git a/source/libs/parser/test/CMakeLists.txt b/source/libs/parser/test/CMakeLists.txt index 03b76152da722e4efc61852755eb28e999d4d0d2..feae00827310a93e9117361cc5d7c682e3582a76 100644 --- a/source/libs/parser/test/CMakeLists.txt +++ b/source/libs/parser/test/CMakeLists.txt @@ -15,7 +15,7 @@ TARGET_INCLUDE_DIRECTORIES( TARGET_LINK_LIBRARIES( parserTest - PUBLIC os util common parser catalog transport gtest function planner query + PUBLIC os util common parser catalog transport gtest function planner qcom ) TARGET_LINK_OPTIONS(parserTest PRIVATE -Wl,-wrap,malloc) diff --git a/source/libs/planner/CMakeLists.txt b/source/libs/planner/CMakeLists.txt index 8a309af526a03251cff147e23a384bb8cf80479a..7f8c1186630fc64cb4c63f0b6575621c4dd35f00 100644 --- a/source/libs/planner/CMakeLists.txt +++ b/source/libs/planner/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( planner - PRIVATE os util common cjson catalog parser transport function query + PRIVATE os util catalog cjson parser transport function qcom ) ADD_SUBDIRECTORY(test) diff --git a/source/libs/planner/test/CMakeLists.txt b/source/libs/planner/test/CMakeLists.txt index f00adfaeb25ce7ea8d1ea72b16f58ade153e7d66..58743567846df2f4c80272cf7433cf3af6b9663a 100644 --- a/source/libs/planner/test/CMakeLists.txt +++ b/source/libs/planner/test/CMakeLists.txt @@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(plannerTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( plannerTest - PUBLIC os util common planner parser catalog transport gtest function query + PUBLIC os util common planner parser catalog transport gtest function qcom ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/libs/qcom/CMakeLists.txt b/source/libs/qcom/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..41cf1826bcd5e99a20093bf33dde102811f31039 --- /dev/null +++ b/source/libs/qcom/CMakeLists.txt @@ -0,0 +1,12 @@ +aux_source_directory(src QUERY_SRC) +add_library(qcom ${QUERY_SRC}) +target_include_directories( + qcom + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/qcom" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + qcom + PRIVATE os util transport +) diff --git a/source/libs/query/inc/queryInt.h b/source/libs/qcom/inc/queryInt.h similarity index 100% rename from source/libs/query/inc/queryInt.h rename to source/libs/qcom/inc/queryInt.h diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c new file mode 100644 index 0000000000000000000000000000000000000000..2a13b708ec537a0eb3d7ff8611c681b8b4e285f9 --- /dev/null +++ b/source/libs/qcom/src/queryUtil.c @@ -0,0 +1,78 @@ +#include "os.h" +#include "taosmsg.h" + +#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS) +#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS) + +static struct SSchema _s = { + .colId = TSDB_TBNAME_COLUMN_INDEX, + .type = TSDB_DATA_TYPE_BINARY, + .bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, + .name = "tbname", +}; + +SSchema* tGetTbnameColumnSchema() { + return &_s; +} + +static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) { + int32_t rowLen = 0; + + for (int32_t i = 0; i < numOfCols; ++i) { + // 1. valid types + if (!isValidDataType(pSchema[i].type)) { + return false; + } + + // 2. valid length for each type + if (pSchema[i].type == TSDB_DATA_TYPE_BINARY) { + if (pSchema[i].bytes > TSDB_MAX_BINARY_LEN) { + return false; + } + } else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { + if (pSchema[i].bytes > TSDB_MAX_NCHAR_LEN) { + return false; + } + } else { + if (pSchema[i].bytes != tDataTypes[pSchema[i].type].bytes) { + return false; + } + } + + // 3. valid column names + for (int32_t j = i + 1; j < numOfCols; ++j) { + if (strncasecmp(pSchema[i].name, pSchema[j].name, sizeof(pSchema[i].name) - 1) == 0) { + return false; + } + } + + rowLen += pSchema[i].bytes; + } + + return rowLen <= maxLen; +} + +bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) { + if (!VALIDNUMOFCOLS(numOfCols)) { + return false; + } + + if (!VALIDNUMOFTAGS(numOfTags)) { + return false; + } + + /* first column must be the timestamp, which is a primary key */ + if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) { + return false; + } + + if (!doValidateSchema(pSchema, numOfCols, TSDB_MAX_BYTES_PER_ROW)) { + return false; + } + + if (!doValidateSchema(&pSchema[numOfCols], numOfTags, TSDB_MAX_TAGS_LEN)) { + return false; + } + + return true; +} \ No newline at end of file diff --git a/source/libs/query/src/querymsg.c b/source/libs/qcom/src/querymsg.c similarity index 100% rename from source/libs/query/src/querymsg.c rename to source/libs/qcom/src/querymsg.c diff --git a/source/libs/query/CMakeLists.txt b/source/libs/query/CMakeLists.txt deleted file mode 100644 index 579a4b279c2509de12c3e0782103ec6e0229ba79..0000000000000000000000000000000000000000 --- a/source/libs/query/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -aux_source_directory(src QUERY_SRC) -add_library(query ${QUERY_SRC}) -target_include_directories( - query - PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/query" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) - -target_link_libraries( - query - PRIVATE os util common transport -) diff --git a/source/libs/scheduler/CMakeLists.txt b/source/libs/scheduler/CMakeLists.txt index 6675b7f5ecc6af37cdb82a5a0e3759d17394458d..31f1c25beae079107d630ad98c6af6bfc38be70f 100644 --- a/source/libs/scheduler/CMakeLists.txt +++ b/source/libs/scheduler/CMakeLists.txt @@ -9,5 +9,5 @@ target_include_directories( target_link_libraries( scheduler - PRIVATE os util planner common query + PRIVATE os util planner qcom common ) \ No newline at end of file diff --git a/source/util/CMakeLists.txt b/source/util/CMakeLists.txt index 7c42afcc51d0917c82de558ff279143948dc8496..d343945a8005ec6f57cbfc9efbcc6c235e7f6d4b 100644 --- a/source/util/CMakeLists.txt +++ b/source/util/CMakeLists.txt @@ -1,3 +1,4 @@ +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c") aux_source_directory(src UTIL_SRC) add_library(util STATIC ${UTIL_SRC}) target_include_directories( @@ -11,6 +12,4 @@ target_link_libraries( PUBLIC zlib PUBLIC lz4_static PUBLIC api -) - -CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c") +) \ No newline at end of file diff --git a/source/util/src/mallocator.c b/source/util/src/mallocator.c index 1819396ccd5525bb30cef44b977419c3443be906..a56fbfa5976dfcaaad681ecfda47ad8a1d415a6e 100644 --- a/source/util/src/mallocator.c +++ b/source/util/src/mallocator.c @@ -16,6 +16,7 @@ #include "mallocator.h" /* ------------------------ HEAP ALLOCATOR ------------------------ */ +#if 0 typedef struct { size_t tusage; } SHeapAllocator; @@ -104,4 +105,5 @@ static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl /* ------------------------ ARENA ALLOCATOR ------------------------ */ typedef struct { size_t usage; -} SArenaAllocator; \ No newline at end of file +} SArenaAllocator; +#endif \ No newline at end of file diff --git a/source/util/src/tlist.c b/source/util/src/tlist.c index 6756af226fda2c0f4e3b9ca13c83c76baeaeb6bc..f79bca1e4b03377cdfdaeda9ad4adf06ddff6de4 100644 --- a/source/util/src/tlist.c +++ b/source/util/src/tlist.c @@ -17,9 +17,8 @@ #include "os.h" void tdListInit(SList *list, int eleSize) { - list->eleSize = eleSize; - list->numOfEles = 0; - list->head = list->tail = NULL; + TD_DLIST_INIT(list); + listEleSize(list) = eleSize; } SList *tdListNew(int eleSize) { @@ -31,14 +30,11 @@ SList *tdListNew(int eleSize) { } void tdListEmpty(SList *list) { - SListNode *node = list->head; - while (node) { - list->head = node->next; + SListNode *node; + while ((node = TD_DLIST_HEAD(list)) != NULL) { + TD_DLIST_POP(list, node); free(node); - node = list->head; } - list->head = list->tail = 0; - list->numOfEles = 0; } void *tdListFree(SList *list) { @@ -50,40 +46,16 @@ void *tdListFree(SList *list) { return NULL; } -void tdListPrependNode(SList *list, SListNode *node) { - if (list->head == NULL) { - list->head = node; - list->tail = node; - } else { - node->next = list->head; - node->prev = NULL; - list->head->prev = node; - list->head = node; - } - list->numOfEles++; -} - -void tdListAppendNode(SList *list, SListNode *node) { - if (list->head == NULL) { - list->head = node; - list->tail = node; - } else { - node->prev = list->tail; - node->next = NULL; - list->tail->next = node; - list->tail = node; - } +void tdListPrependNode(SList *list, SListNode *node) { TD_DLIST_PREPEND(list, node); } - list->numOfEles++; -} +void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node); } int tdListPrepend(SList *list, void *data) { SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize); if (node == NULL) return -1; - node->next = node->prev = NULL; memcpy((void *)(node->data), data, list->eleSize); - tdListPrependNode(list, node); + TD_DLIST_PREPEND(list, node); return 0; } @@ -93,73 +65,40 @@ int tdListAppend(SList *list, void *data) { if (node == NULL) return -1; memcpy((void *)(node->data), data, list->eleSize); - tdListAppendNode(list, node); + TD_DLIST_APPEND(list, node); return 0; } SListNode *tdListPopHead(SList *list) { - if (list->head == NULL) return NULL; - SListNode *node = list->head; - if (node->next == NULL) { - list->head = NULL; - list->tail = NULL; - } else { - list->head = node->next; + SListNode *node; + + node = TD_DLIST_HEAD(list); + + if (node) { + TD_DLIST_POP(list, node); } - list->numOfEles--; - node->next = NULL; - node->prev = NULL; + return node; } SListNode *tdListPopTail(SList *list) { - if (list->tail == NULL) return NULL; - SListNode *node = list->tail; - if (node->prev == NULL) { - list->head = NULL; - list->tail = NULL; - } else { - list->tail = node->prev; - } - list->numOfEles--; - node->next = node->prev = NULL; - return node; -} + SListNode *node; -SListNode *tdListGetHead(SList *list) { - if (list == NULL || list->numOfEles == 0) { - return NULL; + node = TD_DLIST_TAIL(list); + if (node) { + TD_DLIST_POP(list, node); } - return list->head; + return node; } -SListNode *tsListGetTail(SList *list) { - if (list == NULL || list->numOfEles == 0) { - return NULL; - } +SListNode *tdListGetHead(SList *list) { return TD_DLIST_HEAD(list); } - return list->tail; -} +SListNode *tsListGetTail(SList *list) { return TD_DLIST_TAIL(list); } SListNode *tdListPopNode(SList *list, SListNode *node) { - if (list->head == node) { - list->head = node->next; - } - if (list->tail == node) { - list->tail = node->prev; - } - - if (node->prev != NULL) { - node->prev->next = node->next; - } - if (node->next != NULL) { - node->next->prev = node->prev; - } - list->numOfEles--; - node->next = node->prev = NULL; - + TD_DLIST_POP(list, node); return node; } @@ -174,19 +113,19 @@ void tdListMove(SList *src, SList *dst) { void tdListDiscard(SList *list) { if (list) { - list->head = list->tail = NULL; - list->numOfEles = 0; + listHead(list) = listTail(list) = NULL; + listNEles(list) = 0; } } -void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, list->eleSize); } +void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, listEleSize(list)); } void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) { pIter->direction = direction; if (direction == TD_LIST_FORWARD) { - pIter->next = list->head; + pIter->next = listHead(list); } else { - pIter->next = list->tail; + pIter->next = listTail(list); } } @@ -194,9 +133,9 @@ SListNode *tdListNext(SListIter *pIter) { SListNode *node = pIter->next; if (node == NULL) return NULL; if (pIter->direction == TD_LIST_FORWARD) { - pIter->next = node->next; + pIter->next = TD_DLIST_NODE_NEXT(node); } else { - pIter->next = node->prev; + pIter->next = TD_DLIST_NODE_PREV(node); } return node; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 3a6cbd259eed9066afe4f67afef393ab28fd737c..1ad61ee2b0fc1a0edccc0d14f130b382e2c24416 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -341,7 +341,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { return; } - if (true /*!tscIsUpdateQuery(pSql)*/) { // select and show kinds of commands + TAOS_FIELD* pFields = taos_fetch_fields(pSql); + if (pFields != NULL) { // select and show kinds of commands int error_no = 0; int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);