Merge remote-tracking branch 'origin/3.0' into feature/3.0_liaohj
This commit is contained in:
commit
4e7e7e2157
|
@ -937,9 +937,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
|
|||
STColumn *pCol = NULL;
|
||||
STSchema *pSchema = pIter->pSchema;
|
||||
while (pIter->colIdx <= pSchema->numOfCols) {
|
||||
pCol = &pSchema->columns[pIter->colIdx];
|
||||
pCol = &pSchema->columns[pIter->colIdx]; // 1st column of schema is primary TS key
|
||||
if (colId == pCol->colId) {
|
||||
++pIter->colIdx;
|
||||
break;
|
||||
} else if (colId < pCol->colId) {
|
||||
++pIter->colIdx;
|
||||
|
@ -948,7 +947,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
|
|||
return false;
|
||||
}
|
||||
}
|
||||
return tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal);
|
||||
tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal);
|
||||
++pIter->colIdx;
|
||||
} else if (TD_IS_KV_ROW(pIter->pRow)) {
|
||||
return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal);
|
||||
} else {
|
||||
|
|
|
@ -138,59 +138,62 @@
|
|||
#define TK_INTERVAL 120
|
||||
#define TK_TOPIC 121
|
||||
#define TK_AS 122
|
||||
#define TK_EXPLAIN 123
|
||||
#define TK_ANALYZE 124
|
||||
#define TK_VERBOSE 125
|
||||
#define TK_NK_BOOL 126
|
||||
#define TK_RATIO 127
|
||||
#define TK_NULL 128
|
||||
#define TK_NK_VARIABLE 129
|
||||
#define TK_NK_UNDERLINE 130
|
||||
#define TK_ROWTS 131
|
||||
#define TK_TBNAME 132
|
||||
#define TK_QSTARTTS 133
|
||||
#define TK_QENDTS 134
|
||||
#define TK_WSTARTTS 135
|
||||
#define TK_WENDTS 136
|
||||
#define TK_WDURATION 137
|
||||
#define TK_BETWEEN 138
|
||||
#define TK_IS 139
|
||||
#define TK_NK_LT 140
|
||||
#define TK_NK_GT 141
|
||||
#define TK_NK_LE 142
|
||||
#define TK_NK_GE 143
|
||||
#define TK_NK_NE 144
|
||||
#define TK_MATCH 145
|
||||
#define TK_NMATCH 146
|
||||
#define TK_IN 147
|
||||
#define TK_JOIN 148
|
||||
#define TK_INNER 149
|
||||
#define TK_SELECT 150
|
||||
#define TK_DISTINCT 151
|
||||
#define TK_WHERE 152
|
||||
#define TK_PARTITION 153
|
||||
#define TK_BY 154
|
||||
#define TK_SESSION 155
|
||||
#define TK_STATE_WINDOW 156
|
||||
#define TK_SLIDING 157
|
||||
#define TK_FILL 158
|
||||
#define TK_VALUE 159
|
||||
#define TK_NONE 160
|
||||
#define TK_PREV 161
|
||||
#define TK_LINEAR 162
|
||||
#define TK_NEXT 163
|
||||
#define TK_GROUP 164
|
||||
#define TK_HAVING 165
|
||||
#define TK_ORDER 166
|
||||
#define TK_SLIMIT 167
|
||||
#define TK_SOFFSET 168
|
||||
#define TK_LIMIT 169
|
||||
#define TK_OFFSET 170
|
||||
#define TK_ASC 171
|
||||
#define TK_DESC 172
|
||||
#define TK_NULLS 173
|
||||
#define TK_FIRST 174
|
||||
#define TK_LAST 175
|
||||
#define TK_DESC 123
|
||||
#define TK_DESCRIBE 124
|
||||
#define TK_RESET 125
|
||||
#define TK_QUERY 126
|
||||
#define TK_EXPLAIN 127
|
||||
#define TK_ANALYZE 128
|
||||
#define TK_VERBOSE 129
|
||||
#define TK_NK_BOOL 130
|
||||
#define TK_RATIO 131
|
||||
#define TK_NULL 132
|
||||
#define TK_NK_VARIABLE 133
|
||||
#define TK_NK_UNDERLINE 134
|
||||
#define TK_ROWTS 135
|
||||
#define TK_TBNAME 136
|
||||
#define TK_QSTARTTS 137
|
||||
#define TK_QENDTS 138
|
||||
#define TK_WSTARTTS 139
|
||||
#define TK_WENDTS 140
|
||||
#define TK_WDURATION 141
|
||||
#define TK_BETWEEN 142
|
||||
#define TK_IS 143
|
||||
#define TK_NK_LT 144
|
||||
#define TK_NK_GT 145
|
||||
#define TK_NK_LE 146
|
||||
#define TK_NK_GE 147
|
||||
#define TK_NK_NE 148
|
||||
#define TK_MATCH 149
|
||||
#define TK_NMATCH 150
|
||||
#define TK_IN 151
|
||||
#define TK_JOIN 152
|
||||
#define TK_INNER 153
|
||||
#define TK_SELECT 154
|
||||
#define TK_DISTINCT 155
|
||||
#define TK_WHERE 156
|
||||
#define TK_PARTITION 157
|
||||
#define TK_BY 158
|
||||
#define TK_SESSION 159
|
||||
#define TK_STATE_WINDOW 160
|
||||
#define TK_SLIDING 161
|
||||
#define TK_FILL 162
|
||||
#define TK_VALUE 163
|
||||
#define TK_NONE 164
|
||||
#define TK_PREV 165
|
||||
#define TK_LINEAR 166
|
||||
#define TK_NEXT 167
|
||||
#define TK_GROUP 168
|
||||
#define TK_HAVING 169
|
||||
#define TK_ORDER 170
|
||||
#define TK_SLIMIT 171
|
||||
#define TK_SOFFSET 172
|
||||
#define TK_LIMIT 173
|
||||
#define TK_OFFSET 174
|
||||
#define TK_ASC 175
|
||||
#define TK_NULLS 176
|
||||
#define TK_FIRST 177
|
||||
#define TK_LAST 178
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* 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 "cmdnodes.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp);
|
|
@ -20,8 +20,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
#define DESCRIBE_RESULT_COLS 4
|
||||
#define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE)
|
||||
|
||||
typedef struct SDatabaseOptions {
|
||||
ENodeType type;
|
||||
int32_t numOfBlocks;
|
||||
|
@ -247,6 +253,13 @@ typedef struct SAlterLocalStmt {
|
|||
char value[TSDB_DNODE_VALUE_LEN];
|
||||
} SAlterLocalStmt;
|
||||
|
||||
typedef struct SDescribeStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
STableMeta* pMeta;
|
||||
} SDescribeStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -101,6 +101,8 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_DROP_TOPIC_STMT,
|
||||
QUERY_NODE_ALTER_LOCAL_STMT,
|
||||
QUERY_NODE_EXPLAIN_STMT,
|
||||
QUERY_NODE_DESCRIBE_STMT,
|
||||
QUERY_NODE_RESET_QUERY_CACHE_STMT,
|
||||
QUERY_NODE_SHOW_DATABASES_STMT,
|
||||
QUERY_NODE_SHOW_TABLES_STMT,
|
||||
QUERY_NODE_SHOW_STABLES_STMT,
|
||||
|
|
|
@ -55,6 +55,7 @@ typedef struct SQuery {
|
|||
SArray* pDbList;
|
||||
SArray* pTableList;
|
||||
bool showRewrite;
|
||||
bool localCmd;
|
||||
} SQuery;
|
||||
|
||||
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
||||
|
|
|
@ -82,6 +82,7 @@ extern "C" {
|
|||
#include "osLz4.h"
|
||||
#include "osMath.h"
|
||||
#include "osMemory.h"
|
||||
#include "osProc.h"
|
||||
#include "osRand.h"
|
||||
#include "osThread.h"
|
||||
#include "osSemaphore.h"
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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_PROC_H_
|
||||
#define _TD_OS_PROC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t taosNewProc(char **args);
|
||||
void taosSetProcName(int32_t argc, char **argv, const char *name);
|
||||
void taosSetProcPath(int32_t argc, char **argv);
|
||||
bool taosProcExists(int32_t pid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_OS_PROC_H_*/
|
|
@ -29,7 +29,6 @@ typedef struct {
|
|||
int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ;
|
||||
void taosDropShm(SShm *pShm);
|
||||
int32_t taosAttachShm(SShm *pShm);
|
||||
void taosDetachShm(SShm *pShm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
|||
void taosIgnSignal(int32_t signum);
|
||||
void taosDflSignal(int32_t signum);
|
||||
|
||||
void taosKillChildOnParentStopped();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -42,103 +42,103 @@ typedef pthread_barrierattr_t TdThreadBarrierAttr;
|
|||
// 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.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
// #define pthread_t PTHREAD_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_mutexattr_t PTHREAD_MUTEXATTR_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_once_t PTHREAD_ONCE_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_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
|
||||
// #define pthread_key_t PTHREAD_KEY_T_TYPE_TAOS_FORBID
|
||||
// #define pthread_barrier_t PTHREAD_BARRIER_T_TYPE_TAOS_FORBID
|
||||
// #define pthread_barrierattr_t PTHREAD_BARRIERATTR_T_TYPE_TAOS_FORBID
|
||||
// #define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_getdetachstate PTHREAD_ATTR_GETDETACHSTATE_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_getschedpolicy PTHREAD_ATTR_GETSCHEDPOLICY_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_getscope PTHREAD_ATTR_GETSCOPE_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_getstacksize PTHREAD_ATTR_GETSTACKSIZE_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_attr_setinheritsched PTHREAD_ATTR_SETINHERITSCHED_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_setschedparam PTHREAD_ATTR_SETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_setschedpolicy PTHREAD_ATTR_SETSCHEDPOLICY_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_setscope PTHREAD_ATTR_SETSCOPE_FUNC_TAOS_FORBID
|
||||
// #define pthread_attr_setstacksize PTHREAD_ATTR_SETSTACKSIZE_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrier_destroy PTHREAD_BARRIER_DESTROY_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrier_init PTHREAD_BARRIER_INIT_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrier_wait PTHREAD_BARRIER_WAIT_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrierattr_destroy PTHREAD_BARRIERATTR_DESTROY_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrierattr_getpshared PTHREAD_BARRIERATTR_GETPSHARED_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrierattr_init PTHREAD_BARRIERATTR_INIT_FUNC_TAOS_FORBID
|
||||
// #define pthread_barrierattr_setpshared PTHREAD_BARRIERATTR_SETPSHARED_FUNC_TAOS_FORBID
|
||||
// #define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
|
||||
// #define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
|
||||
// #define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
|
||||
// #define pthread_cond_signal PTHREAD_COND_SIGNAL_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
|
||||
#define pthread_t PTHREAD_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_mutexattr_t PTHREAD_MUTEXATTR_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_once_t PTHREAD_ONCE_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_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
|
||||
#define pthread_key_t PTHREAD_KEY_T_TYPE_TAOS_FORBID
|
||||
#define pthread_barrier_t PTHREAD_BARRIER_T_TYPE_TAOS_FORBID
|
||||
#define pthread_barrierattr_t PTHREAD_BARRIERATTR_T_TYPE_TAOS_FORBID
|
||||
#define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_getdetachstate PTHREAD_ATTR_GETDETACHSTATE_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_getschedpolicy PTHREAD_ATTR_GETSCHEDPOLICY_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_getscope PTHREAD_ATTR_GETSCOPE_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_getstacksize PTHREAD_ATTR_GETSTACKSIZE_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_attr_setinheritsched PTHREAD_ATTR_SETINHERITSCHED_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_setschedparam PTHREAD_ATTR_SETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_setschedpolicy PTHREAD_ATTR_SETSCHEDPOLICY_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_setscope PTHREAD_ATTR_SETSCOPE_FUNC_TAOS_FORBID
|
||||
#define pthread_attr_setstacksize PTHREAD_ATTR_SETSTACKSIZE_FUNC_TAOS_FORBID
|
||||
#define pthread_barrier_destroy PTHREAD_BARRIER_DESTROY_FUNC_TAOS_FORBID
|
||||
#define pthread_barrier_init PTHREAD_BARRIER_INIT_FUNC_TAOS_FORBID
|
||||
#define pthread_barrier_wait PTHREAD_BARRIER_WAIT_FUNC_TAOS_FORBID
|
||||
#define pthread_barrierattr_destroy PTHREAD_BARRIERATTR_DESTROY_FUNC_TAOS_FORBID
|
||||
#define pthread_barrierattr_getpshared PTHREAD_BARRIERATTR_GETPSHARED_FUNC_TAOS_FORBID
|
||||
#define pthread_barrierattr_init PTHREAD_BARRIERATTR_INIT_FUNC_TAOS_FORBID
|
||||
#define pthread_barrierattr_setpshared PTHREAD_BARRIERATTR_SETPSHARED_FUNC_TAOS_FORBID
|
||||
#define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
|
||||
#define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
|
||||
#define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
|
||||
#define pthread_cond_signal PTHREAD_COND_SIGNAL_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
|
||||
|
||||
int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg);
|
||||
|
|
|
@ -78,6 +78,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C)
|
||||
#define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D)
|
||||
#define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E)
|
||||
#define TSDB_CODE_INVALID_SHM_ID TAOS_DEF_ERROR_CODE(0, 0x010F)
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
|
||||
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112)
|
||||
|
|
|
@ -32,29 +32,25 @@ typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int16_t headLen, void
|
|||
ProcFuncType ftype);
|
||||
|
||||
typedef struct {
|
||||
int32_t childQueueSize;
|
||||
ProcConsumeFp childConsumeFp;
|
||||
ProcMallocFp childMallocHeadFp;
|
||||
ProcFreeFp childFreeHeadFp;
|
||||
ProcMallocFp childMallocBodyFp;
|
||||
ProcFreeFp childFreeBodyFp;
|
||||
int32_t parentQueueSize;
|
||||
ProcConsumeFp parentConsumeFp;
|
||||
ProcMallocFp parentdMallocHeadFp;
|
||||
ProcMallocFp parentMallocHeadFp;
|
||||
ProcFreeFp parentFreeHeadFp;
|
||||
ProcMallocFp parentMallocBodyFp;
|
||||
ProcFreeFp parentFreeBodyFp;
|
||||
bool testFlag;
|
||||
SShm shm;
|
||||
void *pParent;
|
||||
const char *name;
|
||||
bool isChild;
|
||||
} SProcCfg;
|
||||
|
||||
SProcObj *taosProcInit(const SProcCfg *pCfg);
|
||||
void taosProcCleanup(SProcObj *pProc);
|
||||
int32_t taosProcRun(SProcObj *pProc);
|
||||
void taosProcStop(SProcObj *pProc);
|
||||
bool taosProcIsChild(SProcObj *pProc);
|
||||
int32_t taosProcChildId(SProcObj *pProc);
|
||||
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
|
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
taos
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport nodes parser planner catalog scheduler function qcom
|
||||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "command.h"
|
||||
#include "scheduler.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdef.h"
|
||||
|
@ -170,6 +171,15 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
SRetrieveTableRsp* pRsp = NULL;
|
||||
int32_t code = qExecCommand(pQuery->pRoot, &pRsp);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg;
|
||||
pRequest->type = pMsgInfo->msgType;
|
||||
|
@ -259,7 +269,9 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, false, &pQuery), _return);
|
||||
|
||||
if (pQuery->directRpc) {
|
||||
if (pQuery->localCmd) {
|
||||
CHECK_CODE_GOTO(execLocalCmd(pRequest, pQuery), _return);
|
||||
} else if (pQuery->directRpc) {
|
||||
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return);
|
||||
} else {
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pRequest->body.pDag, pNodeList), _return);
|
||||
|
@ -464,9 +476,11 @@ static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) {
|
|||
taosMemoryFreeClear(pMsgBody->msgInfo.pData);
|
||||
taosMemoryFreeClear(pMsgBody);
|
||||
}
|
||||
|
||||
bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType) {
|
||||
return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || msgType == TDMT_VND_QUERY_HEARTBEAT_RSP;
|
||||
}
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->ahandle;
|
||||
assert(pMsg->ahandle != NULL);
|
||||
|
@ -647,6 +661,11 @@ void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pResultInfo->completed) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
|
|
|
@ -130,7 +130,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succcessed to read file %s", file);
|
||||
dDebug("succcessed to read file %s", file);
|
||||
dmPrintDnodes(pMgmt);
|
||||
|
||||
PRASE_DNODE_OVER:
|
||||
|
|
|
@ -112,6 +112,16 @@ int32_t dmInit(SMgmtWrapper *pWrapper) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitServer(pDnode) != 0) {
|
||||
dError("failed to init trans server since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitClient(pDnode) != 0) {
|
||||
dError("failed to init trans client since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
dInfo("dnode-mgmt is initialized");
|
||||
return 0;
|
||||
|
@ -122,6 +132,7 @@ void dmCleanup(SMgmtWrapper *pWrapper) {
|
|||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("dnode-mgmt start to clean up");
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
dmStopWorker(pMgmt);
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
|
@ -140,6 +151,9 @@ void dmCleanup(SMgmtWrapper *pWrapper) {
|
|||
|
||||
taosMemoryFree(pMgmt);
|
||||
pWrapper->pMgmt = NULL;
|
||||
dndCleanupServer(pDnode);
|
||||
dndCleanupClient(pDnode);
|
||||
|
||||
dInfo("dnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
taosArrayDestroy(req.pVloads);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)9527};
|
||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527};
|
||||
pMgmt->statusSent = 1;
|
||||
|
||||
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
|
||||
|
|
|
@ -30,7 +30,7 @@ static struct {
|
|||
} global = {0};
|
||||
|
||||
static void dndStopDnode(int signum, void *info, void *ctx) {
|
||||
dInfo("signal:%d is received", signum);
|
||||
dInfo("system signal:%d received", signum);
|
||||
SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
|
||||
if (pDnode != NULL) {
|
||||
dndHandleEvent(pDnode, DND_EVENT_STOP);
|
||||
|
@ -38,8 +38,10 @@ static void dndStopDnode(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);
|
||||
dInfo("sigchild received");
|
||||
if (global.pDnode != NULL) {
|
||||
dndHandleEvent(global.pDnode, DND_EVENT_CHILD);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSetSignalHandle() {
|
||||
|
@ -50,15 +52,10 @@ static void dndSetSignalHandle() {
|
|||
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
|
||||
} else if (global.ntype == DNODE || global.ntype == NODE_MAX) {
|
||||
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);
|
||||
taosKillChildOnParentStopped();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,10 +76,14 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
|||
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) {
|
||||
global.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-n") == 0) {
|
||||
global.ntype = atoi(argv[++i]);
|
||||
if (global.ntype <= DNODE || global.ntype > NODE_MAX) {
|
||||
printf("'-n' range is [1-5], default is 0\n");
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
global.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
global.dumpConfig = true;
|
||||
} else if (strcmp(argv[i], "-V") == 0) {
|
||||
|
@ -138,24 +139,24 @@ static int32_t dndInitLog() {
|
|||
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||
}
|
||||
|
||||
static void dndSetProcName(char **argv) {
|
||||
if (global.ntype != DNODE) {
|
||||
static void dndSetProcInfo(int32_t argc, char **argv) {
|
||||
taosSetProcPath(argc, argv);
|
||||
if (global.ntype != DNODE && global.ntype != NODE_MAX) {
|
||||
const char *name = dndNodeProcStr(global.ntype);
|
||||
prctl(PR_SET_NAME, name);
|
||||
strcpy(argv[0], name);
|
||||
taosSetProcName(argc, argv, name);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndRunDnode() {
|
||||
if (dndInit() != 0) {
|
||||
dError("failed to initialize environment since %s", terrstr());
|
||||
dError("failed to init environment since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeOpt option = dndGetOpt();
|
||||
SDnode *pDnode = dndCreate(&option);
|
||||
if (pDnode == NULL) {
|
||||
dError("failed to to create dnode object since %s", terrstr());
|
||||
dError("failed to to create dnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
global.pDnode = pDnode;
|
||||
|
@ -212,6 +213,6 @@ int main(int argc, char const *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
dndSetProcName((char **)argv);
|
||||
dndSetProcInfo(argc, (char **)argv);
|
||||
return dndRunDnode();
|
||||
}
|
||||
|
|
|
@ -95,13 +95,14 @@ typedef struct SMgmtWrapper {
|
|||
bool deployed;
|
||||
bool required;
|
||||
EProcType procType;
|
||||
int32_t procId;
|
||||
SProcObj *pProc;
|
||||
SShm shm;
|
||||
void *pMgmt;
|
||||
SDnode *pDnode;
|
||||
NodeMsgFp msgFps[TDMT_MAX];
|
||||
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
||||
SMgmtFp fp;
|
||||
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
||||
NodeMsgFp msgFps[TDMT_MAX];
|
||||
} SMgmtWrapper;
|
||||
|
||||
typedef struct {
|
||||
|
@ -128,26 +129,31 @@ typedef struct SDnode {
|
|||
EDndStatus status;
|
||||
EDndEvent event;
|
||||
SStartupReq startup;
|
||||
TdFilePtr runtimeFile;
|
||||
TdFilePtr lockfile;
|
||||
STransMgmt trans;
|
||||
SMgmtWrapper wrappers[NODE_MAX];
|
||||
} SDnode;
|
||||
|
||||
const char *dndNodeLogStr(ENodeType ntype);
|
||||
const char *dndNodeProcStr(ENodeType ntype);
|
||||
const char *dndEventStr(EDndEvent ev);
|
||||
EDndStatus dndGetStatus(SDnode *pDnode);
|
||||
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
|
||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
|
||||
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
||||
void dndSendMonitorReport(SDnode *pDnode);
|
||||
|
||||
int32_t dndInitServer(SDnode *pDnode);
|
||||
void dndCleanupServer(SDnode *pDnode);
|
||||
int32_t dndInitClient(SDnode *pDnode);
|
||||
void dndCleanupClient(SDnode *pDnode);
|
||||
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
||||
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
||||
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper);
|
||||
|
||||
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);
|
||||
|
||||
|
|
|
@ -50,17 +50,13 @@ void dndClose(SDnode *pDnode);
|
|||
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
|
||||
|
||||
// dndTransport.c
|
||||
int32_t dndInitServer(SDnode *pDnode);
|
||||
void dndCleanupServer(SDnode *pDnode);
|
||||
int32_t dndInitClient(SDnode *pDnode);
|
||||
void dndCleanupClient(SDnode *pDnode);
|
||||
int32_t dndInitMsgHandle(SDnode *pDnode);
|
||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
||||
|
||||
// dndFile.c
|
||||
int32_t dndOpenRuntimeFile(SDnode *pDnode);
|
||||
int32_t dndWriteRuntimeFile(SDnode *pDnode);
|
||||
void dndCloseRuntimeFile(SDnode *pDnode);
|
||||
TdFilePtr dndCheckRunning(const char *dataDir);
|
||||
int32_t dndReadShmFile(SDnode *pDnode);
|
||||
int32_t dndWriteShmFile(SDnode *pDnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -16,18 +16,9 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
|
||||
static void dndResetLog(SMgmtWrapper *pMgmt) {
|
||||
char logname[24] = {0};
|
||||
snprintf(logname, sizeof(logname), "%slog", pMgmt->name);
|
||||
|
||||
dInfo("node:%s, reset log to %s in child process", pMgmt->name, logname);
|
||||
taosCloseLog();
|
||||
taosInitLog(logname, 1);
|
||||
}
|
||||
|
||||
static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
||||
bool required = false;
|
||||
int32_t code =(*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||
bool required = false;
|
||||
int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||
if (!required) {
|
||||
dDebug("node:%s, no need to start", pWrapper->name);
|
||||
} else {
|
||||
|
@ -37,14 +28,18 @@ static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
|||
}
|
||||
|
||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = (*pWrapper->fp.openFp)(pWrapper);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
}
|
||||
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
return 0;
|
||||
}
|
||||
|
@ -70,54 +65,6 @@ void dndCloseNode(SMgmtWrapper *pWrapper) {
|
|||
dDebug("node:%s, has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in single process mode");
|
||||
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("node:%s, will start in single process", pWrapper->name);
|
||||
pWrapper->procType = PROC_SINGLE;
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->fp.startFp == NULL) continue;
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) {
|
||||
// dndCleanupServer(pDnode);
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
if (except == n) continue;
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
ProcFuncType ftype) {
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
|
@ -163,82 +110,57 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t
|
|||
taosMemoryFree(pMsg);
|
||||
}
|
||||
|
||||
static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in multi process mode");
|
||||
static int32_t dndNewProc(SMgmtWrapper *pWrapper, ENodeType n) {
|
||||
char tstr[8] = {0};
|
||||
char *args[6] = {0};
|
||||
snprintf(tstr, sizeof(tstr), "%d", n);
|
||||
args[1] = "-c";
|
||||
args[2] = configDir;
|
||||
args[3] = "-n";
|
||||
args[4] = tstr;
|
||||
args[5] = NULL;
|
||||
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
int32_t pid = taosNewProc(args);
|
||||
if (pid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->procId = pid;
|
||||
dInfo("node:%s, run in new process, pid:%d", pWrapper->name, pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->shm,
|
||||
.pParent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in single process");
|
||||
|
||||
for (ENodeType n = DNODE; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n == DNODE) {
|
||||
dInfo("node:%s, will start in parent process", pWrapper->name);
|
||||
pWrapper->procType = PROC_SINGLE;
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
SProcCfg cfg = {.childQueueSize = 1024 * 1024 * 2, // size will be a configuration item
|
||||
.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentQueueSize = 1024 * 1024 * 2, // size will be a configuration item
|
||||
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
||||
.parentdMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.pParent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
SProcObj *pProc = taosProcInit(&cfg);
|
||||
if (pProc == NULL) {
|
||||
dError("node:%s, failed to fork since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->pProc = pProc;
|
||||
|
||||
if (taosProcIsChild(pProc)) {
|
||||
dInfo("node:%s, will start in child process", pWrapper->name);
|
||||
pWrapper->procType = PROC_CHILD;
|
||||
dndResetLog(pWrapper);
|
||||
|
||||
dInfo("node:%s, clean up resources inherited from parent", pWrapper->name);
|
||||
dndClearNodesExecpt(pDnode, n);
|
||||
|
||||
dInfo("node:%s, will be initialized in child process", pWrapper->name);
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
dInfo("node:%s, failed to init in child process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosProcRun(pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
dInfo("node:%s, will not start in parent process, child pid:%d", pWrapper->name, taosProcChildId(pProc));
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
if (taosProcRun(pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
@ -247,32 +169,14 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->fp.startFp == NULL) continue;
|
||||
if (pWrapper->procType == PROC_PARENT && n != DNODE) continue;
|
||||
if (pWrapper->procType == PROC_CHILD && n == DNODE) continue;
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndRun(SDnode *pDnode) {
|
||||
if (!tsMultiProcess) {
|
||||
if (dndRunInSingleProcess(pDnode) != 0) {
|
||||
dError("failed to run dnode in single process mode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (dndRunInMultiProcess(pDnode) != 0) {
|
||||
dError("failed to run dnode in multi process mode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
|
||||
while (1) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("dnode is about to stop");
|
||||
|
@ -283,3 +187,146 @@ int32_t dndRun(SDnode *pDnode) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in parent process");
|
||||
SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE];
|
||||
if (dndOpenNode(pDWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
int32_t shmsize = 1024 * 1024 * 2; // size will be a configuration item
|
||||
if (taosCreateShm(&pWrapper->shm, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (dndWriteShmFile(pDnode) != 0) {
|
||||
dError("failed to write runtime file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (pDnode->ntype == NODE_MAX) {
|
||||
dInfo("node:%s, should be started manually", pWrapper->name);
|
||||
} else {
|
||||
if (dndNewProc(pWrapper, n) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
|
||||
while (1) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("dnode is about to stop");
|
||||
break;
|
||||
}
|
||||
|
||||
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pDnode->ntype == NODE_MAX) continue;
|
||||
|
||||
if (pWrapper->procId != 0 && !taosProcExists(pWrapper->procId)) {
|
||||
dInfo("node:%s, process not exist, pid:%d", pWrapper->name, pWrapper->procId);
|
||||
dndNewProc(pWrapper, n);
|
||||
}
|
||||
|
||||
taosMsleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunInChildProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in child process");
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
pWrapper->procType = PROC_CHILD;
|
||||
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = true;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->fp.startFp != NULL) {
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
while (1) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("dnode is about to stop");
|
||||
break;
|
||||
}
|
||||
taosMsleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndRun(SDnode *pDnode) {
|
||||
if (!tsMultiProcess) {
|
||||
return dndRunInSingleProcess(pDnode);
|
||||
} else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
return dndRunInParentProcess(pDnode);
|
||||
} else {
|
||||
return dndRunInChildProcess(pDnode);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,30 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndOpenRuntimeFile(SDnode *pDnode) {
|
||||
TdFilePtr dndCheckRunning(const char *dataDir) {
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int32_t dndReadShmFile(SDnode *pDnode) {
|
||||
int32_t code = -1;
|
||||
char itemName[24] = {0};
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
@ -125,17 +148,11 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
|
|||
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);
|
||||
snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
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());
|
||||
dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -162,10 +179,10 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tsMultiProcess || pDnode->ntype == DNODE) {
|
||||
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
if (pWrapper->shm.id > 0) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
if (pWrapper->shm.id >= 0) {
|
||||
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
|
||||
taosDropShm(&pWrapper->shm);
|
||||
}
|
||||
|
@ -174,27 +191,23 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
|
|||
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());
|
||||
dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
dDebug("shmid:%d, is attached, size:%d", pWrapper->shm.id, pWrapper->shm.size);
|
||||
dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size);
|
||||
}
|
||||
|
||||
dDebug("successed to open %s", file);
|
||||
dDebug("successed to load %s", file);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (code != 0) {
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
} else {
|
||||
pDnode->runtimeFile = pFile;
|
||||
}
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dndWriteRuntimeFile(SDnode *pDnode) {
|
||||
int32_t dndWriteShmFile(SDnode *pDnode) {
|
||||
int32_t code = -1;
|
||||
int32_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
@ -202,8 +215,8 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
|
|||
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);
|
||||
snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
|
@ -214,12 +227,12 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
|
|||
|
||||
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);
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[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);
|
||||
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, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size);
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, MAXLEN - len, "}\n");
|
||||
|
@ -244,7 +257,7 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dDebug("successed to write %s", realfile);
|
||||
dInfo("successed to write %s", realfile);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
@ -254,11 +267,3 @@ _OVER:
|
|||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dndCloseRuntimeFile(SDnode *pDnode) {
|
||||
if (pDnode->runtimeFile) {
|
||||
taosUnLockFile(pDnode->runtimeFile);
|
||||
taosCloseFile(&pDnode->runtimeFile);
|
||||
pDnode->runtimeFile = NULL;
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ int32_t dndInit() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode env is initialized");
|
||||
dInfo("dnode env is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ void dndCleanup() {
|
|||
monCleanup();
|
||||
walCleanUp();
|
||||
taosStopCacheRefreshWorker();
|
||||
dDebug("dnode env is cleaned up");
|
||||
dInfo("dnode env is cleaned up");
|
||||
}
|
||||
|
||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
|
||||
|
|
|
@ -66,7 +66,7 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user);
|
||||
code = (*msgFp)(pWrapper, pMsg);
|
||||
} else if (pWrapper->procType == PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle,
|
||||
dTrace("msg:%p, is created and put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle,
|
||||
pRpc->ahandle, pMsg->user);
|
||||
code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, PROC_REQ);
|
||||
} else {
|
||||
|
|
|
@ -34,6 +34,14 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
pDnode->lockfile = dndCheckRunning(pDnode->dataDir);
|
||||
if (pDnode->lockfile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -42,18 +50,22 @@ static void dndClearVars(SDnode *pDnode) {
|
|||
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
||||
taosMemoryFreeClear(pMgmt->path);
|
||||
}
|
||||
dndCloseRuntimeFile(pDnode);
|
||||
if (pDnode->lockfile != NULL) {
|
||||
taosUnLockFile(pDnode->lockfile);
|
||||
taosCloseFile(&pDnode->lockfile);
|
||||
pDnode->lockfile = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pDnode->localEp);
|
||||
taosMemoryFreeClear(pDnode->localFqdn);
|
||||
taosMemoryFreeClear(pDnode->firstEp);
|
||||
taosMemoryFreeClear(pDnode->secondEp);
|
||||
taosMemoryFreeClear(pDnode->dataDir);
|
||||
taosMemoryFree(pDnode);
|
||||
dDebug("dnode object memory is cleared, data:%p", pDnode);
|
||||
dDebug("dnode memory is cleared, data:%p", pDnode);
|
||||
}
|
||||
|
||||
SDnode *dndCreate(const SDnodeOpt *pOption) {
|
||||
dInfo("start to create dnode object");
|
||||
dDebug("start to create dnode object");
|
||||
int32_t code = -1;
|
||||
char path[PATH_MAX] = {0};
|
||||
SDnode *pDnode = NULL;
|
||||
|
@ -77,29 +89,11 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
|||
smGetMgmtFp(&pDnode->wrappers[SNODE]);
|
||||
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
|
||||
|
||||
if (dndOpenRuntimeFile(pDnode) != 0) {
|
||||
dError("failed to open runtime file since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndInitServer(pDnode) != 0) {
|
||||
dError("failed to init trans server since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndInitClient(pDnode) != 0) {
|
||||
dError("failed to init trans client since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndInitMsgHandle(pDnode) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name);
|
||||
pWrapper->path = strdup(path);
|
||||
pWrapper->shm.id = -1;
|
||||
pWrapper->pDnode = pDnode;
|
||||
if (pWrapper->path == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -110,15 +104,27 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
|||
taosInitRWLatch(&pWrapper->latch);
|
||||
}
|
||||
|
||||
if (dndInitMsgHandle(pDnode) != 0) {
|
||||
dError("failed to msg handles since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndReadShmFile(pDnode) != 0) {
|
||||
dError("failed to read shm file since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
dInfo("dnode is created, data:%p", pDnode);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (code != 0 && pDnode) {
|
||||
dndClearVars(pDnode);
|
||||
pDnode = NULL;
|
||||
dError("failed to create dnode object since %s", terrstr());
|
||||
} else {
|
||||
dInfo("dnode object is created, data:%p", pDnode);
|
||||
dError("failed to create dnode since %s", terrstr());
|
||||
}
|
||||
|
||||
return pDnode;
|
||||
|
@ -135,21 +141,20 @@ void dndClose(SDnode *pDnode) {
|
|||
dInfo("start to close dnode, data:%p", pDnode);
|
||||
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
|
||||
dndCleanupServer(pDnode);
|
||||
dndCleanupClient(pDnode);
|
||||
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dndCloseNode(pWrapper);
|
||||
}
|
||||
|
||||
dndClearVars(pDnode);
|
||||
dInfo("dnode object is closed, data:%p", pDnode);
|
||||
dInfo("dnode is closed, data:%p", pDnode);
|
||||
}
|
||||
|
||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event) {
|
||||
dInfo("dnode object receive event %d, data:%p", event, pDnode);
|
||||
pDnode->event = event;
|
||||
dInfo("dnode receive %s event, data:%p", dndEventStr(event), pDnode);
|
||||
if (event == DND_EVENT_STOP) {
|
||||
pDnode->event = event;
|
||||
}
|
||||
}
|
||||
|
||||
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType ntype) {
|
||||
|
|
|
@ -62,3 +62,16 @@ const char *dndNodeProcStr(ENodeType ntype) {
|
|||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dndEventStr(EDndEvent ev) {
|
||||
switch (ev) {
|
||||
case DND_EVENT_START:
|
||||
return "start";
|
||||
case DND_EVENT_STOP:
|
||||
return "stop";
|
||||
case DND_EVENT_CHILD:
|
||||
return "child";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void
|
|||
return len;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
|
||||
static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) {
|
||||
int code = taosThreadRwlockRdlock(&(pEnv->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -60,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
|
||||
static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) {
|
||||
int code = taosThreadRwlockWrlock(&(pEnv->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -69,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) {
|
||||
static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
|
||||
int code = taosThreadRwlockUnlock(&(pEnv->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
|
|
@ -651,9 +651,8 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
|
|||
*/
|
||||
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen) {
|
||||
SDBFile *pDBFile = &pSmaH->dFile;
|
||||
tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d",
|
||||
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen);
|
||||
printf("\nvgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 "\n",
|
||||
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen);
|
||||
|
||||
// TODO: insert sma data blocks into B+Tree(TDB)
|
||||
if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) {
|
||||
|
@ -874,7 +873,6 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
|
||||
// key: skey + groupId
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
void *pSmaKey = &smaKey;
|
||||
char dataBuf[512] = {0};
|
||||
void *pDataBuf = &dataBuf;
|
||||
int32_t sz = taosArrayGetSize(pDataBlocks);
|
||||
|
@ -887,6 +885,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
for (int32_t j = 0; j < rows; ++j) {
|
||||
printf("|");
|
||||
TSKEY skey = TSKEY_INITIAL_VAL; // the start key of TS window by interval
|
||||
void *pSmaKey = &smaKey;
|
||||
int32_t tlen = 0;
|
||||
for (int32_t k = 0; k < colNum; ++k) {
|
||||
SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
|
@ -894,7 +893,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
switch (pColInfoData->info.type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
skey = *(TSKEY *)var;
|
||||
printf(" skey = %" PRIi64 " groupId = %" PRId64 "|", skey, groupId);
|
||||
printf("==> skey = %" PRIi64 " groupId = %" PRId64 "|", skey, groupId);
|
||||
tsdbEncodeTSmaKey(groupId, skey, &pSmaKey);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
|
@ -976,7 +975,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
|||
}
|
||||
}
|
||||
|
||||
if (tsdbInsertTSmaBlocks(&tSmaH, pSmaKey, SMA_KEY_LEN, pDataBuf, tlen) != 0) {
|
||||
if (tsdbInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, pDataBuf, tlen) != 0) {
|
||||
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));
|
||||
|
@ -1308,22 +1307,19 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
void *pSmaKey = &smaKey;
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
void *pSmaKey = &smaKey;
|
||||
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),
|
||||
tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN);
|
||||
tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb),
|
||||
tReadH.dFile.path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), SMA_KEY_LEN);
|
||||
|
||||
void *result = NULL;
|
||||
uint32_t valueSize = 0;
|
||||
if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) {
|
||||
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64
|
||||
" since %s",
|
||||
REPO_ID(pTsdb), indexUid, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), tstrerror(terrno));
|
||||
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
||||
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
||||
tsdbCloseDBF(&tReadH.dFile);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
|
|
@ -59,20 +59,21 @@ TEST(testCase, unionEncodeDecodeTest) {
|
|||
|
||||
void *buf = taosMemoryMalloc(1024);
|
||||
void *pBuf = buf;
|
||||
void *qBuf = buf;
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedU8(&buf, sut.info);
|
||||
tlen += taosEncodeFixedI16(&buf, sut.nBSmaCols);
|
||||
tlen += taosEncodeFixedU8(&pBuf, sut.info);
|
||||
tlen += taosEncodeFixedI16(&pBuf, sut.nBSmaCols);
|
||||
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
|
||||
tlen += taosEncodeFixedI16(&buf, sut.pBSmaCols[i]);
|
||||
tlen += taosEncodeFixedI16(&pBuf, sut.pBSmaCols[i]);
|
||||
}
|
||||
|
||||
SUnionTest dut = {0};
|
||||
pBuf = taosDecodeFixedU8(pBuf, &dut.info);
|
||||
pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols);
|
||||
qBuf = taosDecodeFixedU8(qBuf, &dut.info);
|
||||
qBuf = taosDecodeFixedI16(qBuf, &dut.nBSmaCols);
|
||||
if (dut.nBSmaCols > 0) {
|
||||
dut.pBSmaCols = (col_id_t *)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t));
|
||||
for (col_id_t i = 0; i < dut.nBSmaCols; ++i) {
|
||||
pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i);
|
||||
qBuf = taosDecodeFixedI16(qBuf, dut.pBSmaCols + i);
|
||||
}
|
||||
} else {
|
||||
dut.pBSmaCols = NULL;
|
||||
|
@ -81,13 +82,17 @@ TEST(testCase, unionEncodeDecodeTest) {
|
|||
printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info);
|
||||
printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info);
|
||||
|
||||
ASSERT_EQ(sut.rollup, dut.rollup);
|
||||
ASSERT_EQ(sut.type, dut.type);
|
||||
ASSERT_EQ(sut.nBSmaCols, dut.nBSmaCols);
|
||||
EXPECT_EQ(sut.rollup, dut.rollup);
|
||||
EXPECT_EQ(sut.type, dut.type);
|
||||
EXPECT_EQ(sut.nBSmaCols, dut.nBSmaCols);
|
||||
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
|
||||
ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]);
|
||||
ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), dut.pBSmaCols[i]);
|
||||
EXPECT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]);
|
||||
EXPECT_EQ(*(col_id_t *)(sut.pBSmaCols + i), dut.pBSmaCols[i]);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(buf);
|
||||
taosMemoryFreeClear(dut.pBSmaCols);
|
||||
taosMemoryFreeClear(sut.pBSmaCols);
|
||||
}
|
||||
#if 1
|
||||
TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
||||
|
@ -107,37 +112,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
|||
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
||||
|
||||
void *buf = taosMemoryCalloc(1, bufLen);
|
||||
ASSERT_NE(buf, nullptr);
|
||||
EXPECT_NE(buf, nullptr);
|
||||
|
||||
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
||||
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
|
||||
|
||||
ASSERT_EQ(len, bufLen);
|
||||
EXPECT_EQ(len, bufLen);
|
||||
|
||||
// decode
|
||||
STSmaWrapper dstTSmaWrapper = {0};
|
||||
void *result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper);
|
||||
ASSERT_NE(result, nullptr);
|
||||
EXPECT_NE(result, nullptr);
|
||||
|
||||
ASSERT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
||||
EXPECT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
||||
|
||||
for (int i = 0; i < tSmaWrapper.number; ++i) {
|
||||
STSma *pSma = tSmaWrapper.tSma + i;
|
||||
STSma *qSma = dstTSmaWrapper.tSma + i;
|
||||
|
||||
ASSERT_EQ(pSma->version, qSma->version);
|
||||
ASSERT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
||||
ASSERT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
||||
ASSERT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
||||
ASSERT_EQ(pSma->timezoneInt, qSma->timezoneInt);
|
||||
ASSERT_EQ(pSma->indexUid, qSma->indexUid);
|
||||
ASSERT_EQ(pSma->tableUid, qSma->tableUid);
|
||||
ASSERT_EQ(pSma->interval, qSma->interval);
|
||||
ASSERT_EQ(pSma->sliding, qSma->sliding);
|
||||
ASSERT_EQ(pSma->exprLen, qSma->exprLen);
|
||||
ASSERT_STRCASEEQ(pSma->expr, qSma->expr);
|
||||
ASSERT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
||||
ASSERT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
||||
EXPECT_EQ(pSma->version, qSma->version);
|
||||
EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
||||
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
||||
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
||||
EXPECT_EQ(pSma->timezoneInt, qSma->timezoneInt);
|
||||
EXPECT_EQ(pSma->indexUid, qSma->indexUid);
|
||||
EXPECT_EQ(pSma->tableUid, qSma->tableUid);
|
||||
EXPECT_EQ(pSma->interval, qSma->interval);
|
||||
EXPECT_EQ(pSma->sliding, qSma->sliding);
|
||||
EXPECT_EQ(pSma->exprLen, qSma->exprLen);
|
||||
EXPECT_STRCASEEQ(pSma->expr, qSma->expr);
|
||||
EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
||||
EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
||||
}
|
||||
|
||||
// resource release
|
||||
|
@ -173,12 +178,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
|
||||
tSma.exprLen = strlen(expr);
|
||||
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1);
|
||||
ASSERT_NE(tSma.expr, nullptr);
|
||||
EXPECT_NE(tSma.expr, nullptr);
|
||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||
|
||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||
tSma.tagsFilter = (char *)taosMemoryCalloc(tSma.tagsFilterLen + 1, 1);
|
||||
ASSERT_NE(tSma.tagsFilter, nullptr);
|
||||
EXPECT_NE(tSma.tagsFilter, nullptr);
|
||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||
|
||||
SMeta *pMeta = NULL;
|
||||
|
@ -190,7 +195,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||
assert(pMeta != NULL);
|
||||
// save index 1
|
||||
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
|
||||
pSmaCfg->indexUid = indexUid2;
|
||||
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
|
||||
|
@ -201,7 +206,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
pSmaCfg->sliding = 5;
|
||||
|
||||
// save index 2
|
||||
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
|
||||
// get value by indexName
|
||||
STSma *qSmaCfg = NULL;
|
||||
|
@ -211,8 +216,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
|
||||
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
||||
ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
||||
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
||||
tdDestroyTSma(qSmaCfg);
|
||||
taosMemoryFreeClear(qSmaCfg);
|
||||
|
||||
|
@ -222,8 +227,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
|
||||
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
||||
ASSERT_EQ(qSmaCfg->interval, tSma.interval);
|
||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
||||
EXPECT_EQ(qSmaCfg->interval, tSma.interval);
|
||||
tdDestroyTSma(qSmaCfg);
|
||||
taosMemoryFreeClear(qSmaCfg);
|
||||
|
||||
|
@ -239,25 +244,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
printf("indexName = %s\n", indexName);
|
||||
++indexCnt;
|
||||
}
|
||||
ASSERT_EQ(indexCnt, nCntTSma);
|
||||
EXPECT_EQ(indexCnt, nCntTSma);
|
||||
metaCloseSmaCurosr(pSmaCur);
|
||||
|
||||
// get wrapper by table uid
|
||||
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
|
||||
assert(pSW != NULL);
|
||||
ASSERT_EQ(pSW->number, nCntTSma);
|
||||
ASSERT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
||||
ASSERT_EQ(pSW->tSma->timezoneInt, timezone);
|
||||
ASSERT_STRCASEEQ(pSW->tSma->expr, expr);
|
||||
ASSERT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
||||
ASSERT_EQ(pSW->tSma->indexUid, indexUid1);
|
||||
ASSERT_EQ(pSW->tSma->tableUid, tbUid);
|
||||
ASSERT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
||||
ASSERT_EQ((pSW->tSma + 1)->timezoneInt, timezone);
|
||||
ASSERT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
||||
ASSERT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
||||
ASSERT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
||||
ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
||||
EXPECT_EQ(pSW->number, nCntTSma);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
||||
EXPECT_EQ(pSW->tSma->timezoneInt, timezone);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->expr, expr);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
||||
EXPECT_EQ(pSW->tSma->indexUid, indexUid1);
|
||||
EXPECT_EQ(pSW->tSma->tableUid, tbUid);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
||||
EXPECT_EQ((pSW->tSma + 1)->timezoneInt, timezone);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
||||
EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
||||
EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
||||
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
|
@ -269,7 +274,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i));
|
||||
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i));
|
||||
}
|
||||
ASSERT_EQ(taosArrayGetSize(pUids), 1);
|
||||
EXPECT_EQ(taosArrayGetSize(pUids), 1);
|
||||
taosArrayDestroy(pUids);
|
||||
|
||||
// resource release
|
||||
|
@ -311,12 +316,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
|
||||
tSma.exprLen = strlen(expr);
|
||||
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1);
|
||||
ASSERT_NE(tSma.expr, nullptr);
|
||||
EXPECT_NE(tSma.expr, nullptr);
|
||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||
|
||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||
tSma.tagsFilter = (char *)taosMemoryCalloc(1, tSma.tagsFilterLen + 1);
|
||||
ASSERT_NE(tSma.tagsFilter, nullptr);
|
||||
EXPECT_NE(tSma.tagsFilter, nullptr);
|
||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||
|
||||
SMeta *pMeta = NULL;
|
||||
|
@ -328,7 +333,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||
assert(pMeta != NULL);
|
||||
// save index 1
|
||||
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
|
||||
// step 2: insert data
|
||||
STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb));
|
||||
|
@ -365,7 +370,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN);
|
||||
int32_t numOfDisks = 1;
|
||||
pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks);
|
||||
ASSERT_NE(pTsdb->pTfs, nullptr);
|
||||
EXPECT_NE(pTsdb->pTfs, nullptr);
|
||||
|
||||
// generate SSubmitReq msg and update expired window
|
||||
int16_t schemaVer = 0;
|
||||
|
@ -375,7 +380,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
uint32_t msgLen = sizeof(SSubmitReq) + mockBlkNum * sizeof(SSubmitBlk) + mockBlkNum * mockRowNum * mockRowLen;
|
||||
|
||||
SSubmitReq *pMsg = (SSubmitReq *)taosMemoryCalloc(1, msgLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
EXPECT_NE(pMsg, nullptr);
|
||||
pMsg->version = htobe64(schemaVer);
|
||||
pMsg->numOfBlocks = htonl(mockBlkNum);
|
||||
pMsg->length = htonl(msgLen);
|
||||
|
@ -401,9 +406,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||
|
||||
ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0);
|
||||
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0);
|
||||
|
||||
// init
|
||||
const int32_t tSmaGroupSize = 4;
|
||||
|
@ -413,7 +418,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
const int32_t tSmaNumOfRows = 2;
|
||||
|
||||
SArray *pDataBlocks = taosArrayInit(tSmaGroupSize, sizeof(SSDataBlock *));
|
||||
ASSERT_NE(pDataBlocks, nullptr);
|
||||
EXPECT_NE(pDataBlocks, nullptr);
|
||||
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};
|
||||
|
@ -427,18 +432,18 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
|
||||
for (int32_t g = 0; g < tSmaGroupSize; ++g) {
|
||||
SSDataBlock *pDataBlock = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
ASSERT_NE(pDataBlock, nullptr);
|
||||
EXPECT_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);
|
||||
EXPECT_NE(pDataBlock->pDataBlock, nullptr);
|
||||
for (int32_t c = 0; c < tSmaNumOfCols; ++c) {
|
||||
|
||||
SColumnInfoData *pColInfoData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData));
|
||||
ASSERT_NE(pColInfoData, nullptr);
|
||||
EXPECT_NE(pColInfoData, nullptr);
|
||||
|
||||
pColInfoData->info.type = tSmaTypeArray[c];
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
|
@ -481,7 +486,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2 + 1], varDataLen(pCellData));
|
||||
break;
|
||||
default:
|
||||
ASSERT_EQ(0, 1); // add definition
|
||||
EXPECT_EQ(0, 1); // add definition
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +498,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
}
|
||||
|
||||
// execute
|
||||
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, tSma.indexUid, (const char *)pDataBlocks), TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(tsdbInsertTSmaData(pTsdb, tSma.indexUid, (const char *)pDataBlocks), TSDB_CODE_SUCCESS);
|
||||
|
||||
#if 0
|
||||
STSmaDataWrapper *pSmaData = NULL;
|
||||
|
@ -512,7 +517,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
int32_t tableDataLen = sizeof(STSmaTbData);
|
||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
||||
if (bufSize - len - tableDataLen < buffer) {
|
||||
ASSERT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
||||
EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
||||
pSmaData = (STSmaDataWrapper *)buf;
|
||||
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
||||
bufSize = taosTSizeof(buf);
|
||||
|
@ -539,14 +544,14 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
}
|
||||
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
|
||||
|
||||
ASSERT_GE(bufSize, pSmaData->dataLen);
|
||||
EXPECT_GE(bufSize, pSmaData->dataLen);
|
||||
// execute
|
||||
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||
#endif
|
||||
|
||||
// step 3: query
|
||||
uint32_t checkDataCnt = 0;
|
||||
ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, skey1, 1), TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, skey1, 1), TSDB_CODE_SUCCESS);
|
||||
++checkDataCnt;
|
||||
|
||||
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
|
||||
|
@ -555,11 +560,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
taosMemoryFreeClear(pMsg);
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pDataBlocks); ++i) {
|
||||
SSDataBlock *pDataBlock = (SSDataBlock *)taosArrayGet(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);
|
||||
SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, j);
|
||||
colDataDestroy(pColInfoData);
|
||||
taosMemoryFreeClear(pColInfoData);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pDataBlock->pDataBlock);
|
||||
|
|
|
@ -17,3 +17,4 @@ add_subdirectory(tfs)
|
|||
add_subdirectory(monitor)
|
||||
add_subdirectory(nodes)
|
||||
add_subdirectory(scalar)
|
||||
add_subdirectory(command)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
aux_source_directory(src COMMAND_SRC)
|
||||
add_library(command STATIC ${COMMAND_SRC})
|
||||
target_include_directories(
|
||||
command
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/command"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
command
|
||||
PRIVATE os util nodes catalog function transport qcom
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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 "command.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
// #define SET_VARSTR(pData, val, pOffset)
|
||||
|
||||
static void buildRspData(const STableMeta* pMeta, char* pData) {
|
||||
int32_t* pColSizes = (int32_t*)pData;
|
||||
pData += DESCRIBE_RESULT_COLS * sizeof(int32_t);
|
||||
int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta);
|
||||
|
||||
// Field
|
||||
int32_t* pOffset = (int32_t*)pData;
|
||||
pData += numOfRows * sizeof(int32_t);
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
STR_TO_VARSTR(pData, pMeta->schema[i].name);
|
||||
int16_t len = varDataTLen(pData);
|
||||
pData += len;
|
||||
*pOffset = pColSizes[0];
|
||||
pOffset += 1;
|
||||
pColSizes[0] += len;
|
||||
}
|
||||
|
||||
// Type
|
||||
pOffset = (int32_t*)pData;
|
||||
pData += numOfRows * sizeof(int32_t);
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
STR_TO_VARSTR(pData, tDataTypes[pMeta->schema[i].type].name);
|
||||
int16_t len = varDataTLen(pData);
|
||||
pData += len;
|
||||
*pOffset = pColSizes[1];
|
||||
pOffset += 1;
|
||||
pColSizes[1] += len;
|
||||
}
|
||||
|
||||
// Length
|
||||
pData += BitmapLen(numOfRows);
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
*(int32_t*)pData = pMeta->schema[i].bytes;
|
||||
pData += sizeof(int32_t);
|
||||
}
|
||||
pColSizes[2] = sizeof(int32_t) * numOfRows;
|
||||
|
||||
// Note
|
||||
pOffset = (int32_t*)pData;
|
||||
pData += numOfRows * sizeof(int32_t);
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
STR_TO_VARSTR(pData, i >= pMeta->tableInfo.numOfColumns ? "TAG" : "");
|
||||
int16_t len = varDataTLen(pData);
|
||||
pData += len;
|
||||
*pOffset = pColSizes[3];
|
||||
pOffset += 1;
|
||||
pColSizes[3] += len;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < DESCRIBE_RESULT_COLS; ++i) {
|
||||
pColSizes[i] = htonl(pColSizes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t calcRspSize(const STableMeta* pMeta) {
|
||||
int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta);
|
||||
return sizeof(SRetrieveTableRsp) +
|
||||
(numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_FIELD_LEN) +
|
||||
(numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_TYPE_LEN) +
|
||||
(BitmapLen(numOfRows) + numOfRows * sizeof(int32_t)) +
|
||||
(numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_NOTE_LEN);
|
||||
}
|
||||
|
||||
static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SDescribeStmt* pDesc = (SDescribeStmt*)pStmt;
|
||||
*pRsp = taosMemoryCalloc(1, calcRspSize(pDesc->pMeta));
|
||||
if (NULL == *pRsp) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(*pRsp)->useconds = 0;
|
||||
(*pRsp)->completed = 1;
|
||||
(*pRsp)->precision = 0;
|
||||
(*pRsp)->compressed = 0;
|
||||
(*pRsp)->compLen = 0;
|
||||
(*pRsp)->numOfRows = htonl(TABLE_TOTAL_COL_NUM(pDesc->pMeta));
|
||||
buildRspData(pDesc->pMeta, (*pRsp)->data);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t execResetQueryCache() {
|
||||
// todo
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return execDescribe(pStmt, pRsp);
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT:
|
||||
return execResetQueryCache();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
MESSAGE(STATUS "build command unit test")
|
||||
|
||||
# GoogleTest requires at least C++11
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
ADD_EXECUTABLE(commandTest ${SOURCE_LIST})
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
commandTest
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/command/"
|
||||
PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/command/inc"
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(
|
||||
commandTest
|
||||
PUBLIC os util common nodes parser catalog transport gtest function qcom
|
||||
)
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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 __INDEX_FST_DFA_H__
|
||||
#define __INDEX_FST_DFA_H__
|
||||
|
||||
#include "indexFstRegex.h"
|
||||
#include "indexFstSparse.h"
|
||||
#include "tarray.h"
|
||||
#include "thash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct FstDfa FstDfa;
|
||||
|
||||
typedef struct {
|
||||
SArray * insts;
|
||||
uint32_t next[256];
|
||||
bool isMatch;
|
||||
} State;
|
||||
|
||||
/*
|
||||
* dfa builder related func
|
||||
**/
|
||||
typedef struct FstDfaBuilder {
|
||||
FstDfa * dfa;
|
||||
SHashObj *cache;
|
||||
} FstDfaBuilder;
|
||||
|
||||
FstDfaBuilder *dfaBuilderCreate(SArray *insts);
|
||||
|
||||
void dfaBuilderDestroy(FstDfaBuilder *builder);
|
||||
|
||||
FstDfa *dfaBuilderBuild(FstDfaBuilder *builder);
|
||||
|
||||
bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t bytes,
|
||||
uint32_t *result);
|
||||
|
||||
bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result);
|
||||
|
||||
/*
|
||||
* dfa related func
|
||||
**/
|
||||
typedef struct FstDfa {
|
||||
SArray *insts;
|
||||
SArray *states;
|
||||
} FstDfa;
|
||||
|
||||
FstDfa *dfaCreate(SArray *insts, SArray *states);
|
||||
bool dfaIsMatch(FstDfa *dfa, uint32_t si);
|
||||
bool dfaAccept(FstDfa *dfa, uint32_t si, uint8_t byte, uint32_t *result);
|
||||
void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip);
|
||||
bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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_FST_REGEX_H_
|
||||
#define _TD_INDEX_FST_REGEX_H_
|
||||
|
||||
//#include "indexFstDfa.h"
|
||||
#include "taos.h"
|
||||
#include "tarray.h"
|
||||
#include "tchecksum.h"
|
||||
#include "thash.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { MATCH, JUMP, SPLIT, RANGE } InstType;
|
||||
|
||||
typedef struct MatchValue {
|
||||
} MatchValue;
|
||||
typedef struct JumpValue {
|
||||
uint32_t step;
|
||||
} JumpValue;
|
||||
|
||||
typedef struct SplitValue {
|
||||
uint32_t len1;
|
||||
uint32_t len2;
|
||||
} SplitValue;
|
||||
|
||||
typedef struct RangeValue {
|
||||
uint8_t start;
|
||||
uint8_t end;
|
||||
} RangeValue;
|
||||
|
||||
typedef struct {
|
||||
InstType ty;
|
||||
union {
|
||||
MatchValue mv;
|
||||
JumpValue jv;
|
||||
SplitValue sv;
|
||||
RangeValue rv;
|
||||
};
|
||||
} Inst;
|
||||
|
||||
typedef struct {
|
||||
char *orig;
|
||||
void *dfa;
|
||||
} FstRegex;
|
||||
|
||||
FstRegex *regexCreate(const char *str);
|
||||
|
||||
void regexSetup(FstRegex *regex, uint32_t size, const char *str);
|
||||
|
||||
// uint32_t regexStart()
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_INDEX_SPARSE_H_
|
||||
#define _TD_INDEX_SPARSE_H_
|
||||
#ifndef _TD_INDEX_FST_SPARSE_H_
|
||||
#define _TD_INDEX_FST_SPARSE_H_
|
||||
|
||||
#include "tarray.h"
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* 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 "indexFstDfa.h"
|
||||
#include "thash.h"
|
||||
|
||||
const static uint32_t STATE_LIMIT = 1000;
|
||||
|
||||
static int dfaInstsEqual(const void *a, const void *b, size_t size) {
|
||||
SArray *ar = (SArray *)a;
|
||||
SArray *br = (SArray *)b;
|
||||
size_t al = ar != NULL ? taosArrayGetSize(ar) : 0;
|
||||
size_t bl = br != NULL ? taosArrayGetSize(br) : 0;
|
||||
if (al != bl) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < al; i++) {
|
||||
uint32_t v1 = *(uint32_t *)taosArrayGet(ar, i);
|
||||
uint32_t v2 = *(uint32_t *)taosArrayGet(br, i);
|
||||
if (v1 != v2) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
FstDfaBuilder *dfaBuilderCreate(SArray *insts) {
|
||||
FstDfaBuilder *builder = taosMemoryCalloc(1, sizeof(FstDfaBuilder));
|
||||
if (builder == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SArray *states = taosArrayInit(4, sizeof(State));
|
||||
|
||||
builder->dfa = dfaCreate(insts, states);
|
||||
builder->cache = taosHashInit(
|
||||
4, taosGetDefaultHashFunction(POINTER_BYTES == sizeof(int64_t) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_INT),
|
||||
false, HASH_NO_LOCK);
|
||||
taosHashSetEqualFp(builder->cache, dfaInstsEqual);
|
||||
return builder;
|
||||
}
|
||||
void dfaBuilderDestroy(FstDfaBuilder *builder) {
|
||||
if (builder == NULL) {
|
||||
return;
|
||||
}
|
||||
void *pIter = builder->cache != NULL ? taosHashIterate(builder->cache, NULL) : NULL;
|
||||
while (pIter) {
|
||||
SArray **key = pIter;
|
||||
taosArrayDestroy(*key);
|
||||
pIter = taosHashIterate(builder->cache, pIter);
|
||||
}
|
||||
taosHashCleanup(builder->cache);
|
||||
}
|
||||
|
||||
FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) {
|
||||
uint32_t sz = taosArrayGetSize(builder->dfa->insts);
|
||||
FstSparseSet *cur = sparSetCreate(sz);
|
||||
FstSparseSet *nxt = sparSetCreate(sz);
|
||||
|
||||
dfaAdd(builder->dfa, cur, 0);
|
||||
|
||||
SArray * states = taosArrayInit(0, sizeof(uint32_t));
|
||||
uint32_t result;
|
||||
if (dfaBuilderCachedState(builder, cur, &result)) {
|
||||
taosArrayPush(states, &result);
|
||||
}
|
||||
SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
while (taosArrayGetSize(states) != 0) {
|
||||
result = *(uint32_t *)taosArrayPop(states);
|
||||
for (int i = 0; i < 256; i++) {
|
||||
uint32_t ns, dummpy = 0;
|
||||
if (dfaBuilderRunState(builder, cur, nxt, result, i, &ns)) {
|
||||
if (taosHashGet(seen, &ns, sizeof(ns)) == NULL) {
|
||||
taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy));
|
||||
taosArrayPush(states, &ns);
|
||||
}
|
||||
}
|
||||
if (taosArrayGetSize(builder->dfa->states) > STATE_LIMIT) {
|
||||
// Too many state;
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(states);
|
||||
taosHashCleanup(seen);
|
||||
return builder->dfa;
|
||||
}
|
||||
|
||||
bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte,
|
||||
uint32_t *result) {
|
||||
sparSetClear(cur);
|
||||
State *t = taosArrayGet(builder->dfa->states, state);
|
||||
for (int i = 0; i < taosArrayGetSize(t->insts); i++) {
|
||||
uint32_t ip = *(int32_t *)taosArrayGet(t->insts, i);
|
||||
sparSetAdd(cur, ip);
|
||||
}
|
||||
dfaRun(builder->dfa, cur, next, byte);
|
||||
|
||||
t = taosArrayGet(builder->dfa->states, state);
|
||||
|
||||
uint32_t nxtState;
|
||||
if (dfaBuilderCachedState(builder, next, &nxtState)) {
|
||||
t->next[byte] = nxtState;
|
||||
*result = nxtState;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) {
|
||||
SArray *tinsts = taosArrayInit(4, sizeof(uint32_t));
|
||||
bool isMatch = false;
|
||||
|
||||
for (int i = 0; i < sparSetLen(set); i++) {
|
||||
uint32_t ip = sparSetGet(set, i);
|
||||
|
||||
Inst *inst = taosArrayGet(builder->dfa->insts, ip);
|
||||
if (inst->ty == JUMP || inst->ty == SPLIT) {
|
||||
continue;
|
||||
} else if (inst->ty == RANGE) {
|
||||
taosArrayPush(tinsts, &ip);
|
||||
} else if (inst->ty == MATCH) {
|
||||
isMatch = true;
|
||||
taosArrayPush(tinsts, &ip);
|
||||
}
|
||||
}
|
||||
if (taosArrayGetSize(tinsts) == 0) {
|
||||
return false;
|
||||
}
|
||||
uint32_t *v = taosHashGet(builder->cache, &tinsts, sizeof(POINTER_BYTES));
|
||||
if (v != NULL) {
|
||||
*result = *v;
|
||||
taosArrayDestroy(tinsts);
|
||||
} else {
|
||||
State st;
|
||||
st.insts = tinsts;
|
||||
st.isMatch = isMatch;
|
||||
taosArrayPush(builder->dfa->states, &st);
|
||||
int32_t sz = taosArrayGetSize(builder->dfa->states) - 1;
|
||||
taosHashPut(builder->cache, &tinsts, sizeof(POINTER_BYTES), &sz, sizeof(sz));
|
||||
*result = sz;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
FstDfa *dfaCreate(SArray *insts, SArray *states) {
|
||||
FstDfa *dfa = taosMemoryCalloc(1, sizeof(FstDfa));
|
||||
if (dfa == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dfa->insts = insts;
|
||||
dfa->states = states;
|
||||
return dfa;
|
||||
}
|
||||
bool dfaIsMatch(FstDfa *dfa, uint32_t si) {
|
||||
if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) {
|
||||
return false;
|
||||
}
|
||||
State *st = taosArrayGet(dfa->states, si);
|
||||
return st != NULL ? st->isMatch : false;
|
||||
}
|
||||
bool dfaAccept(FstDfa *dfa, uint32_t si, uint8_t byte, uint32_t *result) {
|
||||
if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) {
|
||||
return false;
|
||||
}
|
||||
State *st = taosArrayGet(dfa->states, si);
|
||||
*result = st->next[byte];
|
||||
return true;
|
||||
}
|
||||
void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) {
|
||||
if (sparSetContains(set, ip)) {
|
||||
return;
|
||||
}
|
||||
sparSetAdd(set, ip);
|
||||
Inst *inst = taosArrayGet(dfa->insts, ip);
|
||||
if (inst->ty == MATCH || inst->ty == RANGE) {
|
||||
// do nothing
|
||||
} else if (inst->ty == JUMP) {
|
||||
dfaAdd(dfa, set, inst->jv.step);
|
||||
} else if (inst->ty == SPLIT) {
|
||||
dfaAdd(dfa, set, inst->sv.len1);
|
||||
dfaAdd(dfa, set, inst->sv.len2);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte) {
|
||||
bool isMatch = false;
|
||||
sparSetClear(to);
|
||||
for (int i = 0; i < sparSetLen(from); i++) {
|
||||
uint32_t ip = sparSetGet(from, i);
|
||||
|
||||
Inst *inst = taosArrayGet(dfa->insts, ip);
|
||||
if (inst->ty == JUMP || inst->ty == SPLIT) {
|
||||
continue;
|
||||
} else if (inst->ty == MATCH) {
|
||||
isMatch = true;
|
||||
} else if (inst->ty == RANGE) {
|
||||
if (inst->rv.start <= byte && byte <= inst->rv.end) {
|
||||
dfaAdd(dfa, to, ip + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isMatch;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 "indexFstRegex.h"
|
||||
#include "indexFstSparse.h"
|
||||
|
||||
FstRegex *regexCreate(const char *str) {
|
||||
FstRegex *regex = taosMemoryCalloc(1, sizeof(FstRegex));
|
||||
if (regex == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
int32_t sz = (int32_t)strlen(str);
|
||||
char * orig = taosMemoryCalloc(1, sz);
|
||||
memcpy(orig, str, sz);
|
||||
|
||||
regex->orig = orig;
|
||||
}
|
||||
|
||||
void regexSetup(FstRegex *regex, uint32_t size, const char *str) {
|
||||
// return
|
||||
// return;
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "indexSparse.h"
|
||||
#include "indexFstSparse.h"
|
||||
|
||||
FstSparseSet *sparSetCreate(int32_t sz) {
|
||||
FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet));
|
||||
|
|
|
@ -136,6 +136,10 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SDropTopicStmt));
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return makeNode(type, sizeof(SExplainStmt));
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return makeNode(type, sizeof(SDescribeStmt));
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
case QUERY_NODE_SHOW_TABLES_STMT:
|
||||
case QUERY_NODE_SHOW_STABLES_STMT:
|
||||
|
|
|
@ -163,6 +163,8 @@ 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);
|
||||
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
|
||||
int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery);
|
||||
int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery);
|
||||
int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -339,7 +339,14 @@ 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 ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); }
|
||||
|
||||
/************************************************ select **************************************************************/
|
||||
/************************************************ desc/describe *******************************************************/
|
||||
cmd ::= DESC full_table_name(A). { pCxt->pRootNode = createDescribeStmt(pCxt, A); }
|
||||
cmd ::= DESCRIBE full_table_name(A). { pCxt->pRootNode = createDescribeStmt(pCxt, A); }
|
||||
|
||||
/************************************************ reset query cache ***************************************************/
|
||||
cmd ::= RESET QUERY CACHE. { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); }
|
||||
|
||||
/************************************************ explain *************************************************************/
|
||||
cmd ::= EXPLAIN analyze_opt(A) explain_options(B) query_expression(C). { pCxt->pRootNode = createExplainStmt(pCxt, A, B, C); }
|
||||
|
||||
%type analyze_opt { bool }
|
||||
|
|
|
@ -473,6 +473,9 @@ static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t
|
|||
static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool query) {
|
||||
if (NULL == pDbName) {
|
||||
pCxt->valid = (query ? NULL != pCxt->pQueryCxt->db : true);
|
||||
if (!pCxt->valid) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "db not specified");
|
||||
}
|
||||
} else {
|
||||
pCxt->valid = pDbName->n < TSDB_DB_NAME_LEN ? true : false;
|
||||
}
|
||||
|
@ -1017,6 +1020,9 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
|
|||
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
||||
bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SCreateTableStmt* pStmt = (SCreateTableStmt*)nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -1031,6 +1037,9 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
|||
|
||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt,
|
||||
bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SCreateSubTableClause* pStmt = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -1053,6 +1062,9 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables
|
|||
}
|
||||
|
||||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SDropTableClause* pStmt = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -1080,6 +1092,9 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
|
|||
}
|
||||
|
||||
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
|
||||
|
@ -1088,6 +1103,9 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode*
|
|||
}
|
||||
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
|
@ -1097,6 +1115,9 @@ SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable,
|
|||
}
|
||||
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
|
@ -1105,6 +1126,9 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
|
|||
}
|
||||
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
|
@ -1114,6 +1138,9 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int
|
|||
}
|
||||
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
|
||||
|
@ -1343,3 +1370,21 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
|
|||
pStmt->pQuery = pQuery;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
SDescribeStmt* pStmt = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
|
||||
nodesDestroyNode(pRealTable);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt) {
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_RESET_QUERY_CACHE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef struct SInsertParseContext {
|
|||
SVnodeModifOpStmt* pOutput;
|
||||
} SInsertParseContext;
|
||||
|
||||
typedef int32_t (*_row_append_fn_t)(const void *value, int32_t len, void *param);
|
||||
typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void *value, int32_t len, void *param);
|
||||
|
||||
static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE;
|
||||
static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE;
|
||||
|
@ -444,26 +444,26 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
if (isNullStr(pToken)) {
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) {
|
||||
int64_t tmpVal = 0;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
return func(NULL, 0, param);
|
||||
return func(pMsgBuf, NULL, 0, param);
|
||||
}
|
||||
|
||||
switch (pSchema->type) {
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) {
|
||||
if (strncmp(pToken->z, "true", pToken->n) == 0) {
|
||||
return func(&TRUE_VALUE, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &TRUE_VALUE, pSchema->bytes, param);
|
||||
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
|
||||
return func(&FALSE_VALUE, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &FALSE_VALUE, pSchema->bytes, param);
|
||||
} else {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
|
||||
}
|
||||
} else if (pToken->type == TK_NK_INTEGER) {
|
||||
return func(((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
return func(pMsgBuf, ((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
} else if (pToken->type == TK_NK_FLOAT) {
|
||||
return func(((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
return func(pMsgBuf, ((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
} else {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
}
|
||||
|
||||
uint8_t tmpVal = (uint8_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_UTINYINT:{
|
||||
|
@ -487,7 +487,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "unsigned tinyint data overflow", pToken->z);
|
||||
}
|
||||
uint8_t tmpVal = (uint8_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
|
@ -497,7 +497,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "smallint data overflow", pToken->z);
|
||||
}
|
||||
int16_t tmpVal = (int16_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
|
@ -507,7 +507,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "unsigned smallint data overflow", pToken->z);
|
||||
}
|
||||
uint16_t tmpVal = (uint16_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
|
@ -517,7 +517,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "int data overflow", pToken->z);
|
||||
}
|
||||
int32_t tmpVal = (int32_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
|
@ -527,7 +527,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "unsigned int data overflow", pToken->z);
|
||||
}
|
||||
uint32_t tmpVal = (uint32_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
|
@ -536,7 +536,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
} else if (!IS_VALID_BIGINT(iv)) {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "bigint data overflow", pToken->z);
|
||||
}
|
||||
return func(&iv, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &iv, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
|
@ -546,7 +546,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "unsigned bigint data overflow", pToken->z);
|
||||
}
|
||||
uint64_t tmpVal = (uint64_t)iv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
|
@ -558,7 +558,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z);
|
||||
}
|
||||
float tmpVal = (float)dv;
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
|
@ -569,7 +569,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z);
|
||||
}
|
||||
return func(&dv, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &dv, pSchema->bytes, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY: {
|
||||
|
@ -578,11 +578,11 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "string data overflow", pToken->z);
|
||||
}
|
||||
|
||||
return func(pToken->z, pToken->n, param);
|
||||
return func(pMsgBuf, pToken->z, pToken->n, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
return func(pToken->z, pToken->n, param);
|
||||
return func(pMsgBuf, pToken->z, pToken->n, param);
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
|
@ -591,7 +591,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp", pToken->z);
|
||||
}
|
||||
|
||||
return func(&tmpVal, pSchema->bytes, param);
|
||||
return func(pMsgBuf, &tmpVal, pSchema->bytes, param);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -605,7 +605,7 @@ typedef struct SMemParam {
|
|||
col_id_t colIdx;
|
||||
} SMemParam;
|
||||
|
||||
static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* param) {
|
||||
static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) {
|
||||
SMemParam* pa = (SMemParam*)param;
|
||||
SRowBuilder* rb = pa->rb;
|
||||
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
|
||||
|
@ -617,7 +617,9 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
|
|||
int32_t output = 0;
|
||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
||||
if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(rowEnd), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
||||
return buildSyntaxErrMsg(pMsgBuf, buf, value);
|
||||
}
|
||||
varDataSetLen(rowEnd, output);
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
||||
|
@ -714,7 +716,7 @@ typedef struct SKvParam {
|
|||
char buf[TSDB_MAX_TAGS_LEN];
|
||||
} SKvParam;
|
||||
|
||||
static int32_t KvRowAppend(const void *value, int32_t len, void *param) {
|
||||
static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, void *param) {
|
||||
SKvParam* pa = (SKvParam*) param;
|
||||
|
||||
int8_t type = pa->schema->type;
|
||||
|
@ -727,7 +729,9 @@ static int32_t KvRowAppend(const void *value, int32_t len, void *param) {
|
|||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||
int32_t output = 0;
|
||||
if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(pa->buf), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
||||
return buildSyntaxErrMsg(pMsgBuf, buf, value);;
|
||||
}
|
||||
|
||||
varDataSetLen(pa->buf, output);
|
||||
|
|
|
@ -51,6 +51,7 @@ static SKeyword keywordTable[] = {
|
|||
{"DAYS", TK_DAYS},
|
||||
{"DELAY", TK_DELAY},
|
||||
{"DESC", TK_DESC},
|
||||
{"DESCRIBE", TK_DESCRIBE},
|
||||
{"DISTINCT", TK_DISTINCT},
|
||||
{"DNODE", TK_DNODE},
|
||||
{"DNODES", TK_DNODES},
|
||||
|
@ -111,9 +112,11 @@ static SKeyword keywordTable[] = {
|
|||
{"QNODE", TK_QNODE},
|
||||
{"QNODES", TK_QNODES},
|
||||
{"QSTARTTS", TK_QSTARTTS},
|
||||
{"QUERY", TK_QUERY},
|
||||
{"QUORUM", TK_QUORUM},
|
||||
{"RATIO", TK_RATIO},
|
||||
{"REPLICA", TK_REPLICA},
|
||||
{"RESET", TK_RESET},
|
||||
{"RETENTIONS", TK_RETENTIONS},
|
||||
{"ROLLUP", TK_ROLLUP},
|
||||
{"ROWTS", TK_ROWTS},
|
||||
|
@ -186,7 +189,6 @@ static SKeyword keywordTable[] = {
|
|||
// {"SCORES", TK_SCORES},
|
||||
// {"GRANTS", TK_GRANTS},
|
||||
// {"DOT", TK_DOT},
|
||||
// {"DESCRIBE", TK_DESCRIBE},
|
||||
// {"SYNCDB", TK_SYNCDB},
|
||||
// {"LOCAL", TK_LOCAL},
|
||||
// {"PPS", TK_PPS},
|
||||
|
@ -203,8 +205,6 @@ static SKeyword keywordTable[] = {
|
|||
// {"EVERY", TK_EVERY},
|
||||
// {"VARIABLE", TK_VARIABLE},
|
||||
// {"UPDATE", TK_UPDATE},
|
||||
// {"RESET", TK_RESET},
|
||||
// {"QUERY", TK_QUERY},
|
||||
// {"ADD", TK_ADD},
|
||||
// {"COLUMN", TK_COLUMN},
|
||||
// {"TAG", TK_TAG},
|
||||
|
|
|
@ -1812,6 +1812,10 @@ static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) {
|
|||
return translateQuery(pCxt, pStmt->pQuery);
|
||||
}
|
||||
|
||||
static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) {
|
||||
return getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
||||
}
|
||||
|
||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pNode)) {
|
||||
|
@ -1896,6 +1900,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
code = translateExplain(pCxt, (SExplainStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
code = translateDescribe(pCxt, (SDescribeStmt*)pNode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1913,40 +1920,81 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
|
||||
static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* numOfCols, SSchema** pSchema) {
|
||||
*numOfCols = LIST_LENGTH(pSelect->pProjectionList);
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
if (NULL == (*pSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
int32_t index = 0;
|
||||
FOREACH(pNode, pSelect->pProjectionList) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
(*pSchema)[index].type = pExpr->resType.type;
|
||||
(*pSchema)[index].bytes = pExpr->resType.bytes;
|
||||
(*pSchema)[index].colId = index + 1;
|
||||
strcpy((*pSchema)[index].name, pExpr->aliasName);
|
||||
index +=1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t extractExplainResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||
*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;
|
||||
}
|
||||
|
||||
static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||
*numOfCols = DESCRIBE_RESULT_COLS;
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
if (NULL == (*pSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pSchema)[0].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[0].bytes = DESCRIBE_RESULT_FIELD_LEN;
|
||||
strcpy((*pSchema)[0].name, "Field");
|
||||
|
||||
(*pSchema)[1].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[1].bytes = DESCRIBE_RESULT_TYPE_LEN;
|
||||
strcpy((*pSchema)[1].name, "Type");
|
||||
|
||||
(*pSchema)[2].type = TSDB_DATA_TYPE_INT;
|
||||
(*pSchema)[2].bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes;
|
||||
strcpy((*pSchema)[2].name, "Length");
|
||||
|
||||
(*pSchema)[3].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[3].bytes = DESCRIBE_RESULT_NOTE_LEN;
|
||||
strcpy((*pSchema)[3].name, "Note");
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
|
||||
if (NULL == pRoot) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*) pRoot;
|
||||
*numOfCols = LIST_LENGTH(pSelect->pProjectionList);
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
if (NULL == (*pSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
int32_t index = 0;
|
||||
FOREACH(pNode, pSelect->pProjectionList) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
(*pSchema)[index].type = pExpr->resType.type;
|
||||
(*pSchema)[index].bytes = pExpr->resType.bytes;
|
||||
(*pSchema)[index].colId = index + 1;
|
||||
strcpy((*pSchema)[index].name, pExpr->aliasName);
|
||||
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;
|
||||
switch (nodeType(pRoot)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return extractSelectResultSchema((SSelectStmt*)pRoot, numOfCols, pSchema);
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return extractExplainResultSchema(numOfCols, pSchema);
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return extractDescribeResultSchema(numOfCols, pSchema);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static void destroyTranslateContext(STranslateContext* pCxt) {
|
||||
|
@ -2119,7 +2167,7 @@ typedef struct SVgroupTablesBatch {
|
|||
static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) {
|
||||
pSchema->colId = colId;
|
||||
pSchema->type = pCol->dataType.type;
|
||||
pSchema->bytes = pCol->dataType.bytes;
|
||||
pSchema->bytes = calcTypeBytes(pCol->dataType);
|
||||
strcpy(pSchema->name, pCol->colName);
|
||||
}
|
||||
|
||||
|
@ -2530,25 +2578,30 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_SELECT_STMT:
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
pQuery->haveResultSet = true;
|
||||
pQuery->directRpc = false;
|
||||
pQuery->msgType = TDMT_VND_QUERY;
|
||||
if (TSDB_CODE_SUCCESS != qExtractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
break;
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
pQuery->haveResultSet = false;
|
||||
pQuery->directRpc = false;
|
||||
pQuery->msgType = TDMT_VND_CREATE_TABLE;
|
||||
break;
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
pQuery->localCmd = true;
|
||||
pQuery->haveResultSet = true;
|
||||
break;
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT:
|
||||
pQuery->localCmd = true;
|
||||
break;
|
||||
default:
|
||||
pQuery->haveResultSet = false;
|
||||
pQuery->directRpc = true;
|
||||
pQuery->pCmdMsg = pCxt->pCmdMsg;
|
||||
pCxt->pCmdMsg = NULL;
|
||||
TSWAP(pQuery->pCmdMsg, pCxt->pCmdMsg, SCmdMsgInfo*);
|
||||
pQuery->msgType = pQuery->pCmdMsg->msgType;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pQuery->haveResultSet) {
|
||||
if (TSDB_CODE_SUCCESS != extractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pCxt->pDbs) {
|
||||
pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN);
|
||||
|
|
|
@ -62,3 +62,7 @@ void qDestroyQuery(SQuery* pQueryNode) {
|
|||
taosArrayDestroy(pQueryNode->pTableList);
|
||||
taosMemoryFreeClear(pQueryNode);
|
||||
}
|
||||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
|
||||
return extractResultSchema(pRoot, numOfCols, pSchema);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -17,6 +17,8 @@
|
|||
#include <malloc.h>
|
||||
#include "os.h"
|
||||
|
||||
#ifdef USE_TD_MEMORY
|
||||
|
||||
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
|
||||
|
||||
#define TD_MEMORY_STACK_TRACE_DEPTH 10
|
||||
|
@ -70,6 +72,8 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
|
|||
// return backtrace_symbols(buffer, *size);
|
||||
// }
|
||||
|
||||
#endif
|
||||
|
||||
void *taosMemoryMalloc(int32_t size) {
|
||||
#ifdef USE_TD_MEMORY
|
||||
void *tmp = malloc(size + sizeof(TdMemoryInfo));
|
||||
|
@ -126,9 +130,9 @@ void *taosMemoryRealloc(void *ptr, int32_t size) {
|
|||
}
|
||||
|
||||
void taosMemoryFree(const void *ptr) {
|
||||
#ifdef USE_TD_MEMORY
|
||||
if (ptr == NULL) return;
|
||||
|
||||
#ifdef USE_TD_MEMORY
|
||||
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
|
||||
if(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL) {
|
||||
pTdMemoryInfo->memorySize = 0;
|
||||
|
@ -143,9 +147,9 @@ void taosMemoryFree(const void *ptr) {
|
|||
}
|
||||
|
||||
int32_t taosMemorySize(void *ptr) {
|
||||
#ifdef USE_TD_MEMORY
|
||||
if (ptr == NULL) return 0;
|
||||
|
||||
|
||||
#ifdef USE_TD_MEMORY
|
||||
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
|
||||
assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL);
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
static char *tsProcPath = NULL;
|
||||
|
||||
int32_t taosNewProc(char **args) {
|
||||
int32_t pid = fork();
|
||||
if (pid == 0) {
|
||||
args[0] = tsProcPath;
|
||||
return execvp(tsProcPath, args);
|
||||
} else {
|
||||
return pid;
|
||||
}
|
||||
}
|
||||
|
||||
// the length of the new name must be less than the original name to take effect
|
||||
void taosSetProcName(int32_t argc, char **argv, const char *name) {
|
||||
prctl(PR_SET_NAME, name);
|
||||
|
||||
for (int32_t i = 0; i < argc; ++i) {
|
||||
int32_t len = strlen(argv[i]);
|
||||
for (int32_t j = 0; j < len; ++j) {
|
||||
argv[i][j] = 0;
|
||||
}
|
||||
if (i == 0) {
|
||||
tstrncpy(argv[0], name, len + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void taosSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }
|
||||
|
||||
bool taosProcExists(int32_t pid) {
|
||||
int32_t p = getpgid(pid);
|
||||
return p >= 0;
|
||||
}
|
|
@ -18,7 +18,9 @@
|
|||
#include "os.h"
|
||||
|
||||
int32_t taosCreateShm(SShm* pShm, int32_t shmsize) {
|
||||
int32_t shmid = shmget(IPC_PRIVATE, shmsize, IPC_CREAT | 0600);
|
||||
pShm->id = -1;
|
||||
|
||||
int32_t shmid = shmget(0X95279527, shmsize, IPC_CREAT | 0600);
|
||||
if (shmid < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -35,37 +37,23 @@ int32_t taosCreateShm(SShm* pShm, int32_t shmsize) {
|
|||
}
|
||||
|
||||
void taosDropShm(SShm* pShm) {
|
||||
if (pShm->id > 0) {
|
||||
if (pShm->id >= 0) {
|
||||
if (pShm->ptr != NULL) {
|
||||
shmdt(pShm->ptr);
|
||||
}
|
||||
shmctl(pShm->id, IPC_RMID, NULL);
|
||||
}
|
||||
pShm->id = 0;
|
||||
pShm->id = -1;
|
||||
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;
|
||||
}
|
||||
errno = 0;
|
||||
|
||||
void* ptr = shmat(pShm->id, NULL, 0);
|
||||
if (errno == 0) {
|
||||
pShm->ptr = ptr;
|
||||
}
|
||||
|
||||
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;
|
||||
return errno;
|
||||
}
|
||||
|
|
|
@ -71,4 +71,6 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); }
|
|||
|
||||
void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); }
|
||||
|
||||
void taosKillChildOnParentStopped() { prctl(PR_SET_PDEATHSIG, SIGKILL); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -590,12 +590,12 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
|
|||
}
|
||||
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
||||
uInfo("load from global env variables");
|
||||
uInfo("load from global env variables success");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) {
|
||||
uInfo("load from env file %s", filepath);
|
||||
uInfo("load from env file [%s] success", filepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -649,11 +649,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
taosCloseFile(&pFile);
|
||||
if (line != NULL) taosMemoryFreeClear(line);
|
||||
|
||||
uInfo("load from cfg file %s success", filepath);
|
||||
uInfo("load from cfg file [%s] success", filepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||
uInfo("load from apoll url %s", url);
|
||||
uInfo("load from apoll url [%s] success", url);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_CFG_NOT_FOUND, "Config not found")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CFG, "Invalid config option")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_SHM_MEM, "Out of Share memory")
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SHM_ID, "Invalid SHM ID")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed")
|
||||
|
|
|
@ -23,34 +23,36 @@
|
|||
typedef void *(*ProcThreadFp)(void *param);
|
||||
|
||||
typedef struct SProcQueue {
|
||||
int32_t head;
|
||||
int32_t tail;
|
||||
int32_t total;
|
||||
int32_t avail;
|
||||
int32_t items;
|
||||
char *pBuffer;
|
||||
ProcMallocFp mallocHeadFp;
|
||||
ProcFreeFp freeHeadFp;
|
||||
ProcMallocFp mallocBodyFp;
|
||||
ProcFreeFp freeBodyFp;
|
||||
ProcConsumeFp consumeFp;
|
||||
void *pParent;
|
||||
tsem_t sem;
|
||||
TdThreadMutex *mutex;
|
||||
int32_t mutexShmid;
|
||||
int32_t bufferShmid;
|
||||
const char *name;
|
||||
int32_t head;
|
||||
int32_t tail;
|
||||
int32_t total;
|
||||
int32_t avail;
|
||||
int32_t items;
|
||||
char name[8];
|
||||
TdThreadMutex mutex;
|
||||
tsem_t sem;
|
||||
char pBuffer[];
|
||||
} SProcQueue;
|
||||
|
||||
typedef struct SProcObj {
|
||||
TdThread childThread;
|
||||
SProcQueue *pChildQueue;
|
||||
TdThread parentThread;
|
||||
SProcQueue *pParentQueue;
|
||||
const char *name;
|
||||
int32_t pid;
|
||||
bool isChild;
|
||||
bool stopFlag;
|
||||
TdThread thread;
|
||||
SProcQueue *pChildQueue;
|
||||
SProcQueue *pParentQueue;
|
||||
ProcConsumeFp childConsumeFp;
|
||||
ProcMallocFp childMallocHeadFp;
|
||||
ProcFreeFp childFreeHeadFp;
|
||||
ProcMallocFp childMallocBodyFp;
|
||||
ProcFreeFp childFreeBodyFp;
|
||||
ProcConsumeFp parentConsumeFp;
|
||||
ProcMallocFp parentMallocHeadFp;
|
||||
ProcFreeFp parentFreeHeadFp;
|
||||
ProcMallocFp parentMallocBodyFp;
|
||||
ProcFreeFp parentFreeBodyFp;
|
||||
void *pParent;
|
||||
const char *name;
|
||||
int32_t pid;
|
||||
bool isChild;
|
||||
bool stopFlag;
|
||||
} SProcObj;
|
||||
|
||||
static inline int32_t CEIL8(int32_t v) {
|
||||
|
@ -58,150 +60,94 @@ static inline int32_t CEIL8(int32_t v) {
|
|||
return c < 8 ? 8 : c;
|
||||
}
|
||||
|
||||
static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) {
|
||||
TdThreadMutex *pMutex = NULL;
|
||||
static int32_t taosProcInitMutex(SProcQueue *pQueue) {
|
||||
TdThreadMutexAttr mattr = {0};
|
||||
int32_t shmid = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
if (taosThreadMutexAttrInit(&mattr) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init mutex while init attr since %s", terrstr());
|
||||
goto _OVER;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) {
|
||||
taosThreadMutexAttrDestroy(&mattr);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init mutex while set shared since %s", terrstr());
|
||||
goto _OVER;
|
||||
return -1;
|
||||
}
|
||||
|
||||
shmid = shmget(IPC_PRIVATE, sizeof(TdThreadMutex), IPC_CREAT | 0600);
|
||||
if (shmid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init mutex while shmget since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pMutex = (TdThreadMutex *)shmat(shmid, NULL, 0);
|
||||
if (pMutex == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init mutex while shmat since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosThreadMutexInit(pMutex, &mattr) != 0) {
|
||||
if (taosThreadMutexInit(&pQueue->mutex, &mattr) != 0) {
|
||||
taosThreadMutexDestroy(&pQueue->mutex);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init mutex since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
if (pMutex != NULL) {
|
||||
taosThreadMutexDestroy(pMutex);
|
||||
shmdt(pMutex);
|
||||
}
|
||||
if (shmid >= 0) {
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
}
|
||||
} else {
|
||||
*ppMutex = pMutex;
|
||||
*pShmid = shmid;
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosThreadMutexAttrDestroy(&mattr);
|
||||
return code;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void taosProcDestroyMutex(TdThreadMutex *pMutex, int32_t shmid) {
|
||||
if (pMutex != NULL) {
|
||||
taosThreadMutexDestroy(pMutex);
|
||||
}
|
||||
if (shmid >= 0) {
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t taosProcInitBuffer(void **ppBuffer, int32_t size) {
|
||||
int32_t shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600);
|
||||
if (shmid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init buffer while shmget since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *shmptr = shmat(shmid, NULL, 0);
|
||||
if (shmptr == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init buffer while shmat since %s", terrstr());
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ppBuffer = shmptr;
|
||||
return shmid;
|
||||
}
|
||||
|
||||
static void taosProcDestroyBuffer(void *pBuffer, int32_t shmid) {
|
||||
if (shmid > 0) {
|
||||
shmdt(pBuffer);
|
||||
shmctl(shmid, IPC_RMID, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static SProcQueue *taosProcInitQueue(int32_t size) {
|
||||
if (size <= 0) size = SHM_DEFAULT_SIZE;
|
||||
|
||||
int32_t bufSize = CEIL8(size);
|
||||
int32_t headSize = CEIL8(sizeof(SProcQueue));
|
||||
|
||||
SProcQueue *pQueue = NULL;
|
||||
int32_t shmId = taosProcInitBuffer((void **)&pQueue, bufSize + headSize);
|
||||
if (shmId < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
pQueue->bufferShmid = shmId;
|
||||
|
||||
if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) {
|
||||
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t taosProcInitSem(SProcQueue *pQueue) {
|
||||
if (tsem_init(&pQueue->sem, 1, 0) != 0) {
|
||||
taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid);
|
||||
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to init sem");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SProcQueue *taosProcInitQueue(const char *name, bool isChild, char *ptr, int32_t size) {
|
||||
int32_t bufSize = size - CEIL8(sizeof(SProcQueue));
|
||||
if (bufSize <= 1024) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) {
|
||||
tsem_destroy(&pQueue->sem);
|
||||
taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid);
|
||||
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
|
||||
return NULL;
|
||||
SProcQueue *pQueue = (SProcQueue *)(ptr);
|
||||
|
||||
if (!isChild) {
|
||||
if (taosProcInitMutex(pQueue) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (taosProcInitSem(pQueue) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tstrncpy(pQueue->name, name, sizeof(pQueue->name));
|
||||
pQueue->head = 0;
|
||||
pQueue->tail = 0;
|
||||
pQueue->total = bufSize;
|
||||
pQueue->avail = bufSize;
|
||||
pQueue->items = 0;
|
||||
}
|
||||
|
||||
pQueue->head = 0;
|
||||
pQueue->tail = 0;
|
||||
pQueue->total = bufSize;
|
||||
pQueue->avail = bufSize;
|
||||
pQueue->items = 0;
|
||||
pQueue->pBuffer = (char *)pQueue + headSize;
|
||||
return pQueue;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void taosProcDestroyMutex(SProcQueue *pQueue) {
|
||||
if (pQueue->mutex != NULL) {
|
||||
taosThreadMutexDestroy(pQueue->mutex);
|
||||
pQueue->mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void taosProcDestroySem(SProcQueue *pQueue) {
|
||||
if (pQueue->sem != NULL) {
|
||||
tsem_destroy(pQueue->sem);
|
||||
pQueue->sem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void taosProcCleanupQueue(SProcQueue *pQueue) {
|
||||
if (pQueue != NULL) {
|
||||
uDebug("proc:%s, queue:%p clean up", pQueue->name, pQueue);
|
||||
tsem_destroy(&pQueue->sem);
|
||||
taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid);
|
||||
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
|
||||
taosProcDestroyMutex(pQueue);
|
||||
taosProcDestroySem(pQueue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody,
|
||||
int32_t rawBodyLen, ProcFuncType ftype) {
|
||||
|
@ -209,9 +155,9 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t
|
|||
const int32_t bodyLen = CEIL8(rawBodyLen);
|
||||
const int32_t fullLen = headLen + bodyLen + 8;
|
||||
|
||||
taosThreadMutexLock(pQueue->mutex);
|
||||
taosThreadMutexLock(&pQueue->mutex);
|
||||
if (fullLen > pQueue->avail) {
|
||||
taosThreadMutexUnlock(pQueue->mutex);
|
||||
taosThreadMutexUnlock(&pQueue->mutex);
|
||||
terrno = TSDB_CODE_OUT_OF_SHM_MEM;
|
||||
return -1;
|
||||
}
|
||||
|
@ -260,7 +206,7 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t
|
|||
|
||||
pQueue->avail -= fullLen;
|
||||
pQueue->items++;
|
||||
taosThreadMutexUnlock(pQueue->mutex);
|
||||
taosThreadMutexUnlock(&pQueue->mutex);
|
||||
tsem_post(&pQueue->sem);
|
||||
|
||||
uTrace("proc:%s, push msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype,
|
||||
|
@ -268,13 +214,14 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody,
|
||||
int32_t *pBodyLen, ProcFuncType *pFuncType) {
|
||||
static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen,
|
||||
ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp,
|
||||
ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) {
|
||||
tsem_wait(&pQueue->sem);
|
||||
|
||||
taosThreadMutexLock(pQueue->mutex);
|
||||
taosThreadMutexLock(&pQueue->mutex);
|
||||
if (pQueue->total - pQueue->avail <= 0) {
|
||||
taosThreadMutexUnlock(pQueue->mutex);
|
||||
taosThreadMutexUnlock(&pQueue->mutex);
|
||||
tsem_post(&pQueue->sem);
|
||||
terrno = TSDB_CODE_OUT_OF_SHM_MEM;
|
||||
return 0;
|
||||
|
@ -293,13 +240,13 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea
|
|||
bodyLen = *(int32_t *)(pQueue->pBuffer + 4);
|
||||
}
|
||||
|
||||
void *pHead = (*pQueue->mallocHeadFp)(headLen);
|
||||
void *pBody = (*pQueue->mallocBodyFp)(bodyLen);
|
||||
void *pHead = (*mallocHeadFp)(headLen);
|
||||
void *pBody = (*mallocBodyFp)(bodyLen);
|
||||
if (pHead == NULL || pBody == NULL) {
|
||||
taosThreadMutexUnlock(pQueue->mutex);
|
||||
taosThreadMutexUnlock(&pQueue->mutex);
|
||||
tsem_post(&pQueue->sem);
|
||||
(*pQueue->freeHeadFp)(pHead);
|
||||
(*pQueue->freeBodyFp)(pBody);
|
||||
(*freeHeadFp)(pHead);
|
||||
(*freeBodyFp)(pBody);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -338,7 +285,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea
|
|||
|
||||
pQueue->avail = pQueue->avail + headLen + bodyLen + 8;
|
||||
pQueue->items--;
|
||||
taosThreadMutexUnlock(pQueue->mutex);
|
||||
taosThreadMutexUnlock(&pQueue->mutex);
|
||||
|
||||
*ppHead = pHead;
|
||||
*ppBody = pBody;
|
||||
|
@ -358,65 +305,85 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t cstart = 0;
|
||||
int32_t csize = CEIL8(pCfg->shm.size / 2);
|
||||
int32_t pstart = csize;
|
||||
int32_t psize = CEIL8(pCfg->shm.size - pstart);
|
||||
if (pstart + psize > pCfg->shm.size) {
|
||||
psize -= 8;
|
||||
}
|
||||
|
||||
pProc->name = pCfg->name;
|
||||
pProc->pChildQueue = taosProcInitQueue(pCfg->childQueueSize);
|
||||
pProc->pParentQueue = taosProcInitQueue(pCfg->parentQueueSize);
|
||||
pProc->pChildQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + cstart, csize);
|
||||
pProc->pParentQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + pstart, psize);
|
||||
if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) {
|
||||
taosProcCleanupQueue(pProc->pChildQueue);
|
||||
// taosProcCleanupQueue(pProc->pChildQueue);
|
||||
taosMemoryFree(pProc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pProc->pChildQueue->name = pCfg->name;
|
||||
pProc->pChildQueue->pParent = pCfg->pParent;
|
||||
pProc->pChildQueue->mallocHeadFp = pCfg->childMallocHeadFp;
|
||||
pProc->pChildQueue->freeHeadFp = pCfg->childFreeHeadFp;
|
||||
pProc->pChildQueue->mallocBodyFp = pCfg->childMallocBodyFp;
|
||||
pProc->pChildQueue->freeBodyFp = pCfg->childFreeBodyFp;
|
||||
pProc->pChildQueue->consumeFp = pCfg->childConsumeFp;
|
||||
pProc->pParentQueue->name = pCfg->name;
|
||||
pProc->pParentQueue->pParent = pCfg->pParent;
|
||||
pProc->pParentQueue->mallocHeadFp = pCfg->parentdMallocHeadFp;
|
||||
pProc->pParentQueue->freeHeadFp = pCfg->parentFreeHeadFp;
|
||||
pProc->pParentQueue->mallocBodyFp = pCfg->parentMallocBodyFp;
|
||||
pProc->pParentQueue->freeBodyFp = pCfg->parentFreeBodyFp;
|
||||
pProc->pParentQueue->consumeFp = pCfg->parentConsumeFp;
|
||||
pProc->name = pCfg->name;
|
||||
pProc->pParent = pCfg->pParent;
|
||||
pProc->childMallocHeadFp = pCfg->childMallocHeadFp;
|
||||
pProc->childFreeHeadFp = pCfg->childFreeHeadFp;
|
||||
pProc->childMallocBodyFp = pCfg->childMallocBodyFp;
|
||||
pProc->childFreeBodyFp = pCfg->childFreeBodyFp;
|
||||
pProc->childConsumeFp = pCfg->childConsumeFp;
|
||||
pProc->parentMallocHeadFp = pCfg->parentMallocHeadFp;
|
||||
pProc->parentFreeHeadFp = pCfg->parentFreeHeadFp;
|
||||
pProc->parentMallocBodyFp = pCfg->parentMallocBodyFp;
|
||||
pProc->parentFreeBodyFp = pCfg->parentFreeBodyFp;
|
||||
pProc->parentConsumeFp = pCfg->parentConsumeFp;
|
||||
pProc->isChild = pCfg->isChild;
|
||||
|
||||
uDebug("proc:%s, is initialized, child queue:%p parent queue:%p", pProc->name, pProc->pChildQueue, pProc->pParentQueue);
|
||||
|
||||
pProc->pid = fork();
|
||||
if (pProc->pid == 0) {
|
||||
pProc->isChild = 1;
|
||||
prctl(PR_SET_NAME, pProc->name, NULL, NULL, NULL);
|
||||
} else {
|
||||
pProc->isChild = 0;
|
||||
uInfo("this is parent process, child pid:%d", pProc->pid);
|
||||
}
|
||||
uDebug("proc:%s, is initialized, isChild:%d child queue:%p parent queue:%p", pProc->name, pProc->isChild,
|
||||
pProc->pChildQueue, pProc->pParentQueue);
|
||||
|
||||
return pProc;
|
||||
}
|
||||
|
||||
static void taosProcThreadLoop(SProcQueue *pQueue) {
|
||||
ProcConsumeFp consumeFp = pQueue->consumeFp;
|
||||
void *pParent = pQueue->pParent;
|
||||
static void taosProcThreadLoop(SProcObj *pProc) {
|
||||
void *pHead, *pBody;
|
||||
int16_t headLen;
|
||||
ProcFuncType ftype;
|
||||
int32_t bodyLen;
|
||||
SProcQueue *pQueue;
|
||||
ProcConsumeFp consumeFp;
|
||||
ProcMallocFp mallocHeadFp;
|
||||
ProcFreeFp freeHeadFp;
|
||||
ProcMallocFp mallocBodyFp;
|
||||
ProcFreeFp freeBodyFp;
|
||||
|
||||
uDebug("proc:%s, start to get msg from queue:%p", pQueue->name, pQueue);
|
||||
if (pProc->isChild) {
|
||||
pQueue = pProc->pChildQueue;
|
||||
consumeFp = pProc->childConsumeFp;
|
||||
mallocHeadFp = pProc->childMallocHeadFp;
|
||||
freeHeadFp = pProc->childFreeHeadFp;
|
||||
mallocBodyFp = pProc->childMallocBodyFp;
|
||||
freeBodyFp = pProc->childFreeBodyFp;
|
||||
} else {
|
||||
pQueue = pProc->pParentQueue;
|
||||
consumeFp = pProc->parentConsumeFp;
|
||||
mallocHeadFp = pProc->parentMallocHeadFp;
|
||||
freeHeadFp = pProc->parentFreeHeadFp;
|
||||
mallocBodyFp = pProc->parentMallocBodyFp;
|
||||
freeBodyFp = pProc->parentFreeBodyFp;
|
||||
}
|
||||
|
||||
uDebug("proc:%s, start to get msg from queue:%p, isChild:%d", pProc->name, pQueue, pProc->isChild);
|
||||
|
||||
while (1) {
|
||||
int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype);
|
||||
int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen, &ftype, mallocHeadFp, freeHeadFp,
|
||||
mallocBodyFp, freeBodyFp);
|
||||
if (numOfMsgs == 0) {
|
||||
uDebug("proc:%s, get no msg from queue:%p and exit the proc thread", pQueue->name, pQueue);
|
||||
uInfo("proc:%s, get no msg from queue:%p and exit the proc thread", pProc->name, pQueue);
|
||||
break;
|
||||
} else if (numOfMsgs < 0) {
|
||||
uTrace("proc:%s, get no msg from queue:%p since %s", pQueue->name, pQueue, terrstr());
|
||||
uTrace("proc:%s, get no msg from queue:%p since %s", pProc->name, pQueue, terrstr());
|
||||
taosMsleep(1);
|
||||
continue;
|
||||
} else {
|
||||
(*consumeFp)(pParent, pHead, headLen, pBody, bodyLen, ftype);
|
||||
(*consumeFp)(pProc->pParent, pHead, headLen, pBody, bodyLen, ftype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -426,40 +393,37 @@ int32_t taosProcRun(SProcObj *pProc) {
|
|||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pProc->isChild) {
|
||||
if (taosThreadCreate(&pProc->childThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pChildQueue) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to create thread since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
uDebug("proc:%s, child start to consume queue:%p", pProc->name, pProc->pChildQueue);
|
||||
} else {
|
||||
if (taosThreadCreate(&pProc->parentThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pParentQueue) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to create thread since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
uDebug("proc:%s, parent start to consume queue:%p", pProc->name, pProc->pParentQueue);
|
||||
if (taosThreadCreate(&pProc->thread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to create thread since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
uDebug("proc:%s, start to consume queue:%p, thread:%" PRId64, pProc->name, pProc->pChildQueue, pProc->thread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosProcStop(SProcObj *pProc) {
|
||||
pProc->stopFlag = true;
|
||||
// todo join
|
||||
static void taosProcStop(SProcObj *pProc) {
|
||||
if (!taosCheckPthreadValid(pProc->thread)) return;
|
||||
|
||||
uDebug("proc:%s, start to join thread:%" PRId64 ", isChild:%d", pProc->name, pProc->thread, pProc->isChild);
|
||||
SProcQueue *pQueue;
|
||||
if (pProc->isChild) {
|
||||
pQueue = pProc->pChildQueue;
|
||||
} else {
|
||||
pQueue = pProc->pParentQueue;
|
||||
}
|
||||
tsem_post(&pQueue->sem);
|
||||
taosThreadJoin(pProc->thread, NULL);
|
||||
}
|
||||
|
||||
bool taosProcIsChild(SProcObj *pProc) { return pProc->isChild; }
|
||||
|
||||
int32_t taosProcChildId(SProcObj *pProc) { return pProc->pid; }
|
||||
|
||||
void taosProcCleanup(SProcObj *pProc) {
|
||||
if (pProc != NULL) {
|
||||
uDebug("proc:%s, clean up", pProc->name);
|
||||
uDebug("proc:%s, start to clean up", pProc->name);
|
||||
taosProcStop(pProc);
|
||||
taosProcCleanupQueue(pProc->pChildQueue);
|
||||
taosProcCleanupQueue(pProc->pParentQueue);
|
||||
uDebug("proc:%s, is cleaned up", pProc->name);
|
||||
// taosProcCleanupQueue(pProc->pChildQueue);
|
||||
// taosProcCleanupQueue(pProc->pParentQueue);
|
||||
taosMemoryFree(pProc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,108 +26,3 @@ class UtilTestQueue : public ::testing::Test {
|
|||
static void SetUpTestSuite() {}
|
||||
static void TearDownTestSuite() {}
|
||||
};
|
||||
|
||||
#if 0
|
||||
TEST_F(UtilTestQueue, 01_fork) {
|
||||
pid_t pid;
|
||||
int shmid;
|
||||
int* shmptr;
|
||||
int* tmp;
|
||||
|
||||
int err;
|
||||
pthread_mutexattr_t mattr;
|
||||
if ((err = taosThreadMutexAttrInit(&mattr)) < 0) {
|
||||
printf("mutex addr init error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((err = taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED)) < 0) {
|
||||
printf("mutex addr get shared error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pthread_mutex_t* m;
|
||||
int mid = shmget(IPC_PRIVATE, sizeof(pthread_mutex_t), 0600);
|
||||
m = (pthread_mutex_t*)shmat(mid, NULL, 0);
|
||||
|
||||
if ((err = taosThreadMutexInit(m, &mattr)) < 0) {
|
||||
printf("mutex mutex init error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((shmid = shmget(IPC_PRIVATE, 1000, IPC_CREAT | 0600)) < 0) {
|
||||
perror("shmget error");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((shmptr = (int*)shmat(shmid, 0, 0)) == (void*)-1) {
|
||||
perror("shmat error");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tmp = shmptr;
|
||||
|
||||
int shmid2;
|
||||
int** shmptr2;
|
||||
if ((shmid2 = shmget(IPC_PRIVATE, 20, IPC_CREAT | 0600)) < 0) {
|
||||
perror("shmget2 error");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((shmptr2 = (int**)shmat(shmid2, 0, 0)) == (void*)-1) {
|
||||
perror("shmat2 error");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
*shmptr2 = shmptr;
|
||||
|
||||
if ((pid = fork()) < 0) {
|
||||
perror("fork error");
|
||||
exit(1);
|
||||
} else if (pid == 0) {
|
||||
if ((err = taosThreadMutexLock(m)) < 0) {
|
||||
printf("lock error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
**shmptr2 = i;
|
||||
(*shmptr2)++;
|
||||
}
|
||||
|
||||
if ((err = taosThreadMutexUnlock(m)) < 0) {
|
||||
printf("unlock error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
exit(0);
|
||||
|
||||
} else {
|
||||
if ((err = taosThreadMutexLock(m)) < 0) {
|
||||
printf("lock error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
for (int i = 10; i < 42; ++i) {
|
||||
**shmptr2 = i;
|
||||
(*shmptr2)++;
|
||||
}
|
||||
if ((err = taosThreadMutexUnlock(m)) < 0) {
|
||||
printf("unlock error:%s\n", strerror(err));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
wait(NULL);
|
||||
|
||||
for (int i = 0; i < 70; ++i) {
|
||||
printf("%d ", tmp[i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
taosThreadAttrDestroy(&mattr);
|
||||
//销毁mutex
|
||||
taosThreadMutexDestroy(m);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -50,7 +50,10 @@ class TDSql:
|
|||
def prepare(self):
|
||||
tdLog.info("prepare database:db")
|
||||
s = 'reset query cache'
|
||||
self.cursor.execute(s)
|
||||
try:
|
||||
self.cursor.execute(s)
|
||||
except:
|
||||
tdLog.notice("'reset query cache' is not supported")
|
||||
s = 'drop database if exists db'
|
||||
self.cursor.execute(s)
|
||||
s = 'create database db'
|
||||
|
@ -341,4 +344,4 @@ class TDSql:
|
|||
tdLog.info("dir: %s is created" %dir)
|
||||
pass
|
||||
|
||||
tdSql = TDSql()
|
||||
tdSql = TDSql()
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
# ---- query
|
||||
./test.sh -f tsim/query/interval.sim
|
||||
./test.sh -f tsim/query/interval-offset.sim
|
||||
./test.sh -f tsim/query/scalarFunction.sim
|
||||
|
||||
# ---- show
|
||||
./test.sh -f tsim/show/basic.sim
|
||||
|
@ -40,12 +41,12 @@
|
|||
./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
|
||||
./test.sh -f tsim/stable/disk.sim
|
||||
./test.sh -f tsim/stable/dnode3.sim
|
||||
./test.sh -f tsim/stable/metrics.sim
|
||||
./test.sh -f tsim/stable/refcount.sim
|
||||
# ./test.sh -f tsim/stable/show.sim
|
||||
./test.sh -f tsim/stable/values.sim
|
||||
./test.sh -f tsim/stable/vnode3.sim
|
||||
|
||||
#======================b1-end===============
|
||||
|
|
|
@ -0,0 +1,484 @@
|
|||
#### abs, log, pow, sqrt, sin, cos, tan, asin, acos, atan, ceil, floor, round
|
||||
|
||||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/cfg.sh -n dnode1
|
||||
system sh/exec.sh -n dnode1 -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
|
||||
|
||||
$vgroups = 4
|
||||
$dbNamme = d0
|
||||
|
||||
print =============== create database $dbNamme vgroups $vgroups
|
||||
sql create database $dbNamme vgroups $vgroups
|
||||
sql show databases
|
||||
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
|
||||
print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
|
||||
#print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
|
||||
|
||||
sql use $dbNamme
|
||||
|
||||
print =============== create super table
|
||||
sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int)
|
||||
|
||||
print =============== create child table
|
||||
$tbPrefix = ct
|
||||
$tbNum = 100
|
||||
|
||||
$i = 0
|
||||
while $i < $tbNum
|
||||
$tb = $tbPrefix . $i
|
||||
sql create table $tb using stb tags( $i )
|
||||
$i = $i + 1
|
||||
endw
|
||||
|
||||
print =============== create normal table
|
||||
sql create table ntb (ts timestamp, c1 int, c2 float, c3 double)
|
||||
|
||||
sql show tables
|
||||
if $rows != 101 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== insert data
|
||||
$rowNum = 20
|
||||
$tstart = 1640966400000 # 2022-01-01 00:00:00.000
|
||||
|
||||
$i = 0
|
||||
while $i < $tbNum
|
||||
$tb = $tbPrefix . $i
|
||||
|
||||
$x = 0
|
||||
$c1 = 0
|
||||
while $x < $rowNum
|
||||
$c2 = 0 - $c1
|
||||
$c3 = $c1 + 100
|
||||
|
||||
sql insert into $tb values ($tstart , $c1 , $c2 , $c3 )
|
||||
sql insert into ntb values ($tstart , $c1 , $c2 , $c3 )
|
||||
$tstart = $tstart + 1
|
||||
$c1 = $c1 + 5
|
||||
$x = $x + 1
|
||||
endw
|
||||
|
||||
$i = $i + 1
|
||||
$tstart = 1640966400000
|
||||
endw
|
||||
|
||||
$totalRows = $rowNum * $tbNum
|
||||
print ====> totalRows of stb: $totalRows
|
||||
|
||||
$loop_test = 0
|
||||
loop_test_pos:
|
||||
|
||||
print ====> abs
|
||||
sql select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ct1
|
||||
print ====> select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, abs(c1), c2, abs(c2), c3, abs(c3) from stb
|
||||
sql select c1, abs(c1), c2, abs(c2), c3, abs(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ntb
|
||||
sql select c1, abs(c1), c2, abs(c2), c3, abs(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> log
|
||||
sql select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ct1
|
||||
print ====> select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from stb
|
||||
sql select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ntb
|
||||
sql select c1, log(c1, 10), c2, log(c2, 10), c3, log(c3, 10) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> pow
|
||||
sql select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ct1
|
||||
print ====> select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from stb
|
||||
sql select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ntb
|
||||
sql select c1, pow(c1, 2), c2, pow(c2, 2), c3, pow(c3, 2) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> sqrt
|
||||
sql select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ct1
|
||||
print ====> select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from stb
|
||||
sql select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ntb
|
||||
sql select c1, sqrt(c1), c2, sqrt(c2), c3, sqrt(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> sin
|
||||
#sql select c1, sin(c1), sin(c1) * 3.14159265 / 180 from ct1 # TD-14426
|
||||
sql select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ct1
|
||||
print ====> select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, sin(c1), c2, sin(c2), c3, sin(c3) from stb
|
||||
sql select c1, sin(c1), c2, sin(c2), c3, sin(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ntb
|
||||
sql select c1, sin(c1), c2, sin(c2), c3, sin(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> cos
|
||||
sql select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ct1
|
||||
print ====> select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, cos(c1), c2, cos(c2), c3, cos(c3) from stb
|
||||
sql select c1, cos(c1), c2, cos(c2), c3, cos(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ntb
|
||||
sql select c1, cos(c1), c2, cos(c2), c3, cos(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> tan
|
||||
sql select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ct1
|
||||
print ====> select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, tan(c1), c2, tan(c2), c3, tan(c3) from stb
|
||||
sql select c1, tan(c1), c2, tan(c2), c3, tan(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ntb
|
||||
sql select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> asin
|
||||
sql select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ct1
|
||||
print ====> select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, asin(c1), c2, asin(c2), c3, asin(c3) from stb
|
||||
sql select c1, asin(c1), c2, asin(c2), c3, asin(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ntb
|
||||
sql select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> acos
|
||||
sql select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ct1
|
||||
print ====> select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, acos(c1), c2, acos(c2), c3, acos(c3) from stb
|
||||
sql select c1, acos(c1), c2, acos(c2), c3, acos(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ntb
|
||||
sql select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> atan
|
||||
sql select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ct1
|
||||
print ====> select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, atan(c1), c2, atan(c2), c3, atan(c3) from stb
|
||||
sql select c1, atan(c1), c2, atan(c2), c3, atan(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ntb
|
||||
sql select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> ceil
|
||||
sql select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ct1
|
||||
print ====> select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from stb
|
||||
sql select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ntb
|
||||
sql select c1, ceil(c1), c2, ceil(c2), c3, ceil(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ====> floor
|
||||
sql select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ct1
|
||||
print ====> select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, floor(c1), c2, floor(c2), c3, floor(c3) from stb
|
||||
sql select c1, floor(c1), c2, floor(c2), c3, floor(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ntb
|
||||
sql select c1, floor(c1), c2, floor(c2), c3, floor(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
print ====> round
|
||||
sql select c1, round(c1), c2, round(c2), c3, round(c3) from ct1
|
||||
print ====> select c1, round(c1), c2, round(c2), c3, round(c3) from ct1
|
||||
print ====> rows: $rows
|
||||
print ====> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ====> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ====> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ====> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ====> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
print ====> $data50 $data51 $data52 $data53 $data54 $data55
|
||||
print ====> $data60 $data61 $data62 $data63 $data64 $data65
|
||||
print ====> $data70 $data71 $data72 $data73 $data74 $data75
|
||||
print ====> $data80 $data81 $data82 $data83 $data84 $data85
|
||||
print ====> $data90 $data91 $data92 $data93 $data94 $data95
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, round(c1), c2, round(c2), c3, round(c3) from stb
|
||||
sql select c1, round(c1), c2, round(c2), c3, round(c3) from stb
|
||||
if $rows != $totalRows then
|
||||
return -1
|
||||
endi
|
||||
print ====> select c1, round(c1), c2, round(c2), c3, round(c3) from ntb
|
||||
sql select c1, round(c1), c2, round(c2), c3, round(c3) from ntb
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $loop_test == 0 then
|
||||
print =============== stop and restart taosd
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
|
||||
$loop_cnt = 0
|
||||
check_dnode_ready_0:
|
||||
$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_0
|
||||
endi
|
||||
|
||||
$loop_test = 1
|
||||
goto loop_test_pos
|
||||
endi
|
||||
|
||||
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -20,6 +20,7 @@ run tsim/insert/null.sim
|
|||
|
||||
run tsim/query/interval.sim
|
||||
run tsim/query/interval-offset.sim
|
||||
run tsim/query/scalarFunction.sim
|
||||
|
||||
run tsim/show/basic.sim
|
||||
|
||||
|
|
|
@ -66,15 +66,15 @@ print =============== will support: * from stb; function from stb/ctb
|
|||
|
||||
sql create topic topic_stb_column as select ts, c1, c3 from stb
|
||||
#sql create topic topic_stb_all as select * from stb
|
||||
#sql create topic topic_stb_function as select ts, abs(c1), sina(c2) from stb
|
||||
sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb
|
||||
|
||||
sql create topic topic_ctb_column as select ts, c1, c3 from ct0
|
||||
sql create topic topic_ctb_all as select * from ct0
|
||||
#sql create topic topic_ctb_function as select ts, abs(c1), sina(c2) from ct0
|
||||
sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0
|
||||
|
||||
sql create topic topic_ntb_column as select ts, c1, c3 from ntb
|
||||
sql create topic topic_ntb_all as select * from ntb
|
||||
#sql create topic topic_ntb_function as select ts, abs(c1), sina(c2) from ntb
|
||||
sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb
|
||||
|
||||
sql show tables
|
||||
if $rows != 3 then
|
||||
|
@ -147,6 +147,13 @@ endi
|
|||
# return -1
|
||||
#endi
|
||||
|
||||
print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2"
|
||||
system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2"
|
||||
print cmd result----> $system_content
|
||||
if $system_content != @{consume success: 20, 0}@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2"
|
||||
system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2"
|
||||
print cmd result----> $system_content
|
||||
|
@ -161,6 +168,13 @@ if $system_content != @{consume success: 10, 0}@ then
|
|||
return -1
|
||||
endi
|
||||
|
||||
print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2"
|
||||
system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2"
|
||||
print cmd result----> $system_content
|
||||
if $system_content != @{consume success: 10, 0}@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2"
|
||||
system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2"
|
||||
print cmd result----> $system_content
|
||||
|
@ -175,6 +189,13 @@ if $system_content != @{consume success: 20, 0}@ then
|
|||
return -1
|
||||
endi
|
||||
|
||||
print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2"
|
||||
system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2"
|
||||
print cmd result----> $system_content
|
||||
if $system_content != @{consume success: 20, 0}@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== create database , vgroup 4
|
||||
$dbNamme = d1
|
||||
sql create database $dbNamme vgroups 4
|
||||
|
|
|
@ -226,7 +226,7 @@ void loop_consume(tmq_t* tmq) {
|
|||
int32_t totalRows = 0;
|
||||
int32_t skipLogNum = 0;
|
||||
while (running) {
|
||||
tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 1);
|
||||
tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 6000);
|
||||
if (tmqMsg) {
|
||||
totalMsgs++;
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f36b07f710d661dca88fdd70e73b5e3e16a960e0
|
||||
Subproject commit 33cdfe4f90a209f105c1b6091439798a9cde1e93
|
Loading…
Reference in New Issue