提交 4afa7acf 编写于 作者: X Xiaoyu Wang

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

...@@ -2017,7 +2017,6 @@ typedef struct { ...@@ -2017,7 +2017,6 @@ typedef struct {
int8_t slidingUnit; // MACRO: TIME_UNIT_XXX int8_t slidingUnit; // MACRO: TIME_UNIT_XXX
int8_t timezoneInt; // sma data expired if timezone changes. int8_t timezoneInt; // sma data expired if timezone changes.
char indexName[TSDB_INDEX_NAME_LEN]; char indexName[TSDB_INDEX_NAME_LEN];
char timezone[TD_TIMEZONE_LEN];
int32_t exprLen; int32_t exprLen;
int32_t tagsFilterLen; int32_t tagsFilterLen;
int64_t indexUid; int64_t indexUid;
...@@ -2055,32 +2054,6 @@ void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq); ...@@ -2055,32 +2054,6 @@ void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq); int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq); void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
typedef struct {
col_id_t colId;
uint16_t blockSize; // sma data block size
char data[];
} STSmaColData;
typedef struct {
tb_uid_t tableUid; // super/child/normal table uid
int32_t dataLen; // not including head
char data[];
} STSmaTbData;
typedef struct {
int64_t indexUid;
TSKEY skey; // startKey of one interval/sliding window
int64_t interval;
int32_t dataLen; // not including head
int8_t intervalUnit;
char data[];
} STSmaDataWrapper; // sma data for a interval/sliding window
// interval/sliding => window
// => window->table->colId
// => 当一个window下所有的表均计算完成时,流计算告知tsdb清除window的过期标记
// RSma: Rollup SMA // RSma: Rollup SMA
typedef struct { typedef struct {
int64_t interval; int64_t interval;
......
...@@ -937,9 +937,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col ...@@ -937,9 +937,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
STColumn *pCol = NULL; STColumn *pCol = NULL;
STSchema *pSchema = pIter->pSchema; STSchema *pSchema = pIter->pSchema;
while (pIter->colIdx <= pSchema->numOfCols) { 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) { if (colId == pCol->colId) {
++pIter->colIdx;
break; break;
} else if (colId < pCol->colId) { } else if (colId < pCol->colId) {
++pIter->colIdx; ++pIter->colIdx;
...@@ -948,7 +947,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col ...@@ -948,7 +947,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
return false; 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)) { } else if (TD_IS_KV_ROW(pIter->pRow)) {
return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal); return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal);
} else { } else {
......
...@@ -37,6 +37,11 @@ typedef struct SReadHandle { ...@@ -37,6 +37,11 @@ typedef struct SReadHandle {
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1 #define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
#define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2 #define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2
typedef enum {
OPTR_EXEC_MODEL_BATCH = 0x1,
OPTR_EXEC_MODEL_STREAM = 0x2,
} EOPTR_EXEC_MODEL;
/** /**
* Create the exec task for streaming mode * Create the exec task for streaming mode
* @param pMsg * @param pMsg
...@@ -84,7 +89,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA ...@@ -84,7 +89,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA
* @return * @return
*/ */
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan, int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan,
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle); qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, EOPTR_EXEC_MODEL model);
/** /**
* The main task execution function, including query on both table and multiple tables, * The main task execution function, including query on both table and multiple tables,
......
...@@ -82,6 +82,7 @@ extern "C" { ...@@ -82,6 +82,7 @@ extern "C" {
#include "osLz4.h" #include "osLz4.h"
#include "osMath.h" #include "osMath.h"
#include "osMemory.h" #include "osMemory.h"
#include "osProc.h"
#include "osRand.h" #include "osRand.h"
#include "osThread.h" #include "osThread.h"
#include "osSemaphore.h" #include "osSemaphore.h"
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_OS_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 { ...@@ -29,7 +29,6 @@ typedef struct {
int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ; int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ;
void taosDropShm(SShm *pShm); void taosDropShm(SShm *pShm);
int32_t taosAttachShm(SShm *pShm); int32_t taosAttachShm(SShm *pShm);
void taosDetachShm(SShm *pShm);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -49,6 +49,8 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp); ...@@ -49,6 +49,8 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp);
void taosIgnSignal(int32_t signum); void taosIgnSignal(int32_t signum);
void taosDflSignal(int32_t signum); void taosDflSignal(int32_t signum);
void taosKillChildOnParentStopped();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -32,6 +32,9 @@ typedef pthread_once_t TdThreadOnce; ...@@ -32,6 +32,9 @@ typedef pthread_once_t TdThreadOnce;
typedef pthread_rwlockattr_t TdThreadRwlockAttr; typedef pthread_rwlockattr_t TdThreadRwlockAttr;
typedef pthread_cond_t TdThreadCond; typedef pthread_cond_t TdThreadCond;
typedef pthread_condattr_t TdThreadCondAttr; typedef pthread_condattr_t TdThreadCondAttr;
typedef pthread_key_t TdThreadKey;
typedef pthread_barrier_t TdThreadBarrier;
typedef pthread_barrierattr_t TdThreadBarrierAttr;
#define taosThreadCleanupPush pthread_cleanup_push #define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop #define taosThreadCleanupPop pthread_cleanup_pop
...@@ -49,68 +52,180 @@ typedef pthread_condattr_t TdThreadCondAttr; ...@@ -49,68 +52,180 @@ typedef pthread_condattr_t TdThreadCondAttr;
#define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID #define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID
#define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID #define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID
#define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID #define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
#define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID #define pthread_key_t PTHREAD_KEY_T_TYPE_TAOS_FORBID
#define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID #define pthread_barrier_t PTHREAD_BARRIER_T_TYPE_TAOS_FORBID
#define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID #define pthread_barrierattr_t PTHREAD_BARRIERATTR_T_TYPE_TAOS_FORBID
#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
#define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
#define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
#define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
#define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
#define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID
#define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID #define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
#define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
#define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID
#define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID #define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID #define pthread_attr_getdetachstate PTHREAD_ATTR_GETDETACHSTATE_FUNC_TAOS_FORBID
#define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID #define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED_FUNC_TAOS_FORBID
#define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID #define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM_FUNC_TAOS_FORBID
#define pthread_cond_signal PTHREAD_COND_SIGNAL_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_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_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID
#define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
#define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID #define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID
#define pthread_self PTHREAD_SELF_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_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
#define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID #define pthread_exit PTHREAD_EXIT_FUNC_TAOS_FORBID
#define pthread_cancel PTHREAD_CANCEL_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_kill PTHREAD_KILL_FUNC_TAOS_FORBID
#define pthread_mutex_consistent PTHREAD_MUTEX_CONSISTENT_FUNC_TAOS_FORBID
#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
#define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID
#define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
#define pthread_mutex_timedlock PTHREAD_MUTEX_TIMEDLOCK_FUNC_TAOS_FORBID
#define pthread_mutex_trylock PTHREAD_MUTEX_TRYLOCK_FUNC_TAOS_FORBID
#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
#define pthread_mutexattr_destroy PTHREAD_MUTEXATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_mutexattr_getpshared PTHREAD_MUTEXATTR_GETPSHARED_FUNC_TAOS_FORBID
#define pthread_mutexattr_getrobust PTHREAD_MUTEXATTR_GETROBUST_FUNC_TAOS_FORBID
#define pthread_mutexattr_gettype PTHREAD_MUTEXATTR_GETTYPE_FUNC_TAOS_FORBID
#define pthread_mutexattr_init PTHREAD_MUTEXATTR_INIT_FUNC_TAOS_FORBID
#define pthread_mutexattr_setpshared PTHREAD_MUTEXATTR_SETPSHARED_FUNC_TAOS_FORBID
#define pthread_mutexattr_setrobust PTHREAD_MUTEXATTR_SETROBUST_FUNC_TAOS_FORBID
#define pthread_mutexattr_settype PTHREAD_MUTEXATTR_SETTYPE_FUNC_TAOS_FORBID
#define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
#define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID
#define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID
#define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_timedrdlock PTHREAD_RWLOCK_TIMEDRDLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_timedwrlock PTHREAD_RWLOCK_TIMEDWRLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_tryrdlock PTHREAD_RWLOCK_TRYRDLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_trywrlock PTHREAD_RWLOCK_TRYWRLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
#define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
#define pthread_rwlockattr_destroy PTHREAD_RWLOCKATTR_DESTROY_FUNC_TAOS_FORBID
#define pthread_rwlockattr_getpshared PTHREAD_RWLOCKATTR_GETPSHARED_FUNC_TAOS_FORBID
#define pthread_rwlockattr_init PTHREAD_RWLOCKATTR_INIT_FUNC_TAOS_FORBID
#define pthread_rwlockattr_setpshared PTHREAD_RWLOCKATTR_SETPSHARED_FUNC_TAOS_FORBID
#define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID
#define pthread_setcancelstate PTHREAD_SETCANCELSTATE_FUNC_TAOS_FORBID
#define pthread_setcanceltype PTHREAD_SETCANCELTYPE_FUNC_TAOS_FORBID
#define pthread_setschedparam PTHREAD_SETSCHEDPARAM_FUNC_TAOS_FORBID
#define pthread_setspecific PTHREAD_SETSPECIFIC_FUNC_TAOS_FORBID
#define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID
#define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID
#define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
#define pthread_spin_trylock PTHREAD_SPIN_TRYLOCK_FUNC_TAOS_FORBID
#define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
#define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
#define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID
#define sigwait SIGWAIT_FUNC_TAOS_FORBID
#endif #endif
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared); int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg);
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr); int32_t taosThreadAttrDestroy(TdThreadAttr * attr);
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock); int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate);
int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched);
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param);
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy);
int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope);
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize);
int32_t taosThreadAttrInit(TdThreadAttr * attr);
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate);
int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched);
int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param);
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy);
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope);
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize);
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier);
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count);
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier);
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr);
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared);
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr);
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared);
int32_t taosThreadCancel(TdThread thread);
int32_t taosThreadCondDestroy(TdThreadCond * cond);
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr);
int32_t taosThreadCondSignal(TdThreadCond * cond);
int32_t taosThreadCondBroadcast(TdThreadCond * cond);
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex);
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime);
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr);
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared);
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr);
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared);
int32_t taosThreadDetach(TdThread thread);
int32_t taosThreadEqual(TdThread t1, TdThread t2);
void taosThreadExit(void *valuePtr);
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param);
void *taosThreadGetSpecific(TdThreadKey key);
int32_t taosThreadJoin(TdThread thread, void **valuePtr);
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *));
int32_t taosThreadKeyDelete(TdThreadKey key);
int32_t taosThreadKill(TdThread thread, int32_t sig);
int32_t taosThreadMutexConsistent(TdThreadMutex* mutex);
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex); int32_t taosThreadMutexDestroy(TdThreadMutex * mutex);
int32_t taosThreadSpinLock(TdThreadSpinlock *lock); int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr);
int32_t taosThreadMutexLock(TdThreadMutex *mutex); int32_t taosThreadMutexLock(TdThreadMutex * mutex);
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock); int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime);
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock); int32_t taosThreadMutexTryLock(TdThreadMutex * mutex);
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex); int32_t taosThreadMutexUnlock(TdThreadMutex * mutex);
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock); int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr);
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock); int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared);
void taosThreadTestCancel(void); int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust);
int32_t taosThreadAttrInit(TdThreadAttr *attr); int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind);
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg); int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr);
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)); int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared);
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState); int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust);
int32_t taosThreadAttrDestroy(TdThreadAttr *attr); int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind);
int32_t taosThreadJoin(TdThread thread, void **pValue); int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void));
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr); int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock); int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr);
int32_t taosThreadCondSignal(TdThreadCond *cond); int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock);
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr); int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime);
int32_t taosThreadCondBroadcast(TdThreadCond *cond); int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime);
int32_t taosThreadCondDestroy(TdThreadCond *cond); int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock);
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex); int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock);
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr);
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared);
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr);
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared);
TdThread taosThreadSelf(void); TdThread taosThreadSelf(void);
int32_t taosThreadEqual(TdThread t1, TdThread t2); int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate);
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset); int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype);
int32_t taosThreadCancel(TdThread thread); int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param);
int32_t taosThreadKill(TdThread thread, int sig); int32_t taosThreadSetSpecific(TdThreadKey key, const void *value);
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock);
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared);
int32_t taosThreadSpinLock(TdThreadSpinlock * lock);
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock);
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock);
void taosThreadTestCancel(void);
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset);
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include <time.h>
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section. // When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
......
...@@ -78,6 +78,7 @@ int32_t* taosGetErrno(); ...@@ -78,6 +78,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C) #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_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D)
#define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E) #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_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112) #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 ...@@ -32,29 +32,25 @@ typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int16_t headLen, void
ProcFuncType ftype); ProcFuncType ftype);
typedef struct { typedef struct {
int32_t childQueueSize;
ProcConsumeFp childConsumeFp; ProcConsumeFp childConsumeFp;
ProcMallocFp childMallocHeadFp; ProcMallocFp childMallocHeadFp;
ProcFreeFp childFreeHeadFp; ProcFreeFp childFreeHeadFp;
ProcMallocFp childMallocBodyFp; ProcMallocFp childMallocBodyFp;
ProcFreeFp childFreeBodyFp; ProcFreeFp childFreeBodyFp;
int32_t parentQueueSize;
ProcConsumeFp parentConsumeFp; ProcConsumeFp parentConsumeFp;
ProcMallocFp parentdMallocHeadFp; ProcMallocFp parentMallocHeadFp;
ProcFreeFp parentFreeHeadFp; ProcFreeFp parentFreeHeadFp;
ProcMallocFp parentMallocBodyFp; ProcMallocFp parentMallocBodyFp;
ProcFreeFp parentFreeBodyFp; ProcFreeFp parentFreeBodyFp;
bool testFlag; SShm shm;
void *pParent; void *pParent;
const char *name; const char *name;
bool isChild;
} SProcCfg; } SProcCfg;
SProcObj *taosProcInit(const SProcCfg *pCfg); SProcObj *taosProcInit(const SProcCfg *pCfg);
void taosProcCleanup(SProcObj *pProc); void taosProcCleanup(SProcObj *pProc);
int32_t taosProcRun(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, int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
ProcFuncType ftype); ProcFuncType ftype);
int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
......
...@@ -130,7 +130,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { ...@@ -130,7 +130,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
} }
code = 0; code = 0;
dInfo("succcessed to read file %s", file); dDebug("succcessed to read file %s", file);
dmPrintDnodes(pMgmt); dmPrintDnodes(pMgmt);
PRASE_DNODE_OVER: PRASE_DNODE_OVER:
......
...@@ -112,6 +112,16 @@ int32_t dmInit(SMgmtWrapper *pWrapper) { ...@@ -112,6 +112,16 @@ int32_t dmInit(SMgmtWrapper *pWrapper) {
return -1; 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; pWrapper->pMgmt = pMgmt;
dInfo("dnode-mgmt is initialized"); dInfo("dnode-mgmt is initialized");
return 0; return 0;
...@@ -122,6 +132,7 @@ void dmCleanup(SMgmtWrapper *pWrapper) { ...@@ -122,6 +132,7 @@ void dmCleanup(SMgmtWrapper *pWrapper) {
if (pMgmt == NULL) return; if (pMgmt == NULL) return;
dInfo("dnode-mgmt start to clean up"); dInfo("dnode-mgmt start to clean up");
SDnode *pDnode = pMgmt->pDnode;
dmStopWorker(pMgmt); dmStopWorker(pMgmt);
taosWLockLatch(&pMgmt->latch); taosWLockLatch(&pMgmt->latch);
...@@ -140,6 +151,9 @@ void dmCleanup(SMgmtWrapper *pWrapper) { ...@@ -140,6 +151,9 @@ void dmCleanup(SMgmtWrapper *pWrapper) {
taosMemoryFree(pMgmt); taosMemoryFree(pMgmt);
pWrapper->pMgmt = NULL; pWrapper->pMgmt = NULL;
dndCleanupServer(pDnode);
dndCleanupClient(pDnode);
dInfo("dnode-mgmt is cleaned up"); dInfo("dnode-mgmt is cleaned up");
} }
......
...@@ -53,7 +53,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { ...@@ -53,7 +53,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
tSerializeSStatusReq(pHead, contLen, &req); tSerializeSStatusReq(pHead, contLen, &req);
taosArrayDestroy(req.pVloads); 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; pMgmt->statusSent = 1;
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
......
...@@ -30,7 +30,7 @@ static struct { ...@@ -30,7 +30,7 @@ static struct {
} global = {0}; } global = {0};
static void dndStopDnode(int signum, void *info, void *ctx) { 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); SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
if (pDnode != NULL) { if (pDnode != NULL) {
dndHandleEvent(pDnode, DND_EVENT_STOP); dndHandleEvent(pDnode, DND_EVENT_STOP);
...@@ -38,8 +38,10 @@ static void dndStopDnode(int signum, void *info, void *ctx) { ...@@ -38,8 +38,10 @@ static void dndStopDnode(int signum, void *info, void *ctx) {
} }
static void dndHandleChild(int signum, void *info, void *ctx) { static void dndHandleChild(int signum, void *info, void *ctx) {
dInfo("signal:%d is received", signum); dInfo("sigchild received");
if (global.pDnode != NULL) {
dndHandleEvent(global.pDnode, DND_EVENT_CHILD); dndHandleEvent(global.pDnode, DND_EVENT_CHILD);
}
} }
static void dndSetSignalHandle() { static void dndSetSignalHandle() {
...@@ -50,15 +52,10 @@ static void dndSetSignalHandle() { ...@@ -50,15 +52,10 @@ static void dndSetSignalHandle() {
taosSetSignal(SIGBREAK, dndStopDnode); taosSetSignal(SIGBREAK, dndStopDnode);
if (!tsMultiProcess) { if (!tsMultiProcess) {
// Set the single process signal } else if (global.ntype == DNODE || global.ntype == NODE_MAX) {
} else if (global.ntype == DNODE) {
// Set the parent process signal
// When the child process exits, the parent process receives a signal
taosSetSignal(SIGCHLD, dndHandleChild); taosSetSignal(SIGCHLD, dndHandleChild);
} else { } else {
// Set child process signal taosKillChildOnParentStopped();
// When the parent process exits, the child process will receive the SIGKILL signal
prctl(PR_SET_PDEATHSIG, SIGKILL);
} }
} }
...@@ -79,10 +76,14 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { ...@@ -79,10 +76,14 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX); tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-e") == 0) { } else if (strcmp(argv[i], "-e") == 0) {
tstrncpy(global.envFile, argv[++i], PATH_MAX); tstrncpy(global.envFile, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-k") == 0) {
global.generateGrant = true;
} else if (strcmp(argv[i], "-n") == 0) { } else if (strcmp(argv[i], "-n") == 0) {
global.ntype = atoi(argv[++i]); 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) { } else if (strcmp(argv[i], "-C") == 0) {
global.dumpConfig = true; global.dumpConfig = true;
} else if (strcmp(argv[i], "-V") == 0) { } else if (strcmp(argv[i], "-V") == 0) {
...@@ -138,24 +139,24 @@ static int32_t dndInitLog() { ...@@ -138,24 +139,24 @@ static int32_t dndInitLog() {
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
} }
static void dndSetProcName(char **argv) { static void dndSetProcInfo(int32_t argc, char **argv) {
if (global.ntype != DNODE) { taosSetProcPath(argc, argv);
if (global.ntype != DNODE && global.ntype != NODE_MAX) {
const char *name = dndNodeProcStr(global.ntype); const char *name = dndNodeProcStr(global.ntype);
prctl(PR_SET_NAME, name); taosSetProcName(argc, argv, name);
strcpy(argv[0], name);
} }
} }
static int32_t dndRunDnode() { static int32_t dndRunDnode() {
if (dndInit() != 0) { if (dndInit() != 0) {
dError("failed to initialize environment since %s", terrstr()); dError("failed to init environment since %s", terrstr());
return -1; return -1;
} }
SDnodeOpt option = dndGetOpt(); SDnodeOpt option = dndGetOpt();
SDnode *pDnode = dndCreate(&option); SDnode *pDnode = dndCreate(&option);
if (pDnode == NULL) { if (pDnode == NULL) {
dError("failed to to create dnode object since %s", terrstr()); dError("failed to to create dnode since %s", terrstr());
return -1; return -1;
} else { } else {
global.pDnode = pDnode; global.pDnode = pDnode;
...@@ -212,6 +213,6 @@ int main(int argc, char const *argv[]) { ...@@ -212,6 +213,6 @@ int main(int argc, char const *argv[]) {
return 0; return 0;
} }
dndSetProcName((char **)argv); dndSetProcInfo(argc, (char **)argv);
return dndRunDnode(); return dndRunDnode();
} }
...@@ -95,13 +95,14 @@ typedef struct SMgmtWrapper { ...@@ -95,13 +95,14 @@ typedef struct SMgmtWrapper {
bool deployed; bool deployed;
bool required; bool required;
EProcType procType; EProcType procType;
int32_t procId;
SProcObj *pProc; SProcObj *pProc;
SShm shm; SShm shm;
void *pMgmt; void *pMgmt;
SDnode *pDnode; 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; 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; } SMgmtWrapper;
typedef struct { typedef struct {
...@@ -128,26 +129,31 @@ typedef struct SDnode { ...@@ -128,26 +129,31 @@ typedef struct SDnode {
EDndStatus status; EDndStatus status;
EDndEvent event; EDndEvent event;
SStartupReq startup; SStartupReq startup;
TdFilePtr runtimeFile; TdFilePtr lockfile;
STransMgmt trans; STransMgmt trans;
SMgmtWrapper wrappers[NODE_MAX]; SMgmtWrapper wrappers[NODE_MAX];
} SDnode; } SDnode;
const char *dndNodeLogStr(ENodeType ntype); const char *dndNodeLogStr(ENodeType ntype);
const char *dndNodeProcStr(ENodeType ntype); const char *dndNodeProcStr(ENodeType ntype);
const char *dndEventStr(EDndEvent ev);
EDndStatus dndGetStatus(SDnode *pDnode); EDndStatus dndGetStatus(SDnode *pDnode);
void dndSetStatus(SDnode *pDnode, EDndStatus stat); void dndSetStatus(SDnode *pDnode, EDndStatus stat);
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
void dndSendMonitorReport(SDnode *pDnode); void dndSendMonitorReport(SDnode *pDnode);
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 dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg); int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg);
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper);
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);
......
...@@ -50,17 +50,13 @@ void dndClose(SDnode *pDnode); ...@@ -50,17 +50,13 @@ void dndClose(SDnode *pDnode);
void dndHandleEvent(SDnode *pDnode, EDndEvent event); void dndHandleEvent(SDnode *pDnode, EDndEvent event);
// dndTransport.c // 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); int32_t dndInitMsgHandle(SDnode *pDnode);
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
// dndFile.c // dndFile.c
int32_t dndOpenRuntimeFile(SDnode *pDnode); TdFilePtr dndCheckRunning(const char *dataDir);
int32_t dndWriteRuntimeFile(SDnode *pDnode); int32_t dndReadShmFile(SDnode *pDnode);
void dndCloseRuntimeFile(SDnode *pDnode); int32_t dndWriteShmFile(SDnode *pDnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -16,18 +16,9 @@ ...@@ -16,18 +16,9 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #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) { static bool dndRequireNode(SMgmtWrapper *pWrapper) {
bool required = false; bool required = false;
int32_t code =(*pWrapper->fp.requiredFp)(pWrapper, &required); int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
if (!required) { if (!required) {
dDebug("node:%s, no need to start", pWrapper->name); dDebug("node:%s, no need to start", pWrapper->name);
} else { } else {
...@@ -37,14 +28,18 @@ static bool dndRequireNode(SMgmtWrapper *pWrapper) { ...@@ -37,14 +28,18 @@ static bool dndRequireNode(SMgmtWrapper *pWrapper) {
} }
int32_t dndOpenNode(SMgmtWrapper *pWrapper) { int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
int32_t code = (*pWrapper->fp.openFp)(pWrapper); if (taosMkDir(pWrapper->path) != 0) {
if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno);
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
return -1;
}
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
return -1; return -1;
} else {
dDebug("node:%s, has been opened", pWrapper->name);
} }
dDebug("node:%s, has been opened", pWrapper->name);
pWrapper->deployed = true; pWrapper->deployed = true;
return 0; return 0;
} }
...@@ -70,54 +65,6 @@ void dndCloseNode(SMgmtWrapper *pWrapper) { ...@@ -70,54 +65,6 @@ void dndCloseNode(SMgmtWrapper *pWrapper) {
dDebug("node:%s, has been closed", pWrapper->name); 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, static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
ProcFuncType ftype) { ProcFuncType ftype) {
SRpcMsg *pRpc = &pMsg->rpcMsg; SRpcMsg *pRpc = &pMsg->rpcMsg;
...@@ -163,116 +110,206 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t ...@@ -163,116 +110,206 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t
taosMemoryFree(pMsg); taosMemoryFree(pMsg);
} }
static int32_t dndRunInMultiProcess(SDnode *pDnode) { static int32_t dndNewProc(SMgmtWrapper *pWrapper, ENodeType n) {
dInfo("dnode run in multi process mode"); char tstr[8] = {0};
char *args[6] = {0};
for (ENodeType n = 0; n < NODE_MAX; ++n) { snprintf(tstr, sizeof(tstr), "%d", n);
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; args[1] = "-c";
pWrapper->required = dndRequireNode(pWrapper); args[2] = configDir;
if (!pWrapper->required) continue; args[3] = "-n";
args[4] = tstr;
SMsgCb msgCb = dndCreateMsgcb(pWrapper); args[5] = NULL;
tmsgSetDefaultMsgCb(&msgCb);
int32_t pid = taosNewProc(args);
if (taosMkDir(pWrapper->path) != 0) { if (pid <= 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
if (n == DNODE) { pWrapper->procId = pid;
dInfo("node:%s, will start in parent process", pWrapper->name); dInfo("node:%s, run in new process, pid:%d", pWrapper->name, pid);
pWrapper->procType = PROC_SINGLE; return 0;
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 static SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) {
.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem, .childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont, .childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont, .childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
.parentQueueSize = 1024 * 1024 * 2, // size will be a configuration item
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
.parentdMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
.shm = pWrapper->shm,
.pParent = pWrapper, .pParent = pWrapper,
.name = pWrapper->name}; .name = pWrapper->name};
SProcObj *pProc = taosProcInit(&cfg); return cfg;
if (pProc == NULL) { }
dError("node:%s, failed to fork since %s", pWrapper->name, terrstr());
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;
if (dndOpenNode(pWrapper) != 0) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
}
pWrapper->pProc = pProc; dndSetStatus(pDnode, DND_STAT_RUNNING);
if (taosProcIsChild(pProc)) { for (ENodeType n = 0; n < NODE_MAX; ++n) {
dInfo("node:%s, will start in child process", pWrapper->name); SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
pWrapper->procType = PROC_CHILD; if (!pWrapper->required) continue;
dndResetLog(pWrapper); 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;
}
}
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);
}
dInfo("node:%s, clean up resources inherited from parent", pWrapper->name); return 0;
dndClearNodesExecpt(pDnode, n); }
dInfo("node:%s, will be initialized in child process", pWrapper->name); static int32_t dndRunInParentProcess(SDnode *pDnode) {
if (dndOpenNode(pWrapper) != 0) { dInfo("dnode run in parent process");
dInfo("node:%s, failed to init in child process since %s", pWrapper->name, terrstr()); SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE];
if (dndOpenNode(pDWrapper) != 0) {
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
return -1; return -1;
} }
if (taosProcRun(pProc) != 0) { for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); 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; return -1;
} }
break; dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize);
} else {
dInfo("node:%s, will not start in parent process, child pid:%d", pWrapper->name, taosProcChildId(pProc)); SProcCfg cfg = dndGenProcCfg(pWrapper);
cfg.isChild = false;
pWrapper->procType = PROC_PARENT; pWrapper->procType = PROC_PARENT;
if (taosProcRun(pProc) != 0) { pWrapper->pProc = taosProcInit(&cfg);
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); 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; 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); dndSetStatus(pDnode, DND_STAT_RUNNING);
for (ENodeType n = 0; n < NODE_MAX; ++n) { 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]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue; if (!pWrapper->required) continue;
if (pWrapper->fp.startFp == NULL) continue; if (pDnode->ntype == NODE_MAX) continue;
if (pWrapper->procType == PROC_PARENT && n != DNODE) continue;
if (pWrapper->procType == PROC_CHILD && n == DNODE) continue; if (pWrapper->procId != 0 && !taosProcExists(pWrapper->procId)) {
if ((*pWrapper->fp.startFp)(pWrapper) != 0) { dInfo("node:%s, process not exist, pid:%d", pWrapper->name, pWrapper->procId);
dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); dndNewProc(pWrapper, n);
return -1; }
taosMsleep(100);
} }
} }
return 0; return 0;
} }
int32_t dndRun(SDnode *pDnode) { static int32_t dndRunInChildProcess(SDnode *pDnode) {
if (!tsMultiProcess) { dInfo("dnode run in child process");
if (dndRunInSingleProcess(pDnode) != 0) { SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
dError("failed to run dnode in single process mode since %s", terrstr());
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; return -1;
} }
} else {
if (dndRunInMultiProcess(pDnode) != 0) { SProcCfg cfg = dndGenProcCfg(pWrapper);
dError("failed to run dnode in multi process mode since %s", terrstr()); 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; return -1;
} }
} }
dndReportStartup(pDnode, "TDengine", "initialized successfully"); 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) { while (1) {
if (pDnode->event == DND_EVENT_STOP) { if (pDnode->event == DND_EVENT_STOP) {
dInfo("dnode is about to stop"); dInfo("dnode is about to stop");
...@@ -280,6 +317,16 @@ int32_t dndRun(SDnode *pDnode) { ...@@ -280,6 +317,16 @@ int32_t dndRun(SDnode *pDnode) {
} }
taosMsleep(100); 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; return 0;
} }
...@@ -117,7 +117,30 @@ _OVER: ...@@ -117,7 +117,30 @@ _OVER:
return code; 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; int32_t code = -1;
char itemName[24] = {0}; char itemName[24] = {0};
char content[MAXLEN + 1] = {0}; char content[MAXLEN + 1] = {0};
...@@ -125,17 +148,11 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) { ...@@ -125,17 +148,11 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
cJSON *root = NULL; cJSON *root = NULL;
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s.running", pDnode->dataDir, TD_DIRSEP); snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); dDebug("file %s not exist", file);
dError("failed to open file:%s since %s", file, terrstr()); code = 0;
goto _OVER;
}
if (taosLockFile(pFile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to lock file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }
...@@ -162,10 +179,10 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) { ...@@ -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) { for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
if (pWrapper->shm.id > 0) { if (pWrapper->shm.id >= 0) {
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size); dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
taosDropShm(&pWrapper->shm); taosDropShm(&pWrapper->shm);
} }
...@@ -174,27 +191,23 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) { ...@@ -174,27 +191,23 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
if (taosAttachShm(&pWrapper->shm) != 0) { if (taosAttachShm(&pWrapper->shm) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); 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; 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; code = 0;
_OVER: _OVER:
if (root != NULL) cJSON_Delete(root); if (root != NULL) cJSON_Delete(root);
if (code != 0) {
if (pFile != NULL) taosCloseFile(&pFile); if (pFile != NULL) taosCloseFile(&pFile);
} else {
pDnode->runtimeFile = pFile;
}
return code; return code;
} }
int32_t dndWriteRuntimeFile(SDnode *pDnode) { int32_t dndWriteShmFile(SDnode *pDnode) {
int32_t code = -1; int32_t code = -1;
int32_t len = 0; int32_t len = 0;
char content[MAXLEN + 1] = {0}; char content[MAXLEN + 1] = {0};
...@@ -202,8 +215,8 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) { ...@@ -202,8 +215,8 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
char realfile[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0};
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s.running.bak", pDnode->dataDir, TD_DIRSEP); snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP);
snprintf(realfile, sizeof(realfile), "%s%s.running", 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); pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
...@@ -214,12 +227,12 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) { ...@@ -214,12 +227,12 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
len += snprintf(content + len, MAXLEN - len, "{\n"); len += snprintf(content + len, MAXLEN - len, "{\n");
for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\": %d,\n", dndNodeProcStr(ntype), pWrapper->shm.id); len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id);
if (ntype == NODE_MAX - 1) { 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 { } 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"); len += snprintf(content + len, MAXLEN - len, "}\n");
...@@ -244,7 +257,7 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) { ...@@ -244,7 +257,7 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
return -1; return -1;
} }
dDebug("successed to write %s", realfile); dInfo("successed to write %s", realfile);
code = 0; code = 0;
_OVER: _OVER:
...@@ -254,11 +267,3 @@ _OVER: ...@@ -254,11 +267,3 @@ _OVER:
return code; return code;
} }
void dndCloseRuntimeFile(SDnode *pDnode) {
if (pDnode->runtimeFile) {
taosUnLockFile(pDnode->runtimeFile);
taosCloseFile(&pDnode->runtimeFile);
pDnode->runtimeFile = NULL;
}
}
\ No newline at end of file
...@@ -41,7 +41,7 @@ int32_t dndInit() { ...@@ -41,7 +41,7 @@ int32_t dndInit() {
return -1; return -1;
} }
dDebug("dnode env is initialized"); dInfo("dnode env is initialized");
return 0; return 0;
} }
...@@ -55,7 +55,7 @@ void dndCleanup() { ...@@ -55,7 +55,7 @@ void dndCleanup() {
monCleanup(); monCleanup();
walCleanUp(); walCleanUp();
taosStopCacheRefreshWorker(); 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) { void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
......
...@@ -66,7 +66,7 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { ...@@ -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); dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user);
code = (*msgFp)(pWrapper, pMsg); code = (*msgFp)(pWrapper, pMsg);
} else if (pWrapper->procType == PROC_PARENT) { } 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); pRpc->ahandle, pMsg->user);
code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, PROC_REQ); code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, PROC_REQ);
} else { } else {
......
...@@ -34,6 +34,14 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { ...@@ -34,6 +34,14 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
pDnode->lockfile = dndCheckRunning(pDnode->dataDir);
if (pDnode->lockfile == NULL) {
return -1;
}
}
return 0; return 0;
} }
...@@ -42,18 +50,22 @@ static void dndClearVars(SDnode *pDnode) { ...@@ -42,18 +50,22 @@ static void dndClearVars(SDnode *pDnode) {
SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
taosMemoryFreeClear(pMgmt->path); taosMemoryFreeClear(pMgmt->path);
} }
dndCloseRuntimeFile(pDnode); if (pDnode->lockfile != NULL) {
taosUnLockFile(pDnode->lockfile);
taosCloseFile(&pDnode->lockfile);
pDnode->lockfile = NULL;
}
taosMemoryFreeClear(pDnode->localEp); taosMemoryFreeClear(pDnode->localEp);
taosMemoryFreeClear(pDnode->localFqdn); taosMemoryFreeClear(pDnode->localFqdn);
taosMemoryFreeClear(pDnode->firstEp); taosMemoryFreeClear(pDnode->firstEp);
taosMemoryFreeClear(pDnode->secondEp); taosMemoryFreeClear(pDnode->secondEp);
taosMemoryFreeClear(pDnode->dataDir); taosMemoryFreeClear(pDnode->dataDir);
taosMemoryFree(pDnode); taosMemoryFree(pDnode);
dDebug("dnode object memory is cleared, data:%p", pDnode); dDebug("dnode memory is cleared, data:%p", pDnode);
} }
SDnode *dndCreate(const SDnodeOpt *pOption) { SDnode *dndCreate(const SDnodeOpt *pOption) {
dInfo("start to create dnode object"); dDebug("start to create dnode object");
int32_t code = -1; int32_t code = -1;
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
SDnode *pDnode = NULL; SDnode *pDnode = NULL;
...@@ -77,29 +89,11 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { ...@@ -77,29 +89,11 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
smGetMgmtFp(&pDnode->wrappers[SNODE]); smGetMgmtFp(&pDnode->wrappers[SNODE]);
bmGetMgmtFp(&pDnode->wrappers[BNODE]); 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) { for (ENodeType n = 0; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name); snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name);
pWrapper->path = strdup(path); pWrapper->path = strdup(path);
pWrapper->shm.id = -1;
pWrapper->pDnode = pDnode; pWrapper->pDnode = pDnode;
if (pWrapper->path == NULL) { if (pWrapper->path == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -110,15 +104,27 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { ...@@ -110,15 +104,27 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
taosInitRWLatch(&pWrapper->latch); 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; code = 0;
_OVER: _OVER:
if (code != 0 && pDnode) { if (code != 0 && pDnode) {
dndClearVars(pDnode); dndClearVars(pDnode);
pDnode = NULL; pDnode = NULL;
dError("failed to create dnode object since %s", terrstr()); dError("failed to create dnode since %s", terrstr());
} else {
dInfo("dnode object is created, data:%p", pDnode);
} }
return pDnode; return pDnode;
...@@ -135,21 +141,20 @@ void dndClose(SDnode *pDnode) { ...@@ -135,21 +141,20 @@ void dndClose(SDnode *pDnode) {
dInfo("start to close dnode, data:%p", pDnode); dInfo("start to close dnode, data:%p", pDnode);
dndSetStatus(pDnode, DND_STAT_STOPPED); dndSetStatus(pDnode, DND_STAT_STOPPED);
dndCleanupServer(pDnode);
dndCleanupClient(pDnode);
for (ENodeType n = 0; n < NODE_MAX; ++n) { for (ENodeType n = 0; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
dndCloseNode(pWrapper); dndCloseNode(pWrapper);
} }
dndClearVars(pDnode); dndClearVars(pDnode);
dInfo("dnode object is closed, data:%p", pDnode); dInfo("dnode is closed, data:%p", pDnode);
} }
void dndHandleEvent(SDnode *pDnode, EDndEvent event) { void dndHandleEvent(SDnode *pDnode, EDndEvent event) {
dInfo("dnode object receive event %d, data:%p", event, pDnode); dInfo("dnode receive %s event, data:%p", dndEventStr(event), pDnode);
if (event == DND_EVENT_STOP) {
pDnode->event = event; pDnode->event = event;
}
} }
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType ntype) { SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType ntype) {
......
...@@ -62,3 +62,16 @@ const char *dndNodeProcStr(ENodeType ntype) { ...@@ -62,3 +62,16 @@ const char *dndNodeProcStr(ENodeType ntype) {
return "taosd"; 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";
}
}
\ No newline at end of file
...@@ -310,6 +310,8 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { ...@@ -310,6 +310,8 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) {
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
return -1; return -1;
} }
pShow->numOfReads = 0;
} }
ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
...@@ -374,7 +376,7 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { ...@@ -374,7 +376,7 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) {
pReq->pRsp = pRsp; pReq->pRsp = pRsp;
pReq->rspLen = size; pReq->rspLen = size;
if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { if (rowsRead == 0 || rowsToRead == 0 || (rowsRead < rowsToRead)) {
pRsp->completed = 1; pRsp->completed = 1;
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
mndReleaseShowObj((SShowObj*) pShow, true); mndReleaseShowObj((SShowObj*) pShow, true);
......
...@@ -1608,7 +1608,6 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 ...@@ -1608,7 +1608,6 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32
SStbObj *pStb = NULL; SStbObj *pStb = NULL;
int32_t cols = 0; int32_t cols = 0;
char *pWrite; char *pWrite;
char prefix[TSDB_DB_FNAME_LEN] = {0};
SDbObj* pDb = NULL; SDbObj* pDb = NULL;
if (strlen(pShow->db) > 0) { if (strlen(pShow->db) > 0) {
......
...@@ -100,10 +100,11 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, const char *msg); ...@@ -100,10 +100,11 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, const char *msg);
* @brief Insert tSma(Time-range-wise SMA) data from stream computing engine * @brief Insert tSma(Time-range-wise SMA) data from stream computing engine
* *
* @param pTsdb * @param pTsdb
* @param indexUid
* @param msg * @param msg
* @return int32_t * @return int32_t
*/ */
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg); int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg);
/** /**
* @brief Drop tSma data and local cache. * @brief Drop tSma data and local cache.
...@@ -130,16 +131,11 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); ...@@ -130,16 +131,11 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
* @param pTsdb * @param pTsdb
* @param pData * @param pData
* @param indexUid * @param indexUid
* @param interval
* @param intervalUnit
* @param tableUid
* @param colId
* @param querySKey * @param querySKey
* @param nMaxResult * @param nMaxResult
* @return int32_t * @return int32_t
*/ */
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit, int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult);
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult);
// STsdbCfg // STsdbCfg
int tsdbOptionsInit(STsdbCfg *); int tsdbOptionsInit(STsdbCfg *);
......
...@@ -44,15 +44,14 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); ...@@ -44,15 +44,14 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
#endif #endif
// internal func // internal func
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) { static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
int32_t len = 0; int32_t len = 0;
len += taosEncodeFixedI64(pData, tableUid);
len += taosEncodeFixedU16(pData, colId);
len += taosEncodeFixedI64(pData, tsKey); len += taosEncodeFixedI64(pData, tsKey);
len += taosEncodeFixedI64(pData, groupId);
return len; return len;
} }
static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) { static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) {
int code = taosThreadRwlockRdlock(&(pEnv->lock)); int code = taosThreadRwlockRdlock(&(pEnv->lock));
if (code != 0) { if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code); terrno = TAOS_SYSTEM_ERROR(code);
...@@ -61,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) { ...@@ -61,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
return 0; return 0;
} }
static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) { static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) {
int code = taosThreadRwlockWrlock(&(pEnv->lock)); int code = taosThreadRwlockWrlock(&(pEnv->lock));
if (code != 0) { if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code); terrno = TAOS_SYSTEM_ERROR(code);
...@@ -70,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) { ...@@ -70,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
return 0; return 0;
} }
static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) { static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
int code = taosThreadRwlockUnlock(&(pEnv->lock)); int code = taosThreadRwlockUnlock(&(pEnv->lock));
if (code != 0) { if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code); terrno = TAOS_SYSTEM_ERROR(code);
......
...@@ -167,7 +167,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { ...@@ -167,7 +167,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) {
break; break;
} }
if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) { if (colDataAppend(pColData, curRow, sVal.val, false) < 0) {
taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock);
return NULL; return NULL;
} }
......
...@@ -69,9 +69,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { ...@@ -69,9 +69,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
return tqProcessPollReq(pVnode->pTq, pMsg); return tqProcessPollReq(pVnode->pTq, pMsg);
case TDMT_VND_TASK_PIPE_EXEC: case TDMT_VND_TASK_PIPE_EXEC:
case TDMT_VND_TASK_MERGE_EXEC: case TDMT_VND_TASK_MERGE_EXEC:
return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, pInfo->workerId); return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0);
case TDMT_VND_STREAM_TRIGGER: case TDMT_VND_STREAM_TRIGGER:
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, pInfo->workerId); return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0);
case TDMT_VND_QUERY_HEARTBEAT: case TDMT_VND_QUERY_HEARTBEAT:
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
default: default:
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
// TODO // TODO
blockDebugShowData(data); blockDebugShowData(data);
tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data);
} }
void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
...@@ -202,7 +204,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { ...@@ -202,7 +204,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
vCreateSmaReq.tSma.indexUid); vCreateSmaReq.tSma.indexUid);
// record current timezone of server side // record current timezone of server side
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); vCreateSmaReq.tSma.timezoneInt = tsTimezone;
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) { if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
// TODO: handle error // TODO: handle error
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tsdbDef.h> #include <tsdbDef.h>
#include <taoserror.h> #include <taoserror.h>
#include <tglobal.h> #include <tglobal.h>
#include <iostream> #include <iostream>
...@@ -58,20 +59,21 @@ TEST(testCase, unionEncodeDecodeTest) { ...@@ -58,20 +59,21 @@ TEST(testCase, unionEncodeDecodeTest) {
void *buf = taosMemoryMalloc(1024); void *buf = taosMemoryMalloc(1024);
void *pBuf = buf; void *pBuf = buf;
void *qBuf = buf;
int32_t tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedU8(&buf, sut.info); tlen += taosEncodeFixedU8(&pBuf, sut.info);
tlen += taosEncodeFixedI16(&buf, sut.nBSmaCols); tlen += taosEncodeFixedI16(&pBuf, sut.nBSmaCols);
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { 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}; SUnionTest dut = {0};
pBuf = taosDecodeFixedU8(pBuf, &dut.info); qBuf = taosDecodeFixedU8(qBuf, &dut.info);
pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols); qBuf = taosDecodeFixedI16(qBuf, &dut.nBSmaCols);
if (dut.nBSmaCols > 0) { if (dut.nBSmaCols > 0) {
dut.pBSmaCols = (col_id_t *)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t)); dut.pBSmaCols = (col_id_t *)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t));
for (col_id_t i = 0; i < dut.nBSmaCols; ++i) { for (col_id_t i = 0; i < dut.nBSmaCols; ++i) {
pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i); qBuf = taosDecodeFixedI16(qBuf, dut.pBSmaCols + i);
} }
} else { } else {
dut.pBSmaCols = NULL; dut.pBSmaCols = NULL;
...@@ -80,13 +82,17 @@ TEST(testCase, unionEncodeDecodeTest) { ...@@ -80,13 +82,17 @@ TEST(testCase, unionEncodeDecodeTest) {
printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info); 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); printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info);
ASSERT_EQ(sut.rollup, dut.rollup); EXPECT_EQ(sut.rollup, dut.rollup);
ASSERT_EQ(sut.type, dut.type); EXPECT_EQ(sut.type, dut.type);
ASSERT_EQ(sut.nBSmaCols, dut.nBSmaCols); EXPECT_EQ(sut.nBSmaCols, dut.nBSmaCols);
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]); EXPECT_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), dut.pBSmaCols[i]);
} }
taosMemoryFreeClear(buf);
taosMemoryFreeClear(dut.pBSmaCols);
taosMemoryFreeClear(sut.pBSmaCols);
} }
#if 1 #if 1
TEST(testCase, tSma_Meta_Encode_Decode_Test) { TEST(testCase, tSma_Meta_Encode_Decode_Test) {
...@@ -106,37 +112,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) { ...@@ -106,37 +112,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper); uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
void *buf = taosMemoryCalloc(1, bufLen); void *buf = taosMemoryCalloc(1, bufLen);
ASSERT_NE(buf, nullptr); EXPECT_NE(buf, nullptr);
STSmaWrapper *pSW = (STSmaWrapper *)buf; STSmaWrapper *pSW = (STSmaWrapper *)buf;
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper); uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
ASSERT_EQ(len, bufLen); EXPECT_EQ(len, bufLen);
// decode // decode
STSmaWrapper dstTSmaWrapper = {0}; STSmaWrapper dstTSmaWrapper = {0};
void *result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper); 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) { for (int i = 0; i < tSmaWrapper.number; ++i) {
STSma *pSma = tSmaWrapper.tSma + i; STSma *pSma = tSmaWrapper.tSma + i;
STSma *qSma = dstTSmaWrapper.tSma + i; STSma *qSma = dstTSmaWrapper.tSma + i;
ASSERT_EQ(pSma->version, qSma->version); EXPECT_EQ(pSma->version, qSma->version);
ASSERT_EQ(pSma->intervalUnit, qSma->intervalUnit); EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
ASSERT_EQ(pSma->slidingUnit, qSma->slidingUnit); EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
ASSERT_STRCASEEQ(pSma->indexName, qSma->indexName); EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
ASSERT_EQ(pSma->timezoneInt, qSma->timezoneInt); EXPECT_EQ(pSma->timezoneInt, qSma->timezoneInt);
ASSERT_EQ(pSma->indexUid, qSma->indexUid); EXPECT_EQ(pSma->indexUid, qSma->indexUid);
ASSERT_EQ(pSma->tableUid, qSma->tableUid); EXPECT_EQ(pSma->tableUid, qSma->tableUid);
ASSERT_EQ(pSma->interval, qSma->interval); EXPECT_EQ(pSma->interval, qSma->interval);
ASSERT_EQ(pSma->sliding, qSma->sliding); EXPECT_EQ(pSma->sliding, qSma->sliding);
ASSERT_EQ(pSma->exprLen, qSma->exprLen); EXPECT_EQ(pSma->exprLen, qSma->exprLen);
ASSERT_STRCASEEQ(pSma->expr, qSma->expr); EXPECT_STRCASEEQ(pSma->expr, qSma->expr);
ASSERT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen); EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
ASSERT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter); EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
} }
// resource release // resource release
...@@ -172,12 +178,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -172,12 +178,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
tSma.exprLen = strlen(expr); tSma.exprLen = strlen(expr);
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1); 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); tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
tSma.tagsFilterLen = strlen(tagsFilter); tSma.tagsFilterLen = strlen(tagsFilter);
tSma.tagsFilter = (char *)taosMemoryCalloc(tSma.tagsFilterLen + 1, 1); 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); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
SMeta *pMeta = NULL; SMeta *pMeta = NULL;
...@@ -189,7 +195,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -189,7 +195,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL); pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
assert(pMeta != NULL); assert(pMeta != NULL);
// save index 1 // save index 1
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
pSmaCfg->indexUid = indexUid2; pSmaCfg->indexUid = indexUid2;
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN); tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
...@@ -200,7 +206,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -200,7 +206,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
pSmaCfg->sliding = 5; pSmaCfg->sliding = 5;
// save index 2 // save index 2
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
// get value by indexName // get value by indexName
STSma *qSmaCfg = NULL; STSma *qSmaCfg = NULL;
...@@ -210,8 +216,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -210,8 +216,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt); printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : ""); printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid); EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
tdDestroyTSma(qSmaCfg); tdDestroyTSma(qSmaCfg);
taosMemoryFreeClear(qSmaCfg); taosMemoryFreeClear(qSmaCfg);
...@@ -221,8 +227,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -221,8 +227,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt); printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : ""); printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
ASSERT_EQ(qSmaCfg->interval, tSma.interval); EXPECT_EQ(qSmaCfg->interval, tSma.interval);
tdDestroyTSma(qSmaCfg); tdDestroyTSma(qSmaCfg);
taosMemoryFreeClear(qSmaCfg); taosMemoryFreeClear(qSmaCfg);
...@@ -238,25 +244,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -238,25 +244,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf("indexName = %s\n", indexName); printf("indexName = %s\n", indexName);
++indexCnt; ++indexCnt;
} }
ASSERT_EQ(indexCnt, nCntTSma); EXPECT_EQ(indexCnt, nCntTSma);
metaCloseSmaCurosr(pSmaCur); metaCloseSmaCurosr(pSmaCur);
// get wrapper by table uid // get wrapper by table uid
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid); STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
assert(pSW != NULL); assert(pSW != NULL);
ASSERT_EQ(pSW->number, nCntTSma); EXPECT_EQ(pSW->number, nCntTSma);
ASSERT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
ASSERT_EQ(pSW->tSma->timezoneInt, timezone); EXPECT_EQ(pSW->tSma->timezoneInt, timezone);
ASSERT_STRCASEEQ(pSW->tSma->expr, expr); EXPECT_STRCASEEQ(pSW->tSma->expr, expr);
ASSERT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter); EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
ASSERT_EQ(pSW->tSma->indexUid, indexUid1); EXPECT_EQ(pSW->tSma->indexUid, indexUid1);
ASSERT_EQ(pSW->tSma->tableUid, tbUid); EXPECT_EQ(pSW->tSma->tableUid, tbUid);
ASSERT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
ASSERT_EQ((pSW->tSma + 1)->timezoneInt, timezone); EXPECT_EQ((pSW->tSma + 1)->timezoneInt, timezone);
ASSERT_STRCASEEQ((pSW->tSma + 1)->expr, expr); EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
ASSERT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter); EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
ASSERT_EQ((pSW->tSma + 1)->indexUid, indexUid2); EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid); EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid);
tdDestroyTSmaWrapper(pSW); tdDestroyTSmaWrapper(pSW);
taosMemoryFreeClear(pSW); taosMemoryFreeClear(pSW);
...@@ -268,7 +274,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -268,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: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i));
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)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); taosArrayDestroy(pUids);
// resource release // resource release
...@@ -280,7 +286,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ...@@ -280,7 +286,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
} }
#endif #endif
#if 0 #if 1
TEST(testCase, tSma_Data_Insert_Query_Test) { TEST(testCase, tSma_Data_Insert_Query_Test) {
// step 1: prepare meta // step 1: prepare meta
const char *smaIndexName1 = "sma_index_test_1"; const char *smaIndexName1 = "sma_index_test_1";
...@@ -299,9 +305,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -299,9 +305,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
// encode // encode
STSma tSma = {0}; STSma tSma = {0};
tSma.version = 0; tSma.version = 0;
tSma.intervalUnit = TIME_UNIT_DAY; tSma.intervalUnit = TIME_UNIT_MINUTE;
tSma.interval = 1; tSma.interval = 1;
tSma.slidingUnit = TIME_UNIT_HOUR; tSma.slidingUnit = TIME_UNIT_MINUTE;
tSma.sliding = 1; // sliding = interval when it's convert window tSma.sliding = 1; // sliding = interval when it's convert window
tSma.indexUid = indexUid1; tSma.indexUid = indexUid1;
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
...@@ -310,12 +316,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -310,12 +316,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
tSma.exprLen = strlen(expr); tSma.exprLen = strlen(expr);
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1); 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); tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
tSma.tagsFilterLen = strlen(tagsFilter); tSma.tagsFilterLen = strlen(tagsFilter);
tSma.tagsFilter = (char *)taosMemoryCalloc(1, tSma.tagsFilterLen + 1); 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); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
SMeta *pMeta = NULL; SMeta *pMeta = NULL;
...@@ -327,7 +333,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -327,7 +333,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL); pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
assert(pMeta != NULL); assert(pMeta != NULL);
// save index 1 // save index 1
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
// step 2: insert data // step 2: insert data
STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb));
...@@ -364,7 +370,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -364,7 +370,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN); strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN);
int32_t numOfDisks = 1; int32_t numOfDisks = 1;
pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks); pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks);
ASSERT_NE(pTsdb->pTfs, nullptr); EXPECT_NE(pTsdb->pTfs, nullptr);
// generate SSubmitReq msg and update expired window // generate SSubmitReq msg and update expired window
int16_t schemaVer = 0; int16_t schemaVer = 0;
...@@ -374,7 +380,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -374,7 +380,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
uint32_t msgLen = sizeof(SSubmitReq) + mockBlkNum * sizeof(SSubmitBlk) + mockBlkNum * mockRowNum * mockRowLen; uint32_t msgLen = sizeof(SSubmitReq) + mockBlkNum * sizeof(SSubmitBlk) + mockBlkNum * mockRowNum * mockRowLen;
SSubmitReq *pMsg = (SSubmitReq *)taosMemoryCalloc(1, msgLen); SSubmitReq *pMsg = (SSubmitReq *)taosMemoryCalloc(1, msgLen);
ASSERT_NE(pMsg, nullptr); EXPECT_NE(pMsg, nullptr);
pMsg->version = htobe64(schemaVer); pMsg->version = htobe64(schemaVer);
pMsg->numOfBlocks = htonl(mockBlkNum); pMsg->numOfBlocks = htonl(mockBlkNum);
pMsg->length = htonl(msgLen); pMsg->length = htonl(msgLen);
...@@ -400,20 +406,99 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -400,20 +406,99 @@ 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 // init
int32_t allocCnt = 0; const int32_t tSmaGroupSize = 4;
int32_t allocStep = 16384; const int32_t tSmaNumOfTags = 2;
int32_t buffer = 1024; const int64_t tSmaGroupId = 12345670;
void *buf = NULL; const col_id_t tSmaNumOfCols = 9; // binary/nchar/varbinary/varchar are only used for tags for group by conditions.
ASSERT_EQ(tsdbMakeRoom(&buf, allocStep), 0); const int32_t tSmaNumOfRows = 2;
int32_t bufSize = taosTSizeof(buf);
int32_t numOfTables = 10; SArray *pDataBlocks = taosArrayInit(tSmaGroupSize, sizeof(SSDataBlock *));
col_id_t numOfCols = 4096; EXPECT_NE(pDataBlocks, nullptr);
ASSERT_GT(numOfCols, 0); int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_INT,
TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_FLOAT,
TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_VARCHAR, TSDB_DATA_TYPE_NCHAR};
// last 2 columns for group by tags
// int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL};
const char *tSmaGroupbyTags[tSmaGroupSize * tSmaNumOfTags] = {"BeiJing", "HaiDian", "BeiJing", "ChaoYang",
"ShangHai", "PuDong", "ShangHai", "MinHang"};
TSKEY tSmaSKeyMs = (int64_t)1648535332 * 1000;
int64_t tSmaIntervalMs = tSma.interval * 60 * 1000;
int64_t tSmaInitVal = 0;
for (int32_t g = 0; g < tSmaGroupSize; ++g) {
SSDataBlock *pDataBlock = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
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 *));
EXPECT_NE(pDataBlock->pDataBlock, nullptr);
for (int32_t c = 0; c < tSmaNumOfCols; ++c) {
SColumnInfoData *pColInfoData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData));
EXPECT_NE(pColInfoData, nullptr);
pColInfoData->info.type = tSmaTypeArray[c];
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
pColInfoData->info.bytes = 100; // update accordingly
} else {
pColInfoData->info.bytes = TYPE_BYTES[pColInfoData->info.type];
}
pColInfoData->pData = (char *)taosMemoryCalloc(1, tSmaNumOfRows * pColInfoData->info.bytes);
for (int32_t r = 0; r < tSmaNumOfRows; ++r) {
void *pCellData = pColInfoData->pData + r * pColInfoData->info.bytes;
switch (pColInfoData->info.type) {
case TSDB_DATA_TYPE_TIMESTAMP:
*(TSKEY *)pCellData = tSmaSKeyMs + tSmaIntervalMs * r;
break;
case TSDB_DATA_TYPE_BOOL:
*(bool *)pCellData = (bool)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_INT:
*(int *)pCellData = (int)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *)pCellData = (uint64_t)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *)pCellData = (int16_t)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_FLOAT:
*(float *)pCellData = (float)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_DOUBLE:
*(double *)pCellData = (double)tSmaInitVal++;
break;
case TSDB_DATA_TYPE_VARCHAR: // city
varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2]));
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2], varDataLen(pCellData));
break;
case TSDB_DATA_TYPE_NCHAR: // district
varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2 + 1]));
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2 + 1], varDataLen(pCellData));
break;
default:
EXPECT_EQ(0, 1); // add definition
break;
}
}
// push SColumnInfoData
taosArrayPush(pDataBlock->pDataBlock, &pColInfoData);
}
// push SSDataBlock
taosArrayPush(pDataBlocks, &pDataBlock);
}
// execute
EXPECT_EQ(tsdbInsertTSmaData(pTsdb, tSma.indexUid, (const char *)pDataBlocks), TSDB_CODE_SUCCESS);
#if 0 #if 0
STSmaDataWrapper *pSmaData = NULL; STSmaDataWrapper *pSmaData = NULL;
...@@ -432,7 +517,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -432,7 +517,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
int32_t tableDataLen = sizeof(STSmaTbData); int32_t tableDataLen = sizeof(STSmaTbData);
for (col_id_t c = 0; c < numOfCols; ++c) { for (col_id_t c = 0; c < numOfCols; ++c) {
if (bufSize - len - tableDataLen < buffer) { if (bufSize - len - tableDataLen < buffer) {
ASSERT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0); EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
pSmaData = (STSmaDataWrapper *)buf; pSmaData = (STSmaDataWrapper *)buf;
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len); pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
bufSize = taosTSizeof(buf); bufSize = taosTSizeof(buf);
...@@ -459,31 +544,36 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ...@@ -459,31 +544,36 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
} }
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper)); pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
ASSERT_GE(bufSize, pSmaData->dataLen); EXPECT_GE(bufSize, pSmaData->dataLen);
// execute // execute
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); EXPECT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
#endif #endif
SSDataBlock *pSmaData = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
// step 3: query // step 3: query
uint32_t checkDataCnt = 0; uint32_t checkDataCnt = 0;
for (int32_t t = 0; t < numOfTables; ++t) { EXPECT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, skey1, 1), TSDB_CODE_SUCCESS);
for (col_id_t c = 0; c < numOfCols; ++c) {
ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1),
TSDB_CODE_SUCCESS);
++checkDataCnt; ++checkDataCnt;
}
}
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt); printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
// release data // release data
taosMemoryFreeClear(pMsg); taosMemoryFreeClear(pMsg);
taosTZfree(buf);
for (int32_t i = 0; i < taosArrayGetSize(pDataBlocks); ++i) {
SSDataBlock *pDataBlock = *(SSDataBlock **)taosArrayGet(pDataBlocks, i);
int32_t numOfOutput = taosArrayGetSize(pDataBlock->pDataBlock);
for (int32_t j = 0; j < numOfOutput; ++j) {
SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, j);
colDataDestroy(pColInfoData);
taosMemoryFreeClear(pColInfoData);
}
taosArrayDestroy(pDataBlock->pDataBlock);
taosMemoryFreeClear(pDataBlock->pBlockAgg);
taosMemoryFreeClear(pDataBlock);
}
taosArrayDestroy(pDataBlocks);
// release meta // release meta
tdDestroyTSma(&tSma); tdDestroyTSma(&tSma);
tfsClose(pTsdb->pTfs); tfsClose(pTsdb->pTfs);
......
...@@ -156,6 +156,8 @@ SArray* interResFromBinary(const char* data, int32_t len); ...@@ -156,6 +156,8 @@ SArray* interResFromBinary(const char* data, int32_t len);
void freeInterResult(void* param); void freeInterResult(void* param);
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo); void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo);
void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList);
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo); void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo);
bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo); bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo);
bool hasRemainData(SGroupResInfo* pGroupResInfo); bool hasRemainData(SGroupResInfo* pGroupResInfo);
......
...@@ -233,8 +233,8 @@ struct SOperatorInfo; ...@@ -233,8 +233,8 @@ struct SOperatorInfo;
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length); typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length);
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length); typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length);
typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* param); typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* param, bool* newgroup); typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup);
typedef void (*__optr_close_fn_t)(void* param, int32_t num); typedef void (*__optr_close_fn_t)(void* param, int32_t num);
typedef struct STaskIdInfo { typedef struct STaskIdInfo {
...@@ -255,7 +255,8 @@ typedef struct SExecTaskInfo { ...@@ -255,7 +255,8 @@ typedef struct SExecTaskInfo {
uint64_t totalRows; // total number of rows uint64_t totalRows; // total number of rows
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
char* sql; // query sql string char* sql; // query sql string
jmp_buf env; // jmp_buf env; // jump to this position when error happens.
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
struct SOperatorInfo* pRoot; struct SOperatorInfo* pRoot;
} SExecTaskInfo; } SExecTaskInfo;
...@@ -421,6 +422,7 @@ typedef struct SStreamBlockScanInfo { ...@@ -421,6 +422,7 @@ typedef struct SStreamBlockScanInfo {
uint64_t numOfRows; // total scanned rows uint64_t numOfRows; // total scanned rows
uint64_t numOfExec; // execution times uint64_t numOfExec; // execution times
void* readerHandle; // stream block reader handle void* readerHandle; // stream block reader handle
SArray* pColMatchInfo; //
} SStreamBlockScanInfo; } SStreamBlockScanInfo;
typedef struct SSysTableScanInfo { typedef struct SSysTableScanInfo {
...@@ -466,11 +468,6 @@ typedef struct SAggSupporter { ...@@ -466,11 +468,6 @@ typedef struct SAggSupporter {
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
} SAggSupporter; } SAggSupporter;
typedef enum {
OPTR_EXEC_MODEL_BATCH = 0x1,
OPTR_EXEC_MODEL_STREAM = 0x2,
} OPTR_EXEC_MODEL;
typedef struct STableIntervalOperatorInfo { typedef struct STableIntervalOperatorInfo {
SOptrBasicInfo binfo; // basic info SOptrBasicInfo binfo; // basic info
SGroupResInfo groupResInfo; // multiple results build supporter SGroupResInfo groupResInfo; // multiple results build supporter
...@@ -481,7 +478,7 @@ typedef struct STableIntervalOperatorInfo { ...@@ -481,7 +478,7 @@ typedef struct STableIntervalOperatorInfo {
SAggSupporter aggSup; // aggregate supporter SAggSupporter aggSup; // aggregate supporter
STableQueryInfo *pCurrent; // current tableQueryInfo struct STableQueryInfo *pCurrent; // current tableQueryInfo struct
int32_t order; // current SSDataBlock scan order int32_t order; // current SSDataBlock scan order
OPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
SArray *pUpdatedWindow; // updated time window due to the input data block from the downstream operator. SArray *pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
SColumnInfoData timeWindowData; // query time window info for scalar function execution. SColumnInfoData timeWindowData; // query time window info for scalar function execution.
} STableIntervalOperatorInfo; } STableIntervalOperatorInfo;
...@@ -718,7 +715,7 @@ int32_t getMaximumIdleDurationSec(); ...@@ -718,7 +715,7 @@ int32_t getMaximumIdleDurationSec();
void doInvokeUdf(struct SUdfInfo* pUdfInfo, SqlFunctionCtx* pCtx, int32_t idx, int32_t type); void doInvokeUdf(struct SUdfInfo* pUdfInfo, SqlFunctionCtx* pCtx, int32_t idx, int32_t type);
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status); void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId); int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -222,6 +222,16 @@ void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo) ...@@ -222,6 +222,16 @@ void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo)
assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo)); assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
} }
void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList) {
if (pGroupResInfo->pRows != NULL) {
taosArrayDestroy(pGroupResInfo->pRows);
}
pGroupResInfo->pRows = pArrayList;
pGroupResInfo->index = 0;
ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
}
bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo) { bool hasRemainDataInCurrentGroup(SGroupResInfo* pGroupResInfo) {
if (pGroupResInfo->pRows == NULL) { if (pGroupResInfo->pRows == NULL) {
return false; return false;
......
...@@ -113,7 +113,7 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) { ...@@ -113,7 +113,7 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) {
} }
qTaskInfo_t pTaskInfo = NULL; qTaskInfo_t pTaskInfo = NULL;
code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL); code = qCreateExecTask(streamReadHandle, 0, 0, plan, &pTaskInfo, NULL, OPTR_EXEC_MODEL_STREAM);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
// TODO: destroy SSubplan & pTaskInfo // TODO: destroy SSubplan & pTaskInfo
terrno = code; terrno = code;
......
...@@ -51,11 +51,12 @@ static void freeqinfoFn(void *qhandle) { ...@@ -51,11 +51,12 @@ static void freeqinfoFn(void *qhandle) {
qDestroyTask(*handle); qDestroyTask(*handle);
} }
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle) { int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan,
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, EOPTR_EXEC_MODEL model) {
assert(readHandle != NULL && pSubplan != NULL); assert(readHandle != NULL && pSubplan != NULL);
SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo; SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo;
int32_t code = createExecTaskInfoImpl(pSubplan, pTask, readHandle, taskId); int32_t code = createExecTaskInfoImpl(pSubplan, pTask, readHandle, taskId, model);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
goto _error; goto _error;
} }
......
...@@ -1551,8 +1551,8 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe ...@@ -1551,8 +1551,8 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
if (pSDataBlock->pDataBlock != NULL) { if (pSDataBlock->pDataBlock != NULL) {
SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, 0); SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, 0);
tsCols = (int64_t*)pColDataInfo->pData; tsCols = (int64_t*)pColDataInfo->pData;
assert(tsCols[0] == pSDataBlock->info.window.skey && // assert(tsCols[0] == pSDataBlock->info.window.skey &&
tsCols[pSDataBlock->info.rows - 1] == pSDataBlock->info.window.ekey); // tsCols[pSDataBlock->info.rows - 1] == pSDataBlock->info.window.ekey);
} }
int32_t startPos = ascScan? 0 : (pSDataBlock->info.rows - 1); int32_t startPos = ascScan? 0 : (pSDataBlock->info.rows - 1);
...@@ -3660,6 +3660,7 @@ void finalizeUpdatedResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbased ...@@ -3660,6 +3660,7 @@ void finalizeUpdatedResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbased
if (pCtx[j].fpSet.process) { // TODO set the dummy function. if (pCtx[j].fpSet.process) { // TODO set the dummy function.
pCtx[j].fpSet.finalize(&pCtx[j]); pCtx[j].fpSet.finalize(&pCtx[j]);
pResInfo->initialized = true;
} }
if (pRow->numOfRows < pResInfo->numOfRes) { if (pRow->numOfRows < pResInfo->numOfRes) {
...@@ -3778,10 +3779,6 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, S ...@@ -3778,10 +3779,6 @@ void setResultRowOutputBufInitCtx_rv(SDiskbasedBuf* pBuf, SResultRow* pResult, S
continue; continue;
} }
// int32_t functionId = pCtx[i].functionId;
// if (functionId < 0) {
// continue;
// }
// if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) { // if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) {
// if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput; // if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i - 1].pOutput;
// } // }
...@@ -4971,7 +4968,20 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) ...@@ -4971,7 +4968,20 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup)
return NULL; return NULL;
} }
pInfo->pRes->pDataBlock = tqRetrieveDataBlock(pInfo->readerHandle); SArray* pCols = tqRetrieveDataBlock(pInfo->readerHandle);
int32_t numOfCols = pInfo->pRes->info.numOfCols;
for (int32_t i = 0; i < numOfCols; ++i) {
SColumnInfoData* p = taosArrayGet(pCols, i);
SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i);
if (!pColMatchInfo->output) {
continue;
}
ASSERT(pColMatchInfo->colId == p->info.colId);
taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, p);
}
if (pInfo->pRes->pDataBlock == NULL) { if (pInfo->pRes->pDataBlock == NULL) {
// TODO add log // TODO add log
pTaskInfo->code = terrno; pTaskInfo->code = terrno;
...@@ -5625,8 +5635,18 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* ...@@ -5625,8 +5635,18 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
return NULL; return NULL;
} }
int32_t numOfOutput = taosArrayGetSize(pColList);
SArray* pColIds = taosArrayInit(4, sizeof(int16_t));
for(int32_t i = 0; i < numOfOutput; ++i) {
int16_t* id = taosArrayGet(pColList, i);
taosArrayPush(pColIds, id);
}
pInfo->pColMatchInfo = pColList;
// set the extract column id to streamHandle // set the extract column id to streamHandle
tqReadHandleSetColIdList((STqReadHandle*)streamReadHandle, pColList); tqReadHandleSetColIdList((STqReadHandle*)streamReadHandle, pColIds);
int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList); int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList);
if (code != 0) { if (code != 0) {
taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pInfo);
...@@ -5824,6 +5844,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { ...@@ -5824,6 +5844,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
// pInfo->totalBytes; // pInfo->totalBytes;
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
} else { // load the meta from mnode of the given epset } else { // load the meta from mnode of the given epset
if (pOperator->status == OP_EXEC_DONE) {
return NULL;
}
int64_t startTs = taosGetTimestampUs(); int64_t startTs = taosGetTimestampUs();
pInfo->req.type = pInfo->type; pInfo->req.type = pInfo->type;
...@@ -5863,6 +5887,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { ...@@ -5863,6 +5887,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
SRetrieveMetaTableRsp* pRsp = pInfo->pRsp; SRetrieveMetaTableRsp* pRsp = pInfo->pRsp;
pInfo->req.showId = pRsp->handle; pInfo->req.showId = pRsp->handle;
if (pRsp->numOfRows == 0 || pRsp->completed) {
pOperator->status = OP_EXEC_DONE;
}
if (pRsp->numOfRows == 0) { if (pRsp->numOfRows == 0) {
// qDebug("%s vgId:%d, taskID:0x%"PRIx64" %d of total completed, rowsOfSource:%"PRIu64", totalRows:%"PRIu64" // qDebug("%s vgId:%d, taskID:0x%"PRIx64" %d of total completed, rowsOfSource:%"PRIu64", totalRows:%"PRIu64"
// try next", // try next",
...@@ -6930,6 +6958,10 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro ...@@ -6930,6 +6958,10 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro
return NULL; return NULL;
} }
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
return pOperator->getStreamResFn(pOperator, newgroup);
}
pTaskInfo->code = pOperator->_openFn(pOperator); pTaskInfo->code = pOperator->_openFn(pOperator);
if (pTaskInfo->code != TSDB_CODE_SUCCESS) { if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
return NULL; return NULL;
...@@ -6946,7 +6978,7 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro ...@@ -6946,7 +6978,7 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
} }
static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator) { static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) {
STableIntervalOperatorInfo* pInfo = pOperator->info; STableIntervalOperatorInfo* pInfo = pOperator->info;
int32_t order = TSDB_ORDER_ASC; int32_t order = TSDB_ORDER_ASC;
...@@ -6960,18 +6992,18 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator) { ...@@ -6960,18 +6992,18 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator) {
if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
pOperator->status = OP_EXEC_DONE; pOperator->status = OP_EXEC_DONE;
} }
return pInfo->binfo.pRes; return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
} }
// STimeWindow win = {0}; // STimeWindow win = {0};
bool newgroup = false; *newgroup = false;
SOperatorInfo* downstream = pOperator->pDownstream[0]; SOperatorInfo* downstream = pOperator->pDownstream[0];
SArray* pUpdated = NULL; SArray* pUpdated = NULL;
while (1) { while (1) {
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
SSDataBlock* pBlock = downstream->getNextFn(downstream, &newgroup); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
if (pBlock == NULL) { if (pBlock == NULL) {
...@@ -6989,6 +7021,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator) { ...@@ -6989,6 +7021,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator) {
finalizeUpdatedResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset); finalizeUpdatedResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset);
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity);
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity,
pInfo->binfo.rowCellInfoOffset); pInfo->binfo.rowCellInfoOffset);
...@@ -7882,9 +7915,10 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* ...@@ -7882,9 +7915,10 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
} }
pInfo->order = TSDB_ORDER_ASC; pInfo->order = TSDB_ORDER_ASC;
pInfo->win = pTaskInfo->window;
pInfo->interval = *pInterval; pInfo->interval = *pInterval;
pInfo->execModel = OPTR_EXEC_MODEL_BATCH; pInfo->execModel = pTaskInfo->execModel;
pInfo->win = pTaskInfo->window;
pInfo->win.skey = 0; pInfo->win.skey = 0;
pInfo->win.ekey = INT64_MAX; pInfo->win.ekey = INT64_MAX;
...@@ -7909,6 +7943,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* ...@@ -7909,6 +7943,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
pOperator->info = pInfo; pOperator->info = pInfo;
pOperator->_openFn = doOpenIntervalAgg; pOperator->_openFn = doOpenIntervalAgg;
pOperator->getNextFn = doBuildIntervalResult; pOperator->getNextFn = doBuildIntervalResult;
pOperator->getStreamResFn= doStreamIntervalAgg;
pOperator->closeFn = destroyIntervalOperatorInfo; pOperator->closeFn = destroyIntervalOperatorInfo;
code = appendDownstream(pOperator, &downstream, 1); code = appendDownstream(pOperator, &downstream, 1);
...@@ -8736,12 +8771,13 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* ...@@ -8736,12 +8771,13 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
return pExprs; return pExprs;
} }
static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) { static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPTR_EXEC_MODEL model) {
SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo)); SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
pTaskInfo->cost.created = taosGetTimestampMs(); pTaskInfo->cost.created = taosGetTimestampMs();
pTaskInfo->id.queryId = queryId; pTaskInfo->id.queryId = queryId;
pTaskInfo->execModel = model;
char* p = taosMemoryCalloc(1, 128); char* p = taosMemoryCalloc(1, 128);
snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId); snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId);
...@@ -8785,10 +8821,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo ...@@ -8785,10 +8821,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
SArray* tableIdList = extractTableIdList(pTableGroupInfo); SArray* tableIdList = extractTableIdList(pTableGroupInfo);
SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc); SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc);
SArray* colList = extractScanColumnId(pScanPhyNode->pScanCols);
SOperatorInfo* pOperator = int32_t numOfCols = 0;
createStreamScanOperatorInfo(pHandle->reader, pResBlock, colList, tableIdList, pTaskInfo); SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols);
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, pColList, tableIdList, pTaskInfo);
taosArrayDestroy(tableIdList); taosArrayDestroy(tableIdList);
return pOperator; return pOperator;
} else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == nodeType(pPhyNode)) { } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == nodeType(pPhyNode)) {
...@@ -9102,11 +9138,11 @@ _error: ...@@ -9102,11 +9138,11 @@ _error:
return NULL; return NULL;
} }
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId) { int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model) {
uint64_t queryId = pPlan->id.queryId; uint64_t queryId = pPlan->id.queryId;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
*pTaskInfo = createExecTaskInfo(queryId, taskId); *pTaskInfo = createExecTaskInfo(queryId, taskId, model);
if (*pTaskInfo == NULL) { if (*pTaskInfo == NULL) {
code = TSDB_CODE_QRY_OUT_OF_MEMORY; code = TSDB_CODE_QRY_OUT_OF_MEMORY;
goto _complete; goto _complete;
......
...@@ -944,7 +944,7 @@ TEST(testCase, build_executor_tree_Test) { ...@@ -944,7 +944,7 @@ TEST(testCase, build_executor_tree_Test) {
int32_t code = qStringToSubplan(msg, &plan); int32_t code = qStringToSubplan(msg, &plan);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
code = qCreateExecTask(&handle, 2, 1, plan, (void**) &pTaskInfo, &sinkHandle); code = qCreateExecTask(&handle, 2, 1, plan, (void**) &pTaskInfo, &sinkHandle, OPTR_EXEC_MODEL_BATCH);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
} }
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __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
/*
* 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 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_INDEX_SPARSE_H_ #ifndef _TD_INDEX_FST_SPARSE_H_
#define _TD_INDEX_SPARSE_H_ #define _TD_INDEX_FST_SPARSE_H_
#include "tarray.h" #include "tarray.h"
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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;
}
/*
* 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 @@ ...@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "indexSparse.h" #include "indexFstSparse.h"
FstSparseSet *sparSetCreate(int32_t sz) { FstSparseSet *sparSetCreate(int32_t sz) {
FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet)); FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet));
......
...@@ -959,7 +959,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType) { ...@@ -959,7 +959,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType) {
QW_ERR_JRET(code); QW_ERR_JRET(code);
} }
code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle); code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, OPTR_EXEC_MODEL_BATCH);
if (code) { if (code) {
QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code)); QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code));
QW_ERR_JRET(code); QW_ERR_JRET(code);
......
...@@ -152,6 +152,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in ...@@ -152,6 +152,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
// sink // sink
if (pTask->sinkType == TASK_SINK__TABLE) { if (pTask->sinkType == TASK_SINK__TABLE) {
// //
blockDebugShowData(pRes);
} else if (pTask->sinkType == TASK_SINK__SMA) { } else if (pTask->sinkType == TASK_SINK__SMA) {
pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes); pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes);
// //
......
此差异已折叠。
...@@ -35,7 +35,6 @@ struct SBTC { ...@@ -35,7 +35,6 @@ struct SBTC {
int idx; int idx;
int idxStack[BTREE_MAX_DEPTH + 1]; int idxStack[BTREE_MAX_DEPTH + 1];
SPage *pgStack[BTREE_MAX_DEPTH + 1]; SPage *pgStack[BTREE_MAX_DEPTH + 1];
void *pBuf;
}; };
// SBTree // SBTree
...@@ -49,7 +48,6 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL ...@@ -49,7 +48,6 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
int tdbBtcOpen(SBTC *pCur, SBTree *pBt); int tdbBtcOpen(SBTC *pCur, SBTree *pBt);
int tdbBtcMoveToFirst(SBTC *pBtc); int tdbBtcMoveToFirst(SBTC *pBtc);
int tdbBtcMoveToLast(SBTC *pBtc); int tdbBtcMoveToLast(SBTC *pBtc);
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen);
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
int tdbBtcClose(SBTC *pBtc); int tdbBtcClose(SBTC *pBtc);
......
...@@ -64,7 +64,7 @@ typedef TdThreadSpinlock tdb_spinlock_t; ...@@ -64,7 +64,7 @@ typedef TdThreadSpinlock tdb_spinlock_t;
#define tdbSpinlockDestroy taosThreadSpinDestroy #define tdbSpinlockDestroy taosThreadSpinDestroy
#define tdbSpinlockLock taosThreadSpinLock #define tdbSpinlockLock taosThreadSpinLock
#define tdbSpinlockUnlock taosThreadSpinUnlock #define tdbSpinlockUnlock taosThreadSpinUnlock
#define tdbSpinlockTrylock pthread_spin_trylock #define tdbSpinlockTrylock taosThreadSpinTrylock
/* mutex lock */ /* mutex lock */
typedef TdThreadMutex tdb_mutex_t; typedef TdThreadMutex tdb_mutex_t;
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <malloc.h> #include <malloc.h>
#include "os.h" #include "os.h"
#ifdef USE_TD_MEMORY
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') #define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
#define TD_MEMORY_STACK_TRACE_DEPTH 10 #define TD_MEMORY_STACK_TRACE_DEPTH 10
...@@ -70,6 +72,8 @@ int32_t taosBackTrace(void **buffer, int32_t size) { ...@@ -70,6 +72,8 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
// return backtrace_symbols(buffer, *size); // return backtrace_symbols(buffer, *size);
// } // }
#endif
void *taosMemoryMalloc(int32_t size) { void *taosMemoryMalloc(int32_t size) {
#ifdef USE_TD_MEMORY #ifdef USE_TD_MEMORY
void *tmp = malloc(size + sizeof(TdMemoryInfo)); void *tmp = malloc(size + sizeof(TdMemoryInfo));
...@@ -126,9 +130,9 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { ...@@ -126,9 +130,9 @@ void *taosMemoryRealloc(void *ptr, int32_t size) {
} }
void taosMemoryFree(const void *ptr) { void taosMemoryFree(const void *ptr) {
#ifdef USE_TD_MEMORY
if (ptr == NULL) return; if (ptr == NULL) return;
#ifdef USE_TD_MEMORY
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
if(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL) { if(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL) {
pTdMemoryInfo->memorySize = 0; pTdMemoryInfo->memorySize = 0;
...@@ -143,9 +147,9 @@ void taosMemoryFree(const void *ptr) { ...@@ -143,9 +147,9 @@ void taosMemoryFree(const void *ptr) {
} }
int32_t taosMemorySize(void *ptr) { int32_t taosMemorySize(void *ptr) {
#ifdef USE_TD_MEMORY
if (ptr == NULL) return 0; if (ptr == NULL) return 0;
#ifdef USE_TD_MEMORY
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL);
......
/*
* 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 @@ ...@@ -18,7 +18,9 @@
#include "os.h" #include "os.h"
int32_t taosCreateShm(SShm* pShm, int32_t shmsize) { 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) { if (shmid < 0) {
return -1; return -1;
} }
...@@ -35,37 +37,23 @@ int32_t taosCreateShm(SShm* pShm, int32_t shmsize) { ...@@ -35,37 +37,23 @@ int32_t taosCreateShm(SShm* pShm, int32_t shmsize) {
} }
void taosDropShm(SShm* pShm) { void taosDropShm(SShm* pShm) {
if (pShm->id > 0) { if (pShm->id >= 0) {
if (pShm->ptr != NULL) { if (pShm->ptr != NULL) {
shmdt(pShm->ptr); shmdt(pShm->ptr);
} }
shmctl(pShm->id, IPC_RMID, NULL); shmctl(pShm->id, IPC_RMID, NULL);
} }
pShm->id = 0; pShm->id = -1;
pShm->size = 0; pShm->size = 0;
pShm->ptr = NULL; pShm->ptr = NULL;
} }
int32_t taosAttachShm(SShm* pShm) { int32_t taosAttachShm(SShm* pShm) {
if (pShm->id > 0 && pShm->size > 0) { errno = 0;
pShm->ptr = shmat(pShm->id, NULL, 0);
if (pShm->ptr != NULL) {
return 0;
}
}
return -1;
}
void taosDetachShm(SShm* pShm) { void* ptr = shmat(pShm->id, NULL, 0);
if (pShm->id > 0) { if (errno == 0) {
if (pShm->ptr != NULL) { pShm->ptr = ptr;
shmdt(pShm->ptr);
pShm->ptr = NULL;
}
} }
return errno;
pShm->id = 0;
pShm->size = 0;
pShm->ptr = NULL;
} }
...@@ -71,4 +71,6 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); } ...@@ -71,4 +71,6 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); }
void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); } void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); }
void taosKillChildOnParentStopped() { prctl(PR_SET_PDEATHSIG, SIGKILL); }
#endif #endif
...@@ -758,7 +758,7 @@ void taosBlockSIGPIPE() { ...@@ -758,7 +758,7 @@ void taosBlockSIGPIPE() {
sigset_t signal_mask; sigset_t signal_mask;
sigemptyset(&signal_mask); sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGPIPE); sigaddset(&signal_mask, SIGPIPE);
int32_t rc = taosThreadSigmask(SIG_BLOCK, &signal_mask, NULL); int32_t rc = taosThreadSigMask(SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) { if (rc != 0) {
// printf("failed to block SIGPIPE"); // printf("failed to block SIGPIPE");
} }
...@@ -876,7 +876,7 @@ void taosSetMaskSIGPIPE() { ...@@ -876,7 +876,7 @@ void taosSetMaskSIGPIPE() {
sigset_t signal_mask; sigset_t signal_mask;
sigemptyset(&signal_mask); sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGPIPE); sigaddset(&signal_mask, SIGPIPE);
int32_t rc = taosThreadSigmask(SIG_SETMASK, &signal_mask, NULL); int32_t rc = taosThreadSigMask(SIG_SETMASK, &signal_mask, NULL);
if (rc != 0) { if (rc != 0) {
// printf("failed to setmask SIGPIPE"); // printf("failed to setmask SIGPIPE");
} }
......
...@@ -14,132 +14,341 @@ ...@@ -14,132 +14,341 @@
*/ */
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#include <pthread.h>
#include "os.h" #include "os.h"
// int32_t taosThreadSetnameNp(TdThread thread, const char *name) { int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg) {
// return pthread_setname_np(thread,name); return pthread_create(tid, attr, start, arg);
// } }
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared) { int32_t taosThreadAttrDestroy(TdThreadAttr * attr) {
return pthread_spin_init(lock, pshared); return pthread_attr_destroy(attr);
} }
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) { int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate) {
return pthread_mutex_init(mutex, attr); return pthread_attr_getdetachstate(attr, detachstate);
} }
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched) {
return pthread_spin_destroy(lock); return pthread_attr_getinheritsched(attr, inheritsched);
}
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param) {
return pthread_attr_getschedparam(attr, param);
}
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy) {
return pthread_attr_getschedpolicy(attr, policy);
}
int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope) {
return pthread_attr_getscope(attr, contentionscope);
}
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize) {
return pthread_attr_getstacksize(attr, stacksize);
}
int32_t taosThreadAttrInit(TdThreadAttr * attr) {
return pthread_attr_init(attr);
}
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate) {
return pthread_attr_setdetachstate(attr, detachstate);
}
int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched) {
return pthread_attr_setinheritsched(attr, inheritsched);
}
int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param) {
return pthread_attr_setschedparam(attr, param);
}
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy) {
return pthread_attr_setschedpolicy(attr, policy);
}
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope) {
return pthread_attr_setscope(attr, contentionscope);
}
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) {
return pthread_attr_setstacksize(attr, stacksize);
}
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier) {
return pthread_barrier_destroy(barrier);
}
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count) {
return pthread_barrier_init(barrier, attr, count);
}
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier) {
return pthread_barrier_wait(barrier);
}
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr) {
return pthread_barrierattr_destroy(attr);
}
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared) {
return pthread_barrierattr_getpshared(attr, pshared);
}
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr) {
return pthread_barrierattr_init(attr);
}
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared) {
return pthread_barrierattr_setpshared(attr, pshared);
}
int32_t taosThreadCancel(TdThread thread) {
return pthread_cancel(thread);
}
int32_t taosThreadCondDestroy(TdThreadCond * cond) {
return pthread_cond_destroy(cond);
}
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) {
return pthread_cond_init(cond, attr);
}
int32_t taosThreadCondSignal(TdThreadCond * cond) {
return pthread_cond_signal(cond);
}
int32_t taosThreadCondBroadcast(TdThreadCond * cond) {
return pthread_cond_broadcast(cond);
}
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) {
return pthread_cond_wait(cond, mutex);
}
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime) {
return pthread_cond_timedwait(cond, mutex, abstime);
}
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) {
return pthread_condattr_destroy(attr);
}
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared) {
return pthread_condattr_getpshared(attr, pshared);
}
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) {
return pthread_condattr_init(attr);
}
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared) {
return pthread_condattr_setpshared(attr, pshared);
}
int32_t taosThreadDetach(TdThread thread) {
return pthread_detach(thread);
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
return pthread_equal(t1, t2);
}
void taosThreadExit(void *valuePtr) {
return pthread_exit(valuePtr);
}
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
return pthread_getschedparam(thread, policy, param);
}
void *taosThreadGetSpecific(TdThreadKey key) {
return pthread_getspecific(key);
}
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
return pthread_join(thread, valuePtr);
}
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)) {
return pthread_key_create(key, destructor);
}
int32_t taosThreadKeyDelete(TdThreadKey key) {
return pthread_key_delete(key);
}
int32_t taosThreadKill(TdThread thread, int32_t sig) {
return pthread_kill(thread, sig);
}
int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
return pthread_mutex_consistent(mutex);
} }
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) { int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) {
return pthread_mutex_destroy(mutex); return pthread_mutex_destroy(mutex);
} }
int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr) {
return pthread_spin_lock(lock); return pthread_mutex_init(mutex, attr);
} }
int32_t taosThreadMutexLock(TdThreadMutex *mutex) { int32_t taosThreadMutexLock(TdThreadMutex * mutex) {
return pthread_mutex_lock(mutex); return pthread_mutex_lock(mutex);
} }
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) { int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) {
return pthread_spin_unlock(lock); return pthread_mutex_timedlock(mutex, abstime);
}
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) {
return pthread_mutex_trylock(mutex);
} }
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) {
return pthread_mutex_unlock(mutex); return pthread_mutex_unlock(mutex);
} }
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) {
return pthread_rwlock_rdlock(rwlock); return pthread_mutexattr_destroy(attr);
} }
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared) {
return pthread_rwlock_wrlock(rwlock); return pthread_mutexattr_getpshared(attr, pshared);
} }
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust) {
return pthread_rwlock_unlock(rwlock); return pthread_mutexattr_getrobust(attr, robust);
} }
void taosThreadTestCancel(void) { int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind) {
return pthread_testcancel(); return pthread_mutexattr_gettype(attr, kind);
} }
int32_t taosThreadAttrInit(TdThreadAttr *attr) { int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) {
return pthread_attr_init(attr); return pthread_mutexattr_init(attr);
} }
int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void*(*start)(void*), void *arg) { int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) {
return pthread_create(tid, attr, start, arg); return pthread_mutexattr_setpshared(attr, pshared);
} }
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void)) { int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust) {
return pthread_once(onceControl, initRoutine); return pthread_mutexattr_setrobust(attr, robust);
} }
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState) { int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind) {
return pthread_attr_setdetachstate(attr, detachState); return pthread_mutexattr_settype(attr, kind);
} }
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) {
return pthread_attr_destroy(attr); return pthread_once(onceControl, initRoutine);
} }
int32_t taosThreadJoin(TdThread thread, void **pValue) { int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) {
return pthread_join(thread, pValue); return pthread_rwlock_destroy(rwlock);
} }
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) { int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr) {
return pthread_rwlock_init(rwlock, attr); return pthread_rwlock_init(rwlock, attr);
} }
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_destroy(rwlock); return pthread_rwlock_rdlock(rwlock);
} }
int32_t taosThreadCondSignal(TdThreadCond *cond) { int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
return pthread_cond_signal(cond); return pthread_rwlock_timedrdlock(rwlock, abstime);
} }
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
return pthread_cond_init(cond, attr); return pthread_rwlock_timedwrlock(rwlock, abstime);
} }
int32_t taosThreadCondBroadcast(TdThreadCond *cond) { int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) {
return pthread_cond_broadcast(cond); return pthread_rwlock_tryrdlock(rwlock);
} }
int32_t taosThreadCondDestroy(TdThreadCond *cond) { int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) {
return pthread_cond_destroy(cond); return pthread_rwlock_trywrlock(rwlock);
} }
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) {
return pthread_cond_wait(cond, mutex); return pthread_rwlock_unlock(rwlock);
}
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_wrlock(rwlock);
}
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) {
return pthread_rwlockattr_destroy(attr);
}
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared) {
return pthread_rwlockattr_getpshared(attr, pshared);
}
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) {
return pthread_rwlockattr_init(attr);
}
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared) {
return pthread_rwlockattr_setpshared(attr, pshared);
} }
TdThread taosThreadSelf(void) { TdThread taosThreadSelf(void) {
return pthread_self(); return pthread_self();
} }
// int32_t taosThreadGetW32ThreadIdNp(TdThread thread) { int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
// return pthread_getw32threadid_np(thread); return pthread_setcancelstate(state, oldstate);
// } }
int32_t taosThreadEqual(TdThread t1, TdThread t2) { int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
return pthread_equal(t1, t2); return pthread_setcanceltype(type, oldtype);
} }
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset) { int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
return pthread_sigmask(how, set, oset); return pthread_setschedparam(thread, policy, param);
} }
int32_t taosThreadCancel(TdThread thread) { int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
return pthread_cancel(thread); return pthread_setspecific(key, value);
} }
int32_t taosThreadKill(TdThread thread, int sig) { int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
return pthread_kill(thread, sig); return pthread_spin_destroy(lock);
}
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) {
return pthread_spin_init(lock, pshared);
}
int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
return pthread_spin_lock(lock);
}
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
return pthread_spin_trylock(lock);
}
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
return pthread_spin_unlock(lock);
}
void taosThreadTestCancel(void) {
return pthread_testcancel();
}
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset) {
return pthread_sigmask(how, set, oset);
}
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig) {
return sigwait(set, sig);
} }
\ No newline at end of file
...@@ -590,12 +590,12 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { ...@@ -590,12 +590,12 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
} }
int32_t cfgLoadFromEnvVar(SConfig *pConfig) { int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
uInfo("load from global env variables"); uInfo("load from global env variables success");
return 0; return 0;
} }
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { 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; return 0;
} }
...@@ -649,11 +649,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -649,11 +649,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
if (line != NULL) taosMemoryFreeClear(line); if (line != NULL) taosMemoryFreeClear(line);
uInfo("load from cfg file %s success", filepath); uInfo("load from cfg file [%s] success", filepath);
return 0; return 0;
} }
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { 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; return 0;
} }
...@@ -85,7 +85,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization ...@@ -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_CFG_NOT_FOUND, "Config not found")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CFG, "Invalid config option") 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_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_NO_MEMORY, "Ref out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs")
TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed") TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed")
......
...@@ -28,25 +28,27 @@ typedef struct SProcQueue { ...@@ -28,25 +28,27 @@ typedef struct SProcQueue {
int32_t total; int32_t total;
int32_t avail; int32_t avail;
int32_t items; int32_t items;
char *pBuffer; char name[8];
ProcMallocFp mallocHeadFp; TdThreadMutex mutex;
ProcFreeFp freeHeadFp;
ProcMallocFp mallocBodyFp;
ProcFreeFp freeBodyFp;
ProcConsumeFp consumeFp;
void *pParent;
tsem_t sem; tsem_t sem;
TdThreadMutex *mutex; char pBuffer[];
int32_t mutexShmid;
int32_t bufferShmid;
const char *name;
} SProcQueue; } SProcQueue;
typedef struct SProcObj { typedef struct SProcObj {
TdThread childThread; TdThread thread;
SProcQueue *pChildQueue; SProcQueue *pChildQueue;
TdThread parentThread;
SProcQueue *pParentQueue; 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; const char *name;
int32_t pid; int32_t pid;
bool isChild; bool isChild;
...@@ -58,150 +60,94 @@ 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; return c < 8 ? 8 : c;
} }
static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { static int32_t taosProcInitMutex(SProcQueue *pQueue) {
TdThreadMutex *pMutex = NULL;
TdThreadMutexAttr mattr = {0}; TdThreadMutexAttr mattr = {0};
int32_t shmid = -1;
int32_t code = -1;
if (pthread_mutexattr_init(&mattr) != 0) { if (taosThreadMutexAttrInit(&mattr) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to init mutex while init attr since %s", terrstr()); uError("failed to init mutex while init attr since %s", terrstr());
goto _OVER; return -1;
} }
if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) { if (taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) {
taosThreadMutexAttrDestroy(&mattr);
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to init mutex while set shared since %s", terrstr()); uError("failed to init mutex while set shared since %s", terrstr());
goto _OVER; 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); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to init mutex since %s", terrstr()); uError("failed to init mutex since %s", terrstr());
goto _OVER; return -1;
}
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;
} }
pthread_mutexattr_destroy(&mattr); 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) { static int32_t taosProcInitSem(SProcQueue *pQueue) {
int32_t shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600); if (tsem_init(&pQueue->sem, 1, 0) != 0) {
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); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to init buffer while shmat since %s", terrstr()); uError("failed to init sem");
shmctl(shmid, IPC_RMID, NULL);
return -1; return -1;
} }
*ppBuffer = shmptr; return 0;
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) { static SProcQueue *taosProcInitQueue(const char *name, bool isChild, char *ptr, int32_t size) {
if (size <= 0) size = SHM_DEFAULT_SIZE; int32_t bufSize = size - CEIL8(sizeof(SProcQueue));
if (bufSize <= 1024) {
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; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
pQueue->bufferShmid = shmId;
if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { SProcQueue *pQueue = (SProcQueue *)(ptr);
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
return NULL;
}
if (tsem_init(&pQueue->sem, 1, 0) != 0) { if (!isChild) {
taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); if (taosProcInitMutex(pQueue) != 0) {
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { if (taosProcInitSem(pQueue) != 0) {
tsem_destroy(&pQueue->sem);
taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid);
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
return NULL; return NULL;
} }
tstrncpy(pQueue->name, name, sizeof(pQueue->name));
pQueue->head = 0; pQueue->head = 0;
pQueue->tail = 0; pQueue->tail = 0;
pQueue->total = bufSize; pQueue->total = bufSize;
pQueue->avail = bufSize; pQueue->avail = bufSize;
pQueue->items = 0; pQueue->items = 0;
pQueue->pBuffer = (char *)pQueue + headSize; }
return pQueue; 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) { static void taosProcCleanupQueue(SProcQueue *pQueue) {
if (pQueue != NULL) { if (pQueue != NULL) {
uDebug("proc:%s, queue:%p clean up", pQueue->name, pQueue); taosProcDestroyMutex(pQueue);
tsem_destroy(&pQueue->sem); taosProcDestroySem(pQueue);
taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid);
taosProcDestroyBuffer(pQueue, pQueue->bufferShmid);
} }
} }
#endif
static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody, static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, const char *pBody,
int32_t rawBodyLen, ProcFuncType ftype) { int32_t rawBodyLen, ProcFuncType ftype) {
...@@ -209,9 +155,9 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t ...@@ -209,9 +155,9 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t
const int32_t bodyLen = CEIL8(rawBodyLen); const int32_t bodyLen = CEIL8(rawBodyLen);
const int32_t fullLen = headLen + bodyLen + 8; const int32_t fullLen = headLen + bodyLen + 8;
taosThreadMutexLock(pQueue->mutex); taosThreadMutexLock(&pQueue->mutex);
if (fullLen > pQueue->avail) { if (fullLen > pQueue->avail) {
taosThreadMutexUnlock(pQueue->mutex); taosThreadMutexUnlock(&pQueue->mutex);
terrno = TSDB_CODE_OUT_OF_SHM_MEM; terrno = TSDB_CODE_OUT_OF_SHM_MEM;
return -1; return -1;
} }
...@@ -260,7 +206,7 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t ...@@ -260,7 +206,7 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t
pQueue->avail -= fullLen; pQueue->avail -= fullLen;
pQueue->items++; pQueue->items++;
taosThreadMutexUnlock(pQueue->mutex); taosThreadMutexUnlock(&pQueue->mutex);
tsem_post(&pQueue->sem); 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, 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 ...@@ -268,13 +214,14 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, const char *pHead, int16_t
return 0; return 0;
} }
static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen,
int32_t *pBodyLen, ProcFuncType *pFuncType) { ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp,
ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) {
tsem_wait(&pQueue->sem); tsem_wait(&pQueue->sem);
taosThreadMutexLock(pQueue->mutex); taosThreadMutexLock(&pQueue->mutex);
if (pQueue->total - pQueue->avail <= 0) { if (pQueue->total - pQueue->avail <= 0) {
taosThreadMutexUnlock(pQueue->mutex); taosThreadMutexUnlock(&pQueue->mutex);
tsem_post(&pQueue->sem); tsem_post(&pQueue->sem);
terrno = TSDB_CODE_OUT_OF_SHM_MEM; terrno = TSDB_CODE_OUT_OF_SHM_MEM;
return 0; return 0;
...@@ -293,13 +240,13 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea ...@@ -293,13 +240,13 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea
bodyLen = *(int32_t *)(pQueue->pBuffer + 4); bodyLen = *(int32_t *)(pQueue->pBuffer + 4);
} }
void *pHead = (*pQueue->mallocHeadFp)(headLen); void *pHead = (*mallocHeadFp)(headLen);
void *pBody = (*pQueue->mallocBodyFp)(bodyLen); void *pBody = (*mallocBodyFp)(bodyLen);
if (pHead == NULL || pBody == NULL) { if (pHead == NULL || pBody == NULL) {
taosThreadMutexUnlock(pQueue->mutex); taosThreadMutexUnlock(&pQueue->mutex);
tsem_post(&pQueue->sem); tsem_post(&pQueue->sem);
(*pQueue->freeHeadFp)(pHead); (*freeHeadFp)(pHead);
(*pQueue->freeBodyFp)(pBody); (*freeBodyFp)(pBody);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
...@@ -338,7 +285,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea ...@@ -338,7 +285,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea
pQueue->avail = pQueue->avail + headLen + bodyLen + 8; pQueue->avail = pQueue->avail + headLen + bodyLen + 8;
pQueue->items--; pQueue->items--;
taosThreadMutexUnlock(pQueue->mutex); taosThreadMutexUnlock(&pQueue->mutex);
*ppHead = pHead; *ppHead = pHead;
*ppBody = pBody; *ppBody = pBody;
...@@ -358,65 +305,85 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { ...@@ -358,65 +305,85 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) {
return NULL; 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->name = pCfg->name;
pProc->pChildQueue = taosProcInitQueue(pCfg->childQueueSize); pProc->pChildQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + cstart, csize);
pProc->pParentQueue = taosProcInitQueue(pCfg->parentQueueSize); pProc->pParentQueue = taosProcInitQueue(pCfg->name, pCfg->isChild, (char *)pCfg->shm.ptr + pstart, psize);
if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) { if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) {
taosProcCleanupQueue(pProc->pChildQueue); // taosProcCleanupQueue(pProc->pChildQueue);
taosMemoryFree(pProc); taosMemoryFree(pProc);
return NULL; return NULL;
} }
pProc->pChildQueue->name = pCfg->name; pProc->name = pCfg->name;
pProc->pChildQueue->pParent = pCfg->pParent; pProc->pParent = pCfg->pParent;
pProc->pChildQueue->mallocHeadFp = pCfg->childMallocHeadFp; pProc->childMallocHeadFp = pCfg->childMallocHeadFp;
pProc->pChildQueue->freeHeadFp = pCfg->childFreeHeadFp; pProc->childFreeHeadFp = pCfg->childFreeHeadFp;
pProc->pChildQueue->mallocBodyFp = pCfg->childMallocBodyFp; pProc->childMallocBodyFp = pCfg->childMallocBodyFp;
pProc->pChildQueue->freeBodyFp = pCfg->childFreeBodyFp; pProc->childFreeBodyFp = pCfg->childFreeBodyFp;
pProc->pChildQueue->consumeFp = pCfg->childConsumeFp; pProc->childConsumeFp = pCfg->childConsumeFp;
pProc->pParentQueue->name = pCfg->name; pProc->parentMallocHeadFp = pCfg->parentMallocHeadFp;
pProc->pParentQueue->pParent = pCfg->pParent; pProc->parentFreeHeadFp = pCfg->parentFreeHeadFp;
pProc->pParentQueue->mallocHeadFp = pCfg->parentdMallocHeadFp; pProc->parentMallocBodyFp = pCfg->parentMallocBodyFp;
pProc->pParentQueue->freeHeadFp = pCfg->parentFreeHeadFp; pProc->parentFreeBodyFp = pCfg->parentFreeBodyFp;
pProc->pParentQueue->mallocBodyFp = pCfg->parentMallocBodyFp; pProc->parentConsumeFp = pCfg->parentConsumeFp;
pProc->pParentQueue->freeBodyFp = pCfg->parentFreeBodyFp; pProc->isChild = pCfg->isChild;
pProc->pParentQueue->consumeFp = pCfg->parentConsumeFp;
uDebug("proc:%s, is initialized, isChild:%d child queue:%p parent queue:%p", pProc->name, pProc->isChild,
uDebug("proc:%s, is initialized, child queue:%p parent queue:%p", pProc->name, pProc->pChildQueue, pProc->pParentQueue); 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);
}
return pProc; return pProc;
} }
static void taosProcThreadLoop(SProcQueue *pQueue) { static void taosProcThreadLoop(SProcObj *pProc) {
ProcConsumeFp consumeFp = pQueue->consumeFp;
void *pParent = pQueue->pParent;
void *pHead, *pBody; void *pHead, *pBody;
int16_t headLen; int16_t headLen;
ProcFuncType ftype; ProcFuncType ftype;
int32_t bodyLen; int32_t bodyLen;
SProcQueue *pQueue;
ProcConsumeFp consumeFp;
ProcMallocFp mallocHeadFp;
ProcFreeFp freeHeadFp;
ProcMallocFp mallocBodyFp;
ProcFreeFp freeBodyFp;
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", pQueue->name, pQueue); uDebug("proc:%s, start to get msg from queue:%p, isChild:%d", pProc->name, pQueue, pProc->isChild);
while (1) { 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) { 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; break;
} else if (numOfMsgs < 0) { } 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); taosMsleep(1);
continue; continue;
} else { } 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) { ...@@ -426,40 +393,37 @@ int32_t taosProcRun(SProcObj *pProc) {
taosThreadAttrInit(&thAttr); taosThreadAttrInit(&thAttr);
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
if (pProc->isChild) { if (taosThreadCreate(&pProc->thread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc) != 0) {
if (taosThreadCreate(&pProc->childThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pChildQueue) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
uError("failed to create thread since %s", terrstr()); uError("failed to create thread since %s", terrstr());
return -1; 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);
}
uDebug("proc:%s, start to consume queue:%p, thread:%" PRId64, pProc->name, pProc->pChildQueue, pProc->thread);
return 0; return 0;
} }
void taosProcStop(SProcObj *pProc) { static void taosProcStop(SProcObj *pProc) {
pProc->stopFlag = true; if (!taosCheckPthreadValid(pProc->thread)) return;
// todo join
}
bool taosProcIsChild(SProcObj *pProc) { return pProc->isChild; } uDebug("proc:%s, start to join thread:%" PRId64 ", isChild:%d", pProc->name, pProc->thread, pProc->isChild);
SProcQueue *pQueue;
int32_t taosProcChildId(SProcObj *pProc) { return pProc->pid; } if (pProc->isChild) {
pQueue = pProc->pChildQueue;
} else {
pQueue = pProc->pParentQueue;
}
tsem_post(&pQueue->sem);
taosThreadJoin(pProc->thread, NULL);
}
void taosProcCleanup(SProcObj *pProc) { void taosProcCleanup(SProcObj *pProc) {
if (pProc != NULL) { if (pProc != NULL) {
uDebug("proc:%s, clean up", pProc->name); uDebug("proc:%s, start to clean up", pProc->name);
taosProcStop(pProc); taosProcStop(pProc);
taosProcCleanupQueue(pProc->pChildQueue); uDebug("proc:%s, is cleaned up", pProc->name);
taosProcCleanupQueue(pProc->pParentQueue); // taosProcCleanupQueue(pProc->pChildQueue);
// taosProcCleanupQueue(pProc->pParentQueue);
taosMemoryFree(pProc); taosMemoryFree(pProc);
} }
} }
......
此差异已折叠。
...@@ -50,7 +50,10 @@ class TDSql: ...@@ -50,7 +50,10 @@ class TDSql:
def prepare(self): def prepare(self):
tdLog.info("prepare database:db") tdLog.info("prepare database:db")
s = 'reset query cache' s = 'reset query cache'
try:
self.cursor.execute(s) self.cursor.execute(s)
except:
tdLog.notice("'reset query cache' is not supported")
s = 'drop database if exists db' s = 'drop database if exists db'
self.cursor.execute(s) self.cursor.execute(s)
s = 'create database db' s = 'create database db'
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -226,7 +226,7 @@ void loop_consume(tmq_t* tmq) { ...@@ -226,7 +226,7 @@ void loop_consume(tmq_t* tmq) {
int32_t totalRows = 0; int32_t totalRows = 0;
int32_t skipLogNum = 0; int32_t skipLogNum = 0;
while (running) { while (running) {
tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 1); tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 6000);
if (tmqMsg) { if (tmqMsg) {
totalMsgs++; totalMsgs++;
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册