Merge remote-tracking branch 'origin/3.0' into feature/dnode3
This commit is contained in:
commit
4279d6a44d
|
@ -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
|
||||
|
|
|
@ -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 tNameSetDbName(SName* dst, int32_t acctId, const char* dbName, size_t nameLen);
|
||||
|
||||
int32_t tNameFromString(SName* dst, const char* str, uint32_t type);
|
||||
|
||||
int32_t tNameSetAcctId(SName* dst, const char* acct);
|
||||
|
||||
SSchema* tGetTbnameColumnSchema();
|
||||
|
||||
#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
|
||||
|
|
|
@ -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)
|
|
@ -22,23 +22,28 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SMemAllocator SMemAllocator;
|
||||
typedef struct SMemAllocatorFactory SMemAllocatorFactory;
|
||||
// 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_
|
||||
|
||||
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 *);
|
||||
};
|
||||
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
|
||||
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
|
||||
|
||||
struct SMemAllocatorFactory {
|
||||
typedef struct SMemAllocator {
|
||||
void *impl;
|
||||
SMemAllocator *(*create)(SMemAllocatorFactory *);
|
||||
void (*destroy)(SMemAllocatorFactory *, SMemAllocator *);
|
||||
};
|
||||
TD_MEM_ALCT(SMemAllocator);
|
||||
} SMemAllocator;
|
||||
|
||||
typedef struct SMemAllocatorFactory {
|
||||
void *impl;
|
||||
SMemAllocator *(*create)(struct SMemAllocatorFactory *);
|
||||
void (*destroy)(struct SMemAllocatorFactory *, SMemAllocator *);
|
||||
} SMemAllocatorFactory;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
/*
|
||||
* 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_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_*/
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include <catalog.h>
|
||||
#include <tname.h>
|
||||
#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;
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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_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_*/
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "mallocator.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tdlist.h"
|
||||
#include "tlist.h"
|
||||
#include "thash.h"
|
||||
#include "tskiplist.h"
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,4 @@ add_subdirectory(catalog)
|
|||
add_subdirectory(executor)
|
||||
add_subdirectory(planner)
|
||||
add_subdirectory(function)
|
||||
add_subdirectory(query)
|
||||
add_subdirectory(qcom)
|
||||
|
|
|
@ -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)
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
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);
|
||||
// can only perform the parameters based on the macro definitation
|
||||
static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) {
|
||||
char msg[512] = {0};
|
||||
|
||||
strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n);
|
||||
pShowMsg->payloadLen = htons(pEpAddr->n);
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
)
|
|
@ -9,5 +9,5 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
scheduler
|
||||
PRIVATE os util planner common query
|
||||
PRIVATE os util planner qcom common
|
||||
)
|
|
@ -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")
|
||||
)
|
|
@ -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;
|
||||
} SArenaAllocator;
|
||||
#endif
|
|
@ -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 tdListPrependNode(SList *list, SListNode *node) { TD_DLIST_PREPEND(list, node); }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
SListNode *node;
|
||||
|
||||
node = TD_DLIST_TAIL(list);
|
||||
if (node) {
|
||||
TD_DLIST_POP(list, node);
|
||||
}
|
||||
list->numOfEles--;
|
||||
node->next = node->prev = NULL;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
SListNode *tdListGetHead(SList *list) {
|
||||
if (list == NULL || list->numOfEles == 0) {
|
||||
return NULL;
|
||||
}
|
||||
SListNode *tdListGetHead(SList *list) { return TD_DLIST_HEAD(list); }
|
||||
|
||||
return list->head;
|
||||
}
|
||||
|
||||
SListNode *tsListGetTail(SList *list) {
|
||||
if (list == NULL || list->numOfEles == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue