提交 8fe7c183 编写于 作者: H Haojun Liao

Merge remote-tracking branch 'origin/3.0' into feature/3.0_liaohj

...@@ -124,8 +124,25 @@ typedef struct TAOS_MULTI_BIND { ...@@ -124,8 +124,25 @@ typedef struct TAOS_MULTI_BIND {
int num; int num;
} TAOS_MULTI_BIND; } TAOS_MULTI_BIND;
typedef enum {
SET_CONF_RET_SUCC = 0,
SET_CONF_RET_ERR_PART = -1,
SET_CONF_RET_ERR_INNER = -2,
SET_CONF_RET_ERR_JSON_INVALID = -3,
SET_CONF_RET_ERR_JSON_PARSE = -4,
SET_CONF_RET_ERR_ONLY_ONCE = -5,
SET_CONF_RET_ERR_TOO_LONG = -6
} SET_CONF_RET_CODE;
#define RET_MSG_LENGTH 1024
typedef struct setConfRet {
SET_CONF_RET_CODE retCode;
char retMsg[RET_MSG_LENGTH];
} setConfRet;
DLL_EXPORT void taos_cleanup(void); DLL_EXPORT void taos_cleanup(void);
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
DLL_EXPORT setConfRet taos_set_config(const char *config);
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
const char *db, int dbLen, uint16_t port); const char *db, int dbLen, uint16_t port);
...@@ -168,10 +185,13 @@ DLL_EXPORT int taos_select_db(TAOS *taos, const char *db); ...@@ -168,10 +185,13 @@ DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields); DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
DLL_EXPORT void taos_stop_query(TAOS_RES *res); DLL_EXPORT void taos_stop_query(TAOS_RES *res);
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col); DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res); DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
DLL_EXPORT const char *taos_get_server_info(TAOS *taos); DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
DLL_EXPORT const char *taos_get_client_info(); DLL_EXPORT const char *taos_get_client_info();
......
...@@ -51,7 +51,7 @@ extern int32_t tsCompatibleModel; ...@@ -51,7 +51,7 @@ extern int32_t tsCompatibleModel;
extern bool tsEnableSlaveQuery; extern bool tsEnableSlaveQuery;
extern bool tsPrintAuth; extern bool tsPrintAuth;
extern int64_t tsTickPerDay[3]; extern int64_t tsTickPerDay[3];
extern int32_t tsMultiProcess; extern bool tsMultiProcess;
// monitor // monitor
extern bool tsEnableMonitor; extern bool tsEnableMonitor;
......
...@@ -2016,7 +2016,6 @@ typedef struct { ...@@ -2016,7 +2016,6 @@ typedef struct {
int8_t slidingUnit; // MACRO: TIME_UNIT_XXX int8_t slidingUnit; // MACRO: TIME_UNIT_XXX
int8_t timezoneInt; // sma data expired if timezone changes. int8_t timezoneInt; // sma data expired if timezone changes.
char indexName[TSDB_INDEX_NAME_LEN]; char indexName[TSDB_INDEX_NAME_LEN];
char timezone[TD_TIMEZONE_LEN];
int32_t exprLen; int32_t exprLen;
int32_t tagsFilterLen; int32_t tagsFilterLen;
int64_t indexUid; int64_t indexUid;
...@@ -2054,32 +2053,6 @@ void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq); ...@@ -2054,32 +2053,6 @@ void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq); int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq); void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
typedef struct {
col_id_t colId;
uint16_t blockSize; // sma data block size
char data[];
} STSmaColData;
typedef struct {
tb_uid_t tableUid; // super/child/normal table uid
int32_t dataLen; // not including head
char data[];
} STSmaTbData;
typedef struct {
int64_t indexUid;
TSKEY skey; // startKey of one interval/sliding window
int64_t interval;
int32_t dataLen; // not including head
int8_t intervalUnit;
char data[];
} STSmaDataWrapper; // sma data for a interval/sliding window
// interval/sliding => window
// => window->table->colId
// => 当一个window下所有的表均计算完成时,流计算告知tsdb清除window的过期标记
// RSma: Rollup SMA // RSma: Rollup SMA
typedef struct { typedef struct {
int64_t interval; int64_t interval;
......
...@@ -138,55 +138,59 @@ ...@@ -138,55 +138,59 @@
#define TK_INTERVAL 120 #define TK_INTERVAL 120
#define TK_TOPIC 121 #define TK_TOPIC 121
#define TK_AS 122 #define TK_AS 122
#define TK_NK_BOOL 123 #define TK_EXPLAIN 123
#define TK_NULL 124 #define TK_ANALYZE 124
#define TK_NK_VARIABLE 125 #define TK_VERBOSE 125
#define TK_NK_UNDERLINE 126 #define TK_NK_BOOL 126
#define TK_ROWTS 127 #define TK_RATIO 127
#define TK_TBNAME 128 #define TK_NULL 128
#define TK_QSTARTTS 129 #define TK_NK_VARIABLE 129
#define TK_QENDTS 130 #define TK_NK_UNDERLINE 130
#define TK_WSTARTTS 131 #define TK_ROWTS 131
#define TK_WENDTS 132 #define TK_TBNAME 132
#define TK_WDURATION 133 #define TK_QSTARTTS 133
#define TK_BETWEEN 134 #define TK_QENDTS 134
#define TK_IS 135 #define TK_WSTARTTS 135
#define TK_NK_LT 136 #define TK_WENDTS 136
#define TK_NK_GT 137 #define TK_WDURATION 137
#define TK_NK_LE 138 #define TK_BETWEEN 138
#define TK_NK_GE 139 #define TK_IS 139
#define TK_NK_NE 140 #define TK_NK_LT 140
#define TK_MATCH 141 #define TK_NK_GT 141
#define TK_NMATCH 142 #define TK_NK_LE 142
#define TK_IN 143 #define TK_NK_GE 143
#define TK_JOIN 144 #define TK_NK_NE 144
#define TK_INNER 145 #define TK_MATCH 145
#define TK_SELECT 146 #define TK_NMATCH 146
#define TK_DISTINCT 147 #define TK_IN 147
#define TK_WHERE 148 #define TK_JOIN 148
#define TK_PARTITION 149 #define TK_INNER 149
#define TK_BY 150 #define TK_SELECT 150
#define TK_SESSION 151 #define TK_DISTINCT 151
#define TK_STATE_WINDOW 152 #define TK_WHERE 152
#define TK_SLIDING 153 #define TK_PARTITION 153
#define TK_FILL 154 #define TK_BY 154
#define TK_VALUE 155 #define TK_SESSION 155
#define TK_NONE 156 #define TK_STATE_WINDOW 156
#define TK_PREV 157 #define TK_SLIDING 157
#define TK_LINEAR 158 #define TK_FILL 158
#define TK_NEXT 159 #define TK_VALUE 159
#define TK_GROUP 160 #define TK_NONE 160
#define TK_HAVING 161 #define TK_PREV 161
#define TK_ORDER 162 #define TK_LINEAR 162
#define TK_SLIMIT 163 #define TK_NEXT 163
#define TK_SOFFSET 164 #define TK_GROUP 164
#define TK_LIMIT 165 #define TK_HAVING 165
#define TK_OFFSET 166 #define TK_ORDER 166
#define TK_ASC 167 #define TK_SLIMIT 167
#define TK_DESC 168 #define TK_SOFFSET 168
#define TK_NULLS 169 #define TK_LIMIT 169
#define TK_FIRST 170 #define TK_OFFSET 170
#define TK_LAST 171 #define TK_ASC 171
#define TK_DESC 172
#define TK_NULLS 173
#define TK_FIRST 174
#define TK_LAST 175
#define TK_NK_SPACE 300 #define TK_NK_SPACE 300
#define TK_NK_COMMENT 301 #define TK_NK_COMMENT 301
......
...@@ -46,11 +46,12 @@ typedef struct { ...@@ -46,11 +46,12 @@ typedef struct {
char localFqdn[TSDB_FQDN_LEN]; char localFqdn[TSDB_FQDN_LEN];
char firstEp[TSDB_EP_LEN]; char firstEp[TSDB_EP_LEN];
char secondEp[TSDB_EP_LEN]; char secondEp[TSDB_EP_LEN];
SDiskCfg *pDisks; SDiskCfg *disks;
int32_t numOfDisks; int32_t numOfDisks;
int8_t ntype;
} SDnodeOpt; } SDnodeOpt;
typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_RELOAD } EDndEvent; typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent;
/** /**
* @brief Initialize and start the dnode. * @brief Initialize and start the dnode.
......
...@@ -70,6 +70,7 @@ typedef enum ENodeType { ...@@ -70,6 +70,7 @@ typedef enum ENodeType {
QUERY_NODE_DATABASE_OPTIONS, QUERY_NODE_DATABASE_OPTIONS,
QUERY_NODE_TABLE_OPTIONS, QUERY_NODE_TABLE_OPTIONS,
QUERY_NODE_INDEX_OPTIONS, QUERY_NODE_INDEX_OPTIONS,
QUERY_NODE_EXPLAIN_OPTIONS,
// Statement nodes are used in parser and planner module. // Statement nodes are used in parser and planner module.
QUERY_NODE_SET_OPERATOR, QUERY_NODE_SET_OPERATOR,
...@@ -99,6 +100,7 @@ typedef enum ENodeType { ...@@ -99,6 +100,7 @@ typedef enum ENodeType {
QUERY_NODE_CREATE_TOPIC_STMT, QUERY_NODE_CREATE_TOPIC_STMT,
QUERY_NODE_DROP_TOPIC_STMT, QUERY_NODE_DROP_TOPIC_STMT,
QUERY_NODE_ALTER_LOCAL_STMT, QUERY_NODE_ALTER_LOCAL_STMT,
QUERY_NODE_EXPLAIN_STMT,
QUERY_NODE_SHOW_DATABASES_STMT, QUERY_NODE_SHOW_DATABASES_STMT,
QUERY_NODE_SHOW_TABLES_STMT, QUERY_NODE_SHOW_TABLES_STMT,
QUERY_NODE_SHOW_STABLES_STMT, QUERY_NODE_SHOW_STABLES_STMT,
......
...@@ -49,6 +49,7 @@ typedef struct SScanLogicNode { ...@@ -49,6 +49,7 @@ typedef struct SScanLogicNode {
STimeWindow scanRange; STimeWindow scanRange;
SName tableName; SName tableName;
bool showRewrite; bool showRewrite;
double ratio;
} SScanLogicNode; } SScanLogicNode;
typedef struct SJoinLogicNode { typedef struct SJoinLogicNode {
...@@ -197,7 +198,7 @@ typedef struct STableScanPhysiNode { ...@@ -197,7 +198,7 @@ typedef struct STableScanPhysiNode {
SScanPhysiNode scan; SScanPhysiNode scan;
uint8_t scanFlag; // denotes reversed scan of data or not uint8_t scanFlag; // denotes reversed scan of data or not
STimeWindow scanRange; STimeWindow scanRange;
SNode* pScanConditions; double ratio;
} STableScanPhysiNode; } STableScanPhysiNode;
typedef STableScanPhysiNode STableSeqScanPhysiNode; typedef STableScanPhysiNode STableSeqScanPhysiNode;
...@@ -252,6 +253,7 @@ typedef struct SIntervalPhysiNode { ...@@ -252,6 +253,7 @@ typedef struct SIntervalPhysiNode {
int64_t sliding; int64_t sliding;
int8_t intervalUnit; int8_t intervalUnit;
int8_t slidingUnit; int8_t slidingUnit;
uint8_t precision;
SFillNode* pFill; SFillNode* pFill;
} SIntervalPhysiNode; } SIntervalPhysiNode;
...@@ -297,18 +299,23 @@ typedef struct SSubplan { ...@@ -297,18 +299,23 @@ typedef struct SSubplan {
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
} SSubplan; } SSubplan;
typedef enum EQueryMode { typedef enum EExplainMode {
QUERY_MODE_NORMAL = 1, EXPLAIN_MODE_DISABLE = 1,
QUERY_MODE_EXPLAIN, EXPLAIN_MODE_STATIC,
QUERY_MODE_EXPLAIN_AN EXPLAIN_MODE_ANALYZE
} EQueryMode; } EExplainMode;
typedef struct SExplainInfo {
EExplainMode mode;
bool verbose;
} SExplainInfo;
typedef struct SQueryPlan { typedef struct SQueryPlan {
ENodeType type; ENodeType type;
uint64_t queryId; uint64_t queryId;
int32_t numOfSubplans; int32_t numOfSubplans;
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0. SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
SExplainInfo explainInfo;
} SQueryPlan; } SQueryPlan;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -131,6 +131,7 @@ typedef struct SRealTableNode { ...@@ -131,6 +131,7 @@ typedef struct SRealTableNode {
struct STableMeta* pMeta; struct STableMeta* pMeta;
SVgroupsInfo* pVgroupList; SVgroupsInfo* pVgroupList;
char useDbName[TSDB_DB_NAME_LEN]; char useDbName[TSDB_DB_NAME_LEN];
double ratio;
} SRealTableNode; } SRealTableNode;
typedef struct STempTableNode { typedef struct STempTableNode {
...@@ -282,6 +283,19 @@ typedef struct SVnodeModifOpStmt { ...@@ -282,6 +283,19 @@ typedef struct SVnodeModifOpStmt {
const char* sql; // current sql statement position const char* sql; // current sql statement position
} SVnodeModifOpStmt; } SVnodeModifOpStmt;
typedef struct SExplainOptions {
ENodeType type;
bool verbose;
double ratio;
} SExplainOptions;
typedef struct SExplainStmt {
ENodeType type;
bool analyze;
SExplainOptions* pOptions;
SNode* pQuery;
} SExplainStmt;
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext); void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext); void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext);
......
...@@ -42,6 +42,9 @@ extern "C" { ...@@ -42,6 +42,9 @@ extern "C" {
#include <sys/types.h> #include <sys/types.h>
#include <termios.h> #include <termios.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <sys/prctl.h>
#include <sys/shm.h>
#include <sys/wait.h>
#if defined(DARWIN) #if defined(DARWIN)
#else #else
...@@ -70,7 +73,6 @@ extern "C" { ...@@ -70,7 +73,6 @@ extern "C" {
#include <wchar.h> #include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include "osAtomic.h" #include "osAtomic.h"
#include "osDef.h" #include "osDef.h"
#include "osDir.h" #include "osDir.h"
...@@ -84,6 +86,7 @@ extern "C" { ...@@ -84,6 +86,7 @@ extern "C" {
#include "osThread.h" #include "osThread.h"
#include "osSemaphore.h" #include "osSemaphore.h"
#include "osSignal.h" #include "osSignal.h"
#include "osShm.h"
#include "osSleep.h" #include "osSleep.h"
#include "osSocket.h" #include "osSocket.h"
#include "osString.h" #include "osString.h"
......
/*
* 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_OS_SHM_H_
#define _TD_OS_SHM_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int32_t id;
int32_t size;
void* ptr;
} SShm;
int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ;
void taosDropShm(SShm *pShm);
int32_t taosAttachShm(SShm *pShm);
void taosDetachShm(SShm *pShm);
#ifdef __cplusplus
}
#endif
#endif /*_TD_OS_SHM_H_*/
...@@ -32,6 +32,9 @@ typedef pthread_once_t TdThreadOnce; ...@@ -32,6 +32,9 @@ typedef pthread_once_t TdThreadOnce;
typedef pthread_rwlockattr_t TdThreadRwlockAttr; typedef pthread_rwlockattr_t TdThreadRwlockAttr;
typedef pthread_cond_t TdThreadCond; typedef pthread_cond_t TdThreadCond;
typedef pthread_condattr_t TdThreadCondAttr; typedef pthread_condattr_t TdThreadCondAttr;
typedef pthread_key_t TdThreadKey;
typedef pthread_barrier_t TdThreadBarrier;
typedef pthread_barrierattr_t TdThreadBarrierAttr;
#define taosThreadCleanupPush pthread_cleanup_push #define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop #define taosThreadCleanupPop pthread_cleanup_pop
...@@ -39,78 +42,190 @@ typedef pthread_condattr_t TdThreadCondAttr; ...@@ -39,78 +42,190 @@ typedef pthread_condattr_t TdThreadCondAttr;
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section. // When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
#define pthread_t PTHREAD_T_TYPE_TAOS_FORBID // #define pthread_t PTHREAD_T_TYPE_TAOS_FORBID
#define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID // #define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID
#define pthread_mutex_t PTHREAD_MUTEX_T_TYPE_TAOS_FORBID // #define pthread_mutex_t PTHREAD_MUTEX_T_TYPE_TAOS_FORBID
#define pthread_mutexattr_t PTHREAD_MUTEXATTR_T_TYPE_TAOS_FORBID // #define pthread_mutexattr_t PTHREAD_MUTEXATTR_T_TYPE_TAOS_FORBID
#define pthread_rwlock_t PTHREAD_RWLOCK_T_TYPE_TAOS_FORBID // #define pthread_rwlock_t PTHREAD_RWLOCK_T_TYPE_TAOS_FORBID
#define pthread_attr_t PTHREAD_ATTR_T_TYPE_TAOS_FORBID // #define pthread_attr_t PTHREAD_ATTR_T_TYPE_TAOS_FORBID
#define pthread_once_t PTHREAD_ONCE_T_TYPE_TAOS_FORBID // #define pthread_once_t PTHREAD_ONCE_T_TYPE_TAOS_FORBID
#define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID // #define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID
#define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID // #define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID
#define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID // #define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
#define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID // #define pthread_key_t PTHREAD_KEY_T_TYPE_TAOS_FORBID
#define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID // #define pthread_barrier_t PTHREAD_BARRIER_T_TYPE_TAOS_FORBID
#define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID // #define pthread_barrierattr_t PTHREAD_BARRIERATTR_T_TYPE_TAOS_FORBID
#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID // #define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
#define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID // #define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID // #define pthread_attr_getdetachstate PTHREAD_ATTR_GETDETACHSTATE_FUNC_TAOS_FORBID
#define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID // #define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED_FUNC_TAOS_FORBID
#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID // #define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM_FUNC_TAOS_FORBID
#define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID // #define pthread_attr_getschedpolicy PTHREAD_ATTR_GETSCHEDPOLICY_FUNC_TAOS_FORBID
#define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID // #define pthread_attr_getscope PTHREAD_ATTR_GETSCOPE_FUNC_TAOS_FORBID
#define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID // #define pthread_attr_getstacksize PTHREAD_ATTR_GETSTACKSIZE_FUNC_TAOS_FORBID
#define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID // #define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID
#define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID // #define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID
#define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID // #define pthread_attr_setinheritsched PTHREAD_ATTR_SETINHERITSCHED_FUNC_TAOS_FORBID
#define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID // #define pthread_attr_setschedparam PTHREAD_ATTR_SETSCHEDPARAM_FUNC_TAOS_FORBID
#define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID // #define pthread_attr_setschedpolicy PTHREAD_ATTR_SETSCHEDPOLICY_FUNC_TAOS_FORBID
#define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID // #define pthread_attr_setscope PTHREAD_ATTR_SETSCOPE_FUNC_TAOS_FORBID
#define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID // #define pthread_attr_setstacksize PTHREAD_ATTR_SETSTACKSIZE_FUNC_TAOS_FORBID
#define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID // #define pthread_barrier_destroy PTHREAD_BARRIER_DESTROY_FUNC_TAOS_FORBID
#define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID // #define pthread_barrier_init PTHREAD_BARRIER_INIT_FUNC_TAOS_FORBID
#define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID // #define pthread_barrier_wait PTHREAD_BARRIER_WAIT_FUNC_TAOS_FORBID
#define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID // #define pthread_barrierattr_destroy PTHREAD_BARRIERATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID // #define pthread_barrierattr_getpshared PTHREAD_BARRIERATTR_GETPSHARED_FUNC_TAOS_FORBID
#define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID // #define pthread_barrierattr_init PTHREAD_BARRIERATTR_INIT_FUNC_TAOS_FORBID
#define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID // #define pthread_barrierattr_setpshared PTHREAD_BARRIERATTR_SETPSHARED_FUNC_TAOS_FORBID
#define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID // #define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
#define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID // #define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
#define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID // #define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
#define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID // #define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID
#define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID // #define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID
// #define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID
// #define pthread_cond_timedwait PTHREAD_COND_TIMEDWAIT_FUNC_TAOS_FORBID
// #define pthread_condattr_destroy PTHREAD_CONDATTR_DESTROY_FUNC_TAOS_FORBID
// #define pthread_condattr_getpshared PTHREAD_CONDATTR_GETPSHARED_FUNC_TAOS_FORBID
// #define pthread_condattr_init PTHREAD_CONDATTR_INIT_FUNC_TAOS_FORBID
// #define pthread_condattr_setpshared PTHREAD_CONDATTR_SETPSHARED_FUNC_TAOS_FORBID
// #define pthread_detach PTHREAD_DETACH_FUNC_TAOS_FORBID
// #define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
// #define pthread_exit PTHREAD_EXIT_FUNC_TAOS_FORBID
// #define pthread_getschedparam PTHREAD_GETSCHEDPARAM_FUNC_TAOS_FORBID
// #define pthread_getspecific PTHREAD_GETSPECIFIC_FUNC_TAOS_FORBID
// #define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID
// #define pthread_key_create PTHREAD_KEY_CREATE_FUNC_TAOS_FORBID
// #define pthread_key_delete PTHREAD_KEY_DELETE_FUNC_TAOS_FORBID
// #define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID
// #define pthread_mutex_consistent PTHREAD_MUTEX_CONSISTENT_FUNC_TAOS_FORBID
// #define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
// #define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID
// #define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
// #define pthread_mutex_timedlock PTHREAD_MUTEX_TIMEDLOCK_FUNC_TAOS_FORBID
// #define pthread_mutex_trylock PTHREAD_MUTEX_TRYLOCK_FUNC_TAOS_FORBID
// #define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
// #define pthread_mutexattr_destroy PTHREAD_MUTEXATTR_DESTROY_FUNC_TAOS_FORBID
// #define pthread_mutexattr_getpshared PTHREAD_MUTEXATTR_GETPSHARED_FUNC_TAOS_FORBID
// #define pthread_mutexattr_getrobust PTHREAD_MUTEXATTR_GETROBUST_FUNC_TAOS_FORBID
// #define pthread_mutexattr_gettype PTHREAD_MUTEXATTR_GETTYPE_FUNC_TAOS_FORBID
// #define pthread_mutexattr_init PTHREAD_MUTEXATTR_INIT_FUNC_TAOS_FORBID
// #define pthread_mutexattr_setpshared PTHREAD_MUTEXATTR_SETPSHARED_FUNC_TAOS_FORBID
// #define pthread_mutexattr_setrobust PTHREAD_MUTEXATTR_SETROBUST_FUNC_TAOS_FORBID
// #define pthread_mutexattr_settype PTHREAD_MUTEXATTR_SETTYPE_FUNC_TAOS_FORBID
// #define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
// #define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID
// #define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID
// #define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlock_timedrdlock PTHREAD_RWLOCK_TIMEDRDLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlock_timedwrlock PTHREAD_RWLOCK_TIMEDWRLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlock_tryrdlock PTHREAD_RWLOCK_TRYRDLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlock_trywrlock PTHREAD_RWLOCK_TRYWRLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
// #define pthread_rwlockattr_destroy PTHREAD_RWLOCKATTR_DESTROY_FUNC_TAOS_FORBID
// #define pthread_rwlockattr_getpshared PTHREAD_RWLOCKATTR_GETPSHARED_FUNC_TAOS_FORBID
// #define pthread_rwlockattr_init PTHREAD_RWLOCKATTR_INIT_FUNC_TAOS_FORBID
// #define pthread_rwlockattr_setpshared PTHREAD_RWLOCKATTR_SETPSHARED_FUNC_TAOS_FORBID
// #define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID
// #define pthread_setcancelstate PTHREAD_SETCANCELSTATE_FUNC_TAOS_FORBID
// #define pthread_setcanceltype PTHREAD_SETCANCELTYPE_FUNC_TAOS_FORBID
// #define pthread_setschedparam PTHREAD_SETSCHEDPARAM_FUNC_TAOS_FORBID
// #define pthread_setspecific PTHREAD_SETSPECIFIC_FUNC_TAOS_FORBID
// #define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID
// #define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID
// #define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
// #define pthread_spin_trylock PTHREAD_SPIN_TRYLOCK_FUNC_TAOS_FORBID
// #define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
// #define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
// #define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID
// #define sigwait SIGWAIT_FUNC_TAOS_FORBID
#endif #endif
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared); int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg);
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr); int32_t taosThreadAttrDestroy(TdThreadAttr * attr);
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock); int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate);
int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched);
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param);
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy);
int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope);
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize);
int32_t taosThreadAttrInit(TdThreadAttr * attr);
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate);
int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched);
int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param);
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy);
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope);
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize);
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier);
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count);
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier);
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr);
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared);
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr);
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared);
int32_t taosThreadCancel(TdThread thread);
int32_t taosThreadCondDestroy(TdThreadCond * cond);
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr);
int32_t taosThreadCondSignal(TdThreadCond * cond);
int32_t taosThreadCondBroadcast(TdThreadCond * cond);
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex);
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime);
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr);
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared);
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr);
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared);
int32_t taosThreadDetach(TdThread thread);
int32_t taosThreadEqual(TdThread t1, TdThread t2);
void taosThreadExit(void *valuePtr);
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param);
void *taosThreadGetSpecific(TdThreadKey key);
int32_t taosThreadJoin(TdThread thread, void **valuePtr);
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *));
int32_t taosThreadKeyDelete(TdThreadKey key);
int32_t taosThreadKill(TdThread thread, int32_t sig);
int32_t taosThreadMutexConsistent(TdThreadMutex* mutex);
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex); int32_t taosThreadMutexDestroy(TdThreadMutex * mutex);
int32_t taosThreadSpinLock(TdThreadSpinlock *lock); int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr);
int32_t taosThreadMutexLock(TdThreadMutex *mutex); int32_t taosThreadMutexLock(TdThreadMutex * mutex);
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock); int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime);
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock); int32_t taosThreadMutexTryLock(TdThreadMutex * mutex);
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex); int32_t taosThreadMutexUnlock(TdThreadMutex * mutex);
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock); int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr);
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock); int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared);
void taosThreadTestCancel(void); int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust);
int32_t taosThreadAttrInit(TdThreadAttr *attr); int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind);
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg); int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr);
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)); int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared);
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState); int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust);
int32_t taosThreadAttrDestroy(TdThreadAttr *attr); int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind);
int32_t taosThreadJoin(TdThread thread, void **pValue); int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void));
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr); int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock); int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr);
int32_t taosThreadCondSignal(TdThreadCond *cond); int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock);
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr); int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime);
int32_t taosThreadCondBroadcast(TdThreadCond *cond); int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime);
int32_t taosThreadCondDestroy(TdThreadCond *cond); int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock);
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex); int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr);
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared);
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr);
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared);
TdThread taosThreadSelf(void); TdThread taosThreadSelf(void);
int32_t taosThreadEqual(TdThread t1, TdThread t2); int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate);
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset); int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype);
int32_t taosThreadCancel(TdThread thread); int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param);
int32_t taosThreadKill(TdThread thread, int sig); int32_t taosThreadSetSpecific(TdThreadKey key, const void *value);
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock);
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared);
int32_t taosThreadSpinLock(TdThreadSpinlock * lock);
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock);
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock);
void taosThreadTestCancel(void);
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset);
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include <time.h>
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section. // When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_UTIL_TAOS_ERROR_H_ #ifndef _TD_UTIL_TAOS_ERROR_H_
#define _TD_UTIL_TAOS_ERROR_H_ #define _TD_UTIL_TAOS_ERROR_H_
#include "os.h" #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -381,6 +381,14 @@ typedef enum ELogicConditionType { ...@@ -381,6 +381,14 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_DB_DELAY 10 #define TSDB_MAX_DB_DELAY 10
#define TSDB_DEFAULT_DB_DELAY 2 #define TSDB_DEFAULT_DB_DELAY 2
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false
#define TSDB_MIN_EXPLAIN_RATIO 0
#define TSDB_MAX_EXPLAIN_RATIO 1
#define TSDB_DEFAULT_EXPLAIN_RATIO 0.001
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024
#define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_JOIN_TABLE_NUM 10
#define TSDB_MAX_UNION_CLAUSE 5 #define TSDB_MAX_UNION_CLAUSE 5
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "consumer.h"
...@@ -200,6 +200,9 @@ static void doDestroyRequest(void *p) { ...@@ -200,6 +200,9 @@ static void doDestroyRequest(void *p) {
taosArrayDestroy(pRequest->body.showInfo.pArray); taosArrayDestroy(pRequest->body.showInfo.pArray);
} }
taosArrayDestroy(pRequest->tableList);
taosArrayDestroy(pRequest->dbList);
deregisterRequest(pRequest); deregisterRequest(pRequest);
taosMemoryFreeClear(pRequest); taosMemoryFreeClear(pRequest);
} }
......
...@@ -71,6 +71,12 @@ void taos_cleanup(void) { ...@@ -71,6 +71,12 @@ void taos_cleanup(void) {
tscInfo("all local resources released"); tscInfo("all local resources released");
} }
setConfRet taos_set_config(const char *config) {
// TODO
setConfRet ret = {SET_CONF_RET_SUCC, {0}};
return ret;
}
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db); tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db);
if (user == NULL) { if (user == NULL) {
...@@ -257,6 +263,11 @@ int *taos_fetch_lengths(TAOS_RES *res) { ...@@ -257,6 +263,11 @@ int *taos_fetch_lengths(TAOS_RES *res) {
return ((SRequestObj *)res)->body.resInfo.length; return ((SRequestObj *)res)->body.resInfo.length;
} }
TAOS_ROW *taos_result_block(TAOS_RES *res) {
// TODO
return NULL;
}
// todo intergrate with tDataTypes // todo intergrate with tDataTypes
const char *taos_data_type(int type) { const char *taos_data_type(int type) {
switch (type) { switch (type) {
...@@ -353,6 +364,11 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { ...@@ -353,6 +364,11 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
return colDataIsNull_f(pCol->nullbitmap, row); return colDataIsNull_f(pCol->nullbitmap, row);
} }
bool taos_is_update_query(TAOS_RES *res) {
// TODO
return true;
}
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
if (res == NULL) { if (res == NULL) {
return 0; return 0;
...@@ -376,6 +392,11 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -376,6 +392,11 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
int taos_validate_sql(TAOS *taos, const char *sql) { return true; } int taos_validate_sql(TAOS *taos, const char *sql) { return true; }
void taos_reset_current_db(TAOS *taos) {
// TODO
return;
}
const char *taos_get_server_info(TAOS *taos) { const char *taos_get_server_info(TAOS *taos) {
if (taos == NULL) { if (taos == NULL) {
return NULL; return NULL;
...@@ -407,6 +428,11 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { ...@@ -407,6 +428,11 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
// TODO // TODO
} }
int taos_load_table_info(TAOS *taos, const char *tableNameList) {
// TODO
return -1;
}
TAOS_STMT *taos_stmt_init(TAOS *taos) { TAOS_STMT *taos_stmt_init(TAOS *taos) {
// TODO // TODO
return NULL; return NULL;
......
...@@ -241,6 +241,10 @@ void tmq_list_destroy(tmq_list_t* list) { ...@@ -241,6 +241,10 @@ void tmq_list_destroy(tmq_list_t* list) {
taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree); taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree);
} }
static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
return sprintf(dst, "%s:%d", topicName, vg);
}
void tmqClearUnhandleMsg(tmq_t* tmq) { void tmqClearUnhandleMsg(tmq_t* tmq) {
tmq_message_t* msg = NULL; tmq_message_t* msg = NULL;
while (1) { while (1) {
...@@ -827,7 +831,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -827,7 +831,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
SMqClientVg* pVg = pParam->pVg; SMqClientVg* pVg = pParam->pVg;
tmq_t* tmq = pParam->tmq; tmq_t* tmq = pParam->tmq;
if (code != 0) { if (code != 0) {
printf("msg discard, code:%x\n", code); tscWarn("msg discard, code:%x", code);
goto WRITE_QUEUE_FAIL; goto WRITE_QUEUE_FAIL;
} }
...@@ -835,12 +839,12 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -835,12 +839,12 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
int32_t tmqEpoch = atomic_load_32(&tmq->epoch); int32_t tmqEpoch = atomic_load_32(&tmq->epoch);
if (msgEpoch < tmqEpoch) { if (msgEpoch < tmqEpoch) {
tsem_post(&tmq->rspSem); tsem_post(&tmq->rspSem);
printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch); tscWarn("discard rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch);
return 0; return 0;
} }
if (msgEpoch != tmqEpoch) { if (msgEpoch != tmqEpoch) {
printf("mismatch rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch); tscWarn("mismatch rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch);
} else { } else {
atomic_sub_fetch_32(&tmq->waitingRequest, 1); atomic_sub_fetch_32(&tmq->waitingRequest, 1);
} }
...@@ -899,19 +903,54 @@ WRITE_QUEUE_FAIL: ...@@ -899,19 +903,54 @@ WRITE_QUEUE_FAIL:
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
/*printf("call update ep %d\n", epoch);*/ /*printf("call update ep %d\n", epoch);*/
bool set = false; bool set = false;
int32_t sz = taosArrayGetSize(pRsp->topics); int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
for (int32_t i = 0; i < sz; i++) { SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic));
if (newTopics == NULL) {
return false;
}
SHashObj* pHash = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
if (pHash == NULL) {
taosArrayDestroy(newTopics);
return false;
}
// find topic, build hash
for (int32_t i = 0; i < topicNumGet; i++) {
SMqClientTopic topic = {0}; SMqClientTopic topic = {0};
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i); SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
taosHashClear(pHash);
topic.topicName = strdup(pTopicEp->topic); topic.topicName = strdup(pTopicEp->topic);
int32_t vgSz = taosArrayGetSize(pTopicEp->vgs);
topic.vgs = taosArrayInit(vgSz, sizeof(SMqClientVg)); int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
for (int32_t j = 0; j < vgSz; j++) { for (int32_t j = 0; j < topicNumCur; j++) {
// find old topic
SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, j);
if (pTopicCur->vgs && strcmp(pTopicCur->topicName, pTopicEp->topic) == 0) {
int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs);
if (vgNumCur == 0) break;
for (int32_t k = 0; k < vgNumCur; k++) {
SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, k);
sprintf(vgKey, "%s:%d", topic.topicName, pVgCur->vgId);
taosHashPut(pHash, vgKey, strlen(vgKey), &pVgCur->currentOffset, sizeof(int64_t));
}
break;
}
}
int32_t vgNumGet = taosArrayGetSize(pTopicEp->vgs);
topic.vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg));
for (int32_t j = 0; j < vgNumGet; j++) {
SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j); SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j);
sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId);
int64_t* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey));
int64_t offset = pVgEp->offset;
if (pOffset != NULL) {
offset = *pOffset;
}
SMqClientVg clientVg = { SMqClientVg clientVg = {
.pollCnt = 0, .pollCnt = 0,
.currentOffset = pVgEp->offset, .currentOffset = offset,
.vgId = pVgEp->vgId, .vgId = pVgEp->vgId,
.epSet = pVgEp->epSet, .epSet = pVgEp->epSet,
.vgStatus = TMQ_VG_STATUS__IDLE, .vgStatus = TMQ_VG_STATUS__IDLE,
...@@ -922,6 +961,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { ...@@ -922,6 +961,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
taosArrayPush(newTopics, &topic); taosArrayPush(newTopics, &topic);
} }
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics); if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
taosHashCleanup(pHash);
tmq->clientTopics = newTopics; tmq->clientTopics = newTopics;
atomic_store_32(&tmq->epoch, epoch); atomic_store_32(&tmq->epoch, epoch);
return set; return set;
...@@ -931,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -931,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param; SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param;
tmq_t* tmq = pParam->tmq; tmq_t* tmq = pParam->tmq;
if (code != 0) { if (code != 0) {
printf("get topic endpoint error, not ready, wait:%d\n", pParam->sync); tscError("get topic endpoint error, not ready, wait:%d\n", pParam->sync);
goto END; goto END;
} }
...@@ -1302,6 +1342,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { ...@@ -1302,6 +1342,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
while (1) { while (1) {
/*printf("cycle\n");*/ /*printf("cycle\n");*/
tmqAskEp(tmq, false);
tmqPollImpl(tmq, blocking_time); tmqPollImpl(tmq, blocking_time);
tsem_wait(&tmq->rspSem); tsem_wait(&tmq->rspSem);
......
...@@ -45,7 +45,7 @@ float tsRatioOfQueryCores = 1.0f; ...@@ -45,7 +45,7 @@ float tsRatioOfQueryCores = 1.0f;
int32_t tsMaxBinaryDisplayWidth = 30; int32_t tsMaxBinaryDisplayWidth = 30;
bool tsEnableSlaveQuery = 1; bool tsEnableSlaveQuery = 1;
bool tsPrintAuth = 0; bool tsPrintAuth = 0;
int32_t tsMultiProcess = 0; bool tsMultiProcess = 0;
// monitor // monitor
bool tsEnableMonitor = 1; bool tsEnableMonitor = 1;
...@@ -347,7 +347,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { ...@@ -347,7 +347,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1; if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1; if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1;
if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1; if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; if (cfgAddBool(pCfg, "multiProcess", tsMultiProcess, 0) != 0) return -1;
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1;
...@@ -466,7 +466,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { ...@@ -466,7 +466,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval; tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval;
tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval; tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval;
tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval; tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval;
tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->i32; tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval;
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32; tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
......
aux_source_directory(src DNODE_SRC) aux_source_directory(dm/src DNODE_SRC)
aux_source_directory(dnode/src DNODE_SRC) aux_source_directory(qm/src DNODE_SRC)
aux_source_directory(qnode/src DNODE_SRC) aux_source_directory(bm/src DNODE_SRC)
aux_source_directory(bnode/src DNODE_SRC) aux_source_directory(sm/src DNODE_SRC)
aux_source_directory(snode/src DNODE_SRC) aux_source_directory(vm/src DNODE_SRC)
aux_source_directory(vnode/src DNODE_SRC) aux_source_directory(mm/src DNODE_SRC)
aux_source_directory(mnode/src DNODE_SRC) aux_source_directory(main/src DNODE_SRC)
aux_source_directory(container/src DNODE_SRC)
add_library(dnode STATIC ${DNODE_SRC}) add_library(dnode STATIC ${DNODE_SRC})
target_link_libraries( target_link_libraries(
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
...@@ -14,16 +12,22 @@ target_link_libraries( ...@@ -14,16 +12,22 @@ target_link_libraries(
target_include_directories( target_include_directories(
dnode dnode
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt" PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dnode/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dm/inc"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qnode/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qm/inc"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bnode/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bm/inc"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/snode/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/sm/inc"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vnode/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vm/inc"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mnode/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mm/inc"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/container/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/main/inc"
) )
add_subdirectory(main) aux_source_directory(main/exe EXEC_SRC)
add_executable(taosd ${EXEC_SRC})
target_include_directories(
taosd
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/main/inc"
)
target_link_libraries(taosd dnode)
if(${BUILD_TEST}) if(${BUILD_TEST})
add_subdirectory(test) add_subdirectory(test)
......
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "dndInt.h"
#define MAXLEN 1024
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR;
int32_t len = 0;
const int32_t maxLen = MAXLEN;
char content[MAXLEN + 1] = {0};
cJSON *root = NULL;
char file[PATH_MAX];
TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) {
dDebug("file %s not exist", file);
code = 0;
goto _OVER;
}
len = (int32_t)taosReadFile(pFile, content, maxLen);
if (len <= 0) {
dError("failed to read %s since content is null", file);
goto _OVER;
}
content[len] = 0;
root = cJSON_Parse(content);
if (root == NULL) {
dError("failed to read %s since invalid json format", file);
goto _OVER;
}
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
if (!deployed || deployed->type != cJSON_Number) {
dError("failed to read %s since deployed not found", file);
goto _OVER;
}
*pDeployed = deployed->valueint != 0;
code = 0;
dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed);
_OVER:
if (root != NULL) cJSON_Delete(root);
if (pFile != NULL) taosCloseFile(&pFile);
terrno = code;
return code;
}
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to write %s since %s", file, terrstr());
return -1;
}
int32_t len = 0;
const int32_t maxLen = MAXLEN;
char content[MAXLEN + 1] = {0};
len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
len += snprintf(content + len, maxLen - len, "}\n");
taosWriteFile(pFile, content, len);
taosFsyncFile(pFile);
taosCloseFile(&pFile);
char realfile[PATH_MAX] = {0};
snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s since %s", file, terrstr());
return -1;
}
dInfo("successed to write %s, deployed:%d", realfile, deployed);
return 0;
}
aux_source_directory(src EXEC_SRC)
add_executable(taosd ${EXEC_SRC})
target_include_directories(
taosd
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(taosd dnode)
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndMain.h" #include "dnd.h"
#include "tconfig.h"
static struct { static struct {
bool dumpConfig; bool dumpConfig;
...@@ -23,10 +24,12 @@ static struct { ...@@ -23,10 +24,12 @@ static struct {
bool printVersion; bool printVersion;
char envFile[PATH_MAX]; char envFile[PATH_MAX];
char apolloUrl[PATH_MAX]; char apolloUrl[PATH_MAX];
SArray *pArgs; // SConfigPair
SDnode *pDnode; SDnode *pDnode;
ENodeType ntype;
} global = {0}; } global = {0};
static void dndSigintHandle(int signum, void *info, void *ctx) { static void dndStopDnode(int signum, void *info, void *ctx) {
dInfo("signal:%d is received", signum); dInfo("signal:%d is received", signum);
SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
if (pDnode != NULL) { if (pDnode != NULL) {
...@@ -34,15 +37,32 @@ static void dndSigintHandle(int signum, void *info, void *ctx) { ...@@ -34,15 +37,32 @@ static void dndSigintHandle(int signum, void *info, void *ctx) {
} }
} }
static void dndHandleChild(int signum, void *info, void *ctx) {
dInfo("signal:%d is received", signum);
dndHandleEvent(global.pDnode, DND_EVENT_CHILD);
}
static void dndSetSignalHandle() { static void dndSetSignalHandle() {
taosSetSignal(SIGTERM, dndSigintHandle); taosSetSignal(SIGTERM, dndStopDnode);
taosSetSignal(SIGHUP, dndSigintHandle); taosSetSignal(SIGHUP, dndStopDnode);
taosSetSignal(SIGINT, dndSigintHandle); taosSetSignal(SIGINT, dndStopDnode);
taosSetSignal(SIGABRT, dndSigintHandle); taosSetSignal(SIGABRT, dndStopDnode);
taosSetSignal(SIGBREAK, dndSigintHandle); taosSetSignal(SIGBREAK, dndStopDnode);
if (!tsMultiProcess) {
// Set the single process signal
} else if (global.ntype == DNODE) {
// Set the parent process signal
// When the child process exits, the parent process receives a signal
taosSetSignal(SIGCHLD, dndHandleChild);
} else {
// Set child process signal
// When the parent process exits, the child process will receive the SIGKILL signal
prctl(PR_SET_PDEATHSIG, SIGKILL);
}
} }
static int32_t dndParseOption(int32_t argc, char const *argv[]) { static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
for (int32_t i = 1; i < argc; ++i) { for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0) { if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
...@@ -55,10 +75,16 @@ static int32_t dndParseOption(int32_t argc, char const *argv[]) { ...@@ -55,10 +75,16 @@ static int32_t dndParseOption(int32_t argc, char const *argv[]) {
printf("'-c' requires a parameter, default is %s\n", configDir); printf("'-c' requires a parameter, default is %s\n", configDir);
return -1; return -1;
} }
} else if (strcmp(argv[i], "-C") == 0) { } else if (strcmp(argv[i], "-a") == 0) {
global.dumpConfig = true; tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-e") == 0) {
tstrncpy(global.envFile, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-k") == 0) { } else if (strcmp(argv[i], "-k") == 0) {
global.generateGrant = true; global.generateGrant = true;
} else if (strcmp(argv[i], "-n") == 0) {
global.ntype = atoi(argv[++i]);
} else if (strcmp(argv[i], "-C") == 0) {
global.dumpConfig = true;
} else if (strcmp(argv[i], "-V") == 0) { } else if (strcmp(argv[i], "-V") == 0) {
global.printVersion = true; global.printVersion = true;
} else { } else {
...@@ -68,14 +94,65 @@ static int32_t dndParseOption(int32_t argc, char const *argv[]) { ...@@ -68,14 +94,65 @@ static int32_t dndParseOption(int32_t argc, char const *argv[]) {
return 0; return 0;
} }
static void dndGenerateGrant() {
// grantParseParameter();
printf("this feature is not implemented yet\n");
}
static void dndPrintVersion() {
#ifdef TD_ENTERPRISE
char *releaseName = "enterprise";
#else
char *releaseName = "community";
#endif
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
printf("gitinfo: %s\n", gitinfo);
printf("buildInfo: %s\n", buildinfo);
}
static void dndDumpCfg() {
SConfig *pCfg = taosGetCfg();
cfgDumpCfg(pCfg, 0, 1);
}
static SDnodeOpt dndGetOpt() {
SConfig *pCfg = taosGetCfg();
SDnodeOpt option = {0};
option.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
tstrncpy(option.dataDir, tsDataDir, sizeof(option.dataDir));
tstrncpy(option.firstEp, tsFirst, sizeof(option.firstEp));
tstrncpy(option.secondEp, tsSecond, sizeof(option.firstEp));
option.serverPort = tsServerPort;
tstrncpy(option.localFqdn, tsLocalFqdn, sizeof(option.localFqdn));
snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort);
option.disks = tsDiskCfg;
option.numOfDisks = tsDiskCfgNum;
option.ntype = global.ntype;
return option;
}
static int32_t dndInitLog() {
char logName[12] = {0};
snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype));
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
}
static void dndSetProcName(char **argv) {
if (global.ntype != DNODE) {
const char *name = dndNodeProcStr(global.ntype);
prctl(PR_SET_NAME, name);
strcpy(argv[0], name);
}
}
static int32_t dndRunDnode() { static int32_t dndRunDnode() {
if (dndInit() != 0) { if (dndInit() != 0) {
dInfo("failed to initialize dnode environment since %s", terrstr()); dError("failed to initialize environment since %s", terrstr());
return -1; return -1;
} }
SDnodeOpt option = dndGetOpt(); SDnodeOpt option = dndGetOpt();
SDnode *pDnode = dndCreate(&option); SDnode *pDnode = dndCreate(&option);
if (pDnode == NULL) { if (pDnode == NULL) {
dError("failed to to create dnode object since %s", terrstr()); dError("failed to to create dnode object since %s", terrstr());
...@@ -85,9 +162,9 @@ static int32_t dndRunDnode() { ...@@ -85,9 +162,9 @@ static int32_t dndRunDnode() {
dndSetSignalHandle(); dndSetSignalHandle();
} }
dInfo("start the TDengine service"); dInfo("start the service");
int32_t code = dndRun(pDnode); int32_t code = dndRun(pDnode);
dInfo("start shutting down the TDengine service"); dInfo("start shutting down the service");
global.pDnode = NULL; global.pDnode = NULL;
dndClose(pDnode); dndClose(pDnode);
...@@ -99,11 +176,12 @@ static int32_t dndRunDnode() { ...@@ -99,11 +176,12 @@ static int32_t dndRunDnode() {
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
if (!taosCheckSystemIsSmallEnd()) { if (!taosCheckSystemIsSmallEnd()) {
dError("failed to start TDengine since on non-small-end machines"); printf("failed to start since on non-small-end machines\n");
return -1; return -1;
} }
if (dndParseOption(argc, argv) != 0) { if (dndParseArgs(argc, argv) != 0) {
printf("failed to start since parse args error\n");
return -1; return -1;
} }
...@@ -117,13 +195,13 @@ int main(int argc, char const *argv[]) { ...@@ -117,13 +195,13 @@ int main(int argc, char const *argv[]) {
return 0; return 0;
} }
if (taosCreateLog("taosdlog", 1, configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) { if (dndInitLog() != 0) {
dError("failed to start TDengine since read log config error"); printf("failed to start since init log error\n");
return -1; return -1;
} }
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) { if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
dError("failed to start TDengine since read config error"); dError("failed to start since read config error");
return -1; return -1;
} }
...@@ -134,5 +212,6 @@ int main(int argc, char const *argv[]) { ...@@ -134,5 +212,6 @@ int main(int argc, char const *argv[]) {
return 0; return 0;
} }
dndSetProcName((char **)argv);
return dndRunDnode(); return dndRunDnode();
} }
...@@ -96,10 +96,11 @@ typedef struct SMgmtWrapper { ...@@ -96,10 +96,11 @@ typedef struct SMgmtWrapper {
bool required; bool required;
EProcType procType; EProcType procType;
SProcObj *pProc; SProcObj *pProc;
SShm shm;
void *pMgmt; void *pMgmt;
SDnode *pDnode; SDnode *pDnode;
NodeMsgFp msgFps[TDMT_MAX]; NodeMsgFp msgFps[TDMT_MAX];
int32_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
SMgmtFp fp; SMgmtFp fp;
} SMgmtWrapper; } SMgmtWrapper;
...@@ -119,21 +120,24 @@ typedef struct SDnode { ...@@ -119,21 +120,24 @@ typedef struct SDnode {
char *firstEp; char *firstEp;
char *secondEp; char *secondEp;
char *dataDir; char *dataDir;
SDiskCfg *pDisks; SDiskCfg *disks;
int32_t numOfDisks; int32_t numOfDisks;
uint16_t serverPort; uint16_t serverPort;
bool dropped; bool dropped;
ENodeType ntype;
EDndStatus status; EDndStatus status;
EDndEvent event; EDndEvent event;
SStartupReq startup; SStartupReq startup;
TdFilePtr pLockFile; TdFilePtr runtimeFile;
STransMgmt trans; STransMgmt trans;
SMgmtWrapper wrappers[NODE_MAX]; SMgmtWrapper wrappers[NODE_MAX];
} SDnode; } SDnode;
const char *dndNodeLogStr(ENodeType ntype);
const char *dndNodeProcStr(ENodeType ntype);
EDndStatus dndGetStatus(SDnode *pDnode); EDndStatus dndGetStatus(SDnode *pDnode);
void dndSetStatus(SDnode *pDnode, EDndStatus stat); void dndSetStatus(SDnode *pDnode, EDndStatus stat);
void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId); void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
void dndSendMonitorReport(SDnode *pDnode); void dndSendMonitorReport(SDnode *pDnode);
......
...@@ -34,7 +34,6 @@ int32_t dndInit(); ...@@ -34,7 +34,6 @@ int32_t dndInit();
void dndCleanup(); void dndCleanup();
const char *dndStatStr(EDndStatus stat); const char *dndStatStr(EDndStatus stat);
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup); void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
TdFilePtr dndCheckRunning(const char *dataDir);
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
// dndMsg.c // dndMsg.c
...@@ -58,6 +57,11 @@ void dndCleanupClient(SDnode *pDnode); ...@@ -58,6 +57,11 @@ void dndCleanupClient(SDnode *pDnode);
int32_t dndInitMsgHandle(SDnode *pDnode); int32_t dndInitMsgHandle(SDnode *pDnode);
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
// dndFile.c
int32_t dndOpenRuntimeFile(SDnode *pDnode);
int32_t dndWriteRuntimeFile(SDnode *pDnode);
void dndCloseRuntimeFile(SDnode *pDnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
/*
* 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_DND_MAIN_H_
#define _TD_DND_MAIN_H_
#include "dnode.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tlog.h"
#include "version.h"
#ifdef __cplusplus
extern "C" {
#endif
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
void dndDumpCfg();
void dndPrintVersion();
void dndGenerateGrant();
SDnodeOpt dndGetOpt();
#ifdef __cplusplus
}
#endif
#endif /*_TD_DND_MAIN_H_*/
...@@ -259,7 +259,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { ...@@ -259,7 +259,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
} }
int32_t dndRun(SDnode *pDnode) { int32_t dndRun(SDnode *pDnode) {
if (tsMultiProcess == 0) { if (!tsMultiProcess) {
if (dndRunInSingleProcess(pDnode) != 0) { if (dndRunInSingleProcess(pDnode) != 0) {
dError("failed to run dnode in single process mode since %s", terrstr()); dError("failed to run dnode in single process mode since %s", terrstr());
return -1; return -1;
......
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "dndInt.h"
#define MAXLEN 1024
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR;
int64_t len = 0;
char content[MAXLEN + 1] = {0};
cJSON *root = NULL;
char file[PATH_MAX];
TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) {
dDebug("file %s not exist", file);
code = 0;
goto _OVER;
}
len = taosReadFile(pFile, content, MAXLEN);
if (len <= 0) {
dError("failed to read %s since content is null", file);
goto _OVER;
}
root = cJSON_Parse(content);
if (root == NULL) {
dError("failed to read %s since invalid json format", file);
goto _OVER;
}
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
if (!deployed || deployed->type != cJSON_Number) {
dError("failed to read %s since deployed not found", file);
goto _OVER;
}
*pDeployed = deployed->valueint != 0;
dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed);
code = 0;
_OVER:
if (root != NULL) cJSON_Delete(root);
if (pFile != NULL) taosCloseFile(&pFile);
terrno = code;
return code;
}
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
int32_t code = -1;
int32_t len = 0;
char content[MAXLEN + 1] = {0};
char file[PATH_MAX] = {0};
char realfile[PATH_MAX] = {0};
TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to write %s since %s", file, terrstr());
goto _OVER;
}
len += snprintf(content + len, MAXLEN - len, "{\n");
len += snprintf(content + len, MAXLEN - len, " \"deployed\": %d\n", deployed);
len += snprintf(content + len, MAXLEN - len, "}\n");
if (taosWriteFile(pFile, content, len) != len) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to write file:%s since %s", file, terrstr());
goto _OVER;
}
if (taosFsyncFile(pFile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to fsync file:%s since %s", file, terrstr());
goto _OVER;
}
taosCloseFile(&pFile);
if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s since %s", file, terrstr());
return -1;
}
dInfo("successed to write %s, deployed:%d", realfile, deployed);
code = 0;
_OVER:
if (pFile != NULL) {
taosCloseFile(&pFile);
}
return code;
}
int32_t dndOpenRuntimeFile(SDnode *pDnode) {
int32_t code = -1;
char itemName[24] = {0};
char content[MAXLEN + 1] = {0};
char file[PATH_MAX] = {0};
cJSON *root = NULL;
TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s.running", pDnode->dataDir, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to open file:%s since %s", file, terrstr());
goto _OVER;
}
if (taosLockFile(pFile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to lock file:%s since %s", file, terrstr());
goto _OVER;
}
if (taosReadFile(pFile, content, MAXLEN) > 0) {
root = cJSON_Parse(content);
if (root == NULL) {
terrno = TSDB_CODE_NODE_PARSE_FILE_ERROR;
dError("failed to read %s since invalid json format", file);
goto _OVER;
}
for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype));
cJSON *shmid = cJSON_GetObjectItem(root, itemName);
if (shmid && shmid->type == cJSON_Number) {
pDnode->wrappers[ntype].shm.id = shmid->valueint;
}
snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype));
cJSON *shmsize = cJSON_GetObjectItem(root, itemName);
if (shmsize && shmsize->type == cJSON_Number) {
pDnode->wrappers[ntype].shm.size = shmsize->valueint;
}
}
}
if (tsMultiProcess || pDnode->ntype == DNODE) {
for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
if (pWrapper->shm.id > 0) {
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
taosDropShm(&pWrapper->shm);
}
}
} else {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
if (taosAttachShm(&pWrapper->shm) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("shmid:%d, failed to attach since %s", pWrapper->shm.id, terrstr());
goto _OVER;
}
dDebug("shmid:%d, is attached, size:%d", pWrapper->shm.id, pWrapper->shm.size);
}
dDebug("successed to open %s", file);
code = 0;
_OVER:
if (root != NULL) cJSON_Delete(root);
if (code != 0) {
if (pFile != NULL) taosCloseFile(&pFile);
} else {
pDnode->runtimeFile = pFile;
}
return code;
}
int32_t dndWriteRuntimeFile(SDnode *pDnode) {
int32_t code = -1;
int32_t len = 0;
char content[MAXLEN + 1] = {0};
char file[PATH_MAX] = {0};
char realfile[PATH_MAX] = {0};
TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s.running.bak", pDnode->dataDir, TD_DIRSEP);
snprintf(realfile, sizeof(realfile), "%s%s.running", pDnode->dataDir, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to open file:%s since %s", file, terrstr());
goto _OVER;
}
len += snprintf(content + len, MAXLEN - len, "{\n");
for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\": %d,\n", dndNodeProcStr(ntype), pWrapper->shm.id);
if (ntype == NODE_MAX - 1) {
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\": %d\n", dndNodeProcStr(ntype), pWrapper->shm.size);
} else {
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\": %d,\n", dndNodeProcStr(ntype), pWrapper->shm.size);
}
}
len += snprintf(content + len, MAXLEN - len, "}\n");
if (taosWriteFile(pFile, content, len) != len) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to write file:%s since %s", file, terrstr());
goto _OVER;
}
if (taosFsyncFile(pFile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to fsync file:%s since %s", file, terrstr());
goto _OVER;
}
taosCloseFile(&pFile);
if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s to %s since %s", file, realfile, terrstr());
return -1;
}
dDebug("successed to write %s", realfile);
code = 0;
_OVER:
if (pFile != NULL) {
taosCloseFile(&pFile);
}
return code;
}
void dndCloseRuntimeFile(SDnode *pDnode) {
if (pDnode->runtimeFile) {
taosUnLockFile(pDnode->runtimeFile);
taosCloseFile(&pDnode->runtimeFile);
pDnode->runtimeFile = NULL;
}
}
\ No newline at end of file
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
static int8_t once = DND_ENV_INIT; static int8_t once = DND_ENV_INIT;
int32_t dndInit() { int32_t dndInit() {
dInfo("start to init dnode env"); dDebug("start to init dnode env");
if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) { if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
terrno = TSDB_CODE_REPEAT_INIT; terrno = TSDB_CODE_REPEAT_INIT;
dError("failed to init dnode env since %s", terrstr()); dError("failed to init dnode env since %s", terrstr());
...@@ -31,12 +31,6 @@ int32_t dndInit() { ...@@ -31,12 +31,6 @@ int32_t dndInit() {
taosBlockSIGPIPE(); taosBlockSIGPIPE();
taosResolveCRC(); taosResolveCRC();
if (rpcInit() != 0) {
dError("failed to init rpc since %s", terrstr());
dndCleanup();
return -1;
}
SMonCfg monCfg = {0}; SMonCfg monCfg = {0};
monCfg.maxLogs = tsMonitorMaxLogs; monCfg.maxLogs = tsMonitorMaxLogs;
monCfg.port = tsMonitorPort; monCfg.port = tsMonitorPort;
...@@ -44,29 +38,27 @@ int32_t dndInit() { ...@@ -44,29 +38,27 @@ int32_t dndInit() {
monCfg.comp = tsMonitorComp; monCfg.comp = tsMonitorComp;
if (monInit(&monCfg) != 0) { if (monInit(&monCfg) != 0) {
dError("failed to init monitor since %s", terrstr()); dError("failed to init monitor since %s", terrstr());
dndCleanup();
return -1; return -1;
} }
dInfo("dnode env is initialized"); dDebug("dnode env is initialized");
return 0; return 0;
} }
void dndCleanup() { void dndCleanup() {
dInfo("start to cleanup dnode env"); dDebug("start to cleanup dnode env");
if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) { if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
dError("dnode env is already cleaned up"); dError("dnode env is already cleaned up");
return; return;
} }
monCleanup(); monCleanup();
rpcCleanup();
walCleanUp(); walCleanUp();
taosStopCacheRefreshWorker(); taosStopCacheRefreshWorker();
dInfo("dnode env is cleaned up"); dDebug("dnode env is cleaned up");
} }
void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId) { void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
} }
...@@ -80,19 +72,6 @@ void dndSetStatus(SDnode *pDnode, EDndStatus status) { ...@@ -80,19 +72,6 @@ void dndSetStatus(SDnode *pDnode, EDndStatus status) {
} }
} }
const char *dndStatStr(EDndStatus status) {
switch (status) {
case DND_STAT_INIT:
return "init";
case DND_STAT_RUNNING:
return "running";
case DND_STAT_STOPPED:
return "stopped";
default:
return "unknown";
}
}
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
SStartupReq *pStartup = &pDnode->startup; SStartupReq *pStartup = &pDnode->startup;
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
...@@ -105,29 +84,6 @@ void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { ...@@ -105,29 +84,6 @@ void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
} }
TdFilePtr dndCheckRunning(const char *dataDir) {
char filepath[PATH_MAX] = {0};
snprintf(filepath, sizeof(filepath), "%s/.running", dataDir);
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to lock file:%s since %s", filepath, terrstr());
return NULL;
}
int32_t ret = taosLockFile(pFile);
if (ret != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to lock file:%s since %s", filepath, terrstr());
taosCloseFile(&pFile);
return NULL;
}
dDebug("file:%s is locked", filepath);
return pFile;
}
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
dDebug("startup req is received"); dDebug("startup req is received");
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #include "dndInt.h"
static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes;
pDnode->serverPort = pOption->serverPort; pDnode->serverPort = pOption->serverPort;
pDnode->dataDir = strdup(pOption->dataDir); pDnode->dataDir = strdup(pOption->dataDir);
...@@ -24,8 +24,9 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { ...@@ -24,8 +24,9 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
pDnode->localFqdn = strdup(pOption->localFqdn); pDnode->localFqdn = strdup(pOption->localFqdn);
pDnode->firstEp = strdup(pOption->firstEp); pDnode->firstEp = strdup(pOption->firstEp);
pDnode->secondEp = strdup(pOption->secondEp); pDnode->secondEp = strdup(pOption->secondEp);
pDnode->pDisks = pOption->pDisks; pDnode->disks = pOption->disks;
pDnode->numOfDisks = pOption->numOfDisks; pDnode->numOfDisks = pOption->numOfDisks;
pDnode->ntype = pOption->ntype;
pDnode->rebootTime = taosGetTimestampMs(); pDnode->rebootTime = taosGetTimestampMs();
if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL || if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||
...@@ -36,16 +37,12 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { ...@@ -36,16 +37,12 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
return 0; return 0;
} }
static void dndClearMemory(SDnode *pDnode) { static void dndClearVars(SDnode *pDnode) {
for (ENodeType n = 0; n < NODE_MAX; ++n) { for (ENodeType n = 0; n < NODE_MAX; ++n) {
SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
taosMemoryFreeClear(pMgmt->path); taosMemoryFreeClear(pMgmt->path);
} }
if (pDnode->pLockFile != NULL) { dndCloseRuntimeFile(pDnode);
taosUnLockFile(pDnode->pLockFile);
taosCloseFile(&pDnode->pLockFile);
pDnode->pLockFile = NULL;
}
taosMemoryFreeClear(pDnode->localEp); taosMemoryFreeClear(pDnode->localEp);
taosMemoryFreeClear(pDnode->localFqdn); taosMemoryFreeClear(pDnode->localFqdn);
taosMemoryFreeClear(pDnode->firstEp); taosMemoryFreeClear(pDnode->firstEp);
...@@ -67,13 +64,21 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { ...@@ -67,13 +64,21 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
goto _OVER; goto _OVER;
} }
if (dndInitMemory(pDnode, pOption) != 0) { if (dndInitVars(pDnode, pOption) != 0) {
dError("failed to init variables since %s", terrstr());
goto _OVER; goto _OVER;
} }
dndSetStatus(pDnode, DND_STAT_INIT); dndSetStatus(pDnode, DND_STAT_INIT);
pDnode->pLockFile = dndCheckRunning(pDnode->dataDir); dmGetMgmtFp(&pDnode->wrappers[DNODE]);
if (pDnode->pLockFile == NULL) { mmGetMgmtFp(&pDnode->wrappers[MNODE]);
vmGetMgmtFp(&pDnode->wrappers[VNODES]);
qmGetMgmtFp(&pDnode->wrappers[QNODE]);
smGetMgmtFp(&pDnode->wrappers[SNODE]);
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
if (dndOpenRuntimeFile(pDnode) != 0) {
dError("failed to open runtime file since %s", terrstr());
goto _OVER; goto _OVER;
} }
...@@ -87,13 +92,6 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { ...@@ -87,13 +92,6 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
goto _OVER; goto _OVER;
} }
dmGetMgmtFp(&pDnode->wrappers[DNODE]);
mmGetMgmtFp(&pDnode->wrappers[MNODE]);
vmGetMgmtFp(&pDnode->wrappers[VNODES]);
qmGetMgmtFp(&pDnode->wrappers[QNODE]);
smGetMgmtFp(&pDnode->wrappers[SNODE]);
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
if (dndInitMsgHandle(pDnode) != 0) { if (dndInitMsgHandle(pDnode) != 0) {
goto _OVER; goto _OVER;
} }
...@@ -116,7 +114,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { ...@@ -116,7 +114,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
_OVER: _OVER:
if (code != 0 && pDnode) { if (code != 0 && pDnode) {
dndClearMemory(pDnode); dndClearVars(pDnode);
pDnode = NULL; pDnode = NULL;
dError("failed to create dnode object since %s", terrstr()); dError("failed to create dnode object since %s", terrstr());
} else { } else {
...@@ -145,7 +143,7 @@ void dndClose(SDnode *pDnode) { ...@@ -145,7 +143,7 @@ void dndClose(SDnode *pDnode) {
dndCloseNode(pWrapper); dndCloseNode(pWrapper);
} }
dndClearMemory(pDnode); dndClearVars(pDnode);
dInfo("dnode object is closed, data:%p", pDnode); dInfo("dnode object is closed, data:%p", pDnode);
} }
......
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "dndInt.h"
const char *dndStatStr(EDndStatus status) {
switch (status) {
case DND_STAT_INIT:
return "init";
case DND_STAT_RUNNING:
return "running";
case DND_STAT_STOPPED:
return "stopped";
default:
return "unknown";
}
}
const char *dndNodeLogStr(ENodeType ntype) {
switch (ntype) {
case VNODES:
return "vnode";
case QNODE:
return "qnode";
case SNODE:
return "snode";
case MNODE:
return "mnode";
case BNODE:
return "bnode";
default:
return "taosd";
}
}
const char *dndNodeProcStr(ENodeType ntype) {
switch (ntype) {
case VNODES:
return "taosv";
case QNODE:
return "taosq";
case SNODE:
return "taoss";
case MNODE:
return "taosm";
case BNODE:
return "taosb";
default:
return "taosd";
}
}
...@@ -285,7 +285,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { ...@@ -285,7 +285,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN); tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN);
dCfg.level = 0; dCfg.level = 0;
dCfg.primary = 1; dCfg.primary = 1;
SDiskCfg *pDisks = pDnode->pDisks; SDiskCfg *pDisks = pDnode->disks;
int32_t numOfDisks = pDnode->numOfDisks; int32_t numOfDisks = pDnode->numOfDisks;
if (numOfDisks <= 0 || pDisks == NULL) { if (numOfDisks <= 0 || pDisks == NULL) {
pDisks = &dCfg; pDisks = &dCfg;
......
...@@ -76,7 +76,7 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { ...@@ -76,7 +76,7 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
SVnodeObj *pVnode = pInfo->ahandle; SVnodeObj *pVnode = pInfo->ahandle;
dTrace("msg:%p, will be processed in vnode-fetch queue", pMsg); dTrace("msg:%p, will be processed in vnode-fetch queue", pMsg);
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg); int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg, pInfo);
if (code != 0) { if (code != 0) {
vmSendRsp(pVnode->pWrapper, pMsg, code); vmSendRsp(pVnode->pWrapper, pMsg, code);
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
...@@ -168,7 +168,7 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO ...@@ -168,7 +168,7 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
taosGetQitem(qall, (void **)&pMsg); taosGetQitem(qall, (void **)&pMsg);
dTrace("msg:%p, will be processed in vnode-merge queue", pMsg); dTrace("msg:%p, will be processed in vnode-merge queue", pMsg);
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg); int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg, pInfo);
if (code != 0) { if (code != 0) {
vmSendRsp(pVnode->pWrapper, pMsg, code); vmSendRsp(pVnode->pWrapper, pMsg, code);
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
...@@ -414,8 +414,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) { ...@@ -414,8 +414,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) {
pWPool->max = maxMergeThreads; pWPool->max = maxMergeThreads;
if (tWWorkerInit(pWPool) != 0) return -1; if (tWWorkerInit(pWPool) != 0) return -1;
SSingleWorkerCfg cfg = { SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) { if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) {
dError("failed to start vnode-mgmt worker since %s", terrstr()); dError("failed to start vnode-mgmt worker since %s", terrstr());
return -1; return -1;
......
...@@ -46,14 +46,11 @@ target_link_libraries( ...@@ -46,14 +46,11 @@ target_link_libraries(
PUBLIC stream PUBLIC stream
PUBLIC qworker PUBLIC qworker
PUBLIC sync PUBLIC sync
# TODO: get rid of BDB
PUBLIC bdb
PUBLIC tdb
) )
if(${META_DB_IMPL} STREQUAL "BDB")
target_link_libraries(vnode PUBLIC bdb)
elseif(${META_DB_IMPL} STREQUAL "TDB")
target_link_libraries(vnode PUBLIC tdb)
endif()
if(${BUILD_TEST}) if(${BUILD_TEST})
add_subdirectory(test) add_subdirectory(test)
endif(${BUILD_TEST}) endif(${BUILD_TEST})
...@@ -100,10 +100,11 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, const char *msg); ...@@ -100,10 +100,11 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, const char *msg);
* @brief Insert tSma(Time-range-wise SMA) data from stream computing engine * @brief Insert tSma(Time-range-wise SMA) data from stream computing engine
* *
* @param pTsdb * @param pTsdb
* @param indexUid
* @param msg * @param msg
* @return int32_t * @return int32_t
*/ */
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg); int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg);
/** /**
* @brief Drop tSma data and local cache. * @brief Drop tSma data and local cache.
...@@ -130,16 +131,11 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); ...@@ -130,16 +131,11 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
* @param pTsdb * @param pTsdb
* @param pData * @param pData
* @param indexUid * @param indexUid
* @param interval
* @param intervalUnit
* @param tableUid
* @param colId
* @param querySKey * @param querySKey
* @param nMaxResult * @param nMaxResult
* @return int32_t * @return int32_t
*/ */
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit, int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult);
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult);
// STsdbCfg // STsdbCfg
int tsdbOptionsInit(STsdbCfg *); int tsdbOptionsInit(STsdbCfg *);
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
#define _TD_VNODE_H_ #define _TD_VNODE_H_
#include "os.h" #include "os.h"
#include "trpc.h"
#include "tmsgcb.h" #include "tmsgcb.h"
#include "tqueue.h"
#include "trpc.h"
#include "meta.h" #include "meta.h"
#include "tarray.h" #include "tarray.h"
...@@ -166,7 +167,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); ...@@ -166,7 +167,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
* @param pMsg The request message * @param pMsg The request message
* @return int 0 for success, -1 for failure * @return int 0 for success, -1 for failure
*/ */
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg); int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
/* ------------------------ SVnodeCfg ------------------------ */ /* ------------------------ SVnodeCfg ------------------------ */
/** /**
...@@ -185,7 +186,6 @@ void vnodeOptionsClear(SVnodeCfg *pOptions); ...@@ -185,7 +186,6 @@ void vnodeOptionsClear(SVnodeCfg *pOptions);
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName); int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
/* ------------------------ FOR COMPILE ------------------------ */ /* ------------------------ FOR COMPILE ------------------------ */
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
......
...@@ -44,11 +44,10 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); ...@@ -44,11 +44,10 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
#endif #endif
// internal func // internal func
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) { static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
int32_t len = 0; int32_t len = 0;
len += taosEncodeFixedI64(pData, tableUid);
len += taosEncodeFixedU16(pData, colId);
len += taosEncodeFixedI64(pData, tsKey); len += taosEncodeFixedI64(pData, tsKey);
len += taosEncodeFixedI64(pData, groupId);
return len; return len;
} }
......
...@@ -197,9 +197,9 @@ int tqCommit(STQ*); ...@@ -197,9 +197,9 @@ int tqCommit(STQ*);
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
int32_t tqProcessRebReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg);
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
// sma // sma
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
......
...@@ -15,131 +15,637 @@ ...@@ -15,131 +15,637 @@
#include "metaDef.h" #include "metaDef.h"
#include "tdb.h" #include "tdbInt.h"
struct SMetaDB { struct SMetaDB {
TENV *pEnv; TENV *pEnv;
TDB * pTbDB; TDB *pTbDB;
TDB * pSchemaDB; TDB *pSchemaDB;
TDB * pNameIdx; TDB *pNameIdx;
TDB * pStbIdx; TDB *pStbIdx;
TDB * pNtbIdx; TDB *pNtbIdx;
TDB * pCtbIdx; TDB *pCtbIdx;
// tag index hash table
// suid+colid --> TDB *
struct {
} tagIdxHt;
}; };
#define A(op, flag) \ typedef struct __attribute__((__packed__)) {
do { \ tb_uid_t uid;
if ((ret = op) != 0) goto flag; \ int32_t sver;
} while (0) } SSchemaDbKey;
typedef struct {
char *name;
tb_uid_t uid;
} SNameIdxKey;
typedef struct {
tb_uid_t suid;
tb_uid_t uid;
} SCtbIdxKey;
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW);
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW);
static inline int metaUidCmpr(const void *arg1, int len1, const void *arg2, int len2) {
tb_uid_t uid1, uid2;
ASSERT(len1 == sizeof(tb_uid_t));
ASSERT(len2 == sizeof(tb_uid_t));
uid1 = ((tb_uid_t *)arg1)[0];
uid2 = ((tb_uid_t *)arg2)[0];
if (uid1 < uid2) {
return -1;
}
if (uid1 == uid2) {
return 0;
} else {
return 1;
}
}
static inline int metaSchemaKeyCmpr(const void *arg1, int len1, const void *arg2, int len2) {
int c;
SSchemaDbKey *pKey1 = (SSchemaDbKey *)arg1;
SSchemaDbKey *pKey2 = (SSchemaDbKey *)arg2;
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
if (c) return c;
if (pKey1->sver > pKey2->sver) {
return 1;
} else if (pKey1->sver == pKey2->sver) {
return 0;
} else {
return -1;
}
}
static inline int metaNameIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
return strcmp((char *)arg1, (char *)arg2);
}
static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
int c;
SCtbIdxKey *pKey1 = (SCtbIdxKey *)arg1;
SCtbIdxKey *pKey2 = (SCtbIdxKey *)arg2;
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
if (c) return c;
return metaUidCmpr(&pKey1->uid, sizeof(tb_uid_t), &pKey2->uid, sizeof(tb_uid_t));
}
int metaOpenDB(SMeta *pMeta) { int metaOpenDB(SMeta *pMeta) {
SMetaDB *pDb; SMetaDB *pMetaDb;
TENV * pEnv;
TDB * pTbDB;
TDB * pSchemaDB;
TDB * pNameIdx;
TDB * pStbIdx;
TDB * pNtbIdx;
TDB * pCtbIdx;
int ret; int ret;
pDb = (SMetaDB *)taosMemoryCalloc(1, sizeof(*pDb)); // allocate DB handle
if (pDb == NULL) { pMetaDb = taosMemoryCalloc(1, sizeof(*pMetaDb));
if (pMetaDb == NULL) {
// TODO
ASSERT(0);
return -1; return -1;
} }
// Create and open the ENV // open the ENV
A((tdbEnvCreate(&pEnv)), _err); ret = tdbEnvOpen(pMeta->path, 4096, 256, &(pMetaDb->pEnv));
#if 0 if (ret < 0) {
// Set options of the environment // TODO
A(tdbEnvSetPageSize(pEnv, 8192), _err); ASSERT(0);
A(tdbEnvSetCacheSize(pEnv, 16 * 1024 * 1024), _err); return -1;
#endif }
A((tdbEnvOpen(&pEnv)), _err);
// Create and open each DB // open table DB
A(tdbCreate(&pTbDB), _err); ret = tdbDbOpen("table.db", sizeof(tb_uid_t), TDB_VARIANT_LEN, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pTbDB));
A(tdbOpen(&pTbDB, "table.db", NULL, pEnv), _err); if (ret < 0) {
// TODO
ASSERT(0);
return -1;
}
A(tdbCreate(&pSchemaDB), _err); // open schema DB
A(tdbOpen(&pSchemaDB, "schema.db", NULL, pEnv), _err); ret = tdbDbOpen("schema.db", sizeof(SSchemaDbKey), TDB_VARIANT_LEN, metaSchemaKeyCmpr, pMetaDb->pEnv,
&(pMetaDb->pSchemaDB));
if (ret < 0) {
// TODO
ASSERT(0);
return -1;
}
A(tdbCreate(&pNameIdx), _err); ret = tdbDbOpen("name.idx", TDB_VARIANT_LEN, 0, metaNameIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pNameIdx));
A(tdbOpen(&pNameIdx, "name.db", NULL, pEnv), _err); if (ret < 0) {
// tdbAssociate(); // TODO
ASSERT(0);
return -1;
}
pDb->pEnv = pEnv; ret = tdbDbOpen("stb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pStbIdx));
pDb->pTbDB = pTbDB; if (ret < 0) {
pDb->pSchemaDB = pSchemaDB; // TODO
pMeta->pDB = pDb; ASSERT(0);
return 0; return -1;
}
ret = tdbDbOpen("ntb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pNtbIdx));
if (ret < 0) {
// TODO
ASSERT(0);
return -1;
}
_err: ret = tdbDbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, metaCtbIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pCtbIdx));
if (ret < 0) {
// TODO
ASSERT(0);
return -1; return -1;
}
pMeta->pDB = pMetaDb;
return 0;
} }
void metaCloseDB(SMeta *pMeta) { void metaCloseDB(SMeta *pMeta) {
// TODO if (pMeta->pDB) {
tdbDbClose(pMeta->pDB->pCtbIdx);
tdbDbClose(pMeta->pDB->pNtbIdx);
tdbDbClose(pMeta->pDB->pStbIdx);
tdbDbClose(pMeta->pDB->pNameIdx);
tdbDbClose(pMeta->pDB->pSchemaDB);
tdbDbClose(pMeta->pDB->pTbDB);
taosMemoryFree(pMeta->pDB);
}
} }
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
// TODO tb_uid_t uid;
SMetaDB *pMetaDb;
void *pKey;
void *pVal;
int kLen;
int vLen;
int ret;
char buf[512];
void *pBuf;
SCtbIdxKey ctbIdxKey;
SSchemaDbKey schemaDbKey;
SSchemaWrapper schemaWrapper;
pMetaDb = pMeta->pDB;
// TODO: make this operation pre-process
if (pTbCfg->type == META_SUPER_TABLE) {
uid = pTbCfg->stbCfg.suid;
} else {
uid = metaGenerateUid(pMeta);
}
// save to table.db
pKey = &uid;
kLen = sizeof(uid);
pVal = pBuf = buf;
metaEncodeTbInfo(&pBuf, pTbCfg);
vLen = POINTER_DISTANCE(pBuf, buf);
ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen);
if (ret < 0) {
return -1;
}
// save to schema.db for META_SUPER_TABLE and META_NORMAL_TABLE
if (pTbCfg->type != META_CHILD_TABLE) {
schemaDbKey.uid = uid;
schemaDbKey.sver = 0; // TODO
pKey = &schemaDbKey;
kLen = sizeof(schemaDbKey);
if (pTbCfg->type == META_SUPER_TABLE) {
schemaWrapper.nCols = pTbCfg->stbCfg.nCols;
schemaWrapper.pSchema = pTbCfg->stbCfg.pSchema;
} else {
schemaWrapper.nCols = pTbCfg->ntbCfg.nCols;
schemaWrapper.pSchema = pTbCfg->ntbCfg.pSchema;
}
pVal = pBuf = buf;
metaEncodeSchema(&pBuf, &schemaWrapper);
vLen = POINTER_DISTANCE(pBuf, buf);
ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen);
if (ret < 0) {
return -1;
}
}
// update name.idx
int nameLen = strlen(pTbCfg->name);
memcpy(buf, pTbCfg->name, nameLen + 1);
((tb_uid_t *)(buf + nameLen + 1))[0] = uid;
pKey = buf;
kLen = nameLen + 1 + sizeof(uid);
pVal = NULL;
vLen = 0;
ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen);
if (ret < 0) {
return -1;
}
// update other index
if (pTbCfg->type == META_SUPER_TABLE) {
pKey = &uid;
kLen = sizeof(uid);
pVal = NULL;
vLen = 0;
ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen);
if (ret < 0) {
return -1;
}
} else if (pTbCfg->type == META_CHILD_TABLE) {
ctbIdxKey.suid = pTbCfg->ctbCfg.suid;
ctbIdxKey.uid = uid;
pKey = &ctbIdxKey;
kLen = sizeof(ctbIdxKey);
pVal = NULL;
vLen = 0;
ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen);
if (ret < 0) {
return -1;
}
} else if (pTbCfg->type == META_NORMAL_TABLE) {
pKey = &uid;
kLen = sizeof(uid);
pVal = NULL;
vLen = 0;
ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen);
if (ret < 0) {
return -1;
}
}
return 0; return 0;
} }
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) { int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
// TODO // TODO
ASSERT(0);
return 0; return 0;
} }
STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
// TODO int ret;
SMetaDB *pMetaDb = pMeta->pDB;
void *pKey;
void *pVal;
int kLen;
int vLen;
STbCfg *pTbCfg;
// Fetch
pKey = &uid;
kLen = sizeof(uid);
pVal = NULL;
ret = tdbDbGet(pMetaDb->pTbDB, pKey, kLen, &pVal, &vLen);
if (ret < 0) {
return NULL; return NULL;
}
// Decode
pTbCfg = taosMemoryMalloc(sizeof(*pTbCfg));
metaDecodeTbInfo(pVal, pTbCfg);
TDB_FREE(pVal);
return pTbCfg;
} }
STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
// TODO void *pKey;
void *pVal;
void *ppKey;
int pkLen;
int kLen;
int vLen;
int ret;
pKey = tbname;
kLen = strlen(tbname) + 1;
pVal = NULL;
ppKey = NULL;
ret = tdbDbPGet(pMeta->pDB->pNameIdx, pKey, kLen, &ppKey, &pkLen, &pVal, &vLen);
if (ret < 0) {
return NULL; return NULL;
}
ASSERT(pkLen == kLen + sizeof(uid));
*uid = *(tb_uid_t *)POINTER_SHIFT(ppKey, kLen);
TDB_FREE(ppKey);
TDB_FREE(pVal);
return metaGetTbInfoByUid(pMeta, *uid);
} }
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
// TODO void *pKey;
void *pVal;
int kLen;
int vLen;
int ret;
SSchemaDbKey schemaDbKey;
SSchemaWrapper *pSchemaWrapper;
void *pBuf;
// fetch
schemaDbKey.uid = uid;
schemaDbKey.sver = sver;
pKey = &schemaDbKey;
kLen = sizeof(schemaDbKey);
pVal = NULL;
ret = tdbDbGet(pMeta->pDB->pSchemaDB, pKey, kLen, &pVal, &vLen);
if (ret < 0) {
return NULL; return NULL;
}
// decode
pBuf = pVal;
pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper));
metaDecodeSchema(pBuf, pSchemaWrapper);
TDB_FREE(pVal);
return pSchemaWrapper;
} }
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
// TODO tb_uid_t quid;
SSchemaWrapper *pSW;
STSchemaBuilder sb;
SSchema *pSchema;
STSchema *pTSchema;
STbCfg *pTbCfg;
pTbCfg = metaGetTbInfoByUid(pMeta, uid);
if (pTbCfg->type == META_CHILD_TABLE) {
quid = pTbCfg->ctbCfg.suid;
} else {
quid = uid;
}
pSW = metaGetTableSchema(pMeta, quid, sver, true);
if (pSW == NULL) {
return NULL; return NULL;
}
tdInitTSchemaBuilder(&sb, 0);
for (int i = 0; i < pSW->nCols; i++) {
pSchema = pSW->pSchema + i;
tdAddColToSchema(&sb, pSchema->type, pSchema->colId, pSchema->bytes);
}
pTSchema = tdGetSchemaFromBuilder(&sb);
tdDestroyTSchemaBuilder(&sb);
return pTSchema;
} }
struct SMTbCursor {
TDBC *pDbc;
};
SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
// TODO SMTbCursor *pTbCur = NULL;
SMetaDB *pDB = pMeta->pDB;
pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur));
if (pTbCur == NULL) {
return NULL; return NULL;
}
tdbDbcOpen(pDB->pTbDB, &pTbCur->pDbc);
return pTbCur;
} }
void metaCloseTbCursor(SMTbCursor *pTbCur) { void metaCloseTbCursor(SMTbCursor *pTbCur) {
// TODO if (pTbCur) {
if (pTbCur->pDbc) {
tdbDbcClose(pTbCur->pDbc);
}
taosMemoryFree(pTbCur);
}
} }
char *metaTbCursorNext(SMTbCursor *pTbCur) { char *metaTbCursorNext(SMTbCursor *pTbCur) {
// TODO void *pKey = NULL;
void *pVal = NULL;
int kLen;
int vLen;
int ret;
void *pBuf;
STbCfg tbCfg;
for (;;) {
ret = tdbDbNext(pTbCur->pDbc, &pKey, &kLen, &pVal, &vLen);
if (ret < 0) break;
pBuf = pVal;
metaDecodeTbInfo(pBuf, &tbCfg);
if (tbCfg.type == META_SUPER_TABLE) {
taosMemoryFree(tbCfg.name);
taosMemoryFree(tbCfg.stbCfg.pTagSchema);
continue;
;
} else if (tbCfg.type == META_CHILD_TABLE) {
kvRowFree(tbCfg.ctbCfg.pTag);
}
return tbCfg.name;
}
return NULL; return NULL;
} }
struct SMCtbCursor {
TDBC *pCur;
tb_uid_t suid;
void *pKey;
void *pVal;
int kLen;
int vLen;
};
SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
// TODO SMCtbCursor *pCtbCur = NULL;
SMetaDB *pDB = pMeta->pDB;
int ret;
pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur));
if (pCtbCur == NULL) {
return NULL; return NULL;
}
pCtbCur->suid = uid;
ret = tdbDbcOpen(pDB->pCtbIdx, &pCtbCur->pCur);
if (ret < 0) {
taosMemoryFree(pCtbCur);
return NULL;
}
// TODO: move the cursor to the suid there
return pCtbCur;
} }
void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) { void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) {
// TODO if (pCtbCur) {
if (pCtbCur->pCur) {
tdbDbcClose(pCtbCur->pCur);
TDB_FREE(pCtbCur->pKey);
TDB_FREE(pCtbCur->pVal);
}
taosMemoryFree(pCtbCur);
}
} }
tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) { tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
int ret;
SCtbIdxKey *pCtbIdxKey;
ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen);
if (ret < 0) {
return 0;
}
pCtbIdxKey = pCtbCur->pVal;
return pCtbIdxKey->uid;
}
int metaGetTbNum(SMeta *pMeta) {
// TODO
// ASSERT(0);
return 0;
}
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
// TODO // TODO
ASSERT(0);
return NULL;
}
int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) {
// TODO
ASSERT(0);
return 0; return 0;
} }
int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
// TODO
ASSERT(0);
return 0;
}
STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
// TODO
ASSERT(0);
return NULL;
}
const char *metaSmaCursorNext(SMSmaCursor *pCur) {
// TODO
ASSERT(0);
return NULL;
}
void metaCloseSmaCurosr(SMSmaCursor *pCur) {
// TODO
ASSERT(0);
}
SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
// TODO
ASSERT(0);
return NULL;
}
SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) {
// TODO
ASSERT(0);
return NULL;
}
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
int tlen = 0;
SSchema *pSchema;
tlen += taosEncodeFixedU32(buf, pSW->nCols);
for (int i = 0; i < pSW->nCols; i++) {
pSchema = pSW->pSchema + i;
tlen += taosEncodeFixedI8(buf, pSchema->type);
tlen += taosEncodeFixedI16(buf, pSchema->colId);
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
tlen += taosEncodeString(buf, pSchema->name);
}
return tlen;
}
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) {
SSchema *pSchema;
buf = taosDecodeFixedU32(buf, &pSW->nCols);
pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
for (int i = 0; i < pSW->nCols; i++) {
pSchema = pSW->pSchema + i;
buf = taosDecodeFixedI8(buf, &pSchema->type);
buf = taosDecodeFixedI16(buf, &pSchema->colId);
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
buf = taosDecodeStringTo(buf, pSchema->name);
}
return buf;
}
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
int tsize = 0;
tsize += taosEncodeString(buf, pTbCfg->name);
tsize += taosEncodeFixedU32(buf, pTbCfg->ttl);
tsize += taosEncodeFixedU32(buf, pTbCfg->keep);
tsize += taosEncodeFixedU8(buf, pTbCfg->info);
if (pTbCfg->type == META_SUPER_TABLE) {
SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema};
tsize += metaEncodeSchema(buf, &sw);
} else if (pTbCfg->type == META_CHILD_TABLE) {
tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid);
tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag);
} else if (pTbCfg->type == META_NORMAL_TABLE) {
// TODO
} else {
ASSERT(0);
}
return tsize;
}
static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
buf = taosDecodeString(buf, &(pTbCfg->name));
buf = taosDecodeFixedU32(buf, &(pTbCfg->ttl));
buf = taosDecodeFixedU32(buf, &(pTbCfg->keep));
buf = taosDecodeFixedU8(buf, &(pTbCfg->info));
if (pTbCfg->type == META_SUPER_TABLE) {
SSchemaWrapper sw;
buf = metaDecodeSchema(buf, &sw);
pTbCfg->stbCfg.nTagCols = sw.nCols;
pTbCfg->stbCfg.pTagSchema = sw.pSchema;
} else if (pTbCfg->type == META_CHILD_TABLE) {
buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid));
buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag));
} else if (pTbCfg->type == META_NORMAL_TABLE) {
// TODO
} else {
ASSERT(0);
}
return buf;
}
...@@ -356,7 +356,6 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -356,7 +356,6 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
void* buf = rpcMallocCont(tlen); void* buf = rpcMallocCont(tlen);
if (buf == NULL) { if (buf == NULL) {
pMsg->code = -1; pMsg->code = -1;
ASSERT(0);
return -1; return -1;
} }
((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
...@@ -490,7 +489,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { ...@@ -490,7 +489,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
return 0; return 0;
} }
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId) {
void* pIter = NULL; void* pIter = NULL;
while (1) { while (1) {
...@@ -498,14 +497,14 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { ...@@ -498,14 +497,14 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) {
if (pIter == NULL) break; if (pIter == NULL) break;
SStreamTask* pTask = (SStreamTask*)pIter; SStreamTask* pTask = (SStreamTask*)pIter;
if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, 0) < 0) { if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, workerId) < 0) {
// TODO // TODO
} }
} }
return 0; return 0;
} }
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId) {
SStreamTaskExecReq req; SStreamTaskExecReq req;
tDecodeSStreamTaskExecReq(msg, &req); tDecodeSStreamTaskExecReq(msg, &req);
...@@ -515,7 +514,7 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { ...@@ -515,7 +514,7 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) {
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
ASSERT(pTask); ASSERT(pTask);
if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) { if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, workerId) < 0) {
// TODO // TODO
} }
return 0; return 0;
......
...@@ -167,8 +167,10 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { ...@@ -167,8 +167,10 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) {
break; break;
} }
// TODO handle null if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) {
colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL); taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock);
return NULL;
}
} }
curRow++; curRow++;
} }
......
...@@ -24,7 +24,7 @@ static const char *TSDB_SMA_DNAME[] = { ...@@ -24,7 +24,7 @@ static const char *TSDB_SMA_DNAME[] = {
#define SMA_STORAGE_TSDB_DAYS 30 #define SMA_STORAGE_TSDB_DAYS 30
#define SMA_STORAGE_TSDB_TIMES 10 #define SMA_STORAGE_TSDB_TIMES 10
#define SMA_STORAGE_SPLIT_HOURS 24 #define SMA_STORAGE_SPLIT_HOURS 24
#define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8 #define SMA_KEY_LEN 16 // TSKEY+groupId 8+8
#define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds #define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds
#define SMA_STATE_HASH_SLOT 4 #define SMA_STATE_HASH_SLOT 4
...@@ -40,7 +40,7 @@ typedef enum { ...@@ -40,7 +40,7 @@ typedef enum {
typedef struct { typedef struct {
STsdb *pTsdb; STsdb *pTsdb;
SDBFile dFile; SDBFile dFile;
SSDataBlock *pData; // sma data const SArray *pDataBlocks; // sma data
int32_t interval; // interval with the precision of DB int32_t interval; // interval with the precision of DB
} STSmaWriteH; } STSmaWriteH;
...@@ -94,26 +94,24 @@ static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat); ...@@ -94,26 +94,24 @@ static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
// read data // read data
// TODO: This is the basic params, and should wrap the params to a queryHandle. // TODO: This is the basic params, and should wrap the params to a queryHandle.
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult);
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
int32_t nMaxResult);
// insert data // insert data
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, const SArray *pDataBlocks, int64_t interval,
int8_t intervalUnit); int8_t intervalUnit);
static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH); static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit); static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit);
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit); static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit);
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData); static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid);
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen); static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen);
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision); static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted);
static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel); static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel);
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int64_t indexUid, int32_t fid); static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid);
static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey); static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey);
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey); static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey);
static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]); static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]);
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg); static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg); static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
// mgmt interface // mgmt interface
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid); static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
...@@ -387,7 +385,6 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { ...@@ -387,7 +385,6 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
}; };
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey) { static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey) {
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid)); SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
if (pItem == NULL) { if (pItem == NULL) {
...@@ -480,18 +477,15 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) { ...@@ -480,18 +477,15 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) {
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE]; TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
#endif #endif
// Firstly, assume that tSma can only be created on super table/normal table. // Firstly, assume that tSma can only be created on super table/normal table.
// getActiveTimeWindow // getActiveTimeWindow
SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, TSDB_SMA_TYPE_TIME_RANGE); SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, TSDB_SMA_TYPE_TIME_RANGE);
SSmaStat *pStat = SMA_ENV_STAT(pEnv); SSmaStat *pStat = SMA_ENV_STAT(pEnv);
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv); SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL); TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL);
// basic procedure // basic procedure
// TODO: optimization // TODO: optimization
tsdbRefSmaStat(pTsdb, pStat); tsdbRefSmaStat(pTsdb, pStat);
...@@ -523,11 +517,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) { ...@@ -523,11 +517,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) {
tdFreeTSmaWrapper(pSW); tdFreeTSmaWrapper(pSW);
break; break;
} }
if(pSW == NULL) { if (pSW == NULL) {
if((pSW =metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) { if ((pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) {
break; break;
} }
if((pSW->number) <= 0 || (pSW->tSma == NULL)) { if ((pSW->number) <= 0 || (pSW->tSma == NULL)) {
tdFreeTSmaWrapper(pSW); tdFreeTSmaWrapper(pSW);
break; break;
} }
...@@ -683,9 +677,15 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k ...@@ -683,9 +677,15 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k
* @param interval * @param interval
* @param intervalUnit * @param intervalUnit
* @param precision * @param precision
* @param adjusted Interval already adjusted according to DB precision
* @return int64_t * @return int64_t
*/ */
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision) { static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted) {
if (adjusted) {
return interval;
}
switch (intervalUnit) { switch (intervalUnit) {
case TIME_UNIT_YEAR: // approximate value case TIME_UNIT_YEAR: // approximate value
interval *= 365 * 86400 * 1e3; interval *= 365 * 86400 * 1e3;
...@@ -753,59 +753,12 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit ...@@ -753,59 +753,12 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit
return interval; return interval;
} }
/** static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, const SArray *pDataBlocks, int64_t interval,
* @brief Split the TSma data blocks into expected size and insert into B+Tree. int8_t intervalUnit) {
*
* @param pSmaH
* @param pData
* @param nOffset The nOffset of blocks since fid changes.
* @param nBlocks The nBlocks with the same fid since nOffset.
* @return int32_t
*/
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData) {
STsdb *pTsdb = pSmaH->pTsdb;
tsdbDebug("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64, pData->indexUid, pData->skey);
// TODO: check the data integrity
int32_t len = 0;
while (true) {
if (len >= pData->dataLen) {
break;
}
assert(pData->dataLen > 0);
STSmaTbData *pTbData = (STSmaTbData *)POINTER_SHIFT(pData->data, len);
int32_t tbLen = 0;
while (true) {
if (tbLen >= pTbData->dataLen) {
break;
}
assert(pTbData->dataLen > 0);
STSmaColData *pColData = (STSmaColData *)POINTER_SHIFT(pTbData->data, tbLen);
char smaKey[SMA_KEY_LEN] = {0};
void *pSmaKey = &smaKey;
#if 0
printf("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64 " table[%" PRIi64 "]col[%" PRIu16 "]\n",
pData->indexUid, pData->skey, pTbData->tableUid, pColData->colId);
#endif
tsdbEncodeTSmaKey(pTbData->tableUid, pColData->colId, pData->skey, (void **)&pSmaKey);
if (tsdbInsertTSmaBlocks(pSmaH, smaKey, SMA_KEY_LEN, pColData->data, pColData->blockSize) < 0) {
tsdbWarn("vgId:%d insert tSma blocks failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
}
tbLen += (sizeof(STSmaColData) + pColData->blockSize);
}
len += (sizeof(STSmaTbData) + pTbData->dataLen);
}
return TSDB_CODE_SUCCESS;
}
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, int8_t intervalUnit) {
pSmaH->pTsdb = pTsdb; pSmaH->pTsdb = pTsdb;
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision); pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true);
pSmaH->pData = pData; pSmaH->pDataBlocks = pDataBlocks;
pSmaH->dFile.fid = TSDB_IVLD_FID;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -815,7 +768,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) { ...@@ -815,7 +768,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
} }
} }
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int64_t indexUid, int32_t fid) { static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
STsdb *pTsdb = pSmaH->pTsdb; STsdb *pTsdb = pSmaH->pTsdb;
ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL); ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL);
...@@ -859,11 +812,10 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe ...@@ -859,11 +812,10 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
* @param msg * @param msg
* @return int32_t * @return int32_t
*/ */
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg) {
STsdbCfg *pCfg = REPO_CFG(pTsdb); STsdbCfg *pCfg = REPO_CFG(pTsdb);
SSDataBlock *pData = (SSDataBlock *)msg; const SArray *pDataBlocks = (const SArray *)msg;
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
int64_t indexUid = SMA_TEST_INDEX_UID;
if (pEnv == NULL) { if (pEnv == NULL) {
terrno = TSDB_CODE_INVALID_PTR; terrno = TSDB_CODE_INVALID_PTR;
...@@ -871,15 +823,15 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -871,15 +823,15 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
return terrno; return terrno;
} }
if (pData == NULL) { if (pDataBlocks == NULL) {
terrno = TSDB_CODE_INVALID_PTR; terrno = TSDB_CODE_INVALID_PTR;
tsdbWarn("vgId:%d insert tSma data failed since pData is NULL", REPO_ID(pTsdb)); tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
return terrno; return terrno;
} }
if (taosArrayGetSize(pData->pDataBlock) <= 0) { if (taosArrayGetSize(pDataBlocks) <= 0) {
terrno = TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;
tsdbWarn("vgId:%d insert tSma data failed since pDataBlock is empty", REPO_ID(pTsdb)); tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is empty", REPO_ID(pTsdb));
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -899,10 +851,9 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -899,10 +851,9 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
} }
STSma *pSma = pItem->pSma; STSma *pSma = pItem->pSma;
STSmaWriteH tSmaH = {0}; STSmaWriteH tSmaH = {0};
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) { if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pDataBlocks, pSma->interval, pSma->intervalUnit) != 0) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -921,14 +872,101 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -921,14 +872,101 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
// key: skey + groupId
char smaKey[SMA_KEY_LEN] = {0};
void *pSmaKey = &smaKey;
char dataBuf[512] = {0};
void *pDataBuf = &dataBuf;
int32_t sz = taosArrayGetSize(pDataBlocks);
for (int32_t i = 0; i < sz; ++i) {
SSDataBlock *pDataBlock = *(SSDataBlock **)taosArrayGet(pDataBlocks, i);
int32_t colNum = pDataBlock->info.numOfCols;
int32_t rows = pDataBlock->info.rows;
int32_t rowSize = pDataBlock->info.rowSize;
int64_t groupId = pDataBlock->info.groupId;
for (int32_t j = 0; j < rows; ++j) {
printf("|");
TSKEY skey = TSKEY_INITIAL_VAL; // the start key of TS window by interval
int32_t tlen = 0;
for (int32_t k = 0; k < colNum; ++k) {
SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, k);
void *var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
switch (pColInfoData->info.type) {
case TSDB_DATA_TYPE_TIMESTAMP:
skey = *(TSKEY *)var;
printf(" skey = %" PRIi64 " groupId = %" PRId64 "|", skey, groupId);
tsdbEncodeTSmaKey(groupId, skey, &pSmaKey);
break;
case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_UTINYINT:
printf(" %15d |", *(uint8_t *)var);
tlen += taosEncodeFixedU8(&pDataBuf, *(uint8_t *)var);
break;
case TSDB_DATA_TYPE_TINYINT:
printf(" %15d |", *(int8_t *)var);
tlen += taosEncodeFixedI8(&pDataBuf, *(int8_t *)var);
break;
case TSDB_DATA_TYPE_SMALLINT:
printf(" %15d |", *(int16_t *)var);
tlen += taosEncodeFixedI16(&pDataBuf, *(int16_t *)var);
break;
case TSDB_DATA_TYPE_USMALLINT:
printf(" %15d |", *(uint16_t *)var);
tlen += taosEncodeFixedU16(&pDataBuf, *(uint16_t *)var);
break;
case TSDB_DATA_TYPE_INT:
printf(" %15d |", *(int32_t *)var);
tlen += taosEncodeFixedI32(&pDataBuf, *(int32_t *)var);
break;
case TSDB_DATA_TYPE_FLOAT:
case TSDB_DATA_TYPE_UINT:
printf(" %15u |", *(uint32_t *)var);
tlen += taosEncodeFixedU32(&pDataBuf, *(uint32_t *)var);
break;
case TSDB_DATA_TYPE_BIGINT:
printf(" %15ld |", *(int64_t *)var);
tlen += taosEncodeFixedI64(&pDataBuf, *(int64_t *)var);
break;
case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_UBIGINT:
printf(" %15lu |", *(uint64_t *)var);
tlen += taosEncodeFixedU64(&pDataBuf, *(uint64_t *)var);
break;
case TSDB_DATA_TYPE_NCHAR: {
char tmpChar[100] = {0};
strncpy(tmpChar, varDataVal(var), varDataLen(var));
printf(" %s |", tmpChar);
tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var));
break;
}
case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY
char tmpChar[100] = {0};
strncpy(tmpChar, varDataVal(var), varDataLen(var));
printf(" %s |", tmpChar);
tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var));
break;
}
case TSDB_DATA_TYPE_VARBINARY:
// TODO: add binary/varbinary
TASSERT(0);
default:
printf("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
TASSERT(0);
break;
}
}
if ((tlen > 0) && (skey != TSKEY_INITIAL_VAL)) {
int32_t fid = (int32_t)(TSDB_KEY_FID(skey, daysPerFile, pCfg->precision));
#if 0 // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); // file
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
// - Set and open the DFile or the B+Tree file // - Set and open the DFile or the B+Tree file
// TODO: tsdbStartTSmaCommit(); // TODO: tsdbStartTSmaCommit();
tsdbSetTSmaDataFile(&tSmaH, pData, indexUid, fid); if (fid != tSmaH.dFile.fid) {
if (tSmaH.dFile.fid != TSDB_IVLD_FID) {
tsdbCloseDBF(&tSmaH.dFile);
}
tsdbSetTSmaDataFile(&tSmaH, indexUid, fid);
if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) { if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) {
tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb), tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb),
tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno)); tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno));
...@@ -936,18 +974,32 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -936,18 +974,32 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
tsdbUnRefSmaStat(pTsdb, pStat); tsdbUnRefSmaStat(pTsdb, pStat);
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
}
if (tsdbInsertTSmaDataSection(&tSmaH, pData) != 0) { if (tsdbInsertTSmaBlocks(&tSmaH, pSmaKey, SMA_KEY_LEN, pDataBuf, tlen) != 0) {
tsdbWarn("vgId:%d insert tSma data section failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); tsdbWarn("vgId:%d insert tSma data blocks failed for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64
" since %s",
REPO_ID(pTsdb), indexUid, skey, groupId, tstrerror(terrno));
tsdbDestroyTSmaWriteH(&tSmaH); tsdbDestroyTSmaWriteH(&tSmaH);
tsdbUnRefSmaStat(pTsdb, pStat); tsdbUnRefSmaStat(pTsdb, pStat);
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} else {
tsdbWarn("vgId:%d insert tSma data blocks success for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64,
REPO_ID(pTsdb), indexUid, skey, groupId);
} }
// TODO:tsdbEndTSmaCommit(); // TODO:tsdbEndTSmaCommit();
// Step 3: reset the SSmaStat // Step 3: reset the SSmaStat
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey); tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), indexUid, skey);
#endif } else {
tsdbWarn("vgId:%d invalid data skey:%" PRIi64 ", tlen %" PRIi32 " during insert tSma data for %" PRIi64,
REPO_ID(pTsdb), skey, tlen, indexUid);
}
printf("\n");
}
}
tsdbDestroyTSmaWriteH(&tSmaH); tsdbDestroyTSmaWriteH(&tSmaH);
tsdbUnRefSmaStat(pTsdb, pStat); tsdbUnRefSmaStat(pTsdb, pStat);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1002,7 +1054,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) { ...@@ -1002,7 +1054,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) {
// TODO: // TODO:
} }
static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t fid) { static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid) {
STsdb *pTsdb = pSmaH->pTsdb; STsdb *pTsdb = pSmaH->pTsdb;
char tSmaFile[TSDB_FILENAME_LEN] = {0}; char tSmaFile[TSDB_FILENAME_LEN] = {0};
...@@ -1012,9 +1064,9 @@ static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, ...@@ -1012,9 +1064,9 @@ static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData,
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
STsdbCfg *pCfg = REPO_CFG(pTsdb); STsdbCfg *pCfg = REPO_CFG(pTsdb);
SSDataBlock *pData = (SSDataBlock *)msg; const SArray *pDataBlocks = (const SArray *)msg;
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv); SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv);
int64_t indexUid = SMA_TEST_INDEX_UID; int64_t indexUid = SMA_TEST_INDEX_UID;
...@@ -1030,15 +1082,15 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -1030,15 +1082,15 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
return terrno; return terrno;
} }
if (pData == NULL) { if (pDataBlocks == NULL) {
terrno = TSDB_CODE_INVALID_PTR; terrno = TSDB_CODE_INVALID_PTR;
tsdbWarn("vgId:%d insert rSma data failed since pData is NULL", REPO_ID(pTsdb)); tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
return terrno; return terrno;
} }
if (taosArrayGetSize(pData->pDataBlock) <= 0) { if (taosArrayGetSize(pDataBlocks) <= 0) {
terrno = TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;
tsdbWarn("vgId:%d insert rSma data failed since pDataBlock is empty", REPO_ID(pTsdb)); tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is empty", REPO_ID(pTsdb));
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -1061,7 +1113,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -1061,7 +1113,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
STSmaWriteH tSmaH = {0}; STSmaWriteH tSmaH = {0};
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) { if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pDataBlocks, pSma->interval, pSma->intervalUnit) != 0) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -1078,7 +1130,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -1078,7 +1130,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
// Step 1: Judge the storage level and days // Step 1: Judge the storage level and days
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
#if 0 #if 0
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision));
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
...@@ -1119,7 +1171,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { ...@@ -1119,7 +1171,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
*/ */
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit) { static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit) {
pSmaH->pTsdb = pTsdb; pSmaH->pTsdb = pTsdb;
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision); pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true);
pSmaH->storageLevel = tsdbGetSmaStorageLevel(interval, intervalUnit); pSmaH->storageLevel = tsdbGetSmaStorageLevel(interval, intervalUnit);
pSmaH->days = tsdbGetTSmaDays(pTsdb, pSmaH->interval, pSmaH->storageLevel); pSmaH->days = tsdbGetTSmaDays(pTsdb, pSmaH->interval, pSmaH->storageLevel);
} }
...@@ -1185,17 +1237,11 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) { ...@@ -1185,17 +1237,11 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
* @param pTsdb Return the data between queryWin and fill the pData. * @param pTsdb Return the data between queryWin and fill the pData.
* @param pData * @param pData
* @param indexUid * @param indexUid
* @param interval
* @param intervalUnit
* @param tableUid
* @param colId
* @param pQuerySKey * @param pQuerySKey
* @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM. * @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM.
* @return int32_t * @return int32_t
*/ */
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) {
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
int32_t nMaxResult) {
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
if (!pEnv) { if (!pEnv) {
...@@ -1243,14 +1289,19 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ ...@@ -1243,14 +1289,19 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
tsdbDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey, tsdbDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey,
indexUid); indexUid);
} }
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
STSma *pTSma = pItem->pSma;
#endif #endif
STSmaReadH tReadH = {0}; STSmaReadH tReadH = {0};
tsdbInitTSmaReadH(&tReadH, pTsdb, interval, intervalUnit); tsdbInitTSmaReadH(&tReadH, pTsdb, pTSma->interval, pTSma->intervalUnit);
tsdbCloseDBF(&tReadH.dFile); tsdbCloseDBF(&tReadH.dFile);
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
tsdbInitTSmaFile(&tReadH, indexUid, querySKey); tsdbInitTSmaFile(&tReadH, indexUid, querySKey);
if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) { if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) {
tsdbWarn("vgId:%d open DBF %s failed since %s", REPO_ID(pTsdb), tReadH.dFile.path, tstrerror(terrno)); tsdbWarn("vgId:%d open DBF %s failed since %s", REPO_ID(pTsdb), tReadH.dFile.path, tstrerror(terrno));
...@@ -1259,7 +1310,8 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ ...@@ -1259,7 +1310,8 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
char smaKey[SMA_KEY_LEN] = {0}; char smaKey[SMA_KEY_LEN] = {0};
void *pSmaKey = &smaKey; void *pSmaKey = &smaKey;
tsdbEncodeTSmaKey(tableUid, colId, querySKey, (void **)&pSmaKey); int64_t queryGroupId = 1;
tsdbEncodeTSmaKey(queryGroupId, querySKey, (void **)&pSmaKey);
tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb), tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb),
tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
...@@ -1347,11 +1399,10 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, void *smaIndex, STimeWindow *pWin) { ...@@ -1347,11 +1399,10 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, void *smaIndex, STimeWindow *pWin) {
} }
#endif #endif
// TODO: Who is responsible for resource allocate and release? // TODO: Who is responsible for resource allocate and release?
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg) { int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if ((code = tsdbInsertTSmaDataImpl(pTsdb, msg)) < 0) { if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) {
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
} }
return code; return code;
...@@ -1373,18 +1424,14 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) { ...@@ -1373,18 +1424,14 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) {
return code; return code;
} }
int32_t tsdbGetTSmaData(STsdb *pTsdb, char*pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) {
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit,
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, interval, intervalUnit, tableUid, colId, querySKey, if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, querySKey, nMaxResult)) < 0) {
nMaxResult)) < 0) {
tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
} }
return code; return code;
} }
int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid) { int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if ((code = tsdbDropTSmaDataImpl(pTsdb, indexUid)) < 0) { if ((code = tsdbDropTSmaDataImpl(pTsdb, indexUid)) < 0) {
......
...@@ -41,7 +41,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -41,7 +41,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
} }
} }
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
vTrace("message in fetch queue is processing"); vTrace("message in fetch queue is processing");
char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
...@@ -69,9 +69,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -69,9 +69,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
return tqProcessPollReq(pVnode->pTq, pMsg); return tqProcessPollReq(pVnode->pTq, pMsg);
case TDMT_VND_TASK_PIPE_EXEC: case TDMT_VND_TASK_PIPE_EXEC:
case TDMT_VND_TASK_MERGE_EXEC: case TDMT_VND_TASK_MERGE_EXEC:
return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen); return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, pInfo->workerId);
case TDMT_VND_STREAM_TRIGGER: case TDMT_VND_STREAM_TRIGGER:
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, pInfo->workerId);
case TDMT_VND_QUERY_HEARTBEAT: case TDMT_VND_QUERY_HEARTBEAT:
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
default: default:
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
// TODO // TODO
blockDebugShowData(data); blockDebugShowData(data);
tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data);
} }
void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
...@@ -184,8 +186,8 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { ...@@ -184,8 +186,8 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
} }
} break; } break;
case TDMT_VND_TASK_WRITE_EXEC: { case TDMT_VND_TASK_WRITE_EXEC: {
if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead),
pMsg->contLen - sizeof(SMsgHead)) < 0) { 0) < 0) {
} }
} break; } break;
case TDMT_VND_CREATE_SMA: { // timeRangeSMA case TDMT_VND_CREATE_SMA: { // timeRangeSMA
...@@ -194,14 +196,15 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { ...@@ -194,14 +196,15 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
SSmaCfg vCreateSmaReq = {0}; SSmaCfg vCreateSmaReq = {0};
if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) { if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, terrstr(terrno)); vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId,
terrstr(terrno));
return -1; return -1;
} }
vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName, vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName,
vCreateSmaReq.tSma.indexUid); vCreateSmaReq.tSma.indexUid);
// record current timezone of server side // record current timezone of server side
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); vCreateSmaReq.tSma.timezoneInt = tsTimezone;
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) { if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
// TODO: handle error // TODO: handle error
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tsdbDef.h> #include <tsdbDef.h>
#include <taoserror.h> #include <taoserror.h>
#include <tglobal.h> #include <tglobal.h>
#include <iostream> #include <iostream>
...@@ -280,7 +281,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -280,7 +281,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
} }
#endif #endif
#if 0 #if 1
TEST(testCase, tSma_Data_Insert_Query_Test) { TEST(testCase, tSma_Data_Insert_Query_Test) {
// step 1: prepare meta // step 1: prepare meta
const char *smaIndexName1 = "sma_index_test_1"; const char *smaIndexName1 = "sma_index_test_1";
...@@ -299,9 +300,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -299,9 +300,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
// encode // encode
STSma tSma = {0}; STSma tSma = {0};
tSma.version = 0; tSma.version = 0;
tSma.intervalUnit = TIME_UNIT_DAY; tSma.intervalUnit = TIME_UNIT_MINUTE;
tSma.interval = 1; tSma.interval = 1;
tSma.slidingUnit = TIME_UNIT_HOUR; tSma.slidingUnit = TIME_UNIT_MINUTE;
tSma.sliding = 1; // sliding = interval when it's convert window tSma.sliding = 1; // sliding = interval when it's convert window
tSma.indexUid = indexUid1; tSma.indexUid = indexUid1;
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
...@@ -405,15 +406,94 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -405,15 +406,94 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0); ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0);
// init // init
int32_t allocCnt = 0; const int32_t tSmaGroupSize = 4;
int32_t allocStep = 16384; const int32_t tSmaNumOfTags = 2;
int32_t buffer = 1024; const int64_t tSmaGroupId = 12345670;
void *buf = NULL; const col_id_t tSmaNumOfCols = 9; // binary/nchar/varbinary/varchar are only used for tags for group by conditions.
ASSERT_EQ(tsdbMakeRoom(&buf, allocStep), 0); const int32_t tSmaNumOfRows = 2;
int32_t bufSize = taosTSizeof(buf);
int32_t numOfTables = 10; SArray *pDataBlocks = taosArrayInit(tSmaGroupSize, sizeof(SSDataBlock *));
col_id_t numOfCols = 4096; ASSERT_NE(pDataBlocks, nullptr);
ASSERT_GT(numOfCols, 0); int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_INT,
TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_FLOAT,
TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_VARCHAR, TSDB_DATA_TYPE_NCHAR};
// last 2 columns for group by tags
// int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL};
const char *tSmaGroupbyTags[tSmaGroupSize * tSmaNumOfTags] = {"BeiJing", "HaiDian", "BeiJing", "ChaoYang",
"ShangHai", "PuDong", "ShangHai", "MinHang"};
TSKEY tSmaSKeyMs = (int64_t)1648535332 * 1000;
int64_t tSmaIntervalMs = tSma.interval * 60 * 1000;
int64_t tSmaInitVal = 0;
for (int32_t g = 0; g < tSmaGroupSize; ++g) {
SSDataBlock *pDataBlock = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
ASSERT_NE(pDataBlock, nullptr);
pDataBlock->pBlockAgg = NULL;
pDataBlock->info.numOfCols = tSmaNumOfCols;
pDataBlock->info.rows = tSmaNumOfRows;
pDataBlock->info.groupId = tSmaGroupId + g;
pDataBlock->pDataBlock = taosArrayInit(tSmaNumOfCols, sizeof(SColumnInfoData *));
ASSERT_NE(pDataBlock->pDataBlock, nullptr);
for (int32_t c = 0; c < tSmaNumOfCols; ++c) {
SColumnInfoData *pColInfoData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData));
ASSERT_NE(pColInfoData, nullptr);
pColInfoData->info.type = tSmaTypeArray[c];
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
pColInfoData->info.bytes = 100; // update accordingly
} else {
pColInfoData->info.bytes = TYPE_BYTES[pColInfoData->info.type];
}
pColInfoData->pData = (char *)taosMemoryCalloc(1, tSmaNumOfRows * pColInfoData->info.bytes);
for (int32_t r = 0; r < tSmaNumOfRows; ++r) {
void *pCellData = pColInfoData->pData + r * pColInfoData->info.bytes;
switch (pColInfoData->info.type) {
case TSDB_DATA_TYPE_TIMESTAMP:
*(TSKEY *)pCellData = tSmaSKeyMs + tSmaIntervalMs * r;
break;
case TSDB_DATA_TYPE_BOOL:
*(bool *)pCellData = (bool)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_INT:
*(int *)pCellData = (int)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *)pCellData = (uint64_t)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *)pCellData = (int16_t)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_FLOAT:
*(float *)pCellData = (float)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_DOUBLE:
*(double *)pCellData = (double)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_VARCHAR: // city
varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2]));
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2], varDataLen(pCellData));
break;
case TSDB_DATA_TYPE_NCHAR: // district
varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2 + 1]));
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2 + 1], varDataLen(pCellData));
break;
default:
ASSERT_EQ(0, 1); // add definition
break;
}
}
// push SColumnInfoData
taosArrayPush(pDataBlock->pDataBlock, &pColInfoData);
}
// push SSDataBlock
taosArrayPush(pDataBlocks, &pDataBlock);
}
// execute
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, tSma.indexUid, (const char *)pDataBlocks), TSDB_CODE_SUCCESS);
#if 0 #if 0
STSmaDataWrapper *pSmaData = NULL; STSmaDataWrapper *pSmaData = NULL;
...@@ -464,26 +544,30 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -464,26 +544,30 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
#endif #endif
SSDataBlock *pSmaData = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
// step 3: query // step 3: query
uint32_t checkDataCnt = 0; uint32_t checkDataCnt = 0;
for (int32_t t = 0; t < numOfTables; ++t) { ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, skey1, 1), TSDB_CODE_SUCCESS);
for (col_id_t c = 0; c < numOfCols; ++c) {
ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1),
TSDB_CODE_SUCCESS);
++checkDataCnt; ++checkDataCnt;
}
}
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt); printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
// release data // release data
taosMemoryFreeClear(pMsg); taosMemoryFreeClear(pMsg);
taosTZfree(buf);
for (int32_t i = 0; i < taosArrayGetSize(pDataBlocks); ++i) {
SSDataBlock *pDataBlock = (SSDataBlock *)taosArrayGet(pDataBlocks, i);
int32_t numOfOutput = taosArrayGetSize(pDataBlock->pDataBlock);
for (int32_t j = 0; j < numOfOutput; ++j) {
SColumnInfoData *pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j);
colDataDestroy(pColInfoData);
}
taosArrayDestroy(pDataBlock->pDataBlock);
taosMemoryFreeClear(pDataBlock->pBlockAgg);
taosMemoryFreeClear(pDataBlock);
}
taosArrayDestroy(pDataBlocks);
// release meta // release meta
tdDestroyTSma(&tSma); tdDestroyTSma(&tSma);
tfsClose(pTsdb->pTfs); tfsClose(pTsdb->pTfs);
......
/* /*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> *
*
* This program is free software: you can use, redistribute, and/or modify * 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 * it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation. * or later ("AGPL"), as published by the Free Software Foundation.
...@@ -16,7 +15,7 @@ ...@@ -16,7 +15,7 @@
#define __INDEX_CACHE_H__ #define __INDEX_CACHE_H__
#include "indexInt.h" #include "indexInt.h"
#include "index_util.h" #include "indexUtil.h"
#include "tskiplist.h" #include "tskiplist.h"
// ----------------- key structure in skiplist --------------------- // ----------------- key structure in skiplist ---------------------
......
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
extern "C" { extern "C" {
#endif #endif
#include "indexFstAutomation.h"
#include "indexFstCountingWriter.h"
#include "indexFstNode.h"
#include "indexFstRegistry.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_automation.h"
#include "index_fst_counting_writer.h"
#include "index_fst_node.h"
#include "index_fst_registry.h"
#include "index_fst_util.h"
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
extern "C" { extern "C" {
#endif #endif
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_util.h"
typedef struct AutomationCtx AutomationCtx; typedef struct AutomationCtx AutomationCtx;
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
extern "C" { extern "C" {
#endif #endif
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal) #define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal)
#define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0) #define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0)
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
extern "C" { extern "C" {
#endif #endif
#include "indexFstNode.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_node.h"
#include "index_fst_util.h"
typedef struct FstRegistryCell { typedef struct FstRegistryCell {
CompiledAddr addr; CompiledAddr addr;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include "indexFstCommon.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_common.h"
typedef uint64_t FstType; typedef uint64_t FstType;
typedef uint64_t CompiledAddr; typedef uint64_t CompiledAddr;
......
/*
* 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_INDEX_SPARSE_H_
#define _TD_INDEX_SPARSE_H_
#include "tarray.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct FstSparseSet {
SArray *dense;
SArray *sparse;
int32_t size;
} FstSparseSet;
FstSparseSet *sparSetCreate(int32_t sz);
void sparSetDestroy(FstSparseSet *s);
uint32_t sparSetLen(FstSparseSet *ss);
uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip);
uint32_t sparSetGet(FstSparseSet *ss, uint32_t i);
bool sparSetContains(FstSparseSet *ss, uint32_t ip);
void sparSetClear(FstSparseSet *ss);
#ifdef __cplusplus
}
#endif
#endif
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
#ifndef __INDEX_TFILE_H__ #ifndef __INDEX_TFILE_H__
#define __INDEX_TFILE_H__ #define __INDEX_TFILE_H__
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst.h" #include "indexTfile.h"
#include "index_fst_counting_writer.h" #include "indexUtil.h"
#include "index_tfile.h"
#include "index_util.h"
#include "tlockfree.h" #include "tlockfree.h"
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
*/ */
#include "index.h" #include "index.h"
#include "indexCache.h"
#include "indexComm.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "indexTfile.h"
#include "index_comm.h" #include "indexUtil.h"
#include "index_tfile.h"
#include "index_util.h"
#include "tdef.h" #include "tdef.h"
#include "tsched.h" #include "tsched.h"
...@@ -236,7 +236,7 @@ int indexDelete(SIndex* index, SIndexMultiTermQuery* query) { ...@@ -236,7 +236,7 @@ int indexDelete(SIndex* index, SIndexMultiTermQuery* query) {
return 1; return 1;
} }
int indexRebuild(SIndex* index, SIndexOpts* opts){ int indexRebuild(SIndex* index, SIndexOpts* opts) {
#ifdef USE_INVERTED_INDEX #ifdef USE_INVERTED_INDEX
#endif #endif
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_cache.h" #include "indexCache.h"
#include "index_comm.h" #include "indexComm.h"
#include "index_util.h" #include "indexUtil.h"
#include "tcompare.h" #include "tcompare.h"
#include "tsched.h" #include "tsched.h"
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_fst.h" #include "indexFst.h"
#include "indexFstAutomation.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_automation.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "tcoding.h" #include "tcoding.h"
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_fst_automation.h" #include "indexFstAutomation.h"
StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) { StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) {
StartWithStateValue* sv = taosMemoryCalloc(1, sizeof(StartWithStateValue)); StartWithStateValue* sv = taosMemoryCalloc(1, sizeof(StartWithStateValue));
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_fst_common.h" #include "indexFstCommon.h"
const uint8_t COMMON_INPUTS[] = { const uint8_t COMMON_INPUTS[] = {
84, // '\x00' 84, // '\x00'
...@@ -274,20 +274,23 @@ const uint8_t COMMON_INPUTS[] = { ...@@ -274,20 +274,23 @@ const uint8_t COMMON_INPUTS[] = {
}; };
const char COMMON_INPUTS_INV[] = { const char COMMON_INPUTS_INV[] = {
't', 'e', '/', 'o', 'a', 's', 'r', 'i', 'p', 'c', 'n', 'w', '.', 'h', 'l', 'm', 't', 'e', '/', 'o', 'a', 's', 'r', 'i', 'p', 'c', 'n', 'w', '.', 'h',
'-', 'd', 'u', '0', '1', '2', 'g', '=', ':', 'b', 'f', '3', 'y', '5', '&', '_', 'l', 'm', '-', 'd', 'u', '0', '1', '2', 'g', '=', ':', 'b', 'f', '3',
'4', 'v', '9', '6', '7', '8', 'k', '%', '?', 'x', 'C', 'D', 'A', 'S', 'F', 'I', 'y', '5', '&', '_', '4', 'v', '9', '6', '7', '8', 'k', '%', '?', 'x',
'B', 'E', 'j', 'P', 'T', 'z', 'R', 'N', 'M', '+', 'L', 'O', 'q', 'H', 'G', 'W', 'C', 'D', 'A', 'S', 'F', 'I', 'B', 'E', 'j', 'P', 'T', 'z', 'R', 'N',
'U', 'V', ',', 'Y', 'K', 'J', 'Z', 'X', 'Q', ';', ')', '(', '~', '[', ']', '$', 'M', '+', 'L', 'O', 'q', 'H', 'G', 'W', 'U', 'V', ',', 'Y', 'K', 'J',
'!', '\'', '*', '@', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', 'Z', 'X', 'Q', ';', ')', '(', '~', '[', ']', '$', '!', '\'', '*', '@',
'\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r',
'\x1c', '\x1d', '\x1e', '\x1f', ' ', '"', '#', '<', '>', '\\', '^', '`', '{', '|', '}', '\x7f', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b',
'\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '"', '#', '<', '>', '\\', '^', '`', '{', '|',
'\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '}', '\x7f', '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b',
'\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7', '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf', '\x8c', '\x8d', '\x8e', '\x8f', '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99',
'\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7', '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7',
'\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf', '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf', '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5',
'\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf', '\xb6', '\xb7', '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf', '\xc0', '\xc1', '\xc2', '\xc3',
'\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf', '\xd0', '\xd1',
'\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf',
'\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed',
'\xee', '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb',
'\xfc', '\xfd', '\xfe', '\xff',
}; };
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h" #include "indexFstCountingWriter.h"
#include "index_fst_counting_writer.h" #include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_util.h" #include "os.h"
#include "tutil.h" #include "tutil.h"
static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) {
...@@ -82,7 +82,9 @@ static int writeCtxDoFlush(WriterCtx* ctx) { ...@@ -82,7 +82,9 @@ static int writeCtxDoFlush(WriterCtx* ctx) {
WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity) { WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity) {
WriterCtx* ctx = taosMemoryCalloc(1, sizeof(WriterCtx)); WriterCtx* ctx = taosMemoryCalloc(1, sizeof(WriterCtx));
if (ctx == NULL) { return NULL; } if (ctx == NULL) {
return NULL;
}
ctx->type = type; ctx->type = type;
if (ctx->type == TFile) { if (ctx->type == TFile) {
...@@ -126,7 +128,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int ...@@ -126,7 +128,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
return ctx; return ctx;
END: END:
if (ctx->type == TMemory) { taosMemoryFree(ctx->mem.buf); } if (ctx->type == TMemory) {
taosMemoryFree(ctx->mem.buf);
}
taosMemoryFree(ctx); taosMemoryFree(ctx);
return NULL; return NULL;
} }
...@@ -148,14 +152,18 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { ...@@ -148,14 +152,18 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
// stat(ctx->file.buf, &fstat); // stat(ctx->file.buf, &fstat);
// indexError("write file size: %d", (int)(fstat.st_size)); // indexError("write file size: %d", (int)(fstat.st_size));
} }
if (remove) { unlink(ctx->file.buf); } if (remove) {
unlink(ctx->file.buf);
}
} }
taosMemoryFree(ctx); taosMemoryFree(ctx);
} }
FstCountingWriter* fstCountingWriterCreate(void* wrt) { FstCountingWriter* fstCountingWriterCreate(void* wrt) {
FstCountingWriter* cw = taosMemoryCalloc(1, sizeof(FstCountingWriter)); FstCountingWriter* cw = taosMemoryCalloc(1, sizeof(FstCountingWriter));
if (cw == NULL) { return NULL; } if (cw == NULL) {
return NULL;
}
cw->wrt = wrt; cw->wrt = wrt;
//(void *)(writerCtxCreate(TFile, readOnly)); //(void *)(writerCtxCreate(TFile, readOnly));
...@@ -169,7 +177,9 @@ void fstCountingWriterDestroy(FstCountingWriter* cw) { ...@@ -169,7 +177,9 @@ void fstCountingWriterDestroy(FstCountingWriter* cw) {
} }
int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) { int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) {
if (write == NULL) { return 0; } if (write == NULL) {
return 0;
}
// update checksum // update checksum
// write data to file/socket or mem // write data to file/socket or mem
WriterCtx* ctx = write->wrt; WriterCtx* ctx = write->wrt;
...@@ -182,7 +192,9 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) ...@@ -182,7 +192,9 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len)
return len; return len;
} }
int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len) { int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len) {
if (write == NULL) { return 0; } if (write == NULL) {
return 0;
}
WriterCtx* ctx = write->wrt; WriterCtx* ctx = write->wrt;
int nRead = ctx->read(ctx, buf, len); int nRead = ctx->read(ctx, buf, len);
// assert(nRead == len); // assert(nRead == len);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_fst_node.h" #include "indexFstNode.h"
FstBuilderNode* fstBuilderNodeDefault() { FstBuilderNode* fstBuilderNodeDefault() {
FstBuilderNode* bn = taosMemoryMalloc(sizeof(FstBuilderNode)); FstBuilderNode* bn = taosMemoryMalloc(sizeof(FstBuilderNode));
...@@ -22,31 +22,45 @@ FstBuilderNode* fstBuilderNodeDefault() { ...@@ -22,31 +22,45 @@ FstBuilderNode* fstBuilderNodeDefault() {
return bn; return bn;
} }
void fstBuilderNodeDestroy(FstBuilderNode* node) { void fstBuilderNodeDestroy(FstBuilderNode* node) {
if (node == NULL) { return; } if (node == NULL) {
return;
}
taosArrayDestroy(node->trans); taosArrayDestroy(node->trans);
taosMemoryFree(node); taosMemoryFree(node);
} }
bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) { bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) {
if (n1 == n2) { return true; } if (n1 == n2) {
if (n1 == NULL || n2 == NULL) { return false; } return true;
}
if (n1 == NULL || n2 == NULL) {
return false;
}
if (n1->isFinal != n2->isFinal || n1->finalOutput != n2->finalOutput) { return false; } if (n1->isFinal != n2->isFinal || n1->finalOutput != n2->finalOutput) {
return false;
}
size_t s1 = n1->trans ? taosArrayGetSize(n1->trans) : 0; size_t s1 = n1->trans ? taosArrayGetSize(n1->trans) : 0;
size_t s2 = n2->trans ? taosArrayGetSize(n2->trans) : 0; size_t s2 = n2->trans ? taosArrayGetSize(n2->trans) : 0;
if (s1 != s2) { return false; } if (s1 != s2) {
return false;
}
for (size_t i = 0; i < s1; i++) { for (size_t i = 0; i < s1; i++) {
FstTransition* t1 = taosArrayGet(n1->trans, i); FstTransition* t1 = taosArrayGet(n1->trans, i);
FstTransition* t2 = taosArrayGet(n2->trans, i); FstTransition* t2 = taosArrayGet(n2->trans, i);
if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) { return false; } if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) {
return false;
}
} }
return true; return true;
} }
FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) {
FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode)); FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode));
if (node == NULL) { return NULL; } if (node == NULL) {
return NULL;
}
// //
size_t sz = taosArrayGetSize(src->trans); size_t sz = taosArrayGetSize(src->trans);
...@@ -64,7 +78,9 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { ...@@ -64,7 +78,9 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) {
} }
// not destroy src, User's bussiness // not destroy src, User's bussiness
void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) {
if (dst == NULL || src == NULL) { return; } if (dst == NULL || src == NULL) {
return;
}
dst->isFinal = src->isFinal; dst->isFinal = src->isFinal;
dst->finalOutput = src->finalOutput; dst->finalOutput = src->finalOutput;
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "indexFstRegistry.h"
#include "os.h" #include "os.h"
#include "index_fst_registry.h"
uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) {
// TODO(yihaoDeng): refactor later // TODO(yihaoDeng): refactor later
...@@ -35,7 +35,9 @@ uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { ...@@ -35,7 +35,9 @@ uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) {
} }
static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) { static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) {
size_t sz = taosArrayGetSize(arr); size_t sz = taosArrayGetSize(arr);
if (a >= sz || b >= sz) { return; } if (a >= sz || b >= sz) {
return;
}
FstRegistryCell* cell1 = (FstRegistryCell*)taosArrayGet(arr, a); FstRegistryCell* cell1 = (FstRegistryCell*)taosArrayGet(arr, a);
FstRegistryCell* cell2 = (FstRegistryCell*)taosArrayGet(arr, b); FstRegistryCell* cell2 = (FstRegistryCell*)taosArrayGet(arr, b);
...@@ -52,7 +54,9 @@ static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) { ...@@ -52,7 +54,9 @@ static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) {
static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) {
size_t sz = taosArrayGetSize(arr); size_t sz = taosArrayGetSize(arr);
if (start >= sz && end >= sz) { return; } if (start >= sz && end >= sz) {
return;
}
assert(start >= end); assert(start >= end);
...@@ -66,7 +70,9 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { ...@@ -66,7 +70,9 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) {
FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
FstRegistry* registry = taosMemoryMalloc(sizeof(FstRegistry)); FstRegistry* registry = taosMemoryMalloc(sizeof(FstRegistry));
if (registry == NULL) { return NULL; } if (registry == NULL) {
return NULL;
}
uint64_t nCells = tableSize * mruSize; uint64_t nCells = tableSize * mruSize;
SArray* tb = (SArray*)taosArrayInit(nCells, sizeof(FstRegistryCell)); SArray* tb = (SArray*)taosArrayInit(nCells, sizeof(FstRegistryCell));
...@@ -87,7 +93,9 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { ...@@ -87,7 +93,9 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
} }
void fstRegistryDestroy(FstRegistry* registry) { void fstRegistryDestroy(FstRegistry* registry) {
if (registry == NULL) { return; } if (registry == NULL) {
return;
}
SArray* tb = registry->table; SArray* tb = registry->table;
size_t sz = taosArrayGetSize(tb); size_t sz = taosArrayGetSize(tb);
...@@ -100,7 +108,9 @@ void fstRegistryDestroy(FstRegistry* registry) { ...@@ -100,7 +108,9 @@ void fstRegistryDestroy(FstRegistry* registry) {
} }
FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNode) { FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNode) {
if (taosArrayGetSize(registry->table) <= 0) { return NULL; } if (taosArrayGetSize(registry->table) <= 0) {
return NULL;
}
uint64_t bucket = fstRegistryHash(registry, bNode); uint64_t bucket = fstRegistryHash(registry, bNode);
uint64_t start = registry->mruSize * bucket; uint64_t start = registry->mruSize * bucket;
uint64_t end = start + registry->mruSize; uint64_t end = start + registry->mruSize;
...@@ -165,6 +175,4 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo ...@@ -165,6 +175,4 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo
} }
return entry; return entry;
} }
void fstRegistryEntryDestroy(FstRegistryEntry* entry) { void fstRegistryEntryDestroy(FstRegistryEntry* entry) { taosMemoryFree(entry); }
taosMemoryFree(entry);
}
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_fst_util.h" #include "indexFstUtil.h"
#include "index_fst_common.h" #include "indexFstCommon.h"
// A sentinel value used to indicate an empty final state // A sentinel value used to indicate an empty final state
const CompiledAddr EMPTY_ADDRESS = 0; const CompiledAddr EMPTY_ADDRESS = 0;
......
...@@ -13,43 +13,59 @@ ...@@ -13,43 +13,59 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE #include "indexSparse.h"
#include "dndMain.h"
void dndGenerateGrant() { FstSparseSet *sparSetCreate(int32_t sz) {
#if 0 FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet));
grantParseParameter(); if (ss = NULL) {
#endif return NULL;
} }
void dndPrintVersion() { ss->dense = taosArrayInit(sz, sizeof(uint32_t));
#ifdef TD_ENTERPRISE ss->sparse = taosArrayInit(sz, sizeof(uint32_t));
char *releaseName = "enterprise"; ss->size = sz;
#else return ss;
char *releaseName = "community";
#endif
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
printf("gitinfo: %s\n", gitinfo);
printf("builuInfo: %s\n", buildinfo);
} }
void sparSetDestroy(FstSparseSet *ss) {
void dndDumpCfg() { if (ss == NULL) {
SConfig *pCfg = taosGetCfg(); return;
cfgDumpCfg(pCfg, 0, 1); }
taosArrayDestroy(ss->dense);
taosArrayDestroy(ss->sparse);
taosMemoryFree(ss);
} }
uint32_t sparSetLen(FstSparseSet *ss) { return ss == NULL ? 0 : ss->size; }
SDnodeOpt dndGetOpt() { uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip) {
SConfig *pCfg = taosGetCfg(); if (ss == NULL) {
SDnodeOpt option = {0}; return 0;
}
option.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; uint32_t i = ss->size;
tstrncpy(option.dataDir, tsDataDir, sizeof(option.dataDir)); taosArraySet(ss->dense, i, &ip);
tstrncpy(option.firstEp, tsFirst, sizeof(option.firstEp)); taosArraySet(ss->sparse, ip, &i);
tstrncpy(option.secondEp, tsSecond, sizeof(option.firstEp)); ss->size += 1;
option.serverPort = tsServerPort; return i;
tstrncpy(option.localFqdn, tsLocalFqdn, sizeof(option.localFqdn)); }
snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort); uint32_t sparSetGet(FstSparseSet *ss, uint32_t i) {
option.pDisks = tsDiskCfg; if (i >= taosArrayGetSize(ss->dense)) {
option.numOfDisks = tsDiskCfgNum; return 0;
return option; }
uint32_t *v = taosArrayGet(ss->dense, i);
return *v;
}
bool sparSetContains(FstSparseSet *ss, uint32_t ip) {
if (ip >= taosArrayGetSize(ss->sparse)) {
return false;
}
uint32_t i = *(uint32_t *)taosArrayGet(ss->sparse, ip);
if (i >= taosArrayGetSize(ss->dense)) {
return false;
}
uint32_t v = *(uint32_t *)taosArrayGet(ss->dense, i);
return v == ip;
}
void sparSetClear(FstSparseSet *ss) {
if (ss == NULL) {
return;
}
ss->size = 0;
} }
...@@ -13,12 +13,12 @@ p * ...@@ -13,12 +13,12 @@ p *
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_tfile.h" #include "indexTfile.h"
#include "index.h" #include "index.h"
#include "index_comm.h" #include "indexComm.h"
#include "index_fst.h" #include "indexFst.h"
#include "index_fst_counting_writer.h" #include "indexFstCountingWriter.h"
#include "index_util.h" #include "indexUtil.h"
#include "taosdef.h" #include "taosdef.h"
#include "tcoding.h" #include "tcoding.h"
#include "tcompare.h" #include "tcompare.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_util.h" #include "indexUtil.h"
#include "index.h" #include "index.h"
#include "tcompare.h" #include "tcompare.h"
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "index.h" #include "index.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "indexTfile.h"
#include "index_fst.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#include "index_tfile.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tutil.h" #include "tutil.h"
void* callback(void* s) { return s; } void* callback(void* s) { return s; }
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "index.h" #include "index.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "indexTfile.h"
#include "index_fst.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#include "index_tfile.h"
#include "tglobal.h" #include "tglobal.h"
#include "tlog.h" #include "tlog.h"
#include "tskiplist.h" #include "tskiplist.h"
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include "index.h" #include "index.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "indexTfile.h"
#include "index_fst.h" #include "indexUtil.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#include "index_tfile.h"
#include "index_util.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tutil.h" #include "tutil.h"
using namespace std; using namespace std;
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "index.h" #include "index.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "indexTfile.h"
#include "index_fst.h" #include "indexUtil.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#include "index_tfile.h"
#include "index_util.h"
#include "tglobal.h" #include "tglobal.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tutil.h" #include "tutil.h"
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "index.h" #include "index.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "indexTfile.h"
#include "index_fst.h" #include "indexUtil.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#include "index_tfile.h"
#include "index_util.h"
#include "tglobal.h" #include "tglobal.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tutil.h" #include "tutil.h"
......
...@@ -1057,6 +1057,7 @@ static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit"; ...@@ -1057,6 +1057,7 @@ static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
static const char* jkIntervalPhysiPlanFill = "Fill"; static const char* jkIntervalPhysiPlanFill = "Fill";
static const char* jkIntervalPhysiPlanTsPk = "TsPk"; static const char* jkIntervalPhysiPlanTsPk = "TsPk";
static const char* jkIntervalPhysiPlanPrecision = "Precision";
static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj; const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj;
...@@ -1083,6 +1084,9 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { ...@@ -1083,6 +1084,9 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk); code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk);
} }
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanPrecision, pNode->precision);
}
return code; return code;
} }
...@@ -1112,6 +1116,9 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) { ...@@ -1112,6 +1116,9 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) {
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk); code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk);
} }
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetUTinyIntValue(pJson, jkIntervalPhysiPlanPrecision, &pNode->precision);
}
return code; return code;
} }
......
...@@ -82,6 +82,8 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -82,6 +82,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(STableOptions)); return makeNode(type, sizeof(STableOptions));
case QUERY_NODE_INDEX_OPTIONS: case QUERY_NODE_INDEX_OPTIONS:
return makeNode(type, sizeof(SIndexOptions)); return makeNode(type, sizeof(SIndexOptions));
case QUERY_NODE_EXPLAIN_OPTIONS:
return makeNode(type, sizeof(SExplainOptions));
case QUERY_NODE_SET_OPERATOR: case QUERY_NODE_SET_OPERATOR:
return makeNode(type, sizeof(SSetOperator)); return makeNode(type, sizeof(SSetOperator));
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
...@@ -132,6 +134,8 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -132,6 +134,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SCreateTopicStmt)); return makeNode(type, sizeof(SCreateTopicStmt));
case QUERY_NODE_DROP_TOPIC_STMT: case QUERY_NODE_DROP_TOPIC_STMT:
return makeNode(type, sizeof(SDropTopicStmt)); return makeNode(type, sizeof(SDropTopicStmt));
case QUERY_NODE_EXPLAIN_STMT:
return makeNode(type, sizeof(SExplainStmt));
case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_DATABASES_STMT:
case QUERY_NODE_SHOW_TABLES_STMT: case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_STABLES_STMT:
...@@ -204,49 +208,159 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -204,49 +208,159 @@ SNodeptr nodesMakeNode(ENodeType type) {
return NULL; return NULL;
} }
static EDealRes destroyNode(SNode** pNode, void* pContext) { static void destroyVgDataBlockArray(SArray* pArray) {
switch (nodeType(*pNode)) { size_t size = taosArrayGetSize(pArray);
case QUERY_NODE_VALUE: { for (size_t i = 0; i < size; ++i) {
SValueNode* pValue = (SValueNode*)*pNode; SVgDataBlocks* pVg = taosArrayGetP(pArray, i);
taosMemoryFreeClear(pVg->pData);
taosMemoryFreeClear(pVg);
}
taosArrayDestroy(pArray);
}
static void destroyLogicNode(SLogicNode* pNode) {
nodesDestroyList(pNode->pChildren);
nodesDestroyNode(pNode->pConditions);
nodesDestroyList(pNode->pTargets);
}
static void destroyPhysiNode(SPhysiNode* pNode) {
nodesDestroyList(pNode->pChildren);
nodesDestroyNode(pNode->pConditions);
nodesDestroyNode(pNode->pOutputDataBlockDesc);
}
static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) {
destroyPhysiNode((SPhysiNode*)pNode);
nodesDestroyList(pNode->pExprs);
nodesDestroyList(pNode->pFuncs);
}
static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
destroyPhysiNode((SPhysiNode*)pNode);
nodesDestroyList(pNode->pScanCols);
}
static void destroyDataSinkNode(SDataSinkNode* pNode) {
nodesDestroyNode(pNode->pInputDataBlockDesc);
}
void nodesDestroyNode(SNodeptr pNode) {
if (NULL == pNode) {
return;
}
switch (nodeType(pNode)) {
case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release
break;
case QUERY_NODE_VALUE: {
SValueNode* pValue = (SValueNode*)pNode;
taosMemoryFreeClear(pValue->literal); taosMemoryFreeClear(pValue->literal);
if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) { if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) {
taosMemoryFreeClear(pValue->datum.p); taosMemoryFreeClear(pValue->datum.p);
} }
break;
}
case QUERY_NODE_OPERATOR: {
SOperatorNode* pOp = (SOperatorNode*)pNode;
nodesDestroyNode(pOp->pLeft);
nodesDestroyNode(pOp->pRight);
break; break;
} }
case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_LOGIC_CONDITION:
nodesClearList(((SLogicConditionNode*)(*pNode))->pParameterList); nodesDestroyList(((SLogicConditionNode*)pNode)->pParameterList);
break; break;
case QUERY_NODE_FUNCTION: case QUERY_NODE_FUNCTION:
nodesClearList(((SFunctionNode*)(*pNode))->pParameterList); nodesDestroyList(((SFunctionNode*)pNode)->pParameterList);
break; break;
case QUERY_NODE_REAL_TABLE: { case QUERY_NODE_REAL_TABLE: {
SRealTableNode* pReal = (SRealTableNode*)*pNode; SRealTableNode* pReal = (SRealTableNode*)pNode;
taosMemoryFreeClear(pReal->pMeta); taosMemoryFreeClear(pReal->pMeta);
taosMemoryFreeClear(pReal->pVgroupList); taosMemoryFreeClear(pReal->pVgroupList);
break; break;
} }
case QUERY_NODE_TEMP_TABLE: case QUERY_NODE_TEMP_TABLE:
nodesDestroyNode(((STempTableNode*)(*pNode))->pSubquery); nodesDestroyNode(((STempTableNode*)pNode)->pSubquery);
break;
case QUERY_NODE_JOIN_TABLE: {
SJoinTableNode* pJoin = (SJoinTableNode*)pNode;
nodesDestroyNode(pJoin->pLeft);
nodesDestroyNode(pJoin->pRight);
nodesDestroyNode(pJoin->pOnCond);
break; break;
}
case QUERY_NODE_GROUPING_SET: case QUERY_NODE_GROUPING_SET:
nodesClearList(((SGroupingSetNode*)(*pNode))->pParameterList); nodesDestroyList(((SGroupingSetNode*)pNode)->pParameterList);
break;
case QUERY_NODE_ORDER_BY_EXPR:
nodesDestroyNode(((SOrderByExprNode*)pNode)->pExpr);
break; break;
case QUERY_NODE_LIMIT: // no pointer field
break;
case QUERY_NODE_STATE_WINDOW:
nodesDestroyNode(((SStateWindowNode*)pNode)->pCol);
break;
case QUERY_NODE_SESSION_WINDOW: {
SSessionWindowNode* pSession = (SSessionWindowNode*)pNode;
nodesDestroyNode(pSession->pCol);
nodesDestroyNode(pSession->pGap);
break;
}
case QUERY_NODE_INTERVAL_WINDOW: {
SIntervalWindowNode* pJoin = (SIntervalWindowNode*)pNode;
nodesDestroyNode(pJoin->pCol);
nodesDestroyNode(pJoin->pInterval);
nodesDestroyNode(pJoin->pOffset);
nodesDestroyNode(pJoin->pSliding);
nodesDestroyNode(pJoin->pFill);
break;
}
case QUERY_NODE_NODE_LIST: case QUERY_NODE_NODE_LIST:
nodesClearList(((SNodeListNode*)(*pNode))->pNodeList); nodesDestroyList(((SNodeListNode*)pNode)->pNodeList);
break;
case QUERY_NODE_FILL:
nodesDestroyNode(((SFillNode*)pNode)->pValues);
break; break;
case QUERY_NODE_RAW_EXPR:
nodesDestroyNode(((SRawExprNode*)pNode)->pNode);
break;
case QUERY_NODE_TARGET:
nodesDestroyNode(((STargetNode*)pNode)->pExpr);
break;
case QUERY_NODE_DATABLOCK_DESC:
nodesDestroyList(((SDataBlockDescNode*)pNode)->pSlots);
break;
case QUERY_NODE_SLOT_DESC: // no pointer field
case QUERY_NODE_COLUMN_DEF: // no pointer field
case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field
break;
case QUERY_NODE_DATABASE_OPTIONS:
nodesDestroyList(((SDatabaseOptions*)pNode)->pRetentions);
break;
case QUERY_NODE_TABLE_OPTIONS: {
STableOptions* pStmt = (STableOptions*)pNode;
nodesDestroyList(pStmt->pSma);
nodesDestroyList(pStmt->pFuncs);
break;
}
case QUERY_NODE_INDEX_OPTIONS: { case QUERY_NODE_INDEX_OPTIONS: {
SIndexOptions* pStmt = (SIndexOptions*)*pNode; SIndexOptions* pStmt = (SIndexOptions*)pNode;
nodesDestroyList(pStmt->pFuncs); nodesDestroyList(pStmt->pFuncs);
nodesDestroyNode(pStmt->pInterval); nodesDestroyNode(pStmt->pInterval);
nodesDestroyNode(pStmt->pOffset); nodesDestroyNode(pStmt->pOffset);
nodesDestroyNode(pStmt->pSliding); nodesDestroyNode(pStmt->pSliding);
break; break;
} }
case QUERY_NODE_SET_OPERATOR: {
SSetOperator* pStmt = (SSetOperator*)pNode;
nodesDestroyNode(pStmt->pLeft);
nodesDestroyNode(pStmt->pRight);
nodesDestroyList(pStmt->pOrderByList);
nodesDestroyNode(pStmt->pLimit);
break;
}
case QUERY_NODE_SELECT_STMT: { case QUERY_NODE_SELECT_STMT: {
SSelectStmt* pStmt = (SSelectStmt*)*pNode; SSelectStmt* pStmt = (SSelectStmt*)pNode;
nodesDestroyList(pStmt->pProjectionList); nodesDestroyList(pStmt->pProjectionList);
nodesDestroyNode(pStmt->pFromTable); nodesDestroyNode(pStmt->pFromTable);
nodesDestroyNode(pStmt->pWhere); nodesDestroyNode(pStmt->pWhere);
...@@ -259,50 +373,255 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { ...@@ -259,50 +373,255 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
nodesDestroyNode(pStmt->pSlimit); nodesDestroyNode(pStmt->pSlimit);
break; break;
} }
case QUERY_NODE_VNODE_MODIF_STMT: { case QUERY_NODE_VNODE_MODIF_STMT:
SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)*pNode; destroyVgDataBlockArray(((SVnodeModifOpStmt*)pNode)->pDataBlocks);
size_t size = taosArrayGetSize(pStmt->pDataBlocks); break;
for (size_t i = 0; i < size; ++i) { case QUERY_NODE_CREATE_DATABASE_STMT:
SVgDataBlocks* pVg = taosArrayGetP(pStmt->pDataBlocks, i); nodesDestroyNode(((SCreateDatabaseStmt*)pNode)->pOptions);
taosMemoryFreeClear(pVg->pData); break;
taosMemoryFreeClear(pVg); case QUERY_NODE_DROP_DATABASE_STMT: // no pointer field
} break;
taosArrayDestroy(pStmt->pDataBlocks); case QUERY_NODE_ALTER_DATABASE_STMT:
nodesDestroyNode(((SAlterDatabaseStmt*)pNode)->pOptions);
break; break;
}
case QUERY_NODE_CREATE_TABLE_STMT: { case QUERY_NODE_CREATE_TABLE_STMT: {
SCreateTableStmt* pStmt = (SCreateTableStmt*)*pNode; SCreateTableStmt* pStmt = (SCreateTableStmt*)pNode;
nodesDestroyList(pStmt->pCols); nodesDestroyList(pStmt->pCols);
nodesDestroyList(pStmt->pTags); nodesDestroyList(pStmt->pTags);
nodesDestroyNode(pStmt->pOptions);
break; break;
} }
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: { case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: {
SCreateSubTableClause* pStmt = (SCreateSubTableClause*)*pNode; SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode;
nodesDestroyList(pStmt->pSpecificTags); nodesDestroyList(pStmt->pSpecificTags);
nodesDestroyList(pStmt->pValsOfTags); nodesDestroyList(pStmt->pValsOfTags);
break; break;
} }
case QUERY_NODE_CREATE_MULTI_TABLE_STMT: case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables); nodesDestroyList(((SCreateMultiTableStmt*)pNode)->pSubTables);
break;
case QUERY_NODE_DROP_TABLE_CLAUSE: // no pointer field
break;
case QUERY_NODE_DROP_TABLE_STMT:
nodesDestroyNode(((SDropTableStmt*)pNode)->pTables);
break;
case QUERY_NODE_DROP_SUPER_TABLE_STMT: // no pointer field
break;
case QUERY_NODE_ALTER_TABLE_STMT: {
SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode;
nodesDestroyNode(pStmt->pOptions);
nodesDestroyNode(pStmt->pVal);
break;
}
case QUERY_NODE_CREATE_USER_STMT: // no pointer field
case QUERY_NODE_ALTER_USER_STMT: // no pointer field
case QUERY_NODE_DROP_USER_STMT: // no pointer field
case QUERY_NODE_USE_DATABASE_STMT: // no pointer field
case QUERY_NODE_CREATE_DNODE_STMT: // no pointer field
case QUERY_NODE_DROP_DNODE_STMT: // no pointer field
case QUERY_NODE_ALTER_DNODE_STMT: // no pointer field
break; break;
case QUERY_NODE_CREATE_INDEX_STMT: { case QUERY_NODE_CREATE_INDEX_STMT: {
SCreateIndexStmt* pStmt = (SCreateIndexStmt*)*pNode; SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pNode;
nodesDestroyNode(pStmt->pOptions); nodesDestroyNode(pStmt->pOptions);
nodesDestroyList(pStmt->pCols); nodesDestroyList(pStmt->pCols);
break; break;
} }
case QUERY_NODE_DROP_INDEX_STMT: // no pointer field
case QUERY_NODE_CREATE_QNODE_STMT: // no pointer field
case QUERY_NODE_DROP_QNODE_STMT: // no pointer field
break;
case QUERY_NODE_CREATE_TOPIC_STMT:
nodesDestroyNode(((SCreateTopicStmt*)pNode)->pQuery);
break;
case QUERY_NODE_DROP_TOPIC_STMT: // no pointer field
case QUERY_NODE_ALTER_LOCAL_STMT: // no pointer field
break;
case QUERY_NODE_SHOW_DATABASES_STMT:
case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT:
case QUERY_NODE_SHOW_USERS_STMT:
case QUERY_NODE_SHOW_DNODES_STMT:
case QUERY_NODE_SHOW_VGROUPS_STMT:
case QUERY_NODE_SHOW_MNODES_STMT:
case QUERY_NODE_SHOW_MODULES_STMT:
case QUERY_NODE_SHOW_QNODES_STMT:
case QUERY_NODE_SHOW_FUNCTIONS_STMT:
case QUERY_NODE_SHOW_INDEXES_STMT:
case QUERY_NODE_SHOW_STREAMS_STMT: {
SShowStmt* pStmt = (SShowStmt*)pNode;
nodesDestroyNode(pStmt->pDbName);
nodesDestroyNode(pStmt->pTbNamePattern);
break;
}
case QUERY_NODE_LOGIC_PLAN_SCAN: {
SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyList(pLogicNode->pScanCols);
taosMemoryFreeClear(pLogicNode->pMeta);
taosMemoryFreeClear(pLogicNode->pVgroupList);
break;
}
case QUERY_NODE_LOGIC_PLAN_JOIN: {
SJoinLogicNode* pLogicNode = (SJoinLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyNode(pLogicNode->pOnConditions);
break;
}
case QUERY_NODE_LOGIC_PLAN_AGG: {
SAggLogicNode* pLogicNode = (SAggLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyList(pLogicNode->pAggFuncs);
nodesDestroyList(pLogicNode->pGroupKeys);
break;
}
case QUERY_NODE_LOGIC_PLAN_PROJECT: {
SProjectLogicNode* pLogicNode = (SProjectLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyList(pLogicNode->pProjections);
break;
}
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF: {
SVnodeModifLogicNode* pLogicNode = (SVnodeModifLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
destroyVgDataBlockArray(pLogicNode->pDataBlocks);
// pVgDataBlocks is weak reference
break;
}
case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
destroyLogicNode((SLogicNode*)pNode);
break;
case QUERY_NODE_LOGIC_PLAN_WINDOW: {
SWindowLogicNode* pLogicNode = (SWindowLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyList(pLogicNode->pFuncs);
nodesDestroyNode(pLogicNode->pFill);
nodesDestroyNode(pLogicNode->pTspk);
break;
}
case QUERY_NODE_LOGIC_PLAN_SORT: {
SSortLogicNode* pLogicNode = (SSortLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyList(pLogicNode->pSortKeys);
break;
}
case QUERY_NODE_LOGIC_PLAN_PARTITION: {
SPartitionLogicNode* pLogicNode = (SPartitionLogicNode*)pNode;
destroyLogicNode((SLogicNode*)pLogicNode);
nodesDestroyList(pLogicNode->pPartitionKeys);
break;
}
case QUERY_NODE_LOGIC_SUBPLAN: {
SLogicSubplan* pSubplan = (SLogicSubplan*)pNode;
nodesDestroyList(pSubplan->pChildren);
nodesDestroyNode(pSubplan->pNode);
nodesClearList(pSubplan->pParents);
taosMemoryFreeClear(pSubplan->pVgroupList);
break;
}
case QUERY_NODE_LOGIC_PLAN:
nodesDestroyList(((SQueryLogicPlan*)pNode)->pTopSubplans);
break;
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
destroyScanPhysiNode((SScanPhysiNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
destroyScanPhysiNode((SScanPhysiNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
destroyScanPhysiNode((SScanPhysiNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
destroyScanPhysiNode((SScanPhysiNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
destroyScanPhysiNode((SScanPhysiNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_PROJECT: {
SProjectPhysiNode* pPhyNode = (SProjectPhysiNode*)pNode;
destroyPhysiNode((SPhysiNode*)pPhyNode);
nodesDestroyList(pPhyNode->pProjections);
break;
}
case QUERY_NODE_PHYSICAL_PLAN_JOIN: {
SJoinPhysiNode* pPhyNode = (SJoinPhysiNode*)pNode;
destroyPhysiNode((SPhysiNode*)pPhyNode);
nodesDestroyNode(pPhyNode->pOnConditions);
nodesDestroyList(pPhyNode->pTargets);
break;
}
case QUERY_NODE_PHYSICAL_PLAN_AGG: {
SAggPhysiNode* pPhyNode = (SAggPhysiNode*)pNode;
destroyPhysiNode((SPhysiNode*)pPhyNode);
nodesDestroyList(pPhyNode->pExprs);
nodesDestroyList(pPhyNode->pAggFuncs);
nodesDestroyList(pPhyNode->pGroupKeys);
break;
}
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: {
SExchangePhysiNode* pPhyNode = (SExchangePhysiNode*)pNode;
destroyPhysiNode((SPhysiNode*)pPhyNode);
nodesDestroyList(pPhyNode->pSrcEndPoints);
break;
}
case QUERY_NODE_PHYSICAL_PLAN_SORT: {
SSortPhysiNode* pPhyNode = (SSortPhysiNode*)pNode;
destroyPhysiNode((SPhysiNode*)pPhyNode);
nodesDestroyNode(pPhyNode->pExprs);
nodesDestroyNode(pPhyNode->pSortKeys);
break;
}
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL: {
SIntervalPhysiNode* pPhyNode = (SIntervalPhysiNode*)pNode;
destroyWinodwPhysiNode((SWinodwPhysiNode*)pPhyNode);
nodesDestroyNode(pPhyNode->pFill);
nodesDestroyNode(pPhyNode->pTspk);
break;
}
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
destroyDataSinkNode((SDataSinkNode*)pNode);
break;
case QUERY_NODE_PHYSICAL_PLAN_INSERT: {
SDataInserterNode* pSink = (SDataInserterNode*)pNode;
destroyDataSinkNode((SDataSinkNode*)pSink);
taosMemoryFreeClear(pSink->pData);
break;
}
case QUERY_NODE_PHYSICAL_SUBPLAN: {
SSubplan* pSubplan = (SSubplan*)pNode;
nodesDestroyList(pSubplan->pChildren);
nodesDestroyNode(pSubplan->pNode);
nodesDestroyNode(pSubplan->pDataSink);
nodesClearList(pSubplan->pParents);
break;
}
case QUERY_NODE_PHYSICAL_PLAN: {
SQueryPlan* pPlan = (SQueryPlan*)pNode;
if (NULL != pPlan->pSubplans) {
// only need to destroy the top-level subplans, because they will recurse to all the subplans below
bool first = true;
SNode* pElement = NULL;
FOREACH(pElement, pPlan->pSubplans) {
if (first) {
first = false;
nodesDestroyNode(pElement);
} else {
nodesClearList(((SNodeListNode*)pElement)->pNodeList);
taosMemoryFreeClear(pElement);
}
}
nodesClearList(pPlan->pSubplans);
}
break;
}
default: default:
break; break;
} }
taosMemoryFreeClear(*pNode); taosMemoryFreeClear(pNode);
return DEAL_RES_CONTINUE;
}
void nodesDestroyNode(SNodeptr pNode) {
if (NULL == pNode) {
return; return;
}
nodesRewriteNodePostOrder((SNode**)&pNode, destroyNode, NULL);
} }
SNodeList* nodesMakeList() { SNodeList* nodesMakeList() {
......
...@@ -159,6 +159,10 @@ SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId); ...@@ -159,6 +159,10 @@ SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName); SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName);
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName); SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue); SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt);
SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal);
SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal);
SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -339,6 +339,18 @@ cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). ...@@ -339,6 +339,18 @@ cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C).
cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C); } cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C); }
cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); } cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); }
/************************************************ select **************************************************************/
cmd ::= EXPLAIN analyze_opt(A) explain_options(B) query_expression(C). { pCxt->pRootNode = createExplainStmt(pCxt, A, B, C); }
%type analyze_opt { bool }
%destructor analyze_opt { }
analyze_opt(A) ::= . { A = false; }
analyze_opt(A) ::= ANALYZE. { A = true; }
explain_options(A) ::= . { A = createDefaultExplainOptions(pCxt); }
explain_options(A) ::= explain_options(B) VERBOSE NK_BOOL(C). { A = setExplainVerbose(pCxt, B, &C); }
explain_options(A) ::= explain_options(B) RATIO NK_FLOAT(C). { A = setExplainRatio(pCxt, B, &C); }
/************************************************ select **************************************************************/ /************************************************ select **************************************************************/
cmd ::= query_expression(A). { pCxt->pRootNode = A; } cmd ::= query_expression(A). { pCxt->pRootNode = A; }
......
...@@ -1316,3 +1316,30 @@ SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, cons ...@@ -1316,3 +1316,30 @@ SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, cons
} }
return (SNode*)pStmt; return (SNode*)pStmt;
} }
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt) {
SExplainOptions* pOptions = nodesMakeNode(QUERY_NODE_EXPLAIN_OPTIONS);
CHECK_OUT_OF_MEM(pOptions);
pOptions->verbose = TSDB_DEFAULT_EXPLAIN_VERBOSE;
pOptions->ratio = TSDB_DEFAULT_EXPLAIN_RATIO;
return (SNode*)pOptions;
}
SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) {
((SExplainOptions*)pOptions)->verbose = (0 == strncasecmp(pVal->z, "true", pVal->n));
return pOptions;
}
SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) {
((SExplainOptions*)pOptions)->ratio = strtod(pVal->z, NULL);
return pOptions;
}
SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery) {
SExplainStmt* pStmt = nodesMakeNode(QUERY_NODE_EXPLAIN_STMT);
CHECK_OUT_OF_MEM(pStmt);
pStmt->analyze = analyze;
pStmt->pOptions = (SExplainOptions*)pOptions;
pStmt->pQuery = pQuery;
return (SNode*)pStmt;
}
...@@ -31,6 +31,7 @@ static SKeyword keywordTable[] = { ...@@ -31,6 +31,7 @@ static SKeyword keywordTable[] = {
{"ACCOUNT", TK_ACCOUNT}, {"ACCOUNT", TK_ACCOUNT},
{"ALL", TK_ALL}, {"ALL", TK_ALL},
{"ALTER", TK_ALTER}, {"ALTER", TK_ALTER},
{"ANALYZE", TK_ANALYZE},
{"AND", TK_AND}, {"AND", TK_AND},
{"AS", TK_AS}, {"AS", TK_AS},
{"ASC", TK_ASC}, {"ASC", TK_ASC},
...@@ -56,6 +57,7 @@ static SKeyword keywordTable[] = { ...@@ -56,6 +57,7 @@ static SKeyword keywordTable[] = {
{"DOUBLE", TK_DOUBLE}, {"DOUBLE", TK_DOUBLE},
{"DROP", TK_DROP}, {"DROP", TK_DROP},
{"EXISTS", TK_EXISTS}, {"EXISTS", TK_EXISTS},
{"EXPLAIN", TK_EXPLAIN},
{"FILE_FACTOR", TK_FILE_FACTOR}, {"FILE_FACTOR", TK_FILE_FACTOR},
{"FILL", TK_FILL}, {"FILL", TK_FILL},
{"FLOAT", TK_FLOAT}, {"FLOAT", TK_FLOAT},
...@@ -110,6 +112,7 @@ static SKeyword keywordTable[] = { ...@@ -110,6 +112,7 @@ static SKeyword keywordTable[] = {
{"QNODES", TK_QNODES}, {"QNODES", TK_QNODES},
{"QSTARTTS", TK_QSTARTTS}, {"QSTARTTS", TK_QSTARTTS},
{"QUORUM", TK_QUORUM}, {"QUORUM", TK_QUORUM},
{"RATIO", TK_RATIO},
{"REPLICA", TK_REPLICA}, {"REPLICA", TK_REPLICA},
{"RETENTIONS", TK_RETENTIONS}, {"RETENTIONS", TK_RETENTIONS},
{"ROLLUP", TK_ROLLUP}, {"ROLLUP", TK_ROLLUP},
...@@ -144,6 +147,7 @@ static SKeyword keywordTable[] = { ...@@ -144,6 +147,7 @@ static SKeyword keywordTable[] = {
{"USING", TK_USING}, {"USING", TK_USING},
{"VALUES", TK_VALUES}, {"VALUES", TK_VALUES},
{"VARCHAR", TK_VARCHAR}, {"VARCHAR", TK_VARCHAR},
{"VERBOSE", TK_VERBOSE},
{"VGROUPS", TK_VGROUPS}, {"VGROUPS", TK_VGROUPS},
{"WAL", TK_WAL}, {"WAL", TK_WAL},
{"WDURATION", TK_WDURATION}, {"WDURATION", TK_WDURATION},
...@@ -224,7 +228,6 @@ static SKeyword keywordTable[] = { ...@@ -224,7 +228,6 @@ static SKeyword keywordTable[] = {
// {"DETACH", TK_DETACH}, // {"DETACH", TK_DETACH},
// {"EACH", TK_EACH}, // {"EACH", TK_EACH},
// {"END", TK_END}, // {"END", TK_END},
// {"EXPLAIN", TK_EXPLAIN},
// {"FAIL", TK_FAIL}, // {"FAIL", TK_FAIL},
// {"FOR", TK_FOR}, // {"FOR", TK_FOR},
// {"IGNORE", TK_IGNORE}, // {"IGNORE", TK_IGNORE},
......
...@@ -32,6 +32,7 @@ typedef struct STranslateContext { ...@@ -32,6 +32,7 @@ typedef struct STranslateContext {
SCmdMsgInfo* pCmdMsg; SCmdMsgInfo* pCmdMsg;
SHashObj* pDbs; SHashObj* pDbs;
SHashObj* pTables; SHashObj* pTables;
SExplainOptions* pExplainOpt;
} STranslateContext; } STranslateContext;
typedef struct SFullDatabaseName { typedef struct SFullDatabaseName {
...@@ -228,6 +229,9 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p ...@@ -228,6 +229,9 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
pCol->colType = isTag ? COLUMN_TYPE_TAG : COLUMN_TYPE_COLUMN; pCol->colType = isTag ? COLUMN_TYPE_TAG : COLUMN_TYPE_COLUMN;
pCol->node.resType.type = pColSchema->type; pCol->node.resType.type = pColSchema->type;
pCol->node.resType.bytes = pColSchema->bytes; pCol->node.resType.bytes = pColSchema->bytes;
if (TSDB_DATA_TYPE_TIMESTAMP == pCol->node.resType.type) {
pCol->node.resType.precision = pTable->pMeta->tableInfo.precision;
}
} }
static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) { static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) {
...@@ -670,6 +674,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { ...@@ -670,6 +674,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
switch (nodeType(pTable)) { switch (nodeType(pTable)) {
case QUERY_NODE_REAL_TABLE: { case QUERY_NODE_REAL_TABLE: {
SRealTableNode* pRealTable = (SRealTableNode*)pTable; SRealTableNode* pRealTable = (SRealTableNode*)pTable;
pRealTable->ratio = (NULL != pCxt->pExplainOpt ? pCxt->pExplainOpt->ratio : 1.0);
SName name; SName name;
code = getTableMetaImpl(pCxt, code = getTableMetaImpl(pCxt,
toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name), &(pRealTable->pMeta)); toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name), &(pRealTable->pMeta));
...@@ -677,10 +682,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { ...@@ -677,10 +682,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName);
} }
code = setTableVgroupList(pCxt, &name, pRealTable); code = setTableVgroupList(pCxt, &name, pRealTable);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS == code) {
return code;
}
code = addNamespace(pCxt, pRealTable); code = addNamespace(pCxt, pRealTable);
}
break; break;
} }
case QUERY_NODE_TEMP_TABLE: { case QUERY_NODE_TEMP_TABLE: {
...@@ -1801,6 +1805,13 @@ static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pSt ...@@ -1801,6 +1805,13 @@ static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pSt
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) {
if (pStmt->analyze) {
pCxt->pExplainOpt = pStmt->pOptions;
}
return translateQuery(pCxt, pStmt->pQuery);
}
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
switch (nodeType(pNode)) { switch (nodeType(pNode)) {
...@@ -1882,6 +1893,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { ...@@ -1882,6 +1893,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case QUERY_NODE_ALTER_LOCAL_STMT: case QUERY_NODE_ALTER_LOCAL_STMT:
code = translateAlterLocal(pCxt, (SAlterLocalStmt*)pNode); code = translateAlterLocal(pCxt, (SAlterLocalStmt*)pNode);
break; break;
case QUERY_NODE_EXPLAIN_STMT:
code = translateExplain(pCxt, (SExplainStmt*)pNode);
break;
default: default:
break; break;
} }
...@@ -1900,7 +1914,11 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) { ...@@ -1900,7 +1914,11 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
} }
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
if (NULL != pRoot && QUERY_NODE_SELECT_STMT == nodeType(pRoot)) { if (NULL == pRoot) {
return TSDB_CODE_SUCCESS;
}
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
SSelectStmt* pSelect = (SSelectStmt*) pRoot; SSelectStmt* pSelect = (SSelectStmt*) pRoot;
*numOfCols = LIST_LENGTH(pSelect->pProjectionList); *numOfCols = LIST_LENGTH(pSelect->pProjectionList);
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
...@@ -1918,6 +1936,14 @@ int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** p ...@@ -1918,6 +1936,14 @@ int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** p
strcpy((*pSchema)[index].name, pExpr->aliasName); strcpy((*pSchema)[index].name, pExpr->aliasName);
index +=1; index +=1;
} }
} else if (QUERY_NODE_EXPLAIN_STMT == nodeType(pRoot)) {
*numOfCols = 1;
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
if (NULL == (*pSchema)) {
return TSDB_CODE_OUT_OF_MEMORY;
}
(*pSchema)[0].type = TSDB_DATA_TYPE_BINARY;
(*pSchema)[0].bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -2502,6 +2528,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { ...@@ -2502,6 +2528,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
switch (nodeType(pQuery->pRoot)) { switch (nodeType(pQuery->pRoot)) {
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
case QUERY_NODE_EXPLAIN_STMT:
pQuery->haveResultSet = true; pQuery->haveResultSet = true;
pQuery->directRpc = false; pQuery->directRpc = false;
pQuery->msgType = TDMT_VND_QUERY; pQuery->msgType = TDMT_VND_QUERY;
......
...@@ -58,5 +58,7 @@ void qDestroyQuery(SQuery* pQueryNode) { ...@@ -58,5 +58,7 @@ void qDestroyQuery(SQuery* pQueryNode) {
taosMemoryFreeClear(pQueryNode->pCmdMsg->pMsg); taosMemoryFreeClear(pQueryNode->pCmdMsg->pMsg);
taosMemoryFreeClear(pQueryNode->pCmdMsg); taosMemoryFreeClear(pQueryNode->pCmdMsg);
} }
taosArrayDestroy(pQueryNode->pDbList);
taosArrayDestroy(pQueryNode->pTableList);
taosMemoryFreeClear(pQueryNode); taosMemoryFreeClear(pQueryNode);
} }
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -647,3 +647,16 @@ TEST_F(ParserTest, dropTopic) { ...@@ -647,3 +647,16 @@ TEST_F(ParserTest, dropTopic) {
bind("drop topic if exists tp1"); bind("drop topic if exists tp1");
ASSERT_TRUE(run()); ASSERT_TRUE(run());
} }
TEST_F(ParserTest, explain) {
setDatabase("root", "test");
bind("explain SELECT * FROM t1");
ASSERT_TRUE(run());
bind("explain analyze SELECT * FROM t1");
ASSERT_TRUE(run());
bind("explain analyze verbose true ratio 0.01 SELECT * FROM t1");
ASSERT_TRUE(run());
}
...@@ -197,6 +197,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect ...@@ -197,6 +197,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
strcpy(pScan->tableName.dbname, pRealTable->table.dbName); strcpy(pScan->tableName.dbname, pRealTable->table.dbName);
strcpy(pScan->tableName.tname, pRealTable->table.tableName); strcpy(pScan->tableName.tname, pRealTable->table.tableName);
pScan->showRewrite = pCxt->pPlanCxt->showRewrite; pScan->showRewrite = pCxt->pPlanCxt->showRewrite;
pScan->ratio = pRealTable->ratio;
// set columns to scan // set columns to scan
SNodeList* pCols = NULL; SNodeList* pCols = NULL;
...@@ -692,7 +693,7 @@ static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpS ...@@ -692,7 +693,7 @@ static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpS
if (NULL == pModif) { if (NULL == pModif) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
pModif->pDataBlocks = pStmt->pDataBlocks; TSWAP(pModif->pDataBlocks, pStmt->pDataBlocks, SArray*);
pModif->msgType = getMsgType(pStmt->sqlNodeType); pModif->msgType = getMsgType(pStmt->sqlNodeType);
*pLogicNode = (SLogicNode*)pModif; *pLogicNode = (SLogicNode*)pModif;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -704,6 +705,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi ...@@ -704,6 +705,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi
return createSelectLogicNode(pCxt, (SSelectStmt*)pStmt, pLogicNode); return createSelectLogicNode(pCxt, (SSelectStmt*)pStmt, pLogicNode);
case QUERY_NODE_VNODE_MODIF_STMT: case QUERY_NODE_VNODE_MODIF_STMT:
return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt, pLogicNode); return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt, pLogicNode);
case QUERY_NODE_EXPLAIN_STMT:
return createQueryLogicNode(pCxt, ((SExplainStmt*)pStmt)->pQuery, pLogicNode);
default: default:
break; break;
} }
......
...@@ -398,6 +398,7 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp ...@@ -398,6 +398,7 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
pTableScan->scanFlag = pScanLogicNode->scanFlag; pTableScan->scanFlag = pScanLogicNode->scanFlag;
pTableScan->scanRange = pScanLogicNode->scanRange; pTableScan->scanRange = pScanLogicNode->scanRange;
pTableScan->ratio = pScanLogicNode->ratio;
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode);
taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode);
pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable; pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable;
...@@ -780,6 +781,7 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil ...@@ -780,6 +781,7 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
pInterval->sliding = pWindowLogicNode->sliding; pInterval->sliding = pWindowLogicNode->sliding;
pInterval->intervalUnit = pWindowLogicNode->intervalUnit; pInterval->intervalUnit = pWindowLogicNode->intervalUnit;
pInterval->slidingUnit = pWindowLogicNode->slidingUnit; pInterval->slidingUnit = pWindowLogicNode->slidingUnit;
pInterval->precision = ((SColumnNode*)pWindowLogicNode->pTspk)->node.resType.precision;
pInterval->pFill = nodesCloneNode(pWindowLogicNode->pFill); pInterval->pFill = nodesCloneNode(pWindowLogicNode->pFill);
if (NULL != pWindowLogicNode->pFill && NULL == pInterval->pFill) { if (NULL != pWindowLogicNode->pFill && NULL == pInterval->pFill) {
...@@ -1080,6 +1082,30 @@ static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogi ...@@ -1080,6 +1082,30 @@ static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogi
return code; return code;
} }
static void destoryLocationHash(void* p) {
SHashObj* pHash = *(SHashObj**)p;
SSlotIndex* pIndex = taosHashIterate(pHash, NULL);
while (NULL != pIndex) {
taosArrayDestroy(pIndex->pSlotIdsInfo);
pIndex = taosHashIterate(pHash, pIndex);
}
taosHashCleanup(pHash);
}
static void destoryPhysiPlanContext(SPhysiPlanContext* pCxt) {
taosArrayDestroyEx(pCxt->pLocationHelper, destoryLocationHash);
}
static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) {
if (QUERY_NODE_EXPLAIN_STMT == nodeType(pCxt->pAstRoot)) {
SExplainStmt* pStmt = (SExplainStmt*)pCxt->pAstRoot;
pPlan->explainInfo.mode = pStmt->analyze ? EXPLAIN_MODE_ANALYZE : EXPLAIN_MODE_STATIC;
pPlan->explainInfo.verbose = pStmt->pOptions->verbose;
} else {
pPlan->explainInfo.mode = EXPLAIN_MODE_DISABLE;
}
}
int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) { int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) {
SPhysiPlanContext cxt = { SPhysiPlanContext cxt = {
.pPlanCxt = pCxt, .pPlanCxt = pCxt,
...@@ -1091,5 +1117,12 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP ...@@ -1091,5 +1117,12 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP
if (NULL == cxt.pLocationHelper) { if (NULL == cxt.pLocationHelper) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
return doCreatePhysiPlan(&cxt, pLogicPlan, pPlan);
int32_t code = doCreatePhysiPlan(&cxt, pLogicPlan, pPlan);
if (TSDB_CODE_SUCCESS == code) {
setExplainInfo(pCxt, *pPlan);
}
destoryPhysiPlanContext(&cxt);
return code;
} }
...@@ -167,6 +167,8 @@ static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32 ...@@ -167,6 +167,8 @@ static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
nodesDestroyList(pCurrentGroup); nodesDestroyList(pCurrentGroup);
} else {
nodesClearList(pCurrentGroup);
} }
return code; return code;
......
...@@ -140,6 +140,7 @@ static int32_t stsSplit(SSplitContext* pCxt) { ...@@ -140,6 +140,7 @@ static int32_t stsSplit(SSplitContext* pCxt) {
code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan); code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan);
} }
++(pCxt->groupId); ++(pCxt->groupId);
taosMemoryFreeClear(pCxt->pInfo);
return code; return code;
} }
......
...@@ -248,6 +248,11 @@ TEST_F(PlannerTest, showTables) { ...@@ -248,6 +248,11 @@ TEST_F(PlannerTest, showTables) {
bind("show tables"); bind("show tables");
ASSERT_TRUE(run()); ASSERT_TRUE(run());
setDatabase("root", "information_schema");
bind("show tables");
ASSERT_TRUE(run());
} }
TEST_F(PlannerTest, showStables) { TEST_F(PlannerTest, showStables) {
...@@ -277,3 +282,16 @@ TEST_F(PlannerTest, createSmaIndex) { ...@@ -277,3 +282,16 @@ TEST_F(PlannerTest, createSmaIndex) {
bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)"); bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)");
ASSERT_TRUE(run()); ASSERT_TRUE(run());
} }
TEST_F(PlannerTest, explain) {
setDatabase("root", "test");
bind("explain SELECT * FROM t1");
ASSERT_TRUE(run());
bind("explain analyze SELECT * FROM t1");
ASSERT_TRUE(run());
bind("explain analyze verbose true ratio 0.01 SELECT * FROM t1");
ASSERT_TRUE(run());
}
...@@ -9,9 +9,8 @@ target_sources(tdb ...@@ -9,9 +9,8 @@ target_sources(tdb
"src/db/tdbDb.c" "src/db/tdbDb.c"
"src/db/tdbEnv.c" "src/db/tdbEnv.c"
"src/db/tdbTxn.c" "src/db/tdbTxn.c"
"src/db/tdbPage.c"
"src/db/tdbOs.c" "src/db/tdbOs.c"
"src/page/tdbPage.c"
"src/page/tdbPageL.c"
) )
target_include_directories( target_include_directories(
......
...@@ -18,19 +18,12 @@ ...@@ -18,19 +18,12 @@
#define TDB_BTREE_ROOT 0x1 #define TDB_BTREE_ROOT 0x1
#define TDB_BTREE_LEAF 0x2 #define TDB_BTREE_LEAF 0x2
#define TDB_BTREE_PAGE_IS_ROOT(flags) TDB_FLAG_HAS(flags, TDB_BTREE_ROOT)
#define TDB_BTREE_PAGE_IS_LEAF(flags) TDB_FLAG_HAS(flags, TDB_BTREE_LEAF)
#define TDB_BTREE_ASSERT_FLAG(flags) \
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0))
struct SBTree { struct SBTree {
SPgno root; SPgno root;
int keyLen; int keyLen;
int valLen; int valLen;
SPager *pPager; SPager *pPager;
FKeyComparator kcmpr; FKeyComparator kcmpr;
u8 fanout;
int pageSize; int pageSize;
int maxLocal; int maxLocal;
int minLocal; int minLocal;
...@@ -43,6 +36,11 @@ struct SBTree { ...@@ -43,6 +36,11 @@ struct SBTree {
#define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pData[0] #define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pData[0]
#define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pData[0] = (flags)) #define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pData[0] = (flags))
#define TDB_BTREE_PAGE_IS_ROOT(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_ROOT)
#define TDB_BTREE_PAGE_IS_LEAF(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_LEAF)
#define TDB_BTREE_ASSERT_FLAG(flags) \
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0))
typedef struct __attribute__((__packed__)) { typedef struct __attribute__((__packed__)) {
TDB_BTREE_PAGE_COMMON_HDR TDB_BTREE_PAGE_COMMON_HDR
...@@ -60,14 +58,14 @@ typedef struct { ...@@ -60,14 +58,14 @@ typedef struct {
typedef struct { typedef struct {
int kLen; int kLen;
u8 *pKey; const u8 *pKey;
int vLen; int vLen;
u8 *pVal; const u8 *pVal;
SPgno pgno; SPgno pgno;
u8 *pTmpSpace; u8 *pBuf;
} SCellDecoder; } SCellDecoder;
static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst); static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst);
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeOpenImpl(SBTree *pBt);
static int tdbBtreeZeroPage(SPage *pPage, void *arg); static int tdbBtreeZeroPage(SPage *pPage, void *arg);
...@@ -78,13 +76,15 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD ...@@ -78,13 +76,15 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
static int tdbBtreeBalance(SBTC *pBtc); static int tdbBtreeBalance(SBTC *pBtc);
static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell);
static int tdbBtcMoveToNext(SBTC *pBtc); static int tdbBtcMoveToNext(SBTC *pBtc);
static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno); static int tdbBtcMoveDownward(SBTC *pBtc);
static int tdbBtcMoveUpward(SBTC *pBtc); static int tdbBtcMoveUpward(SBTC *pBtc);
int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) {
SBTree *pBt; SBTree *pBt;
int ret; int ret;
ASSERT(keyLen != 0);
*ppBt = NULL; *ppBt = NULL;
pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt)); pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt));
...@@ -93,28 +93,21 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S ...@@ -93,28 +93,21 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S
} }
// pBt->keyLen // pBt->keyLen
pBt->keyLen = keyLen; pBt->keyLen = keyLen < 0 ? TDB_VARIANT_LEN : keyLen;
// pBt->valLen // pBt->valLen
pBt->valLen = valLen; pBt->valLen = valLen < 0 ? TDB_VARIANT_LEN : valLen;
// pBt->pPager // pBt->pPager
pBt->pPager = pPager; pBt->pPager = pPager;
// pBt->kcmpr // pBt->kcmpr
pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn; pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn;
// pBt->fanout
if (keyLen == TDB_VARIANT_LEN) {
pBt->fanout = TDB_DEFAULT_FANOUT;
} else {
ASSERT(0);
// TODO: pBt->fanout = 0;
}
// pBt->pageSize // pBt->pageSize
pBt->pageSize = tdbPagerGetPageSize(pPager); pBt->pageSize = tdbPagerGetPageSize(pPager);
// pBt->maxLocal // pBt->maxLocal
pBt->maxLocal = (pBt->pageSize - 14) / pBt->fanout; pBt->maxLocal = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr)) / 4;
// pBt->minLocal: Should not be allowed smaller than 15, which is [nPayload][nKey][nData] // pBt->minLocal: Should not be allowed smaller than 15, which is [nPayload][nKey][nData]
pBt->minLocal = (pBt->pageSize - 14) / pBt->fanout / 2; pBt->minLocal = pBt->maxLocal / 2;
// pBt->maxLeaf // pBt->maxLeaf
pBt->maxLeaf = pBt->pageSize - 14; pBt->maxLeaf = tdbPageCapacity(pBt->pageSize, sizeof(SLeafHdr));
// pBt->minLeaf // pBt->minLeaf
pBt->minLeaf = pBt->minLocal; pBt->minLeaf = pBt->minLocal;
...@@ -143,7 +136,7 @@ int tdbBtCursorInsert(SBTC *pBtc, const void *pKey, int kLen, const void *pVal, ...@@ -143,7 +136,7 @@ int tdbBtCursorInsert(SBTC *pBtc, const void *pKey, int kLen, const void *pVal,
int cret; int cret;
SBTree *pBt; SBTree *pBt;
ret = tdbBtCursorMoveTo(pBtc, pKey, kLen, &cret); ret = tdbBtcMoveTo(pBtc, pKey, kLen, &cret);
if (ret < 0) { if (ret < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
...@@ -206,7 +199,7 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen ...@@ -206,7 +199,7 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
tdbBtcOpen(&btc, pBt); tdbBtcOpen(&btc, pBt);
tdbBtCursorMoveTo(&btc, pKey, kLen, &cret); tdbBtcMoveTo(&btc, pKey, kLen, &cret);
if (cret) { if (cret) {
return cret; return cret;
...@@ -226,102 +219,39 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen ...@@ -226,102 +219,39 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
return 0; return 0;
} }
static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) {
int ret; SBTC btc;
SBTree *pBt;
SPager *pPager;
pBt = pBtc->pBt;
pPager = pBt->pPager;
if (pBtc->iPage < 0) {
ASSERT(pBtc->iPage == -1);
ASSERT(pBtc->idx == -1);
// Move from the root
ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt);
if (ret < 0) {
ASSERT(0);
return -1;
}
pBtc->iPage = 0;
if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) {
// Current page is empty
// ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pBtc->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
return 0;
}
for (;;) {
int lidx, ridx, midx, c, nCells;
SCell *pCell; SCell *pCell;
SPage *pPage; int cret;
SCellDecoder cd = {0}; void *pTKey;
void *pTVal;
pPage = pBtc->pPage; SCellDecoder cd;
nCells = TDB_PAGE_TOTAL_CELLS(pPage);
lidx = 0;
ridx = nCells - 1;
ASSERT(nCells > 0); tdbBtcOpen(&btc, pBt);
for (;;) { tdbBtcMoveTo(&btc, pKey, kLen, &cret);
if (lidx > ridx) break; if (cret) {
return cret;
}
midx = (lidx + ridx) >> 1; pCell = tdbPageGetCell(btc.pPage, btc.idx);
tdbBtreeDecodeCell(btc.pPage, pCell, &cd);
pCell = tdbPageGetCell(pPage, midx); pTKey = TDB_REALLOC(*ppKey, cd.kLen);
ret = tdbBtreeDecodeCell(pPage, pCell, &cd); pTVal = TDB_REALLOC(*ppVal, cd.vLen);
if (ret < 0) {
// TODO: handle error
ASSERT(0);
return -1;
}
// Compare the key values if (pTKey == NULL || pTVal == NULL) {
c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); TDB_FREE(pTKey);
if (c < 0) { TDB_FREE(pTVal);
/* input-key < cell-key */
ridx = midx - 1;
} else if (c > 0) {
/* input-key > cell-key */
lidx = midx + 1;
} else {
/* input-key == cell-key */
break;
}
} }
// Move downward or break *ppKey = pTKey;
u8 flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); *ppVal = pTVal;
u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); *pkLen = cd.kLen;
if (leaf) { *vLen = cd.vLen;
pBtc->idx = midx;
*pCRst = c;
break;
} else {
if (c <= 0) {
pBtc->idx = midx;
tdbBtcMoveDownward(pBtc, cd.pgno);
} else {
pBtc->idx = midx + 1;
if (midx == nCells - 1) {
/* Move to right-most child */
tdbBtcMoveDownward(pBtc, ((SIntHdr *)pBtc->pPage->pData)->pgno);
} else {
pCell = tdbPageGetCell(pPage, pBtc->idx);
tdbBtreeDecodeCell(pPage, pCell, &cd);
tdbBtcMoveDownward(pBtc, cd.pgno);
}
}
}
}
} else { memcpy(*ppKey, cd.pKey, cd.kLen);
// TODO: Move the cursor from a some position instead of a clear state memcpy(*ppVal, cd.pVal, cd.vLen);
ASSERT(0);
}
return 0; return 0;
} }
...@@ -385,7 +315,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { ...@@ -385,7 +315,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
pBt = (SBTree *)arg; pBt = (SBTree *)arg;
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); flags = TDB_BTREE_PAGE_GET_FLAGS(pPage);
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); isLeaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
ASSERT(flags == TDB_BTREE_PAGE_GET_FLAGS(pPage)); ASSERT(flags == TDB_BTREE_PAGE_GET_FLAGS(pPage));
...@@ -411,15 +341,15 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { ...@@ -411,15 +341,15 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
static int tdbBtreeZeroPage(SPage *pPage, void *arg) { static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
u8 flags; u8 flags;
SBTree *pBt; SBTree *pBt;
u8 isLeaf; u8 leaf;
flags = ((SBtreeInitPageArg *)arg)->flags; flags = ((SBtreeInitPageArg *)arg)->flags;
pBt = ((SBtreeInitPageArg *)arg)->pBt; pBt = ((SBtreeInitPageArg *)arg)->pBt;
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); leaf = flags & TDB_BTREE_LEAF;
tdbPageZero(pPage, isLeaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); tdbPageZero(pPage, leaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize);
if (isLeaf) { if (leaf) {
SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pData); SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pData);
pLeafHdr->flags = flags; pLeafHdr->flags = flags;
...@@ -464,7 +394,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { ...@@ -464,7 +394,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) {
pPager = pRoot->pPager; pPager = pRoot->pPager;
flags = TDB_BTREE_PAGE_GET_FLAGS(pRoot); flags = TDB_BTREE_PAGE_GET_FLAGS(pRoot);
leaf = TDB_BTREE_PAGE_IS_LEAF(flags); leaf = TDB_BTREE_PAGE_IS_LEAF(pRoot);
// Allocate a new child page // Allocate a new child page
zArg.flags = TDB_FLAG_REMOVE(flags, TDB_BTREE_ROOT); zArg.flags = TDB_FLAG_REMOVE(flags, TDB_BTREE_ROOT);
...@@ -530,7 +460,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ...@@ -530,7 +460,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
SPgno pgno; SPgno pgno;
if (sIdx + i == nCells) { if (sIdx + i == nCells) {
ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pParent))); ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pParent));
pgno = ((SIntHdr *)(pParent->pData))->pgno; pgno = ((SIntHdr *)(pParent->pData))->pgno;
} else { } else {
pCell = tdbPageGetCell(pParent, sIdx + i); pCell = tdbPageGetCell(pParent, sIdx + i);
...@@ -544,7 +474,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ...@@ -544,7 +474,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
} }
} }
// copy the parent key out if child pages are not leaf page // copy the parent key out if child pages are not leaf page
childNotLeaf = !TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); childNotLeaf = !TDB_BTREE_PAGE_IS_LEAF(pOlds[0]);
if (childNotLeaf) { if (childNotLeaf) {
for (int i = 0; i < nOlds; i++) { for (int i = 0; i < nOlds; i++) {
if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) { if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) {
...@@ -818,9 +748,8 @@ static int tdbBtreeBalance(SBTC *pBtc) { ...@@ -818,9 +748,8 @@ static int tdbBtreeBalance(SBTC *pBtc) {
for (;;) { for (;;) {
iPage = pBtc->iPage; iPage = pBtc->iPage;
pPage = pBtc->pPage; pPage = pBtc->pPage;
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
leaf = TDB_BTREE_PAGE_IS_LEAF(flags); root = TDB_BTREE_PAGE_IS_ROOT(pPage);
root = TDB_BTREE_PAGE_IS_ROOT(flags);
// when the page is not overflow and not too empty, the balance work // when the page is not overflow and not too empty, the balance work
// is finished. Just break out the balance loop. // is finished. Just break out the balance loop.
...@@ -861,23 +790,17 @@ static int tdbBtreeBalance(SBTC *pBtc) { ...@@ -861,23 +790,17 @@ static int tdbBtreeBalance(SBTC *pBtc) {
} }
#endif #endif
#ifndef TDB_BTREE_CELL // ========================================================= // TDB_BTREE_CELL =====================
static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, int kLen, const void *pVal, int vLen, static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const void *pKey, int kLen, const void *pVal,
int *szPayload) { int vLen, int *szPayload) {
int nPayload; int nPayload;
ASSERT(pKey != NULL);
if (pVal == NULL) {
vLen = 0;
}
nPayload = kLen + vLen; nPayload = kLen + vLen;
if (nPayload <= pPage->maxLocal) { if (nPayload + nHeader <= pPage->maxLocal) {
// General case without overflow // no overflow page is needed
memcpy(pPayload, pKey, kLen); memcpy(pCell + nHeader, pKey, kLen);
if (pVal) { if (pVal) {
memcpy(pPayload + kLen, pVal, vLen); memcpy(pCell + nHeader + kLen, pVal, vLen);
} }
*szPayload = nPayload; *szPayload = nPayload;
...@@ -892,10 +815,8 @@ static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, i ...@@ -892,10 +815,8 @@ static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, i
return 0; return 0;
} }
// TODO: allow vLen = 0
static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell,
int *szCell) { int *szCell) {
u8 flags;
u8 leaf; u8 leaf;
int nHeader; int nHeader;
int nPayload; int nPayload;
...@@ -903,11 +824,11 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo ...@@ -903,11 +824,11 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
ASSERT(pPage->kLen == TDB_VARIANT_LEN || pPage->kLen == kLen); ASSERT(pPage->kLen == TDB_VARIANT_LEN || pPage->kLen == kLen);
ASSERT(pPage->vLen == TDB_VARIANT_LEN || pPage->vLen == vLen); ASSERT(pPage->vLen == TDB_VARIANT_LEN || pPage->vLen == vLen);
ASSERT(pKey != NULL && kLen > 0);
nPayload = 0; nPayload = 0;
nHeader = 0; nHeader = 0;
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
// 1. Encode Header part // 1. Encode Header part
/* Encode SPgno if interior page */ /* Encode SPgno if interior page */
...@@ -929,38 +850,42 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo ...@@ -929,38 +850,42 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
} }
// 2. Encode payload part // 2. Encode payload part
if (leaf) { if ((!leaf) || pPage->vLen == 0) {
ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, pVal, vLen, &nPayload); pVal = NULL;
} else { vLen = 0;
ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, NULL, 0, &nPayload);
} }
ret = tdbBtreeEncodePayload(pPage, pCell, nHeader, pKey, kLen, pVal, vLen, &nPayload);
if (ret < 0) { if (ret < 0) {
// TODO: handle error // TODO
return -1; ASSERT(0);
return 0;
} }
*szCell = nHeader + nPayload; *szCell = nHeader + nPayload;
return 0; return 0;
} }
static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder *pDecoder) { static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder) {
int nPayload; int nPayload;
ASSERT(pDecoder->pKey == NULL);
if (pDecoder->pVal) { if (pDecoder->pVal) {
nPayload = pDecoder->kLen + pDecoder->vLen; ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pPage));
} else {
nPayload = pDecoder->kLen; nPayload = pDecoder->kLen;
} else {
nPayload = pDecoder->kLen + pDecoder->vLen;
} }
if (nPayload <= pPage->maxLocal) { if (nHeader + nPayload <= pPage->maxLocal) {
// General case without overflow // no over flow case
pDecoder->pKey = (void *)pPayload; pDecoder->pKey = pCell + nHeader;
if (!pDecoder->pVal) { if (pDecoder->pVal == NULL && pDecoder->vLen > 0) {
pDecoder->pVal = (void *)(pPayload + pDecoder->kLen); pDecoder->pVal = pCell + nHeader + pDecoder->kLen;
} }
} else { return 0;
}
{
// TODO: handle overflow case // TODO: handle overflow case
ASSERT(0); ASSERT(0);
} }
...@@ -969,14 +894,12 @@ static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder ...@@ -969,14 +894,12 @@ static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder
} }
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) { static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) {
u8 flags;
u8 leaf; u8 leaf;
int nHeader; int nHeader;
int ret; int ret;
nHeader = 0; nHeader = 0;
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
// Clear the state of decoder // Clear the state of decoder
pDecoder->kLen = -1; pDecoder->kLen = -1;
...@@ -1001,13 +924,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD ...@@ -1001,13 +924,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
} }
if (pPage->vLen == TDB_VARIANT_LEN) { if (pPage->vLen == TDB_VARIANT_LEN) {
ASSERT(leaf);
nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->vLen)); nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->vLen));
} else { } else {
pDecoder->vLen = pPage->vLen; pDecoder->vLen = pPage->vLen;
} }
// 2. Decode payload part // 2. Decode payload part
ret = tdbBtreeDecodePayload(pPage, pCell + nHeader, pDecoder); ret = tdbBtreeDecodePayload(pPage, pCell, nHeader, pDecoder);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
...@@ -1016,16 +940,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD ...@@ -1016,16 +940,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
} }
static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) {
u8 flags; u8 leaf;
u8 isLeaf;
int szCell; int szCell;
int kLen = 0, vLen = 0; int kLen = 0, vLen = 0;
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags);
szCell = 0; szCell = 0;
if (!isLeaf) { if (!leaf) {
szCell += sizeof(SPgno); szCell += sizeof(SPgno);
} }
...@@ -1035,21 +957,28 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { ...@@ -1035,21 +957,28 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) {
kLen = pPage->kLen; kLen = pPage->kLen;
} }
if (isLeaf) {
if (pPage->vLen == TDB_VARIANT_LEN) { if (pPage->vLen == TDB_VARIANT_LEN) {
ASSERT(leaf);
szCell += tdbGetVarInt(pCell + szCell, &vLen); szCell += tdbGetVarInt(pCell + szCell, &vLen);
} else { } else if (leaf) {
vLen = pPage->vLen; vLen = pPage->vLen;
} }
}
szCell = szCell + kLen + vLen; szCell = szCell + kLen + vLen;
if (szCell <= pPage->maxLocal) {
return szCell; return szCell;
} }
#endif {
// TODO
ASSERT(0);
return 0;
}
}
// TDB_BTREE_CELL
// TDB_BTREE_CURSOR =====================
int tdbBtcOpen(SBTC *pBtc, SBTree *pBt) { int tdbBtcOpen(SBTC *pBtc, SBTree *pBt) {
pBtc->pBt = pBt; pBtc->pBt = pBt;
pBtc->iPage = -1; pBtc->iPage = -1;
...@@ -1063,7 +992,6 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { ...@@ -1063,7 +992,6 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
int ret; int ret;
SBTree *pBt; SBTree *pBt;
SPager *pPager; SPager *pPager;
u8 flags;
SCell *pCell; SCell *pCell;
SPgno pgno; SPgno pgno;
...@@ -1078,23 +1006,43 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { ...@@ -1078,23 +1006,43 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
return -1; return -1;
} }
ASSERT(TDB_BTREE_PAGE_IS_ROOT(pBtc->pPage));
pBtc->iPage = 0; pBtc->iPage = 0;
if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) > 0) {
pBtc->idx = 0; pBtc->idx = 0;
} else {
// no any data, point to an invalid position
ASSERT(TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage));
pBtc->idx = -1;
return 0;
}
} else { } else {
// move from a position // move from a position
ASSERT(0); int iPage = 0;
for (; iPage < pBtc->iPage; iPage++) {
ASSERT(pBtc->idxStack[iPage] >= 0);
if (pBtc->idxStack[iPage]) break;
} }
// move downward // move upward
for (;;) { for (;;) {
flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); if (pBtc->iPage == 0) {
pBtc->idx = 0;
break;
}
if (TDB_BTREE_PAGE_IS_LEAF(flags)) break; if (pBtc->iPage < iPage) break;
tdbBtcMoveUpward(pBtc);
}
}
pCell = tdbPageGetCell(pBtc->pPage, 0); // move downward
pgno = *(SPgno *)pCell; for (;;) {
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break;
ret = tdbBtcMoveDownward(pBtc, pgno); ret = tdbBtcMoveDownward(pBtc);
if (ret < 0) { if (ret < 0) {
ASSERT(0); ASSERT(0);
return -1; return -1;
...@@ -1110,7 +1058,6 @@ int tdbBtcMoveToLast(SBTC *pBtc) { ...@@ -1110,7 +1058,6 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
int ret; int ret;
SBTree *pBt; SBTree *pBt;
SPager *pPager; SPager *pPager;
u8 flags;
SPgno pgno; SPgno pgno;
pBt = pBtc->pBt; pBt = pBtc->pBt;
...@@ -1132,18 +1079,15 @@ int tdbBtcMoveToLast(SBTC *pBtc) { ...@@ -1132,18 +1079,15 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
// move downward // move downward
for (;;) { for (;;) {
flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
if (TDB_BTREE_PAGE_IS_LEAF(flags)) {
// TODO: handle empty case // TODO: handle empty case
ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) > 0); ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) > 0);
pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1; pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1;
break; break;
} else { } else {
pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno;
ret = tdbBtcMoveDownward(pBtc, pgno); ret = tdbBtcMoveDownward(pBtc);
if (ret < 0) { if (ret < 0) {
ASSERT(0); ASSERT(0);
return -1; return -1;
...@@ -1154,11 +1098,6 @@ int tdbBtcMoveToLast(SBTC *pBtc) { ...@@ -1154,11 +1098,6 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
return 0; return 0;
} }
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen) {
// TODO
return 0;
}
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
SCell *pCell; SCell *pCell;
SCellDecoder cd; SCellDecoder cd;
...@@ -1201,11 +1140,9 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { ...@@ -1201,11 +1140,9 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
static int tdbBtcMoveToNext(SBTC *pBtc) { static int tdbBtcMoveToNext(SBTC *pBtc) {
int nCells; int nCells;
SPgno pgno;
SCell *pCell; SCell *pCell;
u8 flags;
ASSERT(TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage))); ASSERT(TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage));
if (pBtc->idx < 0) return -1; if (pBtc->idx < 0) return -1;
...@@ -1238,18 +1175,11 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { ...@@ -1238,18 +1175,11 @@ static int tdbBtcMoveToNext(SBTC *pBtc) {
// Move downward // Move downward
for (;;) { for (;;) {
nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
if (pBtc->idx < nCells) {
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
pgno = *(SPgno *)pCell;
} else {
pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno;
}
tdbBtcMoveDownward(pBtc, pgno); tdbBtcMoveDownward(pBtc);
pBtc->idx = 0; pBtc->idx = 0;
flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
if (TDB_BTREE_PAGE_IS_LEAF(flags)) {
break; break;
} }
} }
...@@ -1257,13 +1187,20 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { ...@@ -1257,13 +1187,20 @@ static int tdbBtcMoveToNext(SBTC *pBtc) {
return 0; return 0;
} }
int tdbBtcClose(SBTC *pBtc) { static int tdbBtcMoveDownward(SBTC *pBtc) {
// TODO
return 0;
}
static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) {
int ret; int ret;
SPgno pgno;
SCell *pCell;
ASSERT(pBtc->idx >= 0);
ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage));
if (pBtc->idx < TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) {
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
pgno = ((SPgno *)pCell)[0];
} else {
pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno;
}
pBtc->pgStack[pBtc->iPage] = pBtc->pPage; pBtc->pgStack[pBtc->iPage] = pBtc->pPage;
pBtc->idxStack[pBtc->iPage] = pBtc->idx; pBtc->idxStack[pBtc->iPage] = pBtc->idx;
...@@ -1274,6 +1211,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { ...@@ -1274,6 +1211,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) {
ret = tdbPagerFetchPage(pBtc->pBt->pPager, pgno, &pBtc->pPage, tdbBtreeInitPage, pBtc->pBt); ret = tdbPagerFetchPage(pBtc->pBt->pPager, pgno, &pBtc->pPage, tdbBtreeInitPage, pBtc->pBt);
if (ret < 0) { if (ret < 0) {
ASSERT(0); ASSERT(0);
return -1;
} }
return 0; return 0;
...@@ -1282,7 +1220,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { ...@@ -1282,7 +1220,7 @@ static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) {
static int tdbBtcMoveUpward(SBTC *pBtc) { static int tdbBtcMoveUpward(SBTC *pBtc) {
if (pBtc->iPage == 0) return -1; if (pBtc->iPage == 0) return -1;
// tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage);
pBtc->iPage--; pBtc->iPage--;
pBtc->pPage = pBtc->pgStack[pBtc->iPage]; pBtc->pPage = pBtc->pgStack[pBtc->iPage];
...@@ -1291,6 +1229,117 @@ static int tdbBtcMoveUpward(SBTC *pBtc) { ...@@ -1291,6 +1229,117 @@ static int tdbBtcMoveUpward(SBTC *pBtc) {
return 0; return 0;
} }
static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
int ret;
SBTree *pBt;
SPager *pPager;
pBt = pBtc->pBt;
pPager = pBt->pPager;
if (pBtc->iPage < 0) {
ASSERT(pBtc->iPage == -1);
ASSERT(pBtc->idx == -1);
// Move from the root
ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt);
if (ret < 0) {
ASSERT(0);
return -1;
}
pBtc->iPage = 0;
if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) {
// Current page is empty
// ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pBtc->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
return 0;
}
for (;;) {
int lidx, ridx, midx, c, nCells;
SCell *pCell;
SPage *pPage;
SCellDecoder cd = {0};
pPage = pBtc->pPage;
nCells = TDB_PAGE_TOTAL_CELLS(pPage);
lidx = 0;
ridx = nCells - 1;
ASSERT(nCells > 0);
for (;;) {
if (lidx > ridx) break;
midx = (lidx + ridx) >> 1;
pCell = tdbPageGetCell(pPage, midx);
ret = tdbBtreeDecodeCell(pPage, pCell, &cd);
if (ret < 0) {
// TODO: handle error
ASSERT(0);
return -1;
}
// Compare the key values
c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen);
if (c < 0) {
/* input-key < cell-key */
ridx = midx - 1;
} else if (c > 0) {
/* input-key > cell-key */
lidx = midx + 1;
} else {
/* input-key == cell-key */
break;
}
}
// Move downward or break
u8 leaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
if (leaf) {
pBtc->idx = midx;
*pCRst = c;
break;
} else {
if (c <= 0) {
pBtc->idx = midx;
} else {
pBtc->idx = midx + 1;
}
tdbBtcMoveDownward(pBtc);
}
}
} else {
// TODO: Move the cursor from a some position instead of a clear state
ASSERT(0);
}
return 0;
}
int tdbBtcClose(SBTC *pBtc) {
if (pBtc->iPage < 0) return 0;
for (;;) {
ASSERT(pBtc->pPage);
tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage);
pBtc->iPage--;
if (pBtc->iPage < 0) break;
pBtc->pPage = pBtc->pgStack[pBtc->iPage];
pBtc->idx = pBtc->idxStack[pBtc->iPage];
}
return 0;
}
// TDB_BTREE_CURSOR
// TDB_BTREE_DEBUG =====================
#ifndef NODEBUG #ifndef NODEBUG
typedef struct { typedef struct {
SPgno pgno; SPgno pgno;
...@@ -1304,17 +1353,14 @@ typedef struct { ...@@ -1304,17 +1353,14 @@ typedef struct {
SBtPageInfo btPageInfos[20]; SBtPageInfo btPageInfos[20];
void tdbBtPageInfo(SPage *pPage, int idx) { void tdbBtPageInfo(SPage *pPage, int idx) {
u8 flags;
SBtPageInfo *pBtPageInfo; SBtPageInfo *pBtPageInfo;
pBtPageInfo = btPageInfos + idx; pBtPageInfo = btPageInfos + idx;
pBtPageInfo->pgno = TDB_PAGE_PGNO(pPage); pBtPageInfo->pgno = TDB_PAGE_PGNO(pPage);
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); pBtPageInfo->root = TDB_BTREE_PAGE_IS_ROOT(pPage);
pBtPageInfo->leaf = TDB_BTREE_PAGE_IS_LEAF(pPage);
pBtPageInfo->root = TDB_BTREE_PAGE_IS_ROOT(flags);
pBtPageInfo->leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
pBtPageInfo->rChild = 0; pBtPageInfo->rChild = 0;
if (!pBtPageInfo->leaf) { if (!pBtPageInfo->leaf) {
...@@ -1325,3 +1371,4 @@ void tdbBtPageInfo(SPage *pPage, int idx) { ...@@ -1325,3 +1371,4 @@ void tdbBtPageInfo(SPage *pPage, int idx) {
pBtPageInfo->nOvfl = pPage->nOverflow; pBtPageInfo->nOvfl = pPage->nOverflow;
} }
#endif #endif
// TDB_BTREE_DEBUG
\ No newline at end of file
...@@ -96,6 +96,10 @@ int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { ...@@ -96,6 +96,10 @@ int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
} }
int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) {
return tdbBtreePGet(pDb->pBt, pKey, kLen, ppKey, pkLen, ppVal, vLen);
}
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) { int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) {
int ret; int ret;
TDBC *pDbc = NULL; TDBC *pDbc = NULL;
...@@ -131,3 +135,9 @@ int tdbDbcClose(TDBC *pDbc) { ...@@ -131,3 +135,9 @@ int tdbDbcClose(TDBC *pDbc) {
return 0; return 0;
} }
int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) {
// TODO
ASSERT(0);
return 0;
}
\ No newline at end of file
...@@ -122,7 +122,7 @@ static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mute ...@@ -122,7 +122,7 @@ static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mute
static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); }
static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); }
static bool tdbPCacheLocked(SPCache *pCache) { static bool tdbPCacheLocked(SPCache *pCache) {
assert(0); assert(0);
......
...@@ -242,6 +242,18 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { ...@@ -242,6 +242,18 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) {
pToPage->nOverflow = pFromPage->nOverflow; pToPage->nOverflow = pFromPage->nOverflow;
} }
int tdbPageCapacity(int pageSize, int amHdrSize) {
int szPageHdr;
if (pageSize < 65536) {
szPageHdr = pageMethods.szPageHdr;
} else {
szPageHdr = pageLargeMethods.szPageHdr;
}
return pageSize - szPageHdr - amHdrSize;
}
static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) {
SCell *pFreeCell; SCell *pFreeCell;
u8 *pOffset; u8 *pOffset;
...@@ -504,3 +516,80 @@ SPageMethods pageMethods = { ...@@ -504,3 +516,80 @@ SPageMethods pageMethods = {
getPageFreeCellInfo, // getFreeCellInfo getPageFreeCellInfo, // getFreeCellInfo
setPageFreeCellInfo // setFreeCellInfo setPageFreeCellInfo // setFreeCellInfo
}; };
typedef struct __attribute__((__packed__)) {
u8 cellNum[3];
u8 cellBody[3];
u8 cellFree[3];
u8 nFree[3];
} SPageHdrL;
typedef struct __attribute__((__packed__)) {
u8 szCell[3];
u8 nxOffset[3];
} SFreeCellL;
// cellNum
static inline int getLPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); }
static inline void setLPageCellNum(SPage *pPage, int cellNum) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum, cellNum);
}
// cellBody
static inline int getLPageCellBody(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody); }
static inline void setLPageCellBody(SPage *pPage, int cellBody) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody, cellBody);
}
// cellFree
static inline int getLPageCellFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree); }
static inline void setLPageCellFree(SPage *pPage, int cellFree) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree, cellFree);
}
// nFree
static inline int getLPageNFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree); }
static inline void setLPageNFree(SPage *pPage, int nFree) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree, nFree);
}
// cell offset
static inline int getLPageCellOffset(SPage *pPage, int idx) {
ASSERT(idx >= 0 && idx < getPageCellNum(pPage));
return TDB_GET_U24(pPage->pCellIdx + 3 * idx);
}
static inline void setLPageCellOffset(SPage *pPage, int idx, int offset) {
TDB_PUT_U24(pPage->pCellIdx + 3 * idx, offset);
}
// free cell info
static inline void getLPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) {
SFreeCellL *pFreeCell = (SFreeCellL *)pCell;
*szCell = TDB_GET_U24(pFreeCell->szCell);
*nxOffset = TDB_GET_U24(pFreeCell->nxOffset);
}
static inline void setLPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) {
SFreeCellL *pFreeCell = (SFreeCellL *)pCell;
TDB_PUT_U24(pFreeCell->szCell, szCell);
TDB_PUT_U24(pFreeCell->nxOffset, nxOffset);
}
SPageMethods pageLargeMethods = {
3, // szOffset
sizeof(SPageHdrL), // szPageHdr
sizeof(SFreeCellL), // szFreeCell
getLPageCellNum, // getCellNum
setLPageCellNum, // setCellNum
getLPageCellBody, // getCellBody
setLPageCellBody, // setCellBody
getLPageCellFree, // getCellFree
setLPageCellFree, // setCellFree
getLPageNFree, // getFreeBytes
setLPageNFree, // setFreeBytes
getLPageCellOffset, // getCellOffset
setLPageCellOffset, // setCellOffset
getLPageFreeCellInfo, // getFreeCellInfo
setLPageFreeCellInfo // setFreeCellInfo
};
\ No newline at end of file
...@@ -35,7 +35,6 @@ struct SBTC { ...@@ -35,7 +35,6 @@ struct SBTC {
int idx; int idx;
int idxStack[BTREE_MAX_DEPTH + 1]; int idxStack[BTREE_MAX_DEPTH + 1];
SPage *pgStack[BTREE_MAX_DEPTH + 1]; SPage *pgStack[BTREE_MAX_DEPTH + 1];
void *pBuf;
}; };
// SBTree // SBTree
...@@ -43,12 +42,12 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SB ...@@ -43,12 +42,12 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SB
int tdbBtreeClose(SBTree *pBt); int tdbBtreeClose(SBTree *pBt);
int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen); int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen);
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
// SBTC // SBTC
int tdbBtcOpen(SBTC *pCur, SBTree *pBt); int tdbBtcOpen(SBTC *pCur, SBTree *pBt);
int tdbBtcMoveToFirst(SBTC *pBtc); int tdbBtcMoveToFirst(SBTC *pBtc);
int tdbBtcMoveToLast(SBTC *pBtc); int tdbBtcMoveToLast(SBTC *pBtc);
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen);
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
int tdbBtcClose(SBTC *pBtc); int tdbBtcClose(SBTC *pBtc);
......
...@@ -29,11 +29,13 @@ int tdbDbClose(TDB *pDb); ...@@ -29,11 +29,13 @@ int tdbDbClose(TDB *pDb);
int tdbDbDrop(TDB *pDb); int tdbDbDrop(TDB *pDb);
int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen);
int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
// TDBC // TDBC
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc); int tdbDbcOpen(TDB *pDb, TDBC **ppDbc);
int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
int tdbDbcClose(TDBC *pDbc); int tdbDbcClose(TDBC *pDbc);
int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -64,7 +64,7 @@ typedef TdThreadSpinlock tdb_spinlock_t; ...@@ -64,7 +64,7 @@ typedef TdThreadSpinlock tdb_spinlock_t;
#define tdbSpinlockDestroy taosThreadSpinDestroy #define tdbSpinlockDestroy taosThreadSpinDestroy
#define tdbSpinlockLock taosThreadSpinLock #define tdbSpinlockLock taosThreadSpinLock
#define tdbSpinlockUnlock taosThreadSpinUnlock #define tdbSpinlockUnlock taosThreadSpinUnlock
#define tdbSpinlockTrylock pthread_spin_trylock #define tdbSpinlockTrylock taosThreadSpinTrylock
/* mutex lock */ /* mutex lock */
typedef TdThreadMutex tdb_mutex_t; typedef TdThreadMutex tdb_mutex_t;
......
...@@ -111,6 +111,7 @@ void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell ...@@ -111,6 +111,7 @@ void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl); int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
int tdbPageDropCell(SPage *pPage, int idx); int tdbPageDropCell(SPage *pPage, int idx);
void tdbPageCopy(SPage *pFromPage, SPage *pToPage); void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
int tdbPageCapacity(int pageSize, int amHdrSize);
static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
SCell *pCell; SCell *pCell;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
typedef struct STxn STXN; typedef struct STxn TXN;
struct STxn { struct STxn {
u64 txnId; u64 txnId;
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdbInt.h"
typedef struct __attribute__((__packed__)) {
u8 cellNum[3];
u8 cellBody[3];
u8 cellFree[3];
u8 nFree[3];
} SPageHdrL;
typedef struct __attribute__((__packed__)) {
u8 szCell[3];
u8 nxOffset[3];
} SFreeCellL;
// cellNum
static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); }
static inline void setPageCellNum(SPage *pPage, int cellNum) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum, cellNum);
}
// cellBody
static inline int getPageCellBody(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody); }
static inline void setPageCellBody(SPage *pPage, int cellBody) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellBody, cellBody);
}
// cellFree
static inline int getPageCellFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree); }
static inline void setPageCellFree(SPage *pPage, int cellFree) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellFree, cellFree);
}
// nFree
static inline int getPageNFree(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree); }
static inline void setPageNFree(SPage *pPage, int nFree) {
TDB_PUT_U24(((SPageHdrL *)(pPage->pPageHdr))[0].nFree, nFree);
}
// cell offset
static inline int getPageCellOffset(SPage *pPage, int idx) {
ASSERT(idx >= 0 && idx < getPageCellNum(pPage));
return TDB_GET_U24(pPage->pCellIdx + 3 * idx);
}
static inline void setPageCellOffset(SPage *pPage, int idx, int offset) {
TDB_PUT_U24(pPage->pCellIdx + 3 * idx, offset);
}
// free cell info
static inline void getPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) {
SFreeCellL *pFreeCell = (SFreeCellL *)pCell;
*szCell = TDB_GET_U24(pFreeCell->szCell);
*nxOffset = TDB_GET_U24(pFreeCell->nxOffset);
}
static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) {
SFreeCellL *pFreeCell = (SFreeCellL *)pCell;
TDB_PUT_U24(pFreeCell->szCell, szCell);
TDB_PUT_U24(pFreeCell->nxOffset, nxOffset);
}
SPageMethods pageLargeMethods = {
3, // szOffset
sizeof(SPageHdrL), // szPageHdr
sizeof(SFreeCellL), // szFreeCell
getPageCellNum, // getCellNum
setPageCellNum, // setCellNum
getPageCellBody, // getCellBody
setPageCellBody, // setCellBody
getPageCellFree, // getCellFree
setPageCellFree, // setCellFree
getPageNFree, // getFreeBytes
setPageNFree, // setFreeBytes
getPageCellOffset, // getCellOffset
setPageCellOffset, // setCellOffset
getPageFreeCellInfo, // getFreeCellInfo
setPageFreeCellInfo // setFreeCellInfo
};
\ No newline at end of file
/*
* 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/>.
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
int32_t taosCreateShm(SShm* pShm, int32_t shmsize) {
int32_t shmid = shmget(IPC_PRIVATE, shmsize, IPC_CREAT | 0600);
if (shmid < 0) {
return -1;
}
void* shmptr = shmat(shmid, NULL, 0);
if (shmptr == NULL) {
return -1;
}
pShm->id = shmid;
pShm->size = shmsize;
pShm->ptr = shmptr;
return 0;
}
void taosDropShm(SShm* pShm) {
if (pShm->id > 0) {
if (pShm->ptr != NULL) {
shmdt(pShm->ptr);
}
shmctl(pShm->id, IPC_RMID, NULL);
}
pShm->id = 0;
pShm->size = 0;
pShm->ptr = NULL;
}
int32_t taosAttachShm(SShm* pShm) {
if (pShm->id > 0 && pShm->size > 0) {
pShm->ptr = shmat(pShm->id, NULL, 0);
if (pShm->ptr != NULL) {
return 0;
}
}
return -1;
}
void taosDetachShm(SShm* pShm) {
if (pShm->id > 0) {
if (pShm->ptr != NULL) {
shmdt(pShm->ptr);
pShm->ptr = NULL;
}
}
pShm->id = 0;
pShm->size = 0;
pShm->ptr = NULL;
}
...@@ -758,7 +758,7 @@ void taosBlockSIGPIPE() { ...@@ -758,7 +758,7 @@ void taosBlockSIGPIPE() {
sigset_t signal_mask; sigset_t signal_mask;
sigemptyset(&signal_mask); sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGPIPE); sigaddset(&signal_mask, SIGPIPE);
int32_t rc = taosThreadSigmask(SIG_BLOCK, &signal_mask, NULL); int32_t rc = taosThreadSigMask(SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) { if (rc != 0) {
// printf("failed to block SIGPIPE"); // printf("failed to block SIGPIPE");
} }
...@@ -876,7 +876,7 @@ void taosSetMaskSIGPIPE() { ...@@ -876,7 +876,7 @@ void taosSetMaskSIGPIPE() {
sigset_t signal_mask; sigset_t signal_mask;
sigemptyset(&signal_mask); sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGPIPE); sigaddset(&signal_mask, SIGPIPE);
int32_t rc = taosThreadSigmask(SIG_SETMASK, &signal_mask, NULL); int32_t rc = taosThreadSigMask(SIG_SETMASK, &signal_mask, NULL);
if (rc != 0) { if (rc != 0) {
// printf("failed to setmask SIGPIPE"); // printf("failed to setmask SIGPIPE");
} }
......
...@@ -14,132 +14,341 @@ ...@@ -14,132 +14,341 @@
*/ */
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#include <pthread.h>
#include "os.h" #include "os.h"
// int32_t taosThreadSetnameNp(TdThread thread, const char *name) { int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg) {
// return pthread_setname_np(thread,name); return pthread_create(tid, attr, start, arg);
// } }
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared) { int32_t taosThreadAttrDestroy(TdThreadAttr * attr) {
return pthread_spin_init(lock, pshared); return pthread_attr_destroy(attr);
} }
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) { int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate) {
return pthread_mutex_init(mutex, attr); return pthread_attr_getdetachstate(attr, detachstate);
} }
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched) {
return pthread_spin_destroy(lock); return pthread_attr_getinheritsched(attr, inheritsched);
}
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param) {
return pthread_attr_getschedparam(attr, param);
}
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy) {
return pthread_attr_getschedpolicy(attr, policy);
}
int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope) {
return pthread_attr_getscope(attr, contentionscope);
}
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize) {
return pthread_attr_getstacksize(attr, stacksize);
}
int32_t taosThreadAttrInit(TdThreadAttr * attr) {
return pthread_attr_init(attr);
}
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate) {
return pthread_attr_setdetachstate(attr, detachstate);
}
int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched) {
return pthread_attr_setinheritsched(attr, inheritsched);
}
int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param) {
return pthread_attr_setschedparam(attr, param);
}
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy) {
return pthread_attr_setschedpolicy(attr, policy);
}
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope) {
return pthread_attr_setscope(attr, contentionscope);
}
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) {
return pthread_attr_setstacksize(attr, stacksize);
}
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier) {
return pthread_barrier_destroy(barrier);
}
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count) {
return pthread_barrier_init(barrier, attr, count);
}
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier) {
return pthread_barrier_wait(barrier);
}
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr) {
return pthread_barrierattr_destroy(attr);
}
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared) {
return pthread_barrierattr_getpshared(attr, pshared);
}
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr) {
return pthread_barrierattr_init(attr);
}
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared) {
return pthread_barrierattr_setpshared(attr, pshared);
}
int32_t taosThreadCancel(TdThread thread) {
return pthread_cancel(thread);
}
int32_t taosThreadCondDestroy(TdThreadCond * cond) {
return pthread_cond_destroy(cond);
}
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) {
return pthread_cond_init(cond, attr);
}
int32_t taosThreadCondSignal(TdThreadCond * cond) {
return pthread_cond_signal(cond);
}
int32_t taosThreadCondBroadcast(TdThreadCond * cond) {
return pthread_cond_broadcast(cond);
}
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) {
return pthread_cond_wait(cond, mutex);
}
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime) {
return pthread_cond_timedwait(cond, mutex, abstime);
}
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) {
return pthread_condattr_destroy(attr);
}
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared) {
return pthread_condattr_getpshared(attr, pshared);
}
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) {
return pthread_condattr_init(attr);
}
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared) {
return pthread_condattr_setpshared(attr, pshared);
}
int32_t taosThreadDetach(TdThread thread) {
return pthread_detach(thread);
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
return pthread_equal(t1, t2);
}
void taosThreadExit(void *valuePtr) {
return pthread_exit(valuePtr);
}
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
return pthread_getschedparam(thread, policy, param);
}
void *taosThreadGetSpecific(TdThreadKey key) {
return pthread_getspecific(key);
}
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
return pthread_join(thread, valuePtr);
}
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)) {
return pthread_key_create(key, destructor);
}
int32_t taosThreadKeyDelete(TdThreadKey key) {
return pthread_key_delete(key);
}
int32_t taosThreadKill(TdThread thread, int32_t sig) {
return pthread_kill(thread, sig);
}
int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
return pthread_mutex_consistent(mutex);
} }
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) { int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) {
return pthread_mutex_destroy(mutex); return pthread_mutex_destroy(mutex);
} }
int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr) {
return pthread_spin_lock(lock); return pthread_mutex_init(mutex, attr);
} }
int32_t taosThreadMutexLock(TdThreadMutex *mutex) { int32_t taosThreadMutexLock(TdThreadMutex * mutex) {
return pthread_mutex_lock(mutex); return pthread_mutex_lock(mutex);
} }
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) { int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) {
return pthread_spin_unlock(lock); return pthread_mutex_timedlock(mutex, abstime);
}
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) {
return pthread_mutex_trylock(mutex);
} }
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) {
return pthread_mutex_unlock(mutex); return pthread_mutex_unlock(mutex);
} }
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) {
return pthread_rwlock_rdlock(rwlock); return pthread_mutexattr_destroy(attr);
} }
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared) {
return pthread_rwlock_wrlock(rwlock); return pthread_mutexattr_getpshared(attr, pshared);
} }
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust) {
return pthread_rwlock_unlock(rwlock); return pthread_mutexattr_getrobust(attr, robust);
} }
void taosThreadTestCancel(void) { int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind) {
return pthread_testcancel(); return pthread_mutexattr_gettype(attr, kind);
} }
int32_t taosThreadAttrInit(TdThreadAttr *attr) { int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) {
return pthread_attr_init(attr); return pthread_mutexattr_init(attr);
} }
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg) { int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) {
return pthread_create(tid, attr, start, arg); return pthread_mutexattr_setpshared(attr, pshared);
} }
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)) { int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust) {
return pthread_once(onceControl, initRoutine); return pthread_mutexattr_setrobust(attr, robust);
} }
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState) { int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind) {
return pthread_attr_setdetachstate(attr, detachState); return pthread_mutexattr_settype(attr, kind);
} }
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) {
return pthread_attr_destroy(attr); return pthread_once(onceControl, initRoutine);
} }
int32_t taosThreadJoin(TdThread thread, void **pValue) { int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) {
return pthread_join(thread, pValue); return pthread_rwlock_destroy(rwlock);
} }
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) { int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr) {
return pthread_rwlock_init(rwlock, attr); return pthread_rwlock_init(rwlock, attr);
} }
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_destroy(rwlock); return pthread_rwlock_rdlock(rwlock);
} }
int32_t taosThreadCondSignal(TdThreadCond *cond) { int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
return pthread_cond_signal(cond); return pthread_rwlock_timedrdlock(rwlock, abstime);
} }
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
return pthread_cond_init(cond, attr); return pthread_rwlock_timedwrlock(rwlock, abstime);
} }
int32_t taosThreadCondBroadcast(TdThreadCond *cond) { int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) {
return pthread_cond_broadcast(cond); return pthread_rwlock_tryrdlock(rwlock);
} }
int32_t taosThreadCondDestroy(TdThreadCond *cond) { int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) {
return pthread_cond_destroy(cond); return pthread_rwlock_trywrlock(rwlock);
} }
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) {
return pthread_cond_wait(cond, mutex); return pthread_rwlock_unlock(rwlock);
}
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_wrlock(rwlock);
}
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) {
return pthread_rwlockattr_destroy(attr);
}
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared) {
return pthread_rwlockattr_getpshared(attr, pshared);
}
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) {
return pthread_rwlockattr_init(attr);
}
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared) {
return pthread_rwlockattr_setpshared(attr, pshared);
} }
TdThread taosThreadSelf(void) { TdThread taosThreadSelf(void) {
return pthread_self(); return pthread_self();
} }
// int32_t taosThreadGetW32ThreadIdNp(TdThread thread) { int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
// return pthread_getw32threadid_np(thread); return pthread_setcancelstate(state, oldstate);
// } }
int32_t taosThreadEqual(TdThread t1, TdThread t2) { int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
return pthread_equal(t1, t2); return pthread_setcanceltype(type, oldtype);
} }
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset) { int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
return pthread_sigmask(how, set, oset); return pthread_setschedparam(thread, policy, param);
} }
int32_t taosThreadCancel(TdThread thread) { int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
return pthread_cancel(thread); return pthread_setspecific(key, value);
} }
int32_t taosThreadKill(TdThread thread, int sig) { int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
return pthread_kill(thread, sig); return pthread_spin_destroy(lock);
}
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) {
return pthread_spin_init(lock, pshared);
}
int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
return pthread_spin_lock(lock);
}
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
return pthread_spin_trylock(lock);
}
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
return pthread_spin_unlock(lock);
}
void taosThreadTestCancel(void) {
return pthread_testcancel();
}
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset) {
return pthread_sigmask(how, set, oset);
}
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig) {
return sigwait(set, sig);
} }
\ No newline at end of file
...@@ -19,10 +19,6 @@ ...@@ -19,10 +19,6 @@
#include "tlog.h" #include "tlog.h"
#include "tqueue.h" #include "tqueue.h"
// todo
#include <sys/shm.h>
#include <sys/wait.h>
#define SHM_DEFAULT_SIZE (20 * 1024 * 1024) #define SHM_DEFAULT_SIZE (20 * 1024 * 1024)
typedef void *(*ProcThreadFp)(void *param); typedef void *(*ProcThreadFp)(void *param);
...@@ -68,13 +64,13 @@ static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { ...@@ -68,13 +64,13 @@ static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) {
int32_t shmid = -1; int32_t shmid = -1;
int32_t code = -1; int32_t code = -1;
if (pthread_mutexattr_init(&mattr) != 0) { if (taosThreadMutexAttrInit(&mattr) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to init mutex while init attr since %s", terrstr()); uError("failed to init mutex while init attr since %s", terrstr());
goto _OVER; goto _OVER;
} }
if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) { if (taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to init mutex while set shared since %s", terrstr()); uError("failed to init mutex while set shared since %s", terrstr());
goto _OVER; goto _OVER;
...@@ -116,7 +112,7 @@ _OVER: ...@@ -116,7 +112,7 @@ _OVER:
*pShmid = shmid; *pShmid = shmid;
} }
pthread_mutexattr_destroy(&mattr); taosThreadMutexAttrDestroy(&mattr);
return code; return code;
} }
......
...@@ -36,12 +36,12 @@ TEST_F(UtilTestQueue, 01_fork) { ...@@ -36,12 +36,12 @@ TEST_F(UtilTestQueue, 01_fork) {
int err; int err;
pthread_mutexattr_t mattr; pthread_mutexattr_t mattr;
if ((err = pthread_mutexattr_init(&mattr)) < 0) { if ((err = taosThreadMutexAttrInit(&mattr)) < 0) {
printf("mutex addr init error:%s\n", strerror(err)); printf("mutex addr init error:%s\n", strerror(err));
exit(1); exit(1);
} }
if ((err = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED)) < 0) { if ((err = taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED)) < 0) {
printf("mutex addr get shared error:%s\n", strerror(err)); printf("mutex addr get shared error:%s\n", strerror(err));
exit(1); exit(1);
} }
...@@ -50,7 +50,7 @@ TEST_F(UtilTestQueue, 01_fork) { ...@@ -50,7 +50,7 @@ TEST_F(UtilTestQueue, 01_fork) {
int mid = shmget(IPC_PRIVATE, sizeof(pthread_mutex_t), 0600); int mid = shmget(IPC_PRIVATE, sizeof(pthread_mutex_t), 0600);
m = (pthread_mutex_t*)shmat(mid, NULL, 0); m = (pthread_mutex_t*)shmat(mid, NULL, 0);
if ((err = pthread_mutex_init(m, &mattr)) < 0) { if ((err = taosThreadMutexInit(m, &mattr)) < 0) {
printf("mutex mutex init error:%s\n", strerror(err)); printf("mutex mutex init error:%s\n", strerror(err));
exit(1); exit(1);
} }
...@@ -125,7 +125,7 @@ TEST_F(UtilTestQueue, 01_fork) { ...@@ -125,7 +125,7 @@ TEST_F(UtilTestQueue, 01_fork) {
taosThreadAttrDestroy(&mattr); taosThreadAttrDestroy(&mattr);
//销毁mutex //销毁mutex
pthread_mutex_destroy(m); taosThreadMutexDestroy(m);
exit(0); exit(0);
} }
......
...@@ -39,4 +39,13 @@ ...@@ -39,4 +39,13 @@
./test.sh -f tsim/tmq/basic.sim ./test.sh -f tsim/tmq/basic.sim
./test.sh -f tsim/tmq/basic1.sim ./test.sh -f tsim/tmq/basic1.sim
# --- stable
./test.sh -f general/stable/disk.sim
./test.sh -f general/stable/dnode3.sim
./test.sh -f general/stable/metrics.sim
./test.sh -f general/stable/refcount.sim
# ./test.sh -f general/stable/show.sim
./test.sh -f general/stable/values.sim
./test.sh -f general/stable/vnode3.sim
#======================b1-end=============== #======================b1-end===============
...@@ -133,20 +133,17 @@ echo "dDebugFlag 143" >> $TAOS_CFG ...@@ -133,20 +133,17 @@ echo "dDebugFlag 143" >> $TAOS_CFG
echo "vDebugFlag 143" >> $TAOS_CFG echo "vDebugFlag 143" >> $TAOS_CFG
echo "tsdbDebugFlag 143" >> $TAOS_CFG echo "tsdbDebugFlag 143" >> $TAOS_CFG
echo "cDebugFlag 143" >> $TAOS_CFG echo "cDebugFlag 143" >> $TAOS_CFG
echo "jnidebugFlag 143" >> $TAOS_CFG echo "jniDebugFlag 143" >> $TAOS_CFG
echo "qdebugFlag 143" >> $TAOS_CFG echo "qDebugFlag 143" >> $TAOS_CFG
echo "rpcDebugFlag 143" >> $TAOS_CFG echo "rpcDebugFlag 143" >> $TAOS_CFG
echo "tmrDebugFlag 131" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG
echo "udebugFlag 143" >> $TAOS_CFG echo "uDebugFlag 143" >> $TAOS_CFG
echo "sdebugFlag 143" >> $TAOS_CFG echo "sDebugFlag 143" >> $TAOS_CFG
echo "wdebugFlag 143" >> $TAOS_CFG echo "wDebugFlag 143" >> $TAOS_CFG
echo "slaveQuery 0" >> $TAOS_CFG
echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG
echo "defaultPass taosdata" >> $TAOS_CFG
echo "numOfLogLines 20000000" >> $TAOS_CFG echo "numOfLogLines 20000000" >> $TAOS_CFG
echo "statusInterval 1" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG
echo "asyncLog 0" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG
echo "locale en_US.UTF-8" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG
echo "fsync 0" >> $TAOS_CFG
echo "telemetryReporting 0" >> $TAOS_CFG echo "telemetryReporting 0" >> $TAOS_CFG
echo "multiProcess 0" >> $TAOS_CFG
echo " " >> $TAOS_CFG echo " " >> $TAOS_CFG
...@@ -74,7 +74,7 @@ BUILD_DIR=$TAOS_DIR/$BIN_DIR ...@@ -74,7 +74,7 @@ BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim SIM_DIR=$TAOS_DIR/sim
NODE_DIR=$SIM_DIR/$NODE_NAME NODE_DIR=$SIM_DIR/$NODE_NAME
EXE_DIR=$BUILD_DIR/source/dnode/mgmt/main EXE_DIR=$BUILD_DIR/source/dnode/mgmt
CFG_DIR=$NODE_DIR/cfg CFG_DIR=$NODE_DIR/cfg
LOG_DIR=$NODE_DIR/log LOG_DIR=$NODE_DIR/log
DATA_DIR=$NODE_DIR/data DATA_DIR=$NODE_DIR/data
......
...@@ -68,7 +68,7 @@ gitPullBranchInfo $TDengineBrVer ...@@ -68,7 +68,7 @@ gitPullBranchInfo $TDengineBrVer
compileTDengineVersion compileTDengineVersion
taos_dir=${projectDir}/debug/tools/shell taos_dir=${projectDir}/debug/tools/shell
taosd_dir=${projectDir}/debug/source/dnode/mgmt/main taosd_dir=${projectDir}/debug/source/dnode/mgmt
exec_process_dir=${projectDir}/debug/tests/test/c exec_process_dir=${projectDir}/debug/tests/test/c
rm -f /usr/bin/taos rm -f /usr/bin/taos
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
$loop_cnt = 0
check_dnode_ready:
$loop_cnt = $loop_cnt + 1
sleep 200
if $loop_cnt == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05
if $data00 != 1 then
return -1
endi
if $data04 != ready then
goto check_dnode_ready
endi
sql connect
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
$loop_cnt = 0
check_dnode_ready_1:
$loop_cnt = $loop_cnt + 1
sleep 200
if $loop_cnt == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> rows: $rows
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
if $data00 != 1 then
return -1
endi
if $data01 != localhost:7100 then
return -1
endi
if $data04 != ready then
goto check_dnode_ready_1
endi
if $data14 != ready then
goto check_dnode_ready_1
endi
if $data24 != ready then
goto check_dnode_ready_1
endi
print ============= create database
#database_option: {
# BLOCKS value [3~1000, default: 6]
# | CACHE value [default: 16M]
# | CACHELAST value [0, 1, 2, 3]
# | COMP [0 | 1 | 2]
# | DAYS value [unit is minutes]
# | FSYNC value [0 ~ 180000 ms]
# | MAXROWS value [default: 4096]
# | MINROWS value [default: 100]
# | KEEP value [days, 365000]
# | PRECISION ['ms' | 'us' | 'ns']
# | QUORUM value [1 | 2]
# | REPLICA value [1 | 3]
# | TTL value [unit is day, min=1]
# | WAL value [1 | 2]
# | VGROUPS value [default: 2]
# | SINGLE_STABLE [0 | 1]
# | STREAM_MODE [0 | 1]
sql create database db BLOCKS 7 CACHE 3 CACHELAST 3 COMP 0 DAYS 240 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1000 PRECISION 'ns' QUORUM 1 REPLICA 3 TTL 7 WAL 2 VGROUPS 6 SINGLE_STABLE 1 STREAM_MODE 1
sql show databases
print rows: $rows
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ====> dataX_db
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
if $rows != 2 then
return -1
endi
if $data0_db != db then # name
return -1
endi
if $data2_db != 6 then # vgroups
return -1
endi
if $data3_db != 0 then # ntables
return -1
endi
if $data4_db != 3 then # replica
return -1
endi
if $data5_db != 1 then # quorum
return -1
endi
if $data6_db != 240 then # days
return -1
endi
if $data7_db != 1000,1000,1000 then # keep
return -1
endi
if $data8_db != 3 then # cache
return -1
endi
if $data9_db != 7 then # blocks
return -1
endi
if $data10_db != 10 then # minrows
return -1
endi
if $data11_db != 8000 then # maxrows
return -1
endi
if $data12_db != 2 then # wal
return -1
endi
if $data13_db != 1000 then # fsync
return -1
endi
if $data14_db != 0 then # comp
return -1
endi
if $data15_db != 3 then # cachelast
return -1
endi
if $data16_db != ns then # precision
return -1
endi
print ============== not support modify options: name, create_time, vgroups, ntables
sql_error alter database db name dba
sql_error alter database db create_time "2022-03-03 15:08:13.329"
sql_error alter database db vgroups -1
sql_error alter database db vgroups 0
sql_error alter database db vgroups 2
sql_error alter database db vgroups 20
sql_error alter database db ntables -1
sql_error alter database db ntables 0
sql_error alter database db ntables 1
sql_error alter database db ntables 10
#print ============== modify replica
sql_error alter database db replica 2
sql_error alter database db replica 5
sql_error alter database db replica -1
sql_error alter database db replica 0
#sql alter database db replica 1
#sql show databases
#print replica: $data4_db
#if $data4_db != 1 then
# return -1
#endi
#sql alter database db replica 3
#sql show databases
#print replica: $data4_db
#if $data4_db != 3 then
# return -1
#endi
print ============== modify quorum
sql alter database db quorum 2
sql show databases
print quorum $data5_db
if $data5_db != 2 then
return -1
endi
sql alter database db quorum 1
sql show databases
print quorum $data5_db
if $data5_db != 1 then
return -1
endi
sql_error alter database db quorum -1
sql_error alter database db quorum 0
sql_error alter database db quorum 3
sql_error alter database db quorum 4
sql_error alter database db quorum 5
#print ============== modify days
#sql alter database db days 480
#sql show databases
#print days $data6_db
#if $data6_db != 480 then # days
# return -1
#endi
#sql alter database db days 360
#sql show databases
#print days $data6_db
#if $data6_db != 360 then # days
# return -1
#endi
sql_error alter database db days 0
#sql_error alter database db days 14400 # set over than keep
print ============== modify keep
sql alter database db keep 2000
sql show databases
print keep $data7_db
if $data7_db != 1000,1000,2000 then
return -1
endi
#sql alter database db keep 1000,2000
#sql show databases
#print keep $data7_db
#if $data7_db != 500,500,500 then
# return -1
#endi
#sql alter database db keep 40,50
#sql alter database db keep 30,31
#sql alter database db keep 20
#sql_error alter database db keep 10.0
#sql_error alter database db keep 9
#sql_error alter database db keep 1
sql_error alter database db keep 0
sql_error alter database db keep -1
#sql_error alter database db keep 365001
print ============== modify cache
#sql alter database db cache 12
#sql show databases
#print cache $data8_db
#if $data8_db != 12 then
# return -1
#endi
#sql alter database db cache 1
#sql show databases
#print cache $data8_db
#if $data8_db != 6 then
# return -1
#endi
#
#sql_error alter database db cache 60
#sql_error alter database db cache 50
#sql_error alter database db cache 20
#sql_error alter database db cache 3
#sql_error alter database db cache 129
#sql_error alter database db cache 300
sql_error alter database db cache 0
sql_error alter database db cache -1
print ============== modify blocks
sql alter database db blocks 3
sql show databases
print blocks $data9_db
if $data9_db != 3 then
return -1
endi
sql alter database db blocks 11
sql show databases
print blocks $data9_db
if $data9_db != 11 then
return -1
endi
sql alter database db blocks 40
sql alter database db blocks 30
sql alter database db blocks 20
sql alter database db blocks 10
sql_error alter database db blocks 2
sql_error alter database db blocks 1
sql_error alter database db blocks 0
sql_error alter database db blocks -1
sql_error alter database db blocks 10001
#print ============== modify minrows
#sql alter database db minrows 8
#sql show databases
#print minrows $data10_db
#if $data10_db != 8 then
# return -1
#endi
#sql alter database db minrows 200
#sql show databases
#print minrows $data10_db
#if $data10_db != 200 then
# return -1
#endi
#
#sql alter database db minrows 11
#sql show databases
#print minrows $data10_db
#if $data10_db != 11 then
# return -1
#endi
#sql_error alter database db minrows 8000
#sql_error alter database db minrows 8001
#print ============== modify maxrows
#sql alter database db maxrows 1000
#sql show databases
#print maxrows $data11_db
#if $data11_db != 1000 then
# return -1
#endi
#sql alter database db maxrows 2000
#sql show databases
#print maxrows $data11_db
#if $data11_db != 2000 then
# return -1
#endi
#
#sql_error alter database db maxrows 11 # equal minrows
#sql_error alter database db maxrows 10 # little than minrows
print ============== step wal
sql alter database db wal 1
sql show databases
print wal $data12_db
if $data12_db != 1 then
return -1
endi
sql alter database db wal 2
sql show databases
print wal $data12_db
if $data12_db != 2 then
return -1
endi
sql_error alter database db wal 0
sql_error alter database db wal 3
sql_error alter database db wal 100
sql_error alter database db wal -1
print ============== modify fsync
sql alter database db fsync 2000
sql show databases
print fsync $data13_db
if $data13_db != 2000 then
return -1
endi
sql alter database db fsync 500
sql show databases
print fsync $data13_db
if $data13_db != 500 then
return -1
endi
sql_error alter database db fsync 0
sql_error alter database db fsync -1
print ============== modify comp
sql alter database db comp 1
sql show databases
print comp $data14_db
if $data14_db != 1 then
return -1
endi
sql alter database db comp 2
sql show databases
print comp $data14_db
if $data14_db != 2 then
return -1
endi
sql alter database db comp 1
sql show databases
print comp $data14_db
if $data14_db != 1 then
return -1
endi
sql alter database db comp 0
sql show databases
print comp $data14_db
if $data14_db != 0 then
return -1
endi
sql_error alter database db comp 3
sql_error alter database db comp 4
sql_error alter database db comp 5
sql_error alter database db comp -1
print ============== modify cachelast [0, 1, 2, 3]
sql alter database db cachelast 2
sql show databases
print cachelast $data15_db
if $data15_db != 2 then
return -1
endi
sql alter database db cachelast 1
sql show databases
print cachelast $data15_db
if $data15_db != 1 then
return -1
endi
sql alter database db cachelast 0
sql show databases
print cachelast $data15_db
if $data15_db != 0 then
return -1
endi
sql alter database db cachelast 2
sql show databases
print cachelast $data15_db
if $data15_db != 2 then
return -1
endi
sql alter database db cachelast 3
sql show databases
print cachelast $data15_db
if $data15_db != 3 then
return -1
endi
sql_error alter database db comp 4
sql_error alter database db comp 10
sql_error alter database db comp -1
print ============== modify precision
sql alter database db precision 'ms'
sql show databases
print precision $data16_db
if $data16_db != ms then
return -1
endi
sql alter database db precision 'us'
sql show databases
print precision $data16_db
if $data16_db != us then
return -1
endi
sql alter database db precision 'ns'
sql show databases
print precision $data16_db
if $data16_db != ns then
return -1
endi
sql_error alter database db prec 'xs'
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
...@@ -46,12 +46,12 @@ endw ...@@ -46,12 +46,12 @@ endw
sql show vgroups sql show vgroups
print vgroups ==> $rows print vgroups ==> $rows
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
sql select count(*) from $mt sql select count(tbcol) from $mt
print select count(*) from $mt ===> $data00 print select count(tbcol) from $mt ===> $data00
if $data00 != $totalNum then if $data00 != $totalNum then
return -1 return -1
endi endi
...@@ -65,7 +65,7 @@ sleep 6000 ...@@ -65,7 +65,7 @@ sleep 6000
sql use $db sql use $db
sql show vgroups sql show vgroups
print vgroups ==> $rows print vgroups ==> $rows
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -73,7 +73,7 @@ print =============== step2 ...@@ -73,7 +73,7 @@ print =============== step2
$i = 1 $i = 1
$tb = $tbPrefix . $i $tb = $tbPrefix . $i
sql select count(*) from $tb sql select count(tbcol) from $tb
print ===> $data00 print ===> $data00
if $data00 != $rowNum then if $data00 != $rowNum then
return -1 return -1
...@@ -86,11 +86,12 @@ if $data00 != $rowNum then ...@@ -86,11 +86,12 @@ if $data00 != $rowNum then
endi endi
print =============== step3 print =============== step3
sql select count(tbcol) from $tb where ts <= 1519833840000 # TODO : where condition
print ===> $data00 # sql select count(tbcol) from $tb where ts <= 1519833840000
if $data00 != 5 then # print ===> $data00
return -1 # if $data00 != 5 then
endi # return -1
# endi
print =============== step4 print =============== step4
sql select count(tbcol) as b from $tb sql select count(tbcol) as b from $tb
...@@ -101,33 +102,35 @@ endi ...@@ -101,33 +102,35 @@ endi
print =============== step5 print =============== step5
sql select count(tbcol) as b from $tb interval(1m) sql select count(tbcol) as b from $tb interval(1m)
print ===> $data01 print ===> $data00
if $data01 != 1 then if $data00 != 1 then
return -1 return -1
endi endi
sql select count(tbcol) as b from $tb interval(1d) sql select count(tbcol) as b from $tb interval(1d)
print ===> $data01 print ===> $data00
if $data01 != $rowNum then if $data00 != $rowNum then
return -1 return -1
endi endi
print =============== step6 print =============== step6
sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) # TODO
print ===> $data01 # sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m)
if $data01 != 1 then # print ===> $data00
return -1 # if $data00 != 1 then
endi # return -1
if $rows != 5 then # endi
return -1 # if $rows != 5 then
endi # return -1
# endi
print =============== step7 print =============== step7
sql select count(*) from $mt # TODO
print select count(*) from $mt ===> $data00 # sql select count(*) from $mt
if $data00 != $totalNum then # print select count(*) from $mt ===> $data00
return -1 # if $data00 != $totalNum then
endi # return -1
# endi
sql select count(tbcol) from $mt sql select count(tbcol) from $mt
print ===> $data00 print ===> $data00
...@@ -136,63 +139,67 @@ if $data00 != $totalNum then ...@@ -136,63 +139,67 @@ if $data00 != $totalNum then
endi endi
print =============== step8 print =============== step8
sql select count(tbcol) as c from $mt where ts <= 1519833840000 # TODO
print ===> $data00 # sql select count(tbcol) as c from $mt where ts <= 1519833840000
if $data00 != 50 then # print ===> $data00
return -1 # if $data00 != 50 then
endi # return -1
# endi
sql select count(tbcol) as c from $mt where tgcol < 5 #
print ===> $data00 # sql select count(tbcol) as c from $mt where tgcol < 5
if $data00 != 100 then # print ===> $data00
return -1 # if $data00 != 100 then
endi # return -1
# endi
sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 #
print ===> $data00 # sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000
if $data00 != 25 then # print ===> $data00
return -1 # if $data00 != 25 then
endi # return -1
# endi
print =============== step9 print =============== step9
sql select count(tbcol) as b from $mt interval(1m) # TODO : count from stable
print select count(tbcol) as b from $mt interval(1m) ===> $data01 # sql select count(tbcol) as b from $mt interval(1m)
if $data01 != 10 then # print select count(tbcol) as b from $mt interval(1m) ===> $data01
return -1 # if $data01 != 10 then
endi # return -1
# endi
sql select count(tbcol) as b from $mt interval(1d)
print ===> $data02 # sql select count(tbcol) as b from $mt interval(1d)
if $data01 != 200 then # print ===> $data02
return -1 # if $data01 != 200 then
endi # return -1
# endi
print =============== step10 print =============== step10
print select count(tbcol) as b from $mt group by tgcol # TODO
sql select count(tbcol) as b from $mt group by tgcol # print select count(tbcol) as b from $mt group by tgcol
print ===> $data00 # sql select count(tbcol) as b from $mt group by tgcol
if $data00 != $rowNum then # print ===> $data00
return -1 # if $data00 != $rowNum then
endi # return -1
# endi
if $rows != $tbNum then
return -1 # if $rows != $tbNum then
endi # return -1
# endi
#
print =============== step11 print =============== step11
sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol # TODO : where condition
print ===> $data01 # sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol
if $data01 != 1 then # print ===> $data01
return -1 # if $data01 != 1 then
endi # return -1
if $rows != 50 then # endi
return -1 # if $rows != 50 then
endi # return -1
# endi
print =============== clear print =============== clear
sql drop database $db sql drop database $db
sql show databases sql show databases
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
......
...@@ -8,17 +8,16 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1 ...@@ -8,17 +8,16 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/cfg.sh -n dnode2 -c walLevel -v 1 system sh/cfg.sh -n dnode2 -c walLevel -v 1
system sh/cfg.sh -n dnode3 -c walLevel -v 1 system sh/cfg.sh -n dnode3 -c walLevel -v 1
system sh/cfg.sh -n dnode4 -c walLevel -v 1 system sh/cfg.sh -n dnode4 -c walLevel -v 1
system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 # system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4
system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 # system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4
system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 # system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4
system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 # system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
sql connect sql connect
sql create dnode $hostname2 sql create dnode $hostname PORT 7200
sql create dnode $hostname3 sql create dnode $hostname PORT 7300
sql create dnode $hostname4
system sh/exec.sh -n dnode2 -s start system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start system sh/exec.sh -n dnode4 -s start
...@@ -76,7 +75,7 @@ endw ...@@ -76,7 +75,7 @@ endw
sql show vgroups sql show vgroups
print vgroups ==> $rows print vgroups ==> $rows
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -99,11 +98,12 @@ if $data00 != $rowNum then ...@@ -99,11 +98,12 @@ if $data00 != $rowNum then
endi endi
print =============== step3 print =============== step3
sql select count(tbcol) from $tb where ts <= 1519833840000 # TODO : where condition
print ===> $data00 # sql select count(tbcol) from $tb where ts <= 1519833840000
if $data00 != 5 then # print ===> $data00
return -1 # if $data00 != 5 then
endi # return -1
# endi
print =============== step4 print =============== step4
sql select count(tbcol) as b from $tb sql select count(tbcol) as b from $tb
...@@ -114,98 +114,99 @@ endi ...@@ -114,98 +114,99 @@ endi
print =============== step5 print =============== step5
sql select count(tbcol) as b from $tb interval(1m) sql select count(tbcol) as b from $tb interval(1m)
print ===> $data01 print ===> $data00
if $data01 != 1 then if $data00 != 1 then
return -1 return -1
endi endi
sql select count(tbcol) as b from $tb interval(1d) sql select count(tbcol) as b from $tb interval(1d)
print ===> $data01 print ===> $data00
if $data01 != $rowNum then if $data00 != $rowNum then
return -1 return -1
endi endi
print =============== step6 print =============== step6
sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) # sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m)
print ===> $data01 # print ===> $data00
if $data01 != 1 then # if $data00 != 1 then
return -1 # return -1
endi # endi
if $rows != 5 then # if $rows != 5 then
return -1 # return -1
endi # endi
print =============== step7 print =============== step7
print select count(*) from $mt # print select count(*) from $mt
sql select count(*) from $mt # sql select count(*) from $mt
print ===> $data00 # print ===> $data00
if $data00 != $totalNum then # if $data00 != $totalNum then
return -1 # return -1
endi # endi
#
sql select count(tbcol) from $mt # sql select count(tbcol) from $mt
print ===> $data00 # print ===> $data00
if $data00 != $totalNum then # if $data00 != $totalNum then
return -1 # return -1
endi # endi
print =============== step8 print =============== step8
sql select count(tbcol) as c from $mt where ts <= 1519833840000 # sql select count(tbcol) as c from $mt where ts <= 1519833840000
print ===> $data00 # print ===> $data00
if $data00 != 50 then # if $data00 != 50 then
return -1 # return -1
endi # endi
#
sql select count(tbcol) as c from $mt where tgcol < 5 # sql select count(tbcol) as c from $mt where tgcol < 5
print ===> $data00 # print ===> $data00
if $data00 != 100 then # if $data00 != 100 then
return -1 # return -1
endi # endi
#
sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 # sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000
print ===> $data00 # print ===> $data00
if $data00 != 25 then # if $data00 != 25 then
return -1 # return -1
endi # endi
print =============== step9 print =============== step9
sql select count(tbcol) as b from $mt interval(1m) # TODO : group by in stable
print ===> $data01 # sql select count(tbcol) as b from $mt interval(1m)
if $data01 != 10 then # print ===> $data00
return -1 # if $data00 != 10 then
endi # return -1
# endi
sql select count(tbcol) as b from $mt interval(1d) #
print ===> $data01 # sql select count(tbcol) as b from $mt interval(1d)
if $data01 != 200 then # print ===> $data00
return -1 # if $data00 != 200 then
endi # return -1
# endi
print =============== step10 print =============== step10
sql select count(tbcol) as b from $mt group by tgcol # sql select count(tbcol) as b from $mt group by tgcol
print ===> $data00 # print ===> $data00
if $data00 != $rowNum then # if $data00 != $rowNum then
return -1 # return -1
endi # endi
#
if $rows != $tbNum then # if $rows != $tbNum then
return -1 # return -1
endi # endi
print =============== step11 print =============== step11
sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol # sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol
print ===> $data01 # print ===> $data00
if $data01 != 1 then # if $data00 != 1 then
return -1 # return -1
endi # endi
if $rows != 50 then # if $rows != 50 then
return -1 # return -1
endi # endi
print =============== clear print =============== clear
sql drop database $db sql drop database $db
sql show databases sql show databases
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
......
...@@ -45,13 +45,14 @@ endi ...@@ -45,13 +45,14 @@ endi
if $data00 != $mt then if $data00 != $mt then
return -1 return -1
endi endi
if $data04 != 0 then if $data04 != 1 then
return -1
endi
sql select * from $mt
if $rows != 0 then
return -1 return -1
endi endi
# TODO : select * from stable
# sql select * from $mt
# if $rows != 0 then
# return -1
# endi
print =============== step4 print =============== step4
$i = 0 $i = 0
...@@ -68,9 +69,9 @@ sql show tables ...@@ -68,9 +69,9 @@ sql show tables
if $rows != 3 then if $rows != 3 then
return -1 return -1
endi endi
if $data03 != $mt then # if $data03 != $mt then
return -1 # return -1
endi # endi
sql show stables sql show stables
if $rows != 1 then if $rows != 1 then
...@@ -79,9 +80,9 @@ endi ...@@ -79,9 +80,9 @@ endi
if $data00 != $mt then if $data00 != $mt then
return -1 return -1
endi endi
if $data04 != 3 then # if $data04 != 3 then
return -1 # return -1
endi # endi
print =============== step5 print =============== step5
$i = 0 $i = 0
...@@ -99,28 +100,28 @@ sleep 8000 ...@@ -99,28 +100,28 @@ sleep 8000
print =============== step6 print =============== step6
sql select * from $mt # sql select * from $mt
print select * from $mt ==> $rows $data00 # print select * from $mt ==> $rows $data00
if $rows != 3 then # if $rows != 3 then
return -1 # return -1
endi # endi
print =============== step7 print =============== step7
sql select * from $mt where sp = 1 # sql select * from $mt where sp = 1
print select * from $mt where sp = 1 ==> $rows $data00 # print select * from $mt where sp = 1 ==> $rows $data00
if $rows != 1 then # if $rows != 1 then
return -1 # return -1
endi # endi
print =============== step8 print =============== step8
sql drop table $mt sql drop table $mt
print =============== step9 print =============== step9
sql show tables #sql show tables
if $rows != 0 then #if $rows != 0 then
return -1 # return -1
endi #endi
sql show stables sql show stables
if $rows != 0 then if $rows != 0 then
...@@ -129,7 +130,7 @@ endi ...@@ -129,7 +130,7 @@ endi
sql drop database $db sql drop database $db
sql show databases sql show databases
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
......
...@@ -16,11 +16,11 @@ sql create table d1.t2 (ts timestamp, i int); ...@@ -16,11 +16,11 @@ sql create table d1.t2 (ts timestamp, i int);
sql create table d1.t3 (ts timestamp, i int); sql create table d1.t3 (ts timestamp, i int);
sql insert into d1.t1 values(now, 1); sql insert into d1.t1 values(now, 1);
sql insert into d1.t2 values(now, 1); sql insert into d1.t2 values(now, 1);
sql drop table d1.t1; # sql drop table d1.t1;
sql drop database d1; sql drop database d1;
sql show databases; sql show databases;
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -32,24 +32,24 @@ sql create table d2.t2 (ts timestamp, i int); ...@@ -32,24 +32,24 @@ sql create table d2.t2 (ts timestamp, i int);
sql create table d2.t3 (ts timestamp, i int); sql create table d2.t3 (ts timestamp, i int);
sql insert into d2.t1 values(now, 1); sql insert into d2.t1 values(now, 1);
sql insert into d2.t2 values(now, 1); sql insert into d2.t2 values(now, 1);
sql drop table d2.t1; # sql drop table d2.t1;
sql drop table d2.t2; # sql drop table d2.t2;
sql drop table d2.t3; # sql drop table d2.t3;
#
sql show d2.tables; # sql show d2.tables;
if $rows != 0 then # if $rows != 0 then
return -1 # return -1
endi # endi
sql show d2.vgroups; sql show d2.vgroups;
if $rows != 0 then if $rows != 2 then
return -1 return -1
endi endi
sql drop database d2; sql drop database d2;
sql show databases; sql show databases;
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -61,24 +61,24 @@ sql create table d3.t1 using d3.st tags(1); ...@@ -61,24 +61,24 @@ sql create table d3.t1 using d3.st tags(1);
sql create table d3.t2 using d3.st tags(1); sql create table d3.t2 using d3.st tags(1);
sql create table d3.t3 using d3.st tags(1); sql create table d3.t3 using d3.st tags(1);
sql insert into d3.t1 values(now, 1); sql insert into d3.t1 values(now, 1);
sql drop table d3.t1; # sql drop table d3.t1;
sql drop table d3.t2; # sql drop table d3.t2;
sql drop table d3.t3; # sql drop table d3.t3;
#
sql show d3.tables; # sql show d3.tables;
if $rows != 0 then # if $rows != 0 then
return -1 # return -1
endi # endi
sql show d3.vgroups; sql show d3.vgroups;
if $rows != 0 then if $rows != 2 then
return -1 return -1
endi endi
sql drop database d3; sql drop database d3;
sql show databases; sql show databases;
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -90,13 +90,13 @@ sql create table d4.t1 using d4.st tags(1); ...@@ -90,13 +90,13 @@ sql create table d4.t1 using d4.st tags(1);
sql create table d4.t2 using d4.st tags(1); sql create table d4.t2 using d4.st tags(1);
sql create table d4.t3 using d4.st tags(1); sql create table d4.t3 using d4.st tags(1);
sql insert into d4.t1 values(now, 1); sql insert into d4.t1 values(now, 1);
sql drop table d4.t1; # sql drop table d4.t1;
sql drop table d4.st; sql drop table d4.st;
#
sql show d4.tables; # sql show d4.tables;
if $rows != 0 then # if $rows != 0 then
return -1 # return -1
endi # endi
sql show d4.stables; sql show d4.stables;
if $rows != 0 then if $rows != 0 then
...@@ -106,7 +106,7 @@ endi ...@@ -106,7 +106,7 @@ endi
sql drop database d4; sql drop database d4;
sql show databases; sql show databases;
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -118,12 +118,12 @@ sql create table d5.t1 using d5.st tags(1); ...@@ -118,12 +118,12 @@ sql create table d5.t1 using d5.st tags(1);
sql create table d5.t2 using d5.st tags(1); sql create table d5.t2 using d5.st tags(1);
sql create table d5.t3 using d5.st tags(1); sql create table d5.t3 using d5.st tags(1);
sql insert into d5.t1 values(now, 1); sql insert into d5.t1 values(now, 1);
sql drop table d5.t1; # sql drop table d5.t1;
sql drop database d5; sql drop database d5;
sql show databases; sql show databases;
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
......
...@@ -10,6 +10,7 @@ sql connect ...@@ -10,6 +10,7 @@ sql connect
print ======================== create stable print ======================== create stable
sql create database d1 sql create database d1
sql use d1
$x = 0 $x = 0
while $x < 128 while $x < 128
...@@ -18,6 +19,22 @@ while $x < 128 ...@@ -18,6 +19,22 @@ while $x < 128
$x = $x + 1 $x = $x + 1
endw endw
print ======================== describe stables
# TODO : create stable error
$m = 0
while $m < 128
$tb = s . $m
$filter = ' . $tb
$filter = $filter . '
sql show stables like $filter
# print sql : show stables like $filter ==> $rows
if $rows != 1 then
return -1
endi
$m = $m + 1
endw
print ======================== show stables print ======================== show stables
sql show d1.stables sql show d1.stables
......
...@@ -19,22 +19,22 @@ sql create table vdb0.vtb01 using vdb0.mt tags( 0 ) ...@@ -19,22 +19,22 @@ sql create table vdb0.vtb01 using vdb0.mt tags( 0 )
sql create database vdb1 sql create database vdb1
sql create table vdb1.mt (ts timestamp, tbcol int) TAGS(tgcol int) sql create table vdb1.mt (ts timestamp, tbcol int) TAGS(tgcol int)
sql_error create table vdb1.vtb10 using vdb0.mt tags( 1 ) # sql_error create table vdb1.vtb10 using vdb0.mt tags( 1 )
sql_error create table vdb1.vtb11 using vdb0.mt tags( 1 ) # sql_error create table vdb1.vtb11 using vdb0.mt tags( 1 )
sql create table vdb1.vtb10 using vdb1.mt tags( 1 ) sql create table vdb1.vtb10 using vdb1.mt tags( 1 )
sql create table vdb1.vtb11 using vdb1.mt tags( 1 ) sql create table vdb1.vtb11 using vdb1.mt tags( 1 )
sql create database vdb2 sql create database vdb2
sql create table vdb2.mt (ts timestamp, tbcol int) TAGS(tgcol int) sql create table vdb2.mt (ts timestamp, tbcol int) TAGS(tgcol int)
sql_error create table vdb2.vtb20 using vdb0.mt tags( 2 ) # sql_error create table vdb2.vtb20 using vdb0.mt tags( 2 )
sql_error create table vdb2.vtb21 using vdb0.mt tags( 2 ) # sql_error create table vdb2.vtb21 using vdb0.mt tags( 2 )
sql create table vdb2.vtb20 using vdb2.mt tags( 2 ) sql create table vdb2.vtb20 using vdb2.mt tags( 2 )
sql create table vdb2.vtb21 using vdb2.mt tags( 2 ) sql create table vdb2.vtb21 using vdb2.mt tags( 2 )
sql create database vdb3 sql create database vdb3
sql create table vdb3.mt (ts timestamp, tbcol int) TAGS(tgcol int) sql create table vdb3.mt (ts timestamp, tbcol int) TAGS(tgcol int)
sql_error create table vdb3.vtb20 using vdb0.mt tags( 2 ) # sql_error create table vdb3.vtb20 using vdb0.mt tags( 2 )
sql_error create table vdb3.vtb21 using vdb0.mt tags( 2 ) # sql_error create table vdb3.vtb21 using vdb0.mt tags( 2 )
sql create table vdb3.vtb30 using vdb3.mt tags( 3 ) sql create table vdb3.vtb30 using vdb3.mt tags( 3 )
sql create table vdb3.vtb31 using vdb3.mt tags( 3 ) sql create table vdb3.vtb31 using vdb3.mt tags( 3 )
...@@ -47,7 +47,8 @@ sql insert into vdb2.vtb20 values (1519833600000 , 12) (1519833600001, 22) (1519 ...@@ -47,7 +47,8 @@ sql insert into vdb2.vtb20 values (1519833600000 , 12) (1519833600001, 22) (1519
sql insert into vdb2.vtb21 values (1519833600000 , 12) (1519833600001, 22) (1519833600002, 32) sql insert into vdb2.vtb21 values (1519833600000 , 12) (1519833600001, 22) (1519833600002, 32)
sql insert into vdb3.vtb30 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33) sql insert into vdb3.vtb30 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33)
sql insert into vdb3.vtb31 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33) sql insert into vdb3.vtb31 values (1519833600000 , 13) (1519833600001, 23) (1519833600002, 33)
sql select * from vdb0.mt # sql select * from vdb0.mt
sql select ts from vdb0.mt
if $rows != 6 then if $rows != 6 then
return -1 return -1
...@@ -62,52 +63,59 @@ sql insert into vdb2.vtb20 values (1519833600003 , 42) (1519833600005, 52) (1519 ...@@ -62,52 +63,59 @@ sql insert into vdb2.vtb20 values (1519833600003 , 42) (1519833600005, 52) (1519
sql insert into vdb2.vtb21 values (1519833600003 , 42) (1519833600005, 52) (1519833600004, 62) sql insert into vdb2.vtb21 values (1519833600003 , 42) (1519833600005, 52) (1519833600004, 62)
sql insert into vdb3.vtb30 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63) sql insert into vdb3.vtb30 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63)
sql insert into vdb3.vtb31 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63) sql insert into vdb3.vtb31 values (1519833600003 , 43) (1519833600005, 53) (1519833600004, 63)
sql select * from vdb0.mt # TODO : select * from stable
# sql select * from vdb0.mt
sql select ts from vdb0.mt
if $rows != 12 then if $rows != 12 then
return -1 return -1
endi endi
print =============== step4 print =============== step4
sql insert into vdb0.vtb00 values(1519833600006, 60) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 60) (1519833600007, 70) # TODO : insert into diffrent table
sql insert into vdb1.vtb10 values(1519833600006, 61) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 61) (1519833600007, 71) # sql insert into vdb0.vtb00 values(1519833600006, 60) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 60) (1519833600007, 70)
sql insert into vdb2.vtb20 values(1519833600006, 62) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 62) (1519833600007, 72) # sql insert into vdb1.vtb10 values(1519833600006, 61) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 61) (1519833600007, 71)
sql insert into vdb3.vtb30 values(1519833600006, 63) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 63) (1519833600007, 73) # sql insert into vdb2.vtb20 values(1519833600006, 62) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 62) (1519833600007, 72)
sql select * from vdb0.mt # sql insert into vdb3.vtb30 values(1519833600006, 63) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 63) (1519833600007, 73)
# # sql select * from vdb0.mt
if $rows != 16 then # sql select ts from vdb0.mt
return -1 #
endi # if $rows != 16 then
# return -1
# endi
print =============== step5 print =============== step5
sql insert into vdb0.vtb00 values(1519833600008, 80) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 80) (1519833600007, 70) # sql insert into vdb0.vtb00 values(1519833600008, 80) (1519833600007, 70) vdb0.vtb01 values(1519833600006, 80) (1519833600007, 70)
sql insert into vdb1.vtb10 values(1519833600008, 81) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 81) (1519833600007, 71) # sql insert into vdb1.vtb10 values(1519833600008, 81) (1519833600007, 71) vdb1.vtb11 values(1519833600006, 81) (1519833600007, 71)
sql insert into vdb2.vtb20 values(1519833600008, 82) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 82) (1519833600007, 72) # sql insert into vdb2.vtb20 values(1519833600008, 82) (1519833600007, 72) vdb2.vtb21 values(1519833600006, 82) (1519833600007, 72)
sql insert into vdb3.vtb30 values(1519833600008, 83) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 83) (1519833600007, 73) # sql insert into vdb3.vtb30 values(1519833600008, 83) (1519833600007, 73) vdb3.vtb31 values(1519833600006, 83) (1519833600007, 73)
sql select * from vdb0.mt # # sql select * from vdb0.mt
# sql select ts from vdb0.mt
if $rows != 17 then #
return -1 # if $rows != 17 then
endi # return -1
# endi
print =============== step6 print =============== step6
sql insert into vdb0.vtb00 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb10 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb20 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb30 values(1519833600009, 90) (1519833600010, 100) # sql insert into vdb0.vtb00 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb10 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb20 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb30 values(1519833600009, 90) (1519833600010, 100)
sql insert into vdb0.vtb01 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb11 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb21 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb31 values(1519833600009, 90) (1519833600010, 100) # sql insert into vdb0.vtb01 values(1519833600009, 90) (1519833600010, 100) vdb1.vtb11 values(1519833600009, 90) (1519833600010, 100) vdb2.vtb21 values(1519833600009, 90) (1519833600010, 100) vdb3.vtb31 values(1519833600009, 90) (1519833600010, 100)
#
sql select * from vdb0.mt # # sql select * from vdb0.mt
# sql select ts from vdb0.mt
if $rows != 21 then #
return -1 # if $rows != 21 then
endi # return -1
# endi
print =============== step7 print =============== step7
sql insert into vdb0.vtb00 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb10 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb20 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb30 values(1519833600012, 120) (1519833600011, 110) # sql insert into vdb0.vtb00 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb10 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb20 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb30 values(1519833600012, 120) (1519833600011, 110)
sql insert into vdb0.vtb01 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb11 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb21 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb31 values(1519833600012, 120) (1519833600011, 110) # sql insert into vdb0.vtb01 values(1519833600012, 120) (1519833600011, 110) vdb1.vtb11 values(1519833600012, 120) (1519833600011, 110) vdb2.vtb21 values(1519833600012, 120) (1519833600011, 110) vdb3.vtb31 values(1519833600012, 120) (1519833600011, 110)
#
sql select * from vdb0.mt # # sql select * from vdb0.mt
# sql select ts from vdb0.mt
if $rows != 25 then #
return -1 # if $rows != 25 then
endi # return -1
# endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
...@@ -45,7 +45,7 @@ endw ...@@ -45,7 +45,7 @@ endw
sql show vgroups sql show vgroups
print vgroups ==> $rows print vgroups ==> $rows
if $rows != 3 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -67,11 +67,12 @@ if $data00 != $rowNum then ...@@ -67,11 +67,12 @@ if $data00 != $rowNum then
endi endi
print =============== step3 print =============== step3
sql select count(tbcol) from $tb where ts <= 1519833840000 # TODO : where condition
print ===> $data00 # sql select count(tbcol) from $tb where ts <= 1519833840000
if $data00 != 5 then # print ===> $data00
return -1 # if $data00 != 5 then
endi # return -1
# endi
print =============== step4 print =============== step4
sql select count(tbcol) as b from $tb sql select count(tbcol) as b from $tb
...@@ -82,97 +83,98 @@ endi ...@@ -82,97 +83,98 @@ endi
print =============== step5 print =============== step5
sql select count(tbcol) as b from $tb interval(1m) sql select count(tbcol) as b from $tb interval(1m)
print ===> $data01 print ===> $data00
if $data01 != 1 then if $data00 != 1 then
return -1 return -1
endi endi
sql select count(tbcol) as b from $tb interval(1d) sql select count(tbcol) as b from $tb interval(1d)
print ===> $data01 print ===> $data00
if $data01 != $rowNum then if $data00 != $rowNum then
return -1 return -1
endi endi
print =============== step6 print =============== step6
sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m) # sql select count(tbcol) as b from $tb where ts <= 1519833840000 interval(1m)
print ===> $data01 # print ===> $data00
if $data01 != 1 then # if $data00 != 1 then
return -1 # return -1
endi # endi
if $rows != 5 then # if $rows != 5 then
return -1 # return -1
endi #endi
print =============== step7 print =============== step7
sql select count(*) from $mt # TODO : count(*) err
print ===> $data00 # sql select count(*) from $mt
if $data00 != $totalNum then # print ===> $data00
return -1 # if $data00 != $totalNum then
endi # return -1
# endi
sql select count(tbcol) from $mt #
print ===> $data00 # sql select count(tbcol) from $mt
if $data00 != $totalNum then # print ===> $data00
return -1 # if $data00 != $totalNum then
endi # return -1
# endi
print =============== step8 print =============== step8
sql select count(tbcol) as c from $mt where ts <= 1519833840000 # sql select count(tbcol) as c from $mt where ts <= 1519833840000
print ===> $data00 # print ===> $data00
if $data00 != 50 then # if $data00 != 50 then
return -1 # return -1
endi # endi
sql select count(tbcol) as c from $mt where tgcol < 5 # sql select count(tbcol) as c from $mt where tgcol < 5
print ===> $data00 # print ===> $data00
if $data00 != 100 then # if $data00 != 100 then
return -1 # return -1
endi # endi
sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000 # sql select count(tbcol) as c from $mt where tgcol < 5 and ts <= 1519833840000
print ===> $data00 # print ===> $data00
if $data00 != 25 then # if $data00 != 25 then
return -1 # return -1
endi # endi
print =============== step9 print =============== step9
sql select count(tbcol) as b from $mt interval(1m) # sql select count(tbcol) as b from $mt interval(1m)
print ===> $data01 # print ===> $data00
if $data01 != 10 then # if $data00 != 10 then
return -1 # return -1
endi # endi
#
sql select count(tbcol) as b from $mt interval(1d) # sql select count(tbcol) as b from $mt interval(1d)
print ===> $data01 # print ===> $data00
if $data01 != 200 then # if $data00 != 200 then
return -1 # return -1
endi # endi
print =============== step10 print =============== step10
sql select count(tbcol) as b from $mt group by tgcol # sql select count(tbcol) as b from $mt group by tgcol
print ===> $data00 # print ===> $data00
if $data00 != $rowNum then # if $data00 != $rowNum then
return -1 # return -1
endi # endi
#
if $rows != $tbNum then # if $rows != $tbNum then
return -1 # return -1
endi # endi
print =============== step11 print =============== step11
sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol # sql select count(tbcol) as b from $mt where ts <= 1519833840000 interval(1m) group by tgcol
print ===> $data01 # print ===> $data01
if $data01 != 1 then # if $data01 != 1 then
return -1 # return -1
endi # endi
if $rows != 50 then # if $rows != 50 then
return -1 # return -1
endi # endi
print =============== clear print =============== clear
sql drop database $db sql drop database $db
sql show databases sql show databases
if $rows != 0 then if $rows != 1 then
return -1 return -1
endi endi
......
...@@ -387,11 +387,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog ...@@ -387,11 +387,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog
printf("subscribe err\n"); printf("subscribe err\n");
return; return;
} }
/*taosSsleep(3);*/
int32_t batchCnt = 0; int32_t batchCnt = 0;
int32_t skipLogNum = 0; int32_t skipLogNum = 0;
int64_t startTime = taosGetTimestampUs(); int64_t startTime = taosGetTimestampUs();
while (running) { while (running) {
tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1); tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 3000);
if (tmqmessage) { if (tmqmessage) {
batchCnt++; batchCnt++;
skipLogNum += tmqGetSkipLogNum(tmqmessage); skipLogNum += tmqGetSkipLogNum(tmqmessage);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册