Merge remote-tracking branch 'origin/3.0' into fix/TD-31073
This commit is contained in:
commit
ae2210f7cc
|
|
@ -401,7 +401,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('linux test') {
|
stage('linux test') {
|
||||||
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || worker03 || slave215 || slave217 || slave219 "}
|
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
|
||||||
options { skipDefaultCheckout() }
|
options { skipDefaultCheckout() }
|
||||||
when {
|
when {
|
||||||
changeRequest()
|
changeRequest()
|
||||||
|
|
@ -416,7 +416,7 @@ pipeline {
|
||||||
echo "${WKDIR}/restore.sh -p ${BRANCH_NAME} -n ${BUILD_ID} -c {container name}"
|
echo "${WKDIR}/restore.sh -p ${BRANCH_NAME} -n ${BUILD_ID} -c {container name}"
|
||||||
}
|
}
|
||||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||||
timeout(time: 150, unit: 'MINUTES'){
|
timeout(time: 200, unit: 'MINUTES'){
|
||||||
pre_test()
|
pre_test()
|
||||||
script {
|
script {
|
||||||
sh '''
|
sh '''
|
||||||
|
|
@ -454,7 +454,7 @@ pipeline {
|
||||||
cd ${WKC}/tests/parallel_test
|
cd ${WKC}/tests/parallel_test
|
||||||
export DEFAULT_RETRY_TIME=2
|
export DEFAULT_RETRY_TIME=2
|
||||||
date
|
date
|
||||||
''' + timeout_cmd + ''' time ./run.sh -e -m /home/m.json -t cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 900 ''' + extra_param + '''
|
''' + timeout_cmd + ''' time ./run.sh -e -m /home/m.json -t cases.task -b ${BRANCH_NAME}_${BUILD_ID} -l ${WKDIR}/log -o 1200 ''' + extra_param + '''
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ extern "C" {
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
|
||||||
void stopRsync();
|
void stopRsync();
|
||||||
void startRsync();
|
int32_t startRsync();
|
||||||
int32_t uploadByRsync(const char* id, const char* path);
|
int32_t uploadByRsync(const char* id, const char* path);
|
||||||
int32_t downloadRsync(const char* id, const char* path);
|
int32_t downloadRsync(const char* id, const char* path);
|
||||||
int32_t deleteRsync(const char* id);
|
int32_t deleteRsync(const char* id);
|
||||||
|
|
|
||||||
|
|
@ -247,13 +247,13 @@ int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockI
|
||||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize, int32_t extraSize);
|
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize, int32_t extraSize);
|
||||||
|
|
||||||
int32_t blockDataTrimFirstRows(SSDataBlock* pBlock, size_t n);
|
int32_t blockDataTrimFirstRows(SSDataBlock* pBlock, size_t n);
|
||||||
int32_t blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n);
|
void blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n);
|
||||||
|
|
||||||
int32_t assignOneDataBlock(SSDataBlock* dst, const SSDataBlock* src);
|
int32_t assignOneDataBlock(SSDataBlock* dst, const SSDataBlock* src);
|
||||||
int32_t copyDataBlock(SSDataBlock* pDst, const SSDataBlock* pSrc);
|
int32_t copyDataBlock(SSDataBlock* pDst, const SSDataBlock* pSrc);
|
||||||
|
|
||||||
SSDataBlock* createDataBlock();
|
SSDataBlock* createDataBlock();
|
||||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
void blockDataDestroy(SSDataBlock* pBlock);
|
||||||
void blockDataFreeRes(SSDataBlock* pBlock);
|
void blockDataFreeRes(SSDataBlock* pBlock);
|
||||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData);
|
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData);
|
||||||
SSDataBlock* createSpecialDataBlock(EStreamType type);
|
SSDataBlock* createSpecialDataBlock(EStreamType type);
|
||||||
|
|
|
||||||
|
|
@ -329,29 +329,31 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct SStateStore {
|
typedef struct SStateStore {
|
||||||
int32_t (*streamStatePutParName)(SStreamState* pState, int64_t groupId, const char* tbname);
|
int32_t (*streamStatePutParName)(SStreamState* pState, int64_t groupId, const char* tbname);
|
||||||
int32_t (*streamStateGetParName)(SStreamState* pState, int64_t groupId, void** pVal, bool onlyCache);
|
int32_t (*streamStateGetParName)(SStreamState* pState, int64_t groupId, void** pVal, bool onlyCache,
|
||||||
|
int32_t* pWinCode);
|
||||||
|
|
||||||
int32_t (*streamStateAddIfNotExist)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateAddIfNotExist)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen,
|
||||||
int32_t (*streamStateReleaseBuf)(SStreamState* pState, void* pVal, bool used);
|
int32_t* pWinCode);
|
||||||
int32_t (*streamStateClearBuff)(SStreamState* pState, void* pVal);
|
void (*streamStateReleaseBuf)(SStreamState* pState, void* pVal, bool used);
|
||||||
|
void (*streamStateClearBuff)(SStreamState* pState, void* pVal);
|
||||||
void (*streamStateFreeVal)(void* val);
|
void (*streamStateFreeVal)(void* val);
|
||||||
|
|
||||||
int32_t (*streamStatePut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
int32_t (*streamStatePut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
||||||
int32_t (*streamStateGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
bool (*streamStateCheck)(SStreamState* pState, const SWinKey* key);
|
bool (*streamStateCheck)(SStreamState* pState, const SWinKey* key);
|
||||||
int32_t (*streamStateGetByPos)(SStreamState* pState, void* pos, void** pVal);
|
int32_t (*streamStateGetByPos)(SStreamState* pState, void* pos, void** pVal);
|
||||||
int32_t (*streamStateDel)(SStreamState* pState, const SWinKey* key);
|
void (*streamStateDel)(SStreamState* pState, const SWinKey* key);
|
||||||
int32_t (*streamStateClear)(SStreamState* pState);
|
void (*streamStateClear)(SStreamState* pState);
|
||||||
void (*streamStateSetNumber)(SStreamState* pState, int32_t number, int32_t tsIdex);
|
void (*streamStateSetNumber)(SStreamState* pState, int32_t number, int32_t tsIdex);
|
||||||
int32_t (*streamStateSaveInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
|
void (*streamStateSaveInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
|
||||||
int32_t (*streamStateGetInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
|
int32_t (*streamStateGetInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
|
||||||
|
|
||||||
int32_t (*streamStateFillPut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
int32_t (*streamStateFillPut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
||||||
int32_t (*streamStateFillGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateFillGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
||||||
int32_t (*streamStateFillDel)(SStreamState* pState, const SWinKey* key);
|
void (*streamStateFillDel)(SStreamState* pState, const SWinKey* key);
|
||||||
|
|
||||||
int32_t (*streamStateCurNext)(SStreamState* pState, SStreamStateCur* pCur);
|
void (*streamStateCurNext)(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
int32_t (*streamStateCurPrev)(SStreamState* pState, SStreamStateCur* pCur);
|
void (*streamStateCurPrev)(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
|
|
||||||
SStreamStateCur* (*streamStateGetAndCheckCur)(SStreamState* pState, SWinKey* key);
|
SStreamStateCur* (*streamStateGetAndCheckCur)(SStreamState* pState, SWinKey* key);
|
||||||
SStreamStateCur* (*streamStateSeekKeyNext)(SStreamState* pState, const SWinKey* key);
|
SStreamStateCur* (*streamStateSeekKeyNext)(SStreamState* pState, const SWinKey* key);
|
||||||
|
|
@ -363,26 +365,29 @@ typedef struct SStateStore {
|
||||||
int32_t (*streamStateGetKVByCur)(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
int32_t (*streamStateGetKVByCur)(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
int32_t (*streamStateSessionAddIfNotExist)(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal,
|
int32_t (*streamStateSessionAddIfNotExist)(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal,
|
||||||
int32_t* pVLen);
|
int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t (*streamStateSessionPut)(SStreamState* pState, const SSessionKey* key, void* value, int32_t vLen);
|
int32_t (*streamStateSessionPut)(SStreamState* pState, const SSessionKey* key, void* value, int32_t vLen);
|
||||||
int32_t (*streamStateSessionGet)(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateSessionGet)(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen,
|
||||||
int32_t (*streamStateSessionDel)(SStreamState* pState, const SSessionKey* key);
|
int32_t* pWinCode);
|
||||||
int32_t (*streamStateSessionReset)(SStreamState* pState, void* pVal);
|
void (*streamStateSessionDel)(SStreamState* pState, const SSessionKey* key);
|
||||||
int32_t (*streamStateSessionClear)(SStreamState* pState);
|
void (*streamStateSessionReset)(SStreamState* pState, void* pVal);
|
||||||
|
void (*streamStateSessionClear)(SStreamState* pState);
|
||||||
int32_t (*streamStateSessionGetKVByCur)(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateSessionGetKVByCur)(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
int32_t (*streamStateStateAddIfNotExist)(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
int32_t (*streamStateStateAddIfNotExist)(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
||||||
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t (*streamStateSessionGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
int32_t (*streamStateSessionGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
||||||
int32_t (*streamStateCountGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
int32_t (*streamStateCountGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
||||||
int32_t (*streamStateSessionAllocWinBuffByNextPosition)(SStreamState* pState, SStreamStateCur* pCur,
|
int32_t (*streamStateSessionAllocWinBuffByNextPosition)(SStreamState* pState, SStreamStateCur* pCur,
|
||||||
const SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
const SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
int32_t (*streamStateCountWinAddIfNotExist)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount,
|
int32_t (*streamStateCountWinAddIfNotExist)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount,
|
||||||
void** ppVal, int32_t* pVLen);
|
void** ppVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t (*streamStateCountWinAdd)(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateCountWinAdd)(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
int32_t (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
int32_t (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType,
|
||||||
TSKEY (*updateInfoFillBlockData)(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol, int32_t primaryKeyCol);
|
int32_t pkLen, SUpdateInfo** ppInfo);
|
||||||
|
int32_t (*updateInfoFillBlockData)(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol,
|
||||||
|
int32_t primaryKeyCol, TSKEY* pMaxResTs);
|
||||||
bool (*updateInfoIsUpdated)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
bool (*updateInfoIsUpdated)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
||||||
bool (*updateInfoIsTableInserted)(SUpdateInfo* pInfo, int64_t tbUid);
|
bool (*updateInfoIsTableInserted)(SUpdateInfo* pInfo, int64_t tbUid);
|
||||||
bool (*isIncrementalTimeStamp)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
bool (*isIncrementalTimeStamp)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
||||||
|
|
@ -391,7 +396,8 @@ typedef struct SStateStore {
|
||||||
void (*windowSBfDelete)(SUpdateInfo* pInfo, uint64_t count);
|
void (*windowSBfDelete)(SUpdateInfo* pInfo, uint64_t count);
|
||||||
int32_t (*windowSBfAdd)(SUpdateInfo* pInfo, uint64_t count);
|
int32_t (*windowSBfAdd)(SUpdateInfo* pInfo, uint64_t count);
|
||||||
|
|
||||||
int32_t (*updateInfoInitP)(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
int32_t (*updateInfoInitP)(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen,
|
||||||
|
SUpdateInfo** ppInfo);
|
||||||
void (*updateInfoAddCloseWindowSBF)(SUpdateInfo* pInfo);
|
void (*updateInfoAddCloseWindowSBF)(SUpdateInfo* pInfo);
|
||||||
void (*updateInfoDestoryColseWinSBF)(SUpdateInfo* pInfo);
|
void (*updateInfoDestoryColseWinSBF)(SUpdateInfo* pInfo);
|
||||||
int32_t (*updateInfoSerialize)(void* buf, int32_t bufLen, const SUpdateInfo* pInfo, int32_t* pLen);
|
int32_t (*updateInfoSerialize)(void* buf, int32_t bufLen, const SUpdateInfo* pInfo, int32_t* pLen);
|
||||||
|
|
@ -413,7 +419,7 @@ typedef struct SStateStore {
|
||||||
SStreamState* (*streamStateOpen)(const char* path, void* pTask, int64_t streamId, int32_t taskId);
|
SStreamState* (*streamStateOpen)(const char* path, void* pTask, int64_t streamId, int32_t taskId);
|
||||||
void (*streamStateClose)(SStreamState* pState, bool remove);
|
void (*streamStateClose)(SStreamState* pState, bool remove);
|
||||||
int32_t (*streamStateBegin)(SStreamState* pState);
|
int32_t (*streamStateBegin)(SStreamState* pState);
|
||||||
int32_t (*streamStateCommit)(SStreamState* pState);
|
void (*streamStateCommit)(SStreamState* pState);
|
||||||
void (*streamStateDestroy)(SStreamState* pState, bool remove);
|
void (*streamStateDestroy)(SStreamState* pState, bool remove);
|
||||||
int32_t (*streamStateDeleteCheckPoint)(SStreamState* pState, TSKEY mark);
|
int32_t (*streamStateDeleteCheckPoint)(SStreamState* pState, TSKEY mark);
|
||||||
void (*streamStateReloadInfo)(SStreamState* pState, TSKEY ts);
|
void (*streamStateReloadInfo)(SStreamState* pState, TSKEY ts);
|
||||||
|
|
|
||||||
|
|
@ -294,7 +294,7 @@ typedef struct SPoint {
|
||||||
void *val;
|
void *val;
|
||||||
} SPoint;
|
} SPoint;
|
||||||
|
|
||||||
int32_t taosGetLinearInterpolationVal(SPoint *point, int32_t outputType, SPoint *point1, SPoint *point2,
|
void taosGetLinearInterpolationVal(SPoint *point, int32_t outputType, SPoint *point1, SPoint *point2,
|
||||||
int32_t inputType);
|
int32_t inputType);
|
||||||
|
|
||||||
#define LEASTSQUARES_DOUBLE_ITEM_LENGTH 25
|
#define LEASTSQUARES_DOUBLE_ITEM_LENGTH 25
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,7 @@ typedef struct SBoundColInfo {
|
||||||
int16_t* pColIndex; // bound index => schema index
|
int16_t* pColIndex; // bound index => schema index
|
||||||
int32_t numOfCols;
|
int32_t numOfCols;
|
||||||
int32_t numOfBound;
|
int32_t numOfBound;
|
||||||
|
bool hasBoundCols;
|
||||||
} SBoundColInfo;
|
} SBoundColInfo;
|
||||||
|
|
||||||
typedef struct STableColsData {
|
typedef struct STableColsData {
|
||||||
|
|
@ -334,7 +335,7 @@ SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* nam
|
||||||
|
|
||||||
void destroyQueryExecRes(SExecResult* pRes);
|
void destroyQueryExecRes(SExecResult* pRes);
|
||||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
||||||
char* parseTagDatatoJson(void* p);
|
void parseTagDatatoJson(void* p, char** jsonStr);
|
||||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||||
void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType);
|
void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType);
|
||||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ extern "C" {
|
||||||
SStreamState* streamStateOpen(const char* path, void* pTask, int64_t streamId, int32_t taskId);
|
SStreamState* streamStateOpen(const char* path, void* pTask, int64_t streamId, int32_t taskId);
|
||||||
void streamStateClose(SStreamState* pState, bool remove);
|
void streamStateClose(SStreamState* pState, bool remove);
|
||||||
int32_t streamStateBegin(SStreamState* pState);
|
int32_t streamStateBegin(SStreamState* pState);
|
||||||
int32_t streamStateCommit(SStreamState* pState);
|
void streamStateCommit(SStreamState* pState);
|
||||||
void streamStateDestroy(SStreamState* pState, bool remove);
|
void streamStateDestroy(SStreamState* pState, bool remove);
|
||||||
int32_t streamStateDeleteCheckPoint(SStreamState* pState, TSKEY mark);
|
int32_t streamStateDeleteCheckPoint(SStreamState* pState, TSKEY mark);
|
||||||
int32_t streamStateDelTaskDb(SStreamState* pState);
|
int32_t streamStateDelTaskDb(SStreamState* pState);
|
||||||
|
|
@ -41,22 +41,23 @@ int32_t streamStateFuncPut(SStreamState* pState, const SWinKey* key, const void*
|
||||||
int32_t streamStateFuncGet(SStreamState* pState, const SWinKey* key, void** ppVal, int32_t* pVLen);
|
int32_t streamStateFuncGet(SStreamState* pState, const SWinKey* key, void** ppVal, int32_t* pVLen);
|
||||||
|
|
||||||
int32_t streamStatePut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
int32_t streamStatePut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
||||||
int32_t streamStateGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
bool streamStateCheck(SStreamState* pState, const SWinKey* key);
|
bool streamStateCheck(SStreamState* pState, const SWinKey* key);
|
||||||
int32_t streamStateGetByPos(SStreamState* pState, void* pos, void** pVal);
|
int32_t streamStateGetByPos(SStreamState* pState, void* pos, void** pVal);
|
||||||
int32_t streamStateDel(SStreamState* pState, const SWinKey* key);
|
void streamStateDel(SStreamState* pState, const SWinKey* key);
|
||||||
int32_t streamStateClear(SStreamState* pState);
|
void streamStateClear(SStreamState* pState);
|
||||||
void streamStateSetNumber(SStreamState* pState, int32_t number, int32_t tsIdex);
|
void streamStateSetNumber(SStreamState* pState, int32_t number, int32_t tsIdex);
|
||||||
int32_t streamStateSaveInfo(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
|
void streamStateSaveInfo(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
|
||||||
int32_t streamStateGetInfo(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
|
int32_t streamStateGetInfo(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
|
||||||
|
|
||||||
// session window
|
// session window
|
||||||
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen);
|
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen,
|
||||||
|
int32_t* pWinCode);
|
||||||
int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, void* value, int32_t vLen);
|
int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, void* value, int32_t vLen);
|
||||||
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key);
|
void streamStateSessionDel(SStreamState* pState, const SSessionKey* key);
|
||||||
int32_t streamStateSessionReset(SStreamState* pState, void* pVal);
|
void streamStateSessionReset(SStreamState* pState, void* pVal);
|
||||||
int32_t streamStateSessionClear(SStreamState* pState);
|
void streamStateSessionClear(SStreamState* pState);
|
||||||
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
||||||
int32_t streamStateCountGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
int32_t streamStateCountGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
||||||
|
|
@ -70,21 +71,22 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentNext(SStreamState* pState, cons
|
||||||
|
|
||||||
// state window
|
// state window
|
||||||
int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
||||||
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
|
|
||||||
// fill
|
// fill
|
||||||
int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
||||||
int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateFillDel(SStreamState* pState, const SWinKey* key);
|
void streamStateFillDel(SStreamState* pState, const SWinKey* key);
|
||||||
|
|
||||||
int32_t streamStateAddIfNotExist(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateAddIfNotExist(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen,
|
||||||
int32_t streamStateReleaseBuf(SStreamState* pState, void* pVal, bool used);
|
int32_t* pWinCode);
|
||||||
int32_t streamStateClearBuff(SStreamState* pState, void* pVal);
|
void streamStateReleaseBuf(SStreamState* pState, void* pVal, bool used);
|
||||||
|
void streamStateClearBuff(SStreamState* pState, void* pVal);
|
||||||
void streamStateFreeVal(void* val);
|
void streamStateFreeVal(void* val);
|
||||||
|
|
||||||
// count window
|
// count window
|
||||||
int32_t streamStateCountWinAddIfNotExist(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** ppVal,
|
int32_t streamStateCountWinAddIfNotExist(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** ppVal,
|
||||||
int32_t* pVLen);
|
int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
SStreamStateCur* streamStateGetAndCheckCur(SStreamState* pState, SWinKey* key);
|
SStreamStateCur* streamStateGetAndCheckCur(SStreamState* pState, SWinKey* key);
|
||||||
|
|
@ -97,11 +99,11 @@ void streamStateResetCur(SStreamStateCur* pCur);
|
||||||
int32_t streamStateGetGroupKVByCur(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
int32_t streamStateGetGroupKVByCur(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateGetKVByCur(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
int32_t streamStateGetKVByCur(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
int32_t streamStateCurNext(SStreamState* pState, SStreamStateCur* pCur);
|
void streamStateCurNext(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
int32_t streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur);
|
void streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
|
|
||||||
int32_t streamStatePutParName(SStreamState* pState, int64_t groupId, const char* tbname);
|
int32_t streamStatePutParName(SStreamState* pState, int64_t groupId, const char* tbname);
|
||||||
int32_t streamStateGetParName(SStreamState* pState, int64_t groupId, void** pVal, bool onlyCache);
|
int32_t streamStateGetParName(SStreamState* pState, int64_t groupId, void** pVal, bool onlyCache, int32_t* pWinCode);
|
||||||
|
|
||||||
void streamStateReloadInfo(SStreamState* pState, TSKEY ts);
|
void streamStateReloadInfo(SStreamState* pState, TSKEY ts);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -629,7 +629,7 @@ int32_t streamSetupScheduleTrigger(SStreamTask* pTask);
|
||||||
int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg);
|
int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg);
|
||||||
int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, int32_t code);
|
int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, int32_t code);
|
||||||
|
|
||||||
int32_t streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId, SStreamUpstreamEpInfo** pEpInfo);
|
void streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId, SStreamUpstreamEpInfo** pEpInfo);
|
||||||
#if 0
|
#if 0
|
||||||
SEpSet* streamTaskGetDownstreamEpInfo(SStreamTask* pTask, int32_t taskId);
|
SEpSet* streamTaskGetDownstreamEpInfo(SStreamTask* pTask, int32_t taskId);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -659,10 +659,10 @@ int8_t streamTaskSetSchedStatusInactive(SStreamTask* pTask);
|
||||||
int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t clearRelHalt);
|
int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t clearRelHalt);
|
||||||
|
|
||||||
int32_t streamExecTask(SStreamTask* pTask);
|
int32_t streamExecTask(SStreamTask* pTask);
|
||||||
int32_t streamResumeTask(SStreamTask* pTask);
|
void streamResumeTask(SStreamTask* pTask);
|
||||||
int32_t streamTrySchedExec(SStreamTask* pTask);
|
int32_t streamTrySchedExec(SStreamTask* pTask);
|
||||||
int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId, int32_t execType);
|
int32_t streamTaskSchedTask(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId, int32_t execType);
|
||||||
int32_t streamTaskResumeInFuture(SStreamTask* pTask);
|
void streamTaskResumeInFuture(SStreamTask* pTask);
|
||||||
void streamTaskClearSchedIdleInfo(SStreamTask* pTask);
|
void streamTaskClearSchedIdleInfo(SStreamTask* pTask);
|
||||||
void streamTaskSetIdleInfo(SStreamTask* pTask, int32_t idleTime);
|
void streamTaskSetIdleInfo(SStreamTask* pTask, int32_t idleTime);
|
||||||
|
|
||||||
|
|
@ -675,8 +675,8 @@ int32_t streamTaskSendCheckRsp(const SStreamMeta* pMeta, int32_t vgId, SStreamTa
|
||||||
int32_t streamTaskProcessCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp);
|
int32_t streamTaskProcessCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp);
|
||||||
|
|
||||||
// check downstream status
|
// check downstream status
|
||||||
int32_t streamTaskStartMonitorCheckRsp(SStreamTask* pTask);
|
void streamTaskStartMonitorCheckRsp(SStreamTask* pTask);
|
||||||
int32_t streamTaskStopMonitorCheckRsp(STaskCheckInfo* pInfo, const char* id);
|
void streamTaskStopMonitorCheckRsp(STaskCheckInfo* pInfo, const char* id);
|
||||||
void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo);
|
void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo);
|
||||||
|
|
||||||
// fill-history task
|
// fill-history task
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#include "storageapi.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
#include "storageapi.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -32,7 +32,7 @@ typedef SList SStreamSnapshot;
|
||||||
|
|
||||||
typedef void* (*_state_buff_get_fn)(void* pRowBuff, const void* pKey, size_t keyLen);
|
typedef void* (*_state_buff_get_fn)(void* pRowBuff, const void* pKey, size_t keyLen);
|
||||||
typedef int32_t (*_state_buff_remove_fn)(void* pRowBuff, const void* pKey, size_t keyLen);
|
typedef int32_t (*_state_buff_remove_fn)(void* pRowBuff, const void* pKey, size_t keyLen);
|
||||||
typedef int32_t (*_state_buff_remove_by_pos_fn)(SStreamFileState* pState, SRowBuffPos* pPos);
|
typedef void (*_state_buff_remove_by_pos_fn)(SStreamFileState* pState, SRowBuffPos* pPos);
|
||||||
typedef void (*_state_buff_cleanup_fn)(void* pRowBuff);
|
typedef void (*_state_buff_cleanup_fn)(void* pRowBuff);
|
||||||
typedef void* (*_state_buff_create_statekey_fn)(SRowBuffPos* pPos, int64_t num);
|
typedef void* (*_state_buff_create_statekey_fn)(SRowBuffPos* pPos, int64_t num);
|
||||||
|
|
||||||
|
|
@ -40,28 +40,30 @@ typedef int32_t (*_state_file_remove_fn)(SStreamFileState* pFileState, const voi
|
||||||
typedef int32_t (*_state_file_get_fn)(SStreamFileState* pFileState, void* pKey, void* data, int32_t* pDataLen);
|
typedef int32_t (*_state_file_get_fn)(SStreamFileState* pFileState, void* pKey, void* data, int32_t* pDataLen);
|
||||||
typedef int32_t (*_state_file_clear_fn)(SStreamState* pState);
|
typedef int32_t (*_state_file_clear_fn)(SStreamState* pState);
|
||||||
|
|
||||||
typedef int32_t (*_state_fun_get_fn) (SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
typedef int32_t (*_state_fun_get_fn)(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal,
|
||||||
|
int32_t* pVLen, int32_t* pWinCode);
|
||||||
|
|
||||||
typedef int32_t (*range_cmpr_fn)(const SSessionKey* pWin1, const SSessionKey* pWin2);
|
typedef int32_t (*range_cmpr_fn)(const SSessionKey* pWin1, const SSessionKey* pWin2);
|
||||||
|
|
||||||
SStreamFileState* streamFileStateInit(int64_t memSize, uint32_t keySize, uint32_t rowSize, uint32_t selectRowSize,
|
SStreamFileState* streamFileStateInit(int64_t memSize, uint32_t keySize, uint32_t rowSize, uint32_t selectRowSize,
|
||||||
GetTsFun fp, void* pFile, TSKEY delMark, const char* taskId,
|
GetTsFun fp, void* pFile, TSKEY delMark, const char* taskId, int64_t checkpointId,
|
||||||
int64_t checkpointId, int8_t type);
|
int8_t type);
|
||||||
void streamFileStateDestroy(SStreamFileState* pFileState);
|
void streamFileStateDestroy(SStreamFileState* pFileState);
|
||||||
void streamFileStateClear(SStreamFileState* pFileState);
|
void streamFileStateClear(SStreamFileState* pFileState);
|
||||||
bool needClearDiskBuff(SStreamFileState* pFileState);
|
bool needClearDiskBuff(SStreamFileState* pFileState);
|
||||||
void streamFileStateReleaseBuff(SStreamFileState* pFileState, SRowBuffPos* pPos, bool used);
|
void streamFileStateReleaseBuff(SStreamFileState* pFileState, SRowBuffPos* pPos, bool used);
|
||||||
int32_t streamFileStateClearBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
void streamFileStateClearBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
||||||
|
|
||||||
int32_t getRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
int32_t getRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
||||||
int32_t deleteRowBuff(SStreamFileState* pFileState, const void* pKey, int32_t keyLen);
|
int32_t* pWinCode);
|
||||||
|
void deleteRowBuff(SStreamFileState* pFileState, const void* pKey, int32_t keyLen);
|
||||||
int32_t getRowBuffByPos(SStreamFileState* pFileState, SRowBuffPos* pPos, void** pVal);
|
int32_t getRowBuffByPos(SStreamFileState* pFileState, SRowBuffPos* pPos, void** pVal);
|
||||||
bool hasRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen);
|
bool hasRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen);
|
||||||
void putFreeBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
int32_t putFreeBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
||||||
|
|
||||||
SStreamSnapshot* getSnapshot(SStreamFileState* pFileState);
|
SStreamSnapshot* getSnapshot(SStreamFileState* pFileState);
|
||||||
int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot, bool flushState);
|
void flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot, bool flushState);
|
||||||
int32_t recoverSnapshot(SStreamFileState* pFileState, int64_t ckId);
|
void recoverSnapshot(SStreamFileState* pFileState, int64_t ckId);
|
||||||
|
|
||||||
int32_t getSnapshotIdList(SStreamFileState* pFileState, SArray* list);
|
int32_t getSnapshotIdList(SStreamFileState* pFileState, SArray* list);
|
||||||
int32_t deleteExpiredCheckPoint(SStreamFileState* pFileState, TSKEY mark);
|
int32_t deleteExpiredCheckPoint(SStreamFileState* pFileState, TSKEY mark);
|
||||||
|
|
@ -76,16 +78,18 @@ SRowBuffPos* getNewRowPosForWrite(SStreamFileState* pFileState);
|
||||||
int32_t getRowStateRowSize(SStreamFileState* pFileState);
|
int32_t getRowStateRowSize(SStreamFileState* pFileState);
|
||||||
|
|
||||||
// session window
|
// session window
|
||||||
int32_t getSessionWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, TSKEY gap, void** pVal, int32_t* pVLen);
|
int32_t getSessionWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, TSKEY gap, void** pVal, int32_t* pVLen,
|
||||||
|
int32_t* pWinCode);
|
||||||
int32_t putSessionWinResultBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
int32_t putSessionWinResultBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
||||||
int32_t getSessionFlushedBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t getSessionFlushedBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen,
|
||||||
|
int32_t* pWinCode);
|
||||||
int32_t deleteSessionWinStateBuffFn(void* pBuff, const void* key, size_t keyLen);
|
int32_t deleteSessionWinStateBuffFn(void* pBuff, const void* key, size_t keyLen);
|
||||||
int32_t deleteSessionWinStateBuffByPosFn(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
void deleteSessionWinStateBuffByPosFn(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
||||||
int32_t allocSessioncWinBuffByNextPosition(SStreamFileState* pFileState, SStreamStateCur* pCur,
|
int32_t allocSessioncWinBuffByNextPosition(SStreamFileState* pFileState, SStreamStateCur* pCur,
|
||||||
const SSessionKey* pWinKey, void** ppVal, int32_t* pVLen);
|
const SSessionKey* pWinKey, void** ppVal, int32_t* pVLen);
|
||||||
|
|
||||||
SRowBuffPos* createSessionWinBuff(SStreamFileState* pFileState, SSessionKey* pKey, void* p, int32_t* pVLen);
|
SRowBuffPos* createSessionWinBuff(SStreamFileState* pFileState, SSessionKey* pKey, void* p, int32_t* pVLen);
|
||||||
int32_t recoverSesssion(SStreamFileState* pFileState, int64_t ckId);
|
void recoverSesssion(SStreamFileState* pFileState, int64_t ckId);
|
||||||
|
|
||||||
void sessionWinStateClear(SStreamFileState* pFileState);
|
void sessionWinStateClear(SStreamFileState* pFileState);
|
||||||
void sessionWinStateCleanup(void* pBuff);
|
void sessionWinStateCleanup(void* pBuff);
|
||||||
|
|
@ -95,19 +99,22 @@ SStreamStateCur* sessionWinStateSeekKeyCurrentNext(SStreamFileState* pFileState,
|
||||||
SStreamStateCur* sessionWinStateSeekKeyNext(SStreamFileState* pFileState, const SSessionKey* pWinKey);
|
SStreamStateCur* sessionWinStateSeekKeyNext(SStreamFileState* pFileState, const SSessionKey* pWinKey);
|
||||||
SStreamStateCur* countWinStateSeekKeyPrev(SStreamFileState* pFileState, const SSessionKey* pWinKey, COUNT_TYPE count);
|
SStreamStateCur* countWinStateSeekKeyPrev(SStreamFileState* pFileState, const SSessionKey* pWinKey, COUNT_TYPE count);
|
||||||
int32_t sessionWinStateGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t sessionWinStateGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
int32_t sessionWinStateMoveToNext(SStreamStateCur* pCur);
|
void sessionWinStateMoveToNext(SStreamStateCur* pCur);
|
||||||
int32_t sessionWinStateGetKeyByRange(SStreamFileState* pFileState, const SSessionKey* key, SSessionKey* curKey, range_cmpr_fn cmpFn);
|
int32_t sessionWinStateGetKeyByRange(SStreamFileState* pFileState, const SSessionKey* key, SSessionKey* curKey,
|
||||||
|
range_cmpr_fn cmpFn);
|
||||||
|
|
||||||
// state window
|
// state window
|
||||||
int32_t getStateWinResultBuff(SStreamFileState* pFileState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
int32_t getStateWinResultBuff(SStreamFileState* pFileState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
||||||
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
|
|
||||||
// count window
|
// count window
|
||||||
int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen);
|
int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal,
|
||||||
|
int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
// function
|
// function
|
||||||
int32_t getSessionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
int32_t getSessionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
||||||
|
int32_t* pWinCode);
|
||||||
int32_t getFunctionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
int32_t getFunctionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,12 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t updateInfoInitP(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
int32_t updateInfoInitP(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen,
|
||||||
int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
SUpdateInfo** ppInfo);
|
||||||
TSKEY updateInfoFillBlockData(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol, int32_t primaryKeyCol);
|
int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen,
|
||||||
|
SUpdateInfo** ppInfo);
|
||||||
|
int32_t updateInfoFillBlockData(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol, int32_t primaryKeyCol,
|
||||||
|
TSKEY* pMaxResTs);
|
||||||
bool updateInfoIsUpdated(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
bool updateInfoIsUpdated(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
||||||
bool updateInfoIsTableInserted(SUpdateInfo* pInfo, int64_t tbUid);
|
bool updateInfoIsTableInserted(SUpdateInfo* pInfo, int64_t tbUid);
|
||||||
void updateInfoDestroy(SUpdateInfo* pInfo);
|
void updateInfoDestroy(SUpdateInfo* pInfo);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ int32_t taosGetErrSize();
|
||||||
#define terrln (*taosGetErrln())
|
#define terrln (*taosGetErrln())
|
||||||
|
|
||||||
#define SET_ERROR_MSG(MSG, ...) \
|
#define SET_ERROR_MSG(MSG, ...) \
|
||||||
snprintf(terrMsg, ERR_MSG_LEN, MSG, ##__VA_ARGS__)
|
(void)snprintf(terrMsg, ERR_MSG_LEN, MSG, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define TSDB_CODE_SUCCESS 0
|
#define TSDB_CODE_SUCCESS 0
|
||||||
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error
|
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error
|
||||||
|
|
@ -556,6 +556,7 @@ int32_t taosGetErrSize();
|
||||||
#define TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER TAOS_DEF_ERROR_CODE(0, 0x061B)
|
#define TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER TAOS_DEF_ERROR_CODE(0, 0x061B)
|
||||||
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061C)
|
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061C)
|
||||||
#define TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE TAOS_DEF_ERROR_CODE(0, 0x061D)
|
#define TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE TAOS_DEF_ERROR_CODE(0, 0x061D)
|
||||||
|
#define TSDB_CODE_TDB_INCONSISTENT_DB_ID TAOS_DEF_ERROR_CODE(0, 0x061E)
|
||||||
|
|
||||||
// query
|
// query
|
||||||
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ void tdListInit(SList *list, int32_t eleSize);
|
||||||
void tdListEmpty(SList *list);
|
void tdListEmpty(SList *list);
|
||||||
SList *tdListNew(int32_t eleSize);
|
SList *tdListNew(int32_t eleSize);
|
||||||
void *tdListFree(SList *list);
|
void *tdListFree(SList *list);
|
||||||
void *tdListFreeP(SList *list, FDelete fp);
|
void tdListFreeP(SList *list, FDelete fp);
|
||||||
void tdListPrependNode(SList *list, SListNode *node);
|
void tdListPrependNode(SList *list, SListNode *node);
|
||||||
void tdListAppendNode(SList *list, SListNode *node);
|
void tdListAppendNode(SList *list, SListNode *node);
|
||||||
int32_t tdListPrepend(SList *list, void *data);
|
int32_t tdListPrepend(SList *list, void *data);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ typedef struct SScalableBf {
|
||||||
|
|
||||||
int32_t tScalableBfInit(uint64_t expectedEntries, double errorRate, SScalableBf** ppSBf);
|
int32_t tScalableBfInit(uint64_t expectedEntries, double errorRate, SScalableBf** ppSBf);
|
||||||
int32_t tScalableBfPutNoCheck(SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
int32_t tScalableBfPutNoCheck(SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
||||||
int32_t tScalableBfPut(SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
int32_t tScalableBfPut(SScalableBf* pSBf, const void* keyBuf, uint32_t len, int32_t* winRes);
|
||||||
int32_t tScalableBfNoContain(const SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
int32_t tScalableBfNoContain(const SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
||||||
void tScalableBfDestroy(SScalableBf* pSBf);
|
void tScalableBfDestroy(SScalableBf* pSBf);
|
||||||
int32_t tScalableBfEncode(const SScalableBf* pSBf, SEncoder* pEncoder);
|
int32_t tScalableBfEncode(const SScalableBf* pSBf, SEncoder* pEncoder);
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define QUERY_CHECK_CODE TSDB_CHECK_CODE
|
||||||
|
|
||||||
#define TSDB_CHECK_NULL(ptr, CODE, LINO, LABEL, ERRNO) \
|
#define TSDB_CHECK_NULL(ptr, CODE, LINO, LABEL, ERRNO) \
|
||||||
if ((ptr) == NULL) { \
|
if ((ptr) == NULL) { \
|
||||||
(CODE) = (ERRNO); \
|
(CODE) = (ERRNO); \
|
||||||
|
|
@ -142,6 +144,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
goto LABEL; \
|
goto LABEL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define QUERY_CHECK_NULL TSDB_CHECK_NULL
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
|
||||||
#define VND_CHECK_CODE(CODE, LINO, LABEL) TSDB_CHECK_CODE(CODE, LINO, LABEL)
|
#define VND_CHECK_CODE(CODE, LINO, LABEL) TSDB_CHECK_CODE(CODE, LINO, LABEL)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ if [ -f ${insmetaPath}/preun.sh ]; then
|
||||||
else
|
else
|
||||||
bin_link_dir="/usr/bin"
|
bin_link_dir="/usr/bin"
|
||||||
lib_link_dir="/usr/lib"
|
lib_link_dir="/usr/lib"
|
||||||
|
lib64_link_dir="/usr/lib64"
|
||||||
inc_link_dir="/usr/include"
|
inc_link_dir="/usr/include"
|
||||||
|
|
||||||
data_link_dir="/usr/local/taos/data"
|
data_link_dir="/usr/local/taos/data"
|
||||||
|
|
@ -40,9 +41,11 @@ else
|
||||||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||||
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||||
[ -f ${lib_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.so || :
|
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||||
|
${csudo}rm -f ${lib_link_dir}/libtaosws.so || :
|
||||||
|
${csudo}rm -f ${lib64_link_dir}/libtaosws.so || :
|
||||||
|
|
||||||
${csudo}rm -f ${log_link_dir} || :
|
${csudo}rm -f ${log_link_dir} || :
|
||||||
${csudo}rm -f ${data_link_dir} || :
|
${csudo}rm -f ${data_link_dir} || :
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,7 @@ if [ $1 -eq 0 ];then
|
||||||
else
|
else
|
||||||
bin_link_dir="/usr/bin"
|
bin_link_dir="/usr/bin"
|
||||||
lib_link_dir="/usr/lib"
|
lib_link_dir="/usr/lib"
|
||||||
|
lib64_link_dir="/usr/lib64"
|
||||||
inc_link_dir="/usr/include"
|
inc_link_dir="/usr/include"
|
||||||
|
|
||||||
data_link_dir="/usr/local/taos/data"
|
data_link_dir="/usr/local/taos/data"
|
||||||
|
|
@ -235,13 +236,18 @@ if [ $1 -eq 0 ];then
|
||||||
${csudo}rm -f ${bin_link_dir}/udfd || :
|
${csudo}rm -f ${bin_link_dir}/udfd || :
|
||||||
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
||||||
${csudo}rm -f ${bin_link_dir}/taoskeeper || :
|
${csudo}rm -f ${bin_link_dir}/taoskeeper || :
|
||||||
|
${csudo}rm -f ${bin_link_dir}/taosdump || :
|
||||||
|
${csudo}rm -f ${bin_link_dir}/taosBenchmark || :
|
||||||
${csudo}rm -f ${cfg_link_dir}/* || :
|
${csudo}rm -f ${cfg_link_dir}/* || :
|
||||||
${csudo}rm -f ${inc_link_dir}/taos.h || :
|
${csudo}rm -f ${inc_link_dir}/taos.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/taosdef.h || :
|
${csudo}rm -f ${inc_link_dir}/taosdef.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
${csudo}rm -f ${inc_link_dir}/taows.h || :
|
||||||
|
${csudo}rm -f ${lib_link_dir}/libtaos.so || :
|
||||||
|
${csudo}rm -f ${lib_link_dir}/libtaosws.so || :
|
||||||
|
${csudo}rm -f ${lib64_link_dir}/libtaosws.so || :
|
||||||
|
|
||||||
${csudo}rm -f ${log_link_dir} || :
|
${csudo}rm -f ${log_link_dir} || :
|
||||||
${csudo}rm -f ${data_link_dir} || :
|
${csudo}rm -f ${data_link_dir} || :
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ RED='\033[0;31m'
|
||||||
GREEN='\033[1;32m'
|
GREEN='\033[1;32m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
|
PREFIX="taos"
|
||||||
|
|
||||||
if [ "$osType" != "Darwin" ]; then
|
if [ "$osType" != "Darwin" ]; then
|
||||||
installDir="/usr/local/taos"
|
installDir="/usr/local/taos"
|
||||||
bin_link_dir="/usr/bin"
|
bin_link_dir="/usr/bin"
|
||||||
|
|
@ -32,7 +34,6 @@ else
|
||||||
inc_link_dir="/usr/local/include"
|
inc_link_dir="/usr/local/include"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PREFIX="taos"
|
|
||||||
serverName="${PREFIX}d"
|
serverName="${PREFIX}d"
|
||||||
clientName="${PREFIX}"
|
clientName="${PREFIX}"
|
||||||
uninstallScript="rm${PREFIX}"
|
uninstallScript="rm${PREFIX}"
|
||||||
|
|
@ -46,8 +47,6 @@ explorerName="${PREFIX}-explorer"
|
||||||
tarbitratorName="tarbitratord"
|
tarbitratorName="tarbitratord"
|
||||||
productName="TDengine"
|
productName="TDengine"
|
||||||
|
|
||||||
installDir="/usr/local/${PREFIX}"
|
|
||||||
|
|
||||||
#install main path
|
#install main path
|
||||||
install_main_dir=${installDir}
|
install_main_dir=${installDir}
|
||||||
data_link_dir=${installDir}/data
|
data_link_dir=${installDir}/data
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,10 @@ function clean_bin() {
|
||||||
function clean_lib() {
|
function clean_lib() {
|
||||||
# Remove link
|
# Remove link
|
||||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||||
|
[ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || :
|
||||||
|
|
||||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||||
|
[ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || :
|
||||||
#${csudo}rm -rf ${v15_java_app_dir} || :
|
#${csudo}rm -rf ${v15_java_app_dir} || :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,6 +79,7 @@ function clean_header() {
|
||||||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||||
|
${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||||
}
|
}
|
||||||
|
|
||||||
function clean_config() {
|
function clean_config() {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include "tsched.h"
|
#include "tsched.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "tversion.h"
|
#include "tversion.h"
|
||||||
|
#include "tcompare.h"
|
||||||
|
|
||||||
#if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
|
#if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
|
||||||
#include "cus_name.h"
|
#include "cus_name.h"
|
||||||
|
|
@ -875,6 +876,12 @@ void taos_init_imp(void) {
|
||||||
}
|
}
|
||||||
rpcInit();
|
rpcInit();
|
||||||
|
|
||||||
|
if (InitRegexCache() != 0) {
|
||||||
|
tscInitRes = -1;
|
||||||
|
tscError("failed to init regex cache");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
||||||
catalogInit(&cfg);
|
catalogInit(&cfg);
|
||||||
|
|
||||||
|
|
@ -885,7 +892,11 @@ void taos_init_imp(void) {
|
||||||
taosSetCoreDump(true);
|
taosSetCoreDump(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
initTaskQueue();
|
if (initTaskQueue() != 0){
|
||||||
|
tscInitRes = -1;
|
||||||
|
tscError("failed to init task queue");
|
||||||
|
return;
|
||||||
|
}
|
||||||
fmFuncMgtInit();
|
fmFuncMgtInit();
|
||||||
nodesInitAllocatorSet();
|
nodesInitAllocatorSet();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2007,7 +2007,8 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int
|
||||||
sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L);
|
sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L);
|
||||||
varDataSetLen(dst, strlen(varDataVal(dst)));
|
varDataSetLen(dst, strlen(varDataVal(dst)));
|
||||||
} else if (tTagIsJson(data)) {
|
} else if (tTagIsJson(data)) {
|
||||||
char* jsonString = parseTagDatatoJson(data);
|
char* jsonString = NULL;
|
||||||
|
parseTagDatatoJson(data, &jsonString);
|
||||||
STR_TO_VARSTR(dst, jsonString);
|
STR_TO_VARSTR(dst, jsonString);
|
||||||
taosMemoryFree(jsonString);
|
taosMemoryFree(jsonString);
|
||||||
} else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
|
} else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
#include "tcompare.h"
|
||||||
|
|
||||||
#define TSC_VAR_NOT_RELEASE 1
|
#define TSC_VAR_NOT_RELEASE 1
|
||||||
#define TSC_VAR_RELEASED 0
|
#define TSC_VAR_RELEASED 0
|
||||||
|
|
@ -78,6 +79,7 @@ void taos_cleanup(void) {
|
||||||
clientConnRefPool = -1;
|
clientConnRefPool = -1;
|
||||||
taosCloseRef(id);
|
taosCloseRef(id);
|
||||||
|
|
||||||
|
DestroyRegexCache();
|
||||||
rpcCleanup();
|
rpcCleanup();
|
||||||
tscDebug("rpc cleanup");
|
tscDebug("rpc cleanup");
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -23,11 +23,11 @@ TARGET_LINK_LIBRARIES(
|
||||||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom geometry
|
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom geometry
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp)
|
#ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp)
|
||||||
TARGET_LINK_LIBRARIES(
|
#TARGET_LINK_LIBRARIES(
|
||||||
clientMonitorTest
|
# clientMonitorTest
|
||||||
PUBLIC os util common transport monitor parser catalog scheduler function gtest taos_static qcom executor
|
# PUBLIC os util common transport monitor parser catalog scheduler function gtest taos_static qcom executor
|
||||||
)
|
#)
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(
|
TARGET_INCLUDE_DIRECTORIES(
|
||||||
clientTest
|
clientTest
|
||||||
|
|
@ -47,11 +47,11 @@ TARGET_INCLUDE_DIRECTORIES(
|
||||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(
|
#TARGET_INCLUDE_DIRECTORIES(
|
||||||
clientMonitorTest
|
# clientMonitorTest
|
||||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
# PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
# PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||||
)
|
#)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
NAME smlTest
|
NAME smlTest
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,11 @@ static void changeDirFromWindowsToLinux(char* from, char* to) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int32_t generateConfigFile(char* confDir) {
|
static int32_t generateConfigFile(char* confDir) {
|
||||||
|
int32_t code = 0;
|
||||||
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
|
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
|
||||||
return -1;
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
@ -92,7 +93,8 @@ static int32_t generateConfigFile(char* confDir) {
|
||||||
if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) {
|
if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) {
|
||||||
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
|
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return -1;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
|
|
@ -129,11 +131,13 @@ void stopRsync() {
|
||||||
taosMsleep(500); // sleep 500 ms to wait for the completion of kill operation.
|
taosMsleep(500); // sleep 500 ms to wait for the completion of kill operation.
|
||||||
}
|
}
|
||||||
|
|
||||||
void startRsync() {
|
int32_t startRsync() {
|
||||||
|
int32_t code = 0;
|
||||||
if (taosMulMkDir(tsCheckpointBackupDir) != 0) {
|
if (taosMulMkDir(tsCheckpointBackupDir) != 0) {
|
||||||
uError("[rsync] build checkpoint backup dir failed, path:%s," ERRNO_ERR_FORMAT, tsCheckpointBackupDir,
|
uError("[rsync] build checkpoint backup dir failed, path:%s," ERRNO_ERR_FORMAT, tsCheckpointBackupDir,
|
||||||
ERRNO_ERR_DATA);
|
ERRNO_ERR_DATA);
|
||||||
return;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeEmptyDir();
|
removeEmptyDir();
|
||||||
|
|
@ -141,9 +145,9 @@ void startRsync() {
|
||||||
char confDir[PATH_MAX] = {0};
|
char confDir[PATH_MAX] = {0};
|
||||||
snprintf(confDir, PATH_MAX, "%srsync.conf", tsCheckpointBackupDir);
|
snprintf(confDir, PATH_MAX, "%srsync.conf", tsCheckpointBackupDir);
|
||||||
|
|
||||||
int32_t code = generateConfigFile(confDir);
|
code = generateConfigFile(confDir);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
return;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
char cmd[PATH_MAX] = {0};
|
char cmd[PATH_MAX] = {0};
|
||||||
|
|
@ -152,9 +156,11 @@ void startRsync() {
|
||||||
code = system(cmd);
|
code = system(cmd);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
uError("[rsync] cmd:%s start server failed, code:%d," ERRNO_ERR_FORMAT, cmd, code, ERRNO_ERR_DATA);
|
uError("[rsync] cmd:%s start server failed, code:%d," ERRNO_ERR_FORMAT, cmd, code, ERRNO_ERR_DATA);
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
} else {
|
} else {
|
||||||
uInfo("[rsync] cmd:%s start server successful", cmd);
|
uInfo("[rsync] cmd:%s start server successful", cmd);
|
||||||
}
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t uploadByRsync(const char* id, const char* path) {
|
int32_t uploadByRsync(const char* id, const char* path) {
|
||||||
|
|
@ -199,6 +205,7 @@ int32_t uploadByRsync(const char* id, const char* path) {
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
uError("[rsync] s-task:%s prepare checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
uError("[rsync] s-task:%s prepare checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
||||||
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
} else {
|
} else {
|
||||||
int64_t el = (taosGetTimestampMs() - st);
|
int64_t el = (taosGetTimestampMs() - st);
|
||||||
uDebug("[rsync] s-task:%s prepare checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
uDebug("[rsync] s-task:%s prepare checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
||||||
|
|
@ -242,6 +249,7 @@ int32_t uploadByRsync(const char* id, const char* path) {
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
uError("[rsync] s-task:%s upload checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
uError("[rsync] s-task:%s upload checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
||||||
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
} else {
|
} else {
|
||||||
int64_t el = (taosGetTimestampMs() - st);
|
int64_t el = (taosGetTimestampMs() - st);
|
||||||
uDebug("[rsync] s-task:%s upload checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
uDebug("[rsync] s-task:%s upload checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
||||||
|
|
@ -283,13 +291,13 @@ int32_t downloadRsync(const char* id, const char* path) {
|
||||||
uError("[rsync] %s download checkpoint data:%s failed, retry after 1sec, times:%d, code:%d," ERRNO_ERR_FORMAT, id,
|
uError("[rsync] %s download checkpoint data:%s failed, retry after 1sec, times:%d, code:%d," ERRNO_ERR_FORMAT, id,
|
||||||
path, times, code, ERRNO_ERR_DATA);
|
path, times, code, ERRNO_ERR_DATA);
|
||||||
taosSsleep(1);
|
taosSsleep(1);
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
} else {
|
} else {
|
||||||
int32_t el = taosGetTimestampMs() - st;
|
int32_t el = taosGetTimestampMs() - st;
|
||||||
uDebug("[rsync] %s download checkpoint data:%s successfully, elapsed time:%dms", id, path, el);
|
uDebug("[rsync] %s download checkpoint data:%s successfully, elapsed time:%dms", id, path, el);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,7 +306,7 @@ int32_t deleteRsync(const char* id) {
|
||||||
int32_t code = taosMkDir(tmp);
|
int32_t code = taosMkDir(tmp);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
uError("[rsync] make tmp dir failed. code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
uError("[rsync] make tmp dir failed. code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
||||||
return -1;
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
char command[PATH_MAX] = {0};
|
char command[PATH_MAX] = {0};
|
||||||
|
|
@ -310,7 +318,7 @@ int32_t deleteRsync(const char* id) {
|
||||||
taosRemoveDir(tmp);
|
taosRemoveDir(tmp);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
uError("[rsync] get failed code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
uError("[rsync] get failed code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
||||||
return -1;
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
uDebug("[rsync] delete data:%s successful", id);
|
uDebug("[rsync] delete data:%s successful", id);
|
||||||
|
|
|
||||||
|
|
@ -1523,9 +1523,9 @@ void blockDataFreeRes(SSDataBlock* pBlock) {
|
||||||
memset(&pBlock->info, 0, sizeof(SDataBlockInfo));
|
memset(&pBlock->info, 0, sizeof(SDataBlockInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* blockDataDestroy(SSDataBlock* pBlock) {
|
void blockDataDestroy(SSDataBlock* pBlock) {
|
||||||
if (pBlock == NULL) {
|
if (pBlock == NULL) {
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pBlock->info.pks[0].type)) {
|
if (IS_VAR_DATA_TYPE(pBlock->info.pks[0].type)) {
|
||||||
|
|
@ -1535,7 +1535,6 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
|
||||||
|
|
||||||
blockDataFreeRes(pBlock);
|
blockDataFreeRes(pBlock);
|
||||||
taosMemoryFreeClear(pBlock);
|
taosMemoryFreeClear(pBlock);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo remove it
|
// todo remove it
|
||||||
|
|
@ -1991,14 +1990,14 @@ static void colDataKeepFirstNRows(SColumnInfoData* pColInfoData, size_t n, size_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n) {
|
void blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n) {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
blockDataEmpty(pBlock);
|
blockDataEmpty(pBlock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlock->info.rows <= n) {
|
if (pBlock->info.rows <= n) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return ;
|
||||||
} else {
|
} else {
|
||||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
|
|
@ -2008,7 +2007,7 @@ int32_t blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n) {
|
||||||
|
|
||||||
pBlock->info.rows = n;
|
pBlock->info.rows = n;
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) {
|
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) {
|
||||||
|
|
@ -2468,19 +2467,18 @@ char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
||||||
|
|
||||||
int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, char* cname) {
|
int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, char* cname) {
|
||||||
if (stbFullName[0] == 0) {
|
if (stbFullName[0] == 0) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* tags = taosArrayInit(0, sizeof(SSmlKv));
|
SArray* tags = taosArrayInit(0, sizeof(SSmlKv));
|
||||||
if (tags == NULL) {
|
if (tags == NULL) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cname == NULL) {
|
if (cname == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
taosArrayDestroy(tags);
|
taosArrayDestroy(tags);
|
||||||
return TSDB_CODE_FAILED;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t type = TSDB_DATA_TYPE_UBIGINT;
|
int8_t type = TSDB_DATA_TYPE_UBIGINT;
|
||||||
|
|
|
||||||
|
|
@ -1369,58 +1369,68 @@ static int32_t taosCheckGlobalCfg() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t cfgInitWrapper(SConfig **pCfg) {
|
||||||
|
if (*pCfg == NULL) {
|
||||||
|
*pCfg = cfgInit();
|
||||||
|
if (*pCfg == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs,
|
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs,
|
||||||
bool tsc) {
|
bool tsc) {
|
||||||
if (tsCfg != NULL) return 0;
|
if (tsCfg != NULL) return 0;
|
||||||
tsCfg = cfgInit();
|
|
||||||
|
int32_t code = cfgInitWrapper(&tsCfg);
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||||
} else {
|
} else {
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddServerCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddServerLogCfg(tsCfg)) != 0) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosAddSystemCfg(tsCfg);
|
code = taosAddSystemCfg(tsCfg);
|
||||||
|
|
||||||
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
|
||||||
uError("failed to load cfg since %s", terrstr());
|
uError("failed to load cfg since %s", tstrerror(code));
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
tsCfg = NULL;
|
tsCfg = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
|
if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) {
|
||||||
uError("failed to load cfg from array since %s", terrstr());
|
uError("failed to load cfg from array since %s", tstrerror(code));
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
tsCfg = NULL;
|
tsCfg = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
if (taosSetClientCfg(tsCfg)) return -1;
|
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||||
} else {
|
} else {
|
||||||
if (taosSetClientCfg(tsCfg)) return -1;
|
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||||
if (taosUpdateServerCfg(tsCfg)) return -1;
|
if ((code = taosUpdateServerCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetServerCfg(tsCfg)) return -1;
|
if ((code = taosSetServerCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetReleaseCfg(tsCfg)) return -1;
|
if ((code = taosSetReleaseCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetTfsCfg(tsCfg) != 0) return -1;
|
if ((code = taosSetTfsCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetS3Cfg(tsCfg) != 0) return -1;
|
if ((code = taosSetS3Cfg(tsCfg)) != 0) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosSetSystemCfg(tsCfg);
|
taosSetSystemCfg(tsCfg);
|
||||||
|
|
||||||
if (taosSetFileHandlesLimit() != 0) return -1;
|
if ((code = taosSetFileHandlesLimit()) != 0) return code;
|
||||||
|
|
||||||
taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32);
|
taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32);
|
||||||
|
|
||||||
cfgDumpCfg(tsCfg, tsc, false);
|
cfgDumpCfg(tsCfg, tsc, false);
|
||||||
|
|
||||||
if (taosCheckGlobalCfg() != 0) {
|
if ((code = taosCheckGlobalCfg()) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -10828,7 +10828,9 @@ int32_t tDecodeMqBatchMetaRsp(SDecoder *pDecoder, SMqBatchMetaRsp *pRsp) {
|
||||||
if (tDecodeI32(pDecoder, &size) < 0) return -1;
|
if (tDecodeI32(pDecoder, &size) < 0) return -1;
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
pRsp->batchMetaReq = taosArrayInit(size, POINTER_BYTES);
|
pRsp->batchMetaReq = taosArrayInit(size, POINTER_BYTES);
|
||||||
|
if (!pRsp->batchMetaReq) return -1;
|
||||||
pRsp->batchMetaLen = taosArrayInit(size, sizeof(int32_t));
|
pRsp->batchMetaLen = taosArrayInit(size, sizeof(int32_t));
|
||||||
|
if (!pRsp->batchMetaLen) return -1;
|
||||||
for (int32_t i = 0; i < size; i++) {
|
for (int32_t i = 0; i < size; i++) {
|
||||||
void *pCreate = NULL;
|
void *pCreate = NULL;
|
||||||
uint64_t len = 0;
|
uint64_t len = 0;
|
||||||
|
|
|
||||||
|
|
@ -167,23 +167,23 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
printf("config file path overflow");
|
printf("config file path overflow");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-a") == 0) {
|
} else if (strcmp(argv[i], "-a") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
printf("apollo url overflow");
|
printf("apollo url overflow");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
|
tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
printf("'-a' requires a parameter\n");
|
printf("'-a' requires a parameter\n");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-s") == 0) {
|
} else if (strcmp(argv[i], "-s") == 0) {
|
||||||
global.dumpSdb = true;
|
global.dumpSdb = true;
|
||||||
|
|
@ -191,12 +191,12 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
printf("env file path overflow");
|
printf("env file path overflow");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(global.envFile, argv[i], PATH_MAX);
|
tstrncpy(global.envFile, argv[i], PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
printf("'-E' requires a parameter\n");
|
printf("'-E' requires a parameter\n");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-k") == 0) {
|
} else if (strcmp(argv[i], "-k") == 0) {
|
||||||
global.generateGrant = true;
|
global.generateGrant = true;
|
||||||
|
|
@ -206,16 +206,16 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
int32_t len = strlen(argv[++i]);
|
int32_t len = strlen(argv[++i]);
|
||||||
if (len < ENCRYPT_KEY_LEN_MIN) {
|
if (len < ENCRYPT_KEY_LEN_MIN) {
|
||||||
printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
|
printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
if (len > ENCRYPT_KEY_LEN) {
|
if (len > ENCRYPT_KEY_LEN) {
|
||||||
printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
|
printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN);
|
tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN);
|
||||||
} else {
|
} else {
|
||||||
printf("'-y' requires a parameter\n");
|
printf("'-y' requires a parameter\n");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-C") == 0) {
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
global.dumpConfig = true;
|
global.dumpConfig = true;
|
||||||
|
|
@ -310,6 +310,7 @@ static void taosCleanupArgs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char const *argv[]) {
|
int main(int argc, char const *argv[]) {
|
||||||
|
int32_t code = 0;
|
||||||
#ifdef TD_JEMALLOC_ENABLED
|
#ifdef TD_JEMALLOC_ENABLED
|
||||||
bool jeBackgroundThread = true;
|
bool jeBackgroundThread = true;
|
||||||
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
||||||
|
|
@ -319,10 +320,10 @@ int main(int argc, char const *argv[]) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmParseArgs(argc, argv) != 0) {
|
if ((code = dmParseArgs(argc, argv)) != 0) {
|
||||||
// printf("failed to start since parse args error\n");
|
// printf("failed to start since parse args error\n");
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
@ -335,6 +336,7 @@ int main(int argc, char const *argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int mainWindows(int argc, char **argv) {
|
int mainWindows(int argc, char **argv) {
|
||||||
|
int32_t code = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (global.generateGrant) {
|
if (global.generateGrant) {
|
||||||
|
|
@ -357,7 +359,7 @@ int mainWindows(int argc, char **argv) {
|
||||||
|
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
if (global.memDbg) {
|
if (global.memDbg) {
|
||||||
int32_t code = taosMemoryDbgInit();
|
code = taosMemoryDbgInit();
|
||||||
if (code) {
|
if (code) {
|
||||||
printf("failed to init memory dbg, error:%s\n", tstrerror(code));
|
printf("failed to init memory dbg, error:%s\n", tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -368,14 +370,16 @@ int mainWindows(int argc, char **argv) {
|
||||||
#endif
|
#endif
|
||||||
if (global.generateCode) {
|
if (global.generateCode) {
|
||||||
bool toLogFile = false;
|
bool toLogFile = false;
|
||||||
if(taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs) != 0){
|
if ((code = taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs)) != 0) {
|
||||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file");
|
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s",
|
||||||
return -1;
|
tstrerror(code));
|
||||||
|
return code;
|
||||||
};
|
};
|
||||||
|
TdFilePtr pFile;
|
||||||
if(dmCheckRunning(tsDataDir) == NULL) {
|
if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
|
||||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first");
|
encryptError("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
|
||||||
return -1;
|
tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
|
|
@ -383,30 +387,30 @@ int mainWindows(int argc, char **argv) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmInitLog() != 0) {
|
if ((code = dmInitLog()) != 0) {
|
||||||
printf("failed to start since init log error\n");
|
printf("failed to start since init log error\n");
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmPrintArgs(argc, argv);
|
dmPrintArgs(argc, argv);
|
||||||
|
|
||||||
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
if ((code = taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0)) != 0) {
|
||||||
dError("failed to start since read config error");
|
dError("failed to start since read config error");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosConvInit() != 0) {
|
if ((code = taosConvInit()) != 0) {
|
||||||
dError("failed to init conv");
|
dError("failed to init conv");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.checkS3) {
|
if (global.checkS3) {
|
||||||
int32_t code = dmCheckS3();
|
code = dmCheckS3();
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
|
|
@ -435,31 +439,32 @@ int mainWindows(int argc, char **argv) {
|
||||||
osSetProcPath(argc, (char **)argv);
|
osSetProcPath(argc, (char **)argv);
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
|
|
||||||
if(dmGetEncryptKey() != 0){
|
if ((code = dmGetEncryptKey()) != 0) {
|
||||||
dError("failed to start since failed to get encrypt key");
|
dError("failed to start since failed to get encrypt key");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (dmInit() != 0) {
|
if ((code = dmInit()) != 0) {
|
||||||
if (terrno == TSDB_CODE_NOT_FOUND) {
|
if (code == TSDB_CODE_NOT_FOUND) {
|
||||||
dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support");
|
dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support");
|
||||||
} else {
|
} else {
|
||||||
dError("failed to init dnode since %s", terrstr());
|
dError("failed to init dnode since %s", tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosConvDestroy();
|
taosConvDestroy();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("start to init service");
|
dInfo("start to init service");
|
||||||
dmSetSignalHandle();
|
dmSetSignalHandle();
|
||||||
tsDndStart = taosGetTimestampMs();
|
tsDndStart = taosGetTimestampMs();
|
||||||
tsDndStartOsUptime = taosGetOsUptime();
|
tsDndStartOsUptime = taosGetOsUptime();
|
||||||
int32_t code = dmRun();
|
|
||||||
|
code = dmRun();
|
||||||
dInfo("shutting down the service");
|
dInfo("shutting down the service");
|
||||||
|
|
||||||
dmCleanup();
|
dmCleanup();
|
||||||
|
|
|
||||||
|
|
@ -207,18 +207,26 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCfgDnodeReq cfgReq = {0};
|
SDCfgDnodeReq cfgReq = {0};
|
||||||
if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
|
if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||||
|
|
||||||
SConfig *pCfg = taosGetCfg();
|
SConfig *pCfg = taosGetCfg();
|
||||||
cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
|
||||||
taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
code = cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
||||||
return 0;
|
if (code != 0) {
|
||||||
|
if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
|
||||||
|
code = 0;
|
||||||
|
} else {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
|
@ -276,32 +284,49 @@ static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
dDebug("server run status req is received");
|
dDebug("server run status req is received");
|
||||||
SServerStatusRsp statusRsp = {0};
|
SServerStatusRsp statusRsp = {0};
|
||||||
dmGetServerRunStatus(pMgmt, &statusRsp);
|
dmGetServerRunStatus(pMgmt, &statusRsp);
|
||||||
|
|
||||||
|
pMsg->info.rsp = NULL;
|
||||||
|
pMsg->info.rspLen = 0;
|
||||||
|
|
||||||
SRpcMsg rspMsg = {.info = pMsg->info};
|
SRpcMsg rspMsg = {.info = pMsg->info};
|
||||||
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
|
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
|
||||||
if (rspLen < 0) {
|
if (rspLen < 0) {
|
||||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
// return rspMsg.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pRsp = rpcMallocCont(rspLen);
|
void *pRsp = rpcMallocCont(rspLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
// return rspMsg.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
||||||
|
if (rspLen < 0) {
|
||||||
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
|
||||||
pMsg->info.rsp = pRsp;
|
pMsg->info.rsp = pRsp;
|
||||||
pMsg->info.rspLen = rspLen;
|
pMsg->info.rspLen = rspLen;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock *dmBuildVariablesBlock(void) {
|
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
|
if (pBlock == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
const SSysTableMeta *pMeta = NULL;
|
const SSysTableMeta *pMeta = NULL;
|
||||||
getInfosDbMeta(&pMeta, &size);
|
getInfosDbMeta(&pMeta, &size);
|
||||||
|
|
||||||
|
|
@ -314,52 +339,74 @@ SSDataBlock *dmBuildVariablesBlock(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
|
pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
|
||||||
|
if (pBlock->pDataBlock == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
||||||
SColumnInfoData colInfoData = {0};
|
SColumnInfoData colInfoData = {0};
|
||||||
colInfoData.info.colId = i + 1;
|
colInfoData.info.colId = i + 1;
|
||||||
colInfoData.info.type = pMeta[index].schema[i].type;
|
colInfoData.info.type = pMeta[index].schema[i].type;
|
||||||
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
||||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->info.hasVarCol = true;
|
pBlock->info.hasVarCol = true;
|
||||||
|
_exit:
|
||||||
return pBlock;
|
if (code != 0) {
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
} else {
|
||||||
|
*ppBlock = pBlock;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
|
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
|
||||||
/*int32_t code = */dumpConfToDataBlock(pBlock, 1);
|
int32_t code = dumpConfToDataBlock(pBlock, 1);
|
||||||
|
if (code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
if (pColInfo == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
int32_t rowsRead = 0;
|
int32_t rowsRead = 0;
|
||||||
|
int32_t code = 0;
|
||||||
SRetrieveTableReq retrieveReq = {0};
|
SRetrieveTableReq retrieveReq = {0};
|
||||||
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
|
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
|
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
|
||||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
|
if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock *pBlock = dmBuildVariablesBlock();
|
SSDataBlock *pBlock = NULL;
|
||||||
|
if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
||||||
|
if (code != 0) {
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||||
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols +
|
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols +
|
||||||
|
|
@ -367,10 +414,10 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
dError("failed to retrieve data since %s", terrstr());
|
dError("failed to retrieve data since %s", tstrerror(code));
|
||||||
blockDataDestroy(pBlock);
|
blockDataDestroy(pBlock);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = pRsp->data;
|
char *pStart = pRsp->data;
|
||||||
|
|
@ -404,7 +451,9 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
SArray *dmGetMsgHandles() {
|
SArray *dmGetMsgHandles() {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
|
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
|
||||||
if (pArray == NULL) goto _OVER;
|
if (pArray == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Requests handled by DNODE
|
// Requests handled by DNODE
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
|
||||||
|
|
@ -18,22 +18,23 @@
|
||||||
#include "libs/function/tudf.h"
|
#include "libs/function/tudf.h"
|
||||||
|
|
||||||
static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
||||||
if (dmStartStatusThread(pMgmt) != 0) {
|
int32_t code = 0;
|
||||||
return -1;
|
if ((code = dmStartStatusThread(pMgmt)) != 0) {
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
#if defined(TD_ENTERPRISE)
|
#if defined(TD_ENTERPRISE)
|
||||||
if (dmStartNotifyThread(pMgmt) != 0) {
|
if ((code = dmStartNotifyThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (dmStartMonitorThread(pMgmt) != 0) {
|
if ((code = dmStartMonitorThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (dmStartAuditThread(pMgmt) != 0) {
|
if ((code = dmStartAuditThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (dmStartCrashReportThread(pMgmt) != 0) {
|
if ((code = dmStartCrashReportThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -50,10 +51,10 @@ static void dmStopMgmt(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
|
@ -70,12 +71,11 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
|
pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
|
||||||
pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
|
pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
|
||||||
|
|
||||||
// pMgmt->pData->ipWhiteVer = 0;
|
if ((code = dmStartWorker(pMgmt)) != 0) {
|
||||||
if (dmStartWorker(pMgmt) != 0) {
|
return code;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (udfStartUdfd(pMgmt->pData->dnodeId) != 0) {
|
if ((code = udfStartUdfd(pMgmt->pData->dnodeId)) != 0) {
|
||||||
dError("failed to start udfd");
|
dError("failed to start udfd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,12 +264,14 @@ static void *dmCrashReportThreadFp(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create status thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create status thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -285,12 +287,14 @@ void dmStopStatusThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create notify thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create notify thread since %s", strerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -308,12 +312,14 @@ void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create monitor thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create monitor thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -322,12 +328,14 @@ int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create audit thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create audit thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -350,6 +358,7 @@ void dmStopAuditThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
if (!tsEnableCrashReport) {
|
if (!tsEnableCrashReport) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -358,8 +367,9 @@ int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create crashReport thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create crashReport thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -431,8 +441,8 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
|
code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
dGError("msg:%p, not processed in mgmt queue", pMsg);
|
dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
||||||
if (code < 0) return 0;
|
if (code < 0) return code;
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "lastIndex", pOption->lastIndex, code);
|
tjsonGetInt32ValueFromDouble(pJson, "lastIndex", pOption->lastIndex, code);
|
||||||
if (code < 0) return 0;
|
if (code < 0) return code;
|
||||||
|
|
||||||
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
||||||
if (replicas == NULL) return 0;
|
if (replicas == NULL) return 0;
|
||||||
|
|
@ -35,17 +35,17 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
||||||
|
|
||||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||||
SJson *replica = tjsonGetArrayItem(replicas, i);
|
SJson *replica = tjsonGetArrayItem(replicas, i);
|
||||||
if (replica == NULL) return -1;
|
if (replica == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
|
||||||
SReplica *pReplica = pOption->replicas + i;
|
SReplica *pReplica = pOption->replicas + i;
|
||||||
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
|
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
|
if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
|
||||||
pOption->numOfReplicas++;
|
pOption->numOfReplicas++;
|
||||||
}
|
}
|
||||||
|
|
@ -63,36 +63,41 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
char *pData = NULL;
|
char *pData = NULL;
|
||||||
SJson *pJson = NULL;
|
SJson *pJson = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
|
||||||
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("mnode file:%s not exist", file);
|
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open mnode file:%s since %s", file, terrstr());
|
dError("failed to open mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pData = taosMemoryMalloc(size + 1);
|
pData = taosMemoryMalloc(size + 1);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,12 +105,11 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
|
|
||||||
pJson = tjsonParse(pData);
|
pJson = tjsonParse(pData);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmDecodeOption(pJson, pOption) < 0) {
|
if ((code = mmDecodeOption(pJson, pOption)) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,37 +122,42 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pOption->deploy && pOption->numOfTotalReplicas > 0) {
|
if (pOption->deploy && pOption->numOfTotalReplicas > 0) {
|
||||||
if (tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex)) < 0) return code;
|
||||||
|
|
||||||
SJson *replicas = tjsonCreateArray();
|
SJson *replicas = tjsonCreateArray();
|
||||||
if (replicas == NULL) return -1;
|
if (replicas == NULL) {
|
||||||
if (tjsonAddItemToObject(pJson, "replicas", replicas) < 0) return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if ((code = tjsonAddItemToObject(pJson, "replicas", replicas)) < 0) return code;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||||
SJson *replica = tjsonCreateObject();
|
SJson *replica = tjsonCreateObject();
|
||||||
if (replica == NULL) return -1;
|
if (replica == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
const SReplica *pReplica = pOption->replicas + i;
|
const SReplica *pReplica = pOption->replicas + i;
|
||||||
if (tjsonAddDoubleToObject(replica, "id", pReplica->id) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(replica, "id", pReplica->id)) < 0) return code;
|
||||||
if (tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn) < 0) return -1;
|
if ((code = tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(replica, "port", pReplica->port) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(replica, "port", pReplica->port)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i]) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i])) < 0) return code;
|
||||||
if (tjsonAddItemToArray(replicas, replica) < 0) return -1;
|
if ((code = tjsonAddItemToArray(replicas, replica)) < 0) return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex)) < 0) return code;
|
||||||
|
|
||||||
if (tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy)) < 0) return code;
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
|
@ -158,28 +167,59 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) {
|
||||||
if (mmEncodeOption(pJson, pOption) != 0) goto _OVER;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAOS_CHECK_GOTO(mmEncodeOption(pJson, pOption), NULL, _OVER);
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosCloseFile(&pFile) < 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
|
||||||
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
|
@ -188,8 +228,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, tstrerror(code), pOption->deploy);
|
||||||
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, terrstr(), pOption->deploy);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,12 @@ void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SDCreateMnodeReq createReq = {0};
|
SDCreateMnodeReq createReq = {0};
|
||||||
if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnodeOpt option = {.deploy = true,
|
SMnodeOpt option = {.deploy = true,
|
||||||
|
|
@ -56,43 +57,45 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option.selfIndex == -1) {
|
if (option.selfIndex == -1) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dGError("failed to create mnode since %s, selfIndex is -1", terrstr());
|
dGError("failed to create mnode since %s, selfIndex is -1", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||||
dGError("failed to write mnode file since %s", terrstr());
|
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SDDropMnodeReq dropReq = {0};
|
SDDropMnodeReq dropReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dGError("failed to drop mnode since %s", terrstr());
|
dGError("failed to drop mnode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnodeOpt option = {.deploy = false};
|
SMnodeOpt option = {.deploy = false};
|
||||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||||
dGError("failed to write mnode file since %s", terrstr());
|
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray *mmGetMsgHandles() {
|
SArray *mmGetMsgHandles() {
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,10 @@ static bool mmDeployRequired(const SMgmtInputOpt *pInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
||||||
|
int32_t code = 0;
|
||||||
SMnodeOpt option = {0};
|
SMnodeOpt option = {0};
|
||||||
if (mmReadFile(pInput->path, &option) != 0) {
|
if ((code = mmReadFile(pInput->path, &option)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!option.deploy) {
|
if (!option.deploy) {
|
||||||
|
|
@ -41,7 +42,7 @@ static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
||||||
dInfo("deploy mnode required. option deploy:%d", option.deploy);
|
dInfo("deploy mnode required. option deploy:%d", option.deploy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
|
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
|
||||||
|
|
@ -73,22 +74,31 @@ static void mmClose(SMnodeMgmt *pMgmt) {
|
||||||
|
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
static int32_t mndOpenWrapper(const char *path, SMnodeOpt *opt, SMnode **pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
|
*pMnode = mndOpen(path, opt);
|
||||||
|
if (*pMnode == NULL) {
|
||||||
|
code = terrno;
|
||||||
|
}
|
||||||
|
///*pMnode = pNode;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
if (walInit() != 0) {
|
int32_t code = 0;
|
||||||
dError("failed to init wal since %s", terrstr());
|
if ((code = walInit()) != 0) {
|
||||||
return -1;
|
dError("failed to init wal since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syncInit() != 0) {
|
if ((code = syncInit()) != 0) {
|
||||||
dError("failed to init sync since %s", terrstr());
|
dError("failed to init sync since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
|
SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
|
@ -100,10 +110,10 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||||
|
|
||||||
SMnodeOpt option = {0};
|
SMnodeOpt option = {0};
|
||||||
if (mmReadFile(pMgmt->path, &option) != 0) {
|
if ((code = mmReadFile(pMgmt->path, &option)) != 0) {
|
||||||
dError("failed to read file since %s", terrstr());
|
dError("failed to read file since %s", tstrerror(code));
|
||||||
mmClose(pMgmt);
|
mmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!option.deploy) {
|
if (!option.deploy) {
|
||||||
|
|
@ -115,18 +125,18 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
mmBuildOptionForOpen(pMgmt, &option);
|
mmBuildOptionForOpen(pMgmt, &option);
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
code = mndOpenWrapper(pMgmt->path, &option, &pMgmt->pMnode);
|
||||||
if (pMgmt->pMnode == NULL) {
|
if (code != 0) {
|
||||||
dError("failed to open mnode since %s", terrstr());
|
dError("failed to open mnode since %s", tstrerror(code));
|
||||||
mmClose(pMgmt);
|
mmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("mnode-impl", "initialized");
|
tmsgReportStartup("mnode-impl", "initialized");
|
||||||
|
|
||||||
if (mmStartWorker(pMgmt) != 0) {
|
if ((code = mmStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to start mnode worker since %s", terrstr());
|
dError("failed to start mnode worker since %s", tstrerror(code));
|
||||||
mmClose(pMgmt);
|
mmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("mnode-worker", "initialized");
|
tmsgReportStartup("mnode-worker", "initialized");
|
||||||
|
|
||||||
|
|
@ -134,9 +144,9 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
option.deploy = true;
|
option.deploy = true;
|
||||||
option.numOfReplicas = 0;
|
option.numOfReplicas = 0;
|
||||||
option.numOfTotalReplicas = 0;
|
option.numOfTotalReplicas = 0;
|
||||||
if (mmWriteFile(pMgmt->path, &option) != 0) {
|
if ((code = mmWriteFile(pMgmt->path, &option)) != 0) {
|
||||||
dError("failed to write mnode file since %s", terrstr());
|
dError("failed to write mnode file since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,13 +170,9 @@ static void mmStop(SMnodeMgmt *pMgmt) {
|
||||||
mndStop(pMgmt->pMnode);
|
mndStop(pMgmt->pMnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) {
|
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) { return mndIsCatchUp(pMgmt->pMnode); }
|
||||||
return mndIsCatchUp(pMgmt->pMnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) {
|
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) { return mndGetRole(pMgmt->pMnode); }
|
||||||
return mndGetRole(pMgmt->pMnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
SMgmtFunc mmGetMgmtFunc() {
|
SMgmtFunc mmGetMgmtFunc() {
|
||||||
SMgmtFunc mgmtFunc = {0};
|
SMgmtFunc mgmtFunc = {0};
|
||||||
|
|
|
||||||
|
|
@ -179,13 +179,15 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
pWorker = &pMgmt->syncRdWorker;
|
pWorker = &pMgmt->syncRdWorker;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWorker == NULL) return -1;
|
if (pWorker == NULL) return code;
|
||||||
|
|
||||||
SRpcMsg *pMsg;
|
SRpcMsg *pMsg;
|
||||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
|
|
||||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
|
|
||||||
|
|
@ -201,6 +203,7 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
SSingleWorkerCfg qCfg = {
|
SSingleWorkerCfg qCfg = {
|
||||||
.min = tsNumOfMnodeQueryThreads,
|
.min = tsNumOfMnodeQueryThreads,
|
||||||
.max = tsNumOfMnodeQueryThreads,
|
.max = tsNumOfMnodeQueryThreads,
|
||||||
|
|
@ -209,9 +212,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &qCfg)) != 0) {
|
||||||
dError("failed to start mnode-query worker since %s", terrstr());
|
dError("failed to start mnode-query worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg fCfg = {
|
SSingleWorkerCfg fCfg = {
|
||||||
|
|
@ -221,9 +224,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg)) != 0) {
|
||||||
dError("failed to start mnode-fetch worker since %s", terrstr());
|
dError("failed to start mnode-fetch worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg rCfg = {
|
SSingleWorkerCfg rCfg = {
|
||||||
|
|
@ -233,9 +236,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->readWorker, &rCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->readWorker, &rCfg)) != 0) {
|
||||||
dError("failed to start mnode-read worker since %s", terrstr());
|
dError("failed to start mnode-read worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg wCfg = {
|
SSingleWorkerCfg wCfg = {
|
||||||
|
|
@ -245,9 +248,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->writeWorker, &wCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->writeWorker, &wCfg)) != 0) {
|
||||||
dError("failed to start mnode-write worker since %s", terrstr());
|
dError("failed to start mnode-write worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg sCfg = {
|
SSingleWorkerCfg sCfg = {
|
||||||
|
|
@ -257,9 +260,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessSyncMsg,
|
.fp = (FItem)mmProcessSyncMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->syncWorker, &sCfg)) != 0) {
|
||||||
dError("failed to start mnode mnode-sync worker since %s", terrstr());
|
dError("failed to start mnode mnode-sync worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg scCfg = {
|
SSingleWorkerCfg scCfg = {
|
||||||
|
|
@ -269,9 +272,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessSyncMsg,
|
.fp = (FItem)mmProcessSyncMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg)) != 0) {
|
||||||
dError("failed to start mnode mnode-sync-rd worker since %s", terrstr());
|
dError("failed to start mnode mnode-sync-rd worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg arbCfg = {
|
SSingleWorkerCfg arbCfg = {
|
||||||
|
|
@ -281,13 +284,13 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg)) != 0) {
|
||||||
dError("failed to start mnode mnode-arb worker since %s", terrstr());
|
dError("failed to start mnode mnode-arb worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("mnode workers are initialized");
|
dDebug("mnode workers are initialized");
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
||||||
|
|
|
||||||
|
|
@ -30,24 +30,25 @@ void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCreateQnodeReq createReq = {0};
|
SDCreateQnodeReq createReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to create qnode since %s", terrstr());
|
dError("failed to create qnode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = true;
|
bool deployed = true;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write qnode file since %s", terrstr());
|
dError("failed to write qnode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
|
|
@ -55,24 +56,25 @@ int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDDropQnodeReq dropReq = {0};
|
SDDropQnodeReq dropReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to drop qnode since %s", terrstr());
|
dError("failed to drop qnode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = false;
|
bool deployed = false;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write qnode file since %s", terrstr());
|
dError("failed to write qnode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,18 @@ static void qmClose(SQnodeMgmt *pMgmt) {
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t qndOpenWrapper(SQnodeOpt *pOption, SQnode **pQnode) {
|
||||||
|
*pQnode = qndOpen(pOption);
|
||||||
|
if (*pQnode == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
int32_t code = 0;
|
||||||
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
|
@ -50,29 +57,30 @@ static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
|
||||||
SQnodeOpt option = {0};
|
SQnodeOpt option = {0};
|
||||||
qmInitOption(pMgmt, &option);
|
qmInitOption(pMgmt, &option);
|
||||||
pMgmt->pQnode = qndOpen(&option);
|
|
||||||
if (pMgmt->pQnode == NULL) {
|
code = qndOpenWrapper(&option, &pMgmt->pQnode);
|
||||||
dError("failed to open qnode since %s", terrstr());
|
if (code != 0) {
|
||||||
|
dError("failed to open qnode since %s", tstrerror(code));
|
||||||
qmClose(pMgmt);
|
qmClose(pMgmt);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("qnode-impl", "initialized");
|
tmsgReportStartup("qnode-impl", "initialized");
|
||||||
|
|
||||||
if (udfcOpen() != 0) {
|
if ((code = udfcOpen()) != 0) {
|
||||||
dError("qnode can not open udfc");
|
dError("qnode can not open udfc");
|
||||||
qmClose(pMgmt);
|
qmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qmStartWorker(pMgmt) != 0) {
|
if ((code = qmStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to start qnode worker since %s", terrstr());
|
dError("failed to start qnode worker since %s", tstrerror(code));
|
||||||
qmClose(pMgmt);
|
qmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("qnode-worker", "initialized");
|
tmsgReportStartup("qnode-worker", "initialized");
|
||||||
|
|
||||||
pOutput->pMgmt = pMgmt;
|
pOutput->pMgmt = pMgmt;
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMgmtFunc qmGetMgmtFunc() {
|
SMgmtFunc qmGetMgmtFunc() {
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
SSingleWorkerCfg queryCfg = {
|
SSingleWorkerCfg queryCfg = {
|
||||||
.min = tsNumOfVnodeQueryThreads,
|
.min = tsNumOfVnodeQueryThreads,
|
||||||
.max = tsNumOfVnodeQueryThreads,
|
.max = tsNumOfVnodeQueryThreads,
|
||||||
|
|
@ -111,9 +113,9 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg)) != 0) {
|
||||||
dError("failed to start qnode-query worker since %s", terrstr());
|
dError("failed to start qnode-query worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg fetchCfg = {
|
SSingleWorkerCfg fetchCfg = {
|
||||||
|
|
@ -124,13 +126,13 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg)) != 0) {
|
||||||
dError("failed to start qnode-fetch worker since %s", terrstr());
|
dError("failed to start qnode-fetch worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("qnode workers are initialized");
|
dDebug("qnode workers are initialized");
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmStopWorker(SQnodeMgmt *pMgmt) {
|
void qmStopWorker(SQnodeMgmt *pMgmt) {
|
||||||
|
|
|
||||||
|
|
@ -19,24 +19,25 @@
|
||||||
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
|
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
|
||||||
|
|
||||||
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCreateSnodeReq createReq = {0};
|
SDCreateSnodeReq createReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to create snode since %s", terrstr());
|
dError("failed to create snode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = true;
|
bool deployed = true;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write snode file since %s", terrstr());
|
dError("failed to write snode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
|
|
@ -44,24 +45,26 @@ int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDDropSnodeReq dropReq = {0};
|
SDDropSnodeReq dropReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to drop snode since %s", terrstr());
|
dError("failed to drop snode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = false;
|
bool deployed = false;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write snode file since %s", terrstr());
|
dError("failed to write snode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,19 @@ static void smClose(SSnodeMgmt *pMgmt) {
|
||||||
|
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
int32_t sndOpenWrapper(const char *path, SSnodeOpt *pOption, SSnode **pNode) {
|
||||||
|
*pNode = sndOpen(path, pOption);
|
||||||
|
if (*pNode == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
int32_t code = 0;
|
||||||
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
|
@ -50,35 +57,34 @@ int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
|
||||||
SSnodeOpt option = {0};
|
SSnodeOpt option = {0};
|
||||||
smInitOption(pMgmt, &option);
|
smInitOption(pMgmt, &option);
|
||||||
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
|
||||||
if (pMgmt->pSnode == NULL) {
|
code = sndOpenWrapper(pMgmt->path, &option, &pMgmt->pSnode);
|
||||||
dError("failed to open snode since %s", terrstr());
|
if (code != 0) {
|
||||||
|
dError("failed to open snode since %s", tstrerror(code));
|
||||||
smClose(pMgmt);
|
smClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmsgReportStartup("snode-impl", "initialized");
|
tmsgReportStartup("snode-impl", "initialized");
|
||||||
|
|
||||||
if (smStartWorker(pMgmt) != 0) {
|
if ((code = smStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to start snode worker since %s", terrstr());
|
dError("failed to start snode worker since %s", tstrerror(code));
|
||||||
smClose(pMgmt);
|
smClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("snode-worker", "initialized");
|
tmsgReportStartup("snode-worker", "initialized");
|
||||||
|
|
||||||
if (udfcOpen() != 0) {
|
if ((code = udfcOpen()) != 0) {
|
||||||
dError("failed to open udfc in snode");
|
dError("failed to open udfc in snode since:%s", tstrerror(code));
|
||||||
smClose(pMgmt);
|
smClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pOutput->pMgmt = pMgmt;
|
pOutput->pMgmt = pMgmt;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) {
|
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) { return sndInit(pMgmt->pSnode); }
|
||||||
return sndInit(pMgmt->pSnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
SMgmtFunc smGetMgmtFunc() {
|
SMgmtFunc smGetMgmtFunc() {
|
||||||
SMgmtFunc mgmtFunc = {0};
|
SMgmtFunc mgmtFunc = {0};
|
||||||
|
|
|
||||||
|
|
@ -68,17 +68,18 @@ static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *));
|
pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *));
|
||||||
if (pMgmt->writeWroker == NULL) {
|
if (pMgmt->writeWroker == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) {
|
for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) {
|
||||||
SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker));
|
SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker));
|
||||||
if (pWriteWorker == NULL) {
|
if (pWriteWorker == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMultiWorkerCfg cfg = {
|
SMultiWorkerCfg cfg = {
|
||||||
|
|
@ -87,13 +88,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||||
.fp = smProcessWriteQueue,
|
.fp = smProcessWriteQueue,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tMultiWorkerInit(pWriteWorker, &cfg) != 0) {
|
if ((code = tMultiWorkerInit(pWriteWorker, &cfg)) != 0) {
|
||||||
dError("failed to start snode-unique worker since %s", terrstr());
|
dError("failed to start snode-unique worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) {
|
if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,13 +106,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) {
|
if ((code = tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) != 0) {
|
||||||
dError("failed to start snode shared-worker since %s", terrstr());
|
dError("failed to start snode shared-worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("snode workers are initialized");
|
dDebug("snode workers are initialized");
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void smStopWorker(SSnodeMgmt *pMgmt) {
|
void smStopWorker(SSnodeMgmt *pMgmt) {
|
||||||
|
|
@ -133,17 +134,18 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
if (code) {
|
if (code) {
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return code = terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSnode *pSnode = pMgmt->pSnode;
|
SSnode *pSnode = pMgmt->pSnode;
|
||||||
if (pSnode == NULL) {
|
if (pSnode == NULL) {
|
||||||
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, terrstr(),
|
code = terrno;
|
||||||
|
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, tstrerror(code),
|
||||||
TMSG_INFO(pMsg->msgType), qtype, pRpc->contLen);
|
TMSG_INFO(pMsg->msgType), qtype, pRpc->contLen);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pRpc->pCont;
|
SMsgHead *pHead = pRpc->pCont;
|
||||||
|
|
@ -154,48 +156,44 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
|
|
||||||
switch (qtype) {
|
switch (qtype) {
|
||||||
case STREAM_QUEUE:
|
case STREAM_QUEUE:
|
||||||
smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
code = smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
||||||
break;
|
break;
|
||||||
case WRITE_QUEUE:
|
case WRITE_QUEUE:
|
||||||
smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
code = smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||||
if (pWorker == NULL) {
|
if (pWorker == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
return taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||||
if (pWorker == NULL) {
|
if (pWorker == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
return taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
SSingleWorker *pWorker = &pMgmt->streamWorker;
|
SSingleWorker *pWorker = &pMgmt->streamWorker;
|
||||||
|
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
return taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
// vmFile.c
|
// vmFile.c
|
||||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
||||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes);
|
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes);
|
||||||
|
|
||||||
// vmWorker.c
|
// vmWorker.c
|
||||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt);
|
int32_t vmStartWorker(SVnodeMgmt *pMgmt);
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
||||||
|
|
||||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) {
|
||||||
taosThreadRwlockRdlock(&pMgmt->lock);
|
taosThreadRwlockRdlock(&pMgmt->lock);
|
||||||
|
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
int32_t size = taosHashGetSize(pMgmt->hash);
|
int32_t size = taosHashGetSize(pMgmt->hash);
|
||||||
SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *));
|
SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *));
|
||||||
|
if (pVnodes == NULL) {
|
||||||
|
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
|
|
@ -42,8 +46,9 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
||||||
|
|
||||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||||
*numOfVnodes = num;
|
*numOfVnodes = num;
|
||||||
|
*ppVnodes = pVnodes;
|
||||||
|
|
||||||
return pVnodes;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
||||||
|
|
@ -52,29 +57,32 @@ static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **
|
||||||
*ppCfgs = NULL;
|
*ppCfgs = NULL;
|
||||||
|
|
||||||
SJson *vnodes = tjsonGetObjectItem(pJson, "vnodes");
|
SJson *vnodes = tjsonGetObjectItem(pJson, "vnodes");
|
||||||
if (vnodes == NULL) return -1;
|
if (vnodes == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
|
||||||
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
||||||
if (vnodesNum > 0) {
|
if (vnodesNum > 0) {
|
||||||
pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg));
|
pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg));
|
||||||
if (pCfgs == NULL) return -1;
|
if (pCfgs == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||||
SJson *vnode = tjsonGetArrayItem(vnodes, i);
|
SJson *vnode = tjsonGetArrayItem(vnodes, i);
|
||||||
if (vnode == NULL) goto _OVER;
|
if (vnode == NULL) {
|
||||||
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
SWrapperCfg *pCfg = &pCfgs[i];
|
SWrapperCfg *pCfg = &pCfgs[i];
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "vgId", pCfg->vgId, code);
|
tjsonGetInt32ValueFromDouble(vnode, "vgId", pCfg->vgId, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "dropped", pCfg->dropped, code);
|
tjsonGetInt32ValueFromDouble(vnode, "dropped", pCfg->dropped, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "diskPrimary", pCfg->diskPrimary, code);
|
tjsonGetInt32ValueFromDouble(vnode, "diskPrimary", pCfg->diskPrimary, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
|
|
||||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
||||||
}
|
}
|
||||||
|
|
@ -98,33 +106,35 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("vnode file:%s not exist", file);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return 0;
|
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||||
|
code = 0;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open vnode file:%s since %s", file, terrstr());
|
dError("failed to open vnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pData = taosMemoryMalloc(size + 1);
|
pData = taosMemoryMalloc(size + 1);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,12 +142,12 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
|
|
||||||
pJson = tjsonParse(pData);
|
pJson = tjsonParse(pData);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vmDecodeVnodeList(pJson, pMgmt, ppCfgs, numOfVnodes) < 0) {
|
if (vmDecodeVnodeList(pJson, pMgmt, ppCfgs, numOfVnodes) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,28 +160,36 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
||||||
|
int32_t code = 0;
|
||||||
SJson *vnodes = tjsonCreateArray();
|
SJson *vnodes = tjsonCreateArray();
|
||||||
if (vnodes == NULL) return -1;
|
if (vnodes == NULL) {
|
||||||
if (tjsonAddItemToObject(pJson, "vnodes", vnodes) < 0) return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if ((code = tjsonAddItemToObject(pJson, "vnodes", vnodes)) < 0) {
|
||||||
|
tjsonDelete(vnodes);
|
||||||
|
return code;
|
||||||
|
};
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
SVnodeObj *pVnode = ppVnodes[i];
|
SVnodeObj *pVnode = ppVnodes[i];
|
||||||
if (pVnode == NULL) continue;
|
if (pVnode == NULL) continue;
|
||||||
|
|
||||||
SJson *vnode = tjsonCreateObject();
|
SJson *vnode = tjsonCreateObject();
|
||||||
if (vnode == NULL) return -1;
|
if (vnode == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
if (tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary)) < 0) return code;
|
||||||
if (pVnode->toVgId && tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId) < 0) return -1;
|
if (pVnode->toVgId) {
|
||||||
if (tjsonAddItemToArray(vnodes, vnode) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId)) < 0) return code;
|
||||||
|
}
|
||||||
|
if ((code = tjsonAddItemToArray(vnodes, vnode)) < 0) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -185,30 +203,60 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
||||||
SVnodeObj **ppVnodes = NULL;
|
SVnodeObj **ppVnodes = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
if (ppVnodes == NULL) goto _OVER;
|
if (code) goto _OVER;
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) {
|
||||||
if (vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes) != 0) goto _OVER;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if ((code = vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes)) != 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
code = taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
||||||
|
|
@ -228,8 +276,7 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, tstrerror(code), numOfVnodes);
|
||||||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, terrstr(), numOfVnodes);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -256,8 +256,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
char path[TSDB_FILENAME_LEN] = {0};
|
char path[TSDB_FILENAME_LEN] = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateVnodeReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
if (tDeserializeSCreateVnodeReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.learnerReplica == 0) {
|
if (req.learnerReplica == 0) {
|
||||||
|
|
@ -298,25 +297,24 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
|
if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
|
||||||
strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
|
strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode", req.vgId, pReplica->id, pReplica->fqdn,
|
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode, reason:%s", req.vgId, pReplica->id,
|
||||||
pReplica->port);
|
pReplica->fqdn, pReplica->port, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.encryptAlgorithm == DND_CA_SM4) {
|
if (req.encryptAlgorithm == DND_CA_SM4) {
|
||||||
if (strlen(tsEncryptKey) == 0) {
|
if (strlen(tsEncryptKey) == 0) {
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||||
dError("vgId:%d, failed to create vnode since encrypt key is empty", req.vgId);
|
dError("vgId:%d, failed to create vnode since encrypt key is empty, reason:%s", req.vgId, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
||||||
|
|
||||||
if (vmTsmaAdjustDays(&vnodeCfg, &req) < 0) {
|
if ((code = vmTsmaAdjustDays(&vnodeCfg, &req)) < 0) {
|
||||||
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, terrstr());
|
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, tstrerror(code));
|
||||||
code = terrno != 0 ? terrno : -1;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -327,8 +325,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
dError("vgId:%d, already exist", req.vgId);
|
dError("vgId:%d, already exist", req.vgId);
|
||||||
tFreeSCreateVnodeReq(&req);
|
tFreeSCreateVnodeReq(&req);
|
||||||
vmReleaseVnode(pMgmt, pVnode);
|
vmReleaseVnode(pMgmt, pVnode);
|
||||||
terrno = TSDB_CODE_VND_ALREADY_EXIST;
|
code = TSDB_CODE_VND_ALREADY_EXIST;
|
||||||
code = terrno;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ int32_t vmGetPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
|
int32_t code = 0;
|
||||||
STfs *pTfs = pMgmt->pTfs;
|
STfs *pTfs = pMgmt->pTfs;
|
||||||
int32_t diskId = 0;
|
int32_t diskId = 0;
|
||||||
if (!pTfs) {
|
if (!pTfs) {
|
||||||
|
|
@ -59,7 +60,12 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
// alloc
|
// alloc
|
||||||
int32_t disks[TFS_MAX_DISKS_PER_TIER] = {0};
|
int32_t disks[TFS_MAX_DISKS_PER_TIER] = {0};
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
for (int32_t v = 0; v < numOfVnodes; v++) {
|
for (int32_t v = 0; v < numOfVnodes; v++) {
|
||||||
SVnodeObj *pVnode = ppVnodes[v];
|
SVnodeObj *pVnode = ppVnodes[v];
|
||||||
disks[pVnode->diskPrimary] += 1;
|
disks[pVnode->diskPrimary] += 1;
|
||||||
|
|
@ -436,6 +442,7 @@ static void *vmCloseVnodeInThread(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
dInfo("start to close all vnodes");
|
dInfo("start to close all vnodes");
|
||||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||||
dInfo("vnodes mgmt worker is stopped");
|
dInfo("vnodes mgmt worker is stopped");
|
||||||
|
|
@ -443,7 +450,12 @@ static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||||
dInfo("vnodes multiple mgmt worker is stopped");
|
dInfo("vnodes multiple mgmt worker is stopped");
|
||||||
|
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get vnode list since %s", tstrerror(code));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t threadNum = tsNumOfCores / 2;
|
int32_t threadNum = tsNumOfCores / 2;
|
||||||
if (threadNum < 1) threadNum = 1;
|
if (threadNum < 1) threadNum = 1;
|
||||||
|
|
@ -513,8 +525,14 @@ static void vmCleanup(SVnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmCheckSyncTimeout(SVnodeMgmt *pMgmt) {
|
static void vmCheckSyncTimeout(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get vnode list since %s", tstrerror(code));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ppVnodes != NULL) {
|
if (ppVnodes != NULL) {
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
|
|
@ -549,12 +567,14 @@ static void *vmThreadFp(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmInitTimer(SVnodeMgmt *pMgmt) {
|
static int32_t vmInitTimer(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create vnode timer thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create vnode timer thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -573,7 +593,10 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
SVnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodeMgmt));
|
SVnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodeMgmt));
|
||||||
if (pMgmt == NULL) goto _OVER;
|
if (pMgmt == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
pMgmt->path = pInput->path;
|
pMgmt->path = pInput->path;
|
||||||
|
|
@ -582,8 +605,18 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
|
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
|
||||||
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
|
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
|
||||||
pMgmt->msgCb.mgmt = pMgmt;
|
pMgmt->msgCb.mgmt = pMgmt;
|
||||||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
|
||||||
taosThreadMutexInit(&pMgmt->createLock, NULL);
|
code = taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||||
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = taosThreadMutexInit(&pMgmt->createLock, NULL);
|
||||||
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pMgmt->pTfs = pInput->pTfs;
|
pMgmt->pTfs = pInput->pTfs;
|
||||||
if (pMgmt->pTfs == NULL) {
|
if (pMgmt->pTfs == NULL) {
|
||||||
|
|
@ -592,38 +625,39 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-tfs", "initialized");
|
tmsgReportStartup("vnode-tfs", "initialized");
|
||||||
|
|
||||||
if (walInit() != 0) {
|
if ((code = walInit()) != 0) {
|
||||||
dError("failed to init wal since %s", terrstr());
|
dError("failed to init wal since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmsgReportStartup("vnode-wal", "initialized");
|
tmsgReportStartup("vnode-wal", "initialized");
|
||||||
|
|
||||||
if (syncInit() != 0) {
|
if ((code = syncInit()) != 0) {
|
||||||
dError("failed to open sync since %s", terrstr());
|
dError("failed to open sync since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-sync", "initialized");
|
tmsgReportStartup("vnode-sync", "initialized");
|
||||||
|
|
||||||
if (vnodeInit(tsNumOfCommitThreads) != 0) {
|
if ((code = vnodeInit(tsNumOfCommitThreads)) != 0) {
|
||||||
dError("failed to init vnode since %s", terrstr());
|
dError("failed to init vnode since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-commit", "initialized");
|
tmsgReportStartup("vnode-commit", "initialized");
|
||||||
|
|
||||||
if (vmStartWorker(pMgmt) != 0) {
|
if ((code = vmStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to init workers since %s", terrstr());
|
dError("failed to init workers since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-worker", "initialized");
|
tmsgReportStartup("vnode-worker", "initialized");
|
||||||
|
|
||||||
if (vmOpenVnodes(pMgmt) != 0) {
|
if ((code = vmOpenVnodes(pMgmt)) != 0) {
|
||||||
dError("failed to open all vnodes since %s", terrstr());
|
dError("failed to open all vnodes since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-vnodes", "initialized");
|
tmsgReportStartup("vnode-vnodes", "initialized");
|
||||||
|
|
||||||
if (udfcOpen() != 0) {
|
if ((code = udfcOpen()) != 0) {
|
||||||
dError("failed to open udfc in vnode");
|
dError("failed to open udfc in vnode since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -633,7 +667,7 @@ _OVER:
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
pOutput->pMgmt = pMgmt;
|
pOutput->pMgmt = pMgmt;
|
||||||
} else {
|
} else {
|
||||||
dError("failed to init vnodes-mgmt since %s", terrstr());
|
dError("failed to init vnodes-mgmt since %s", tstrerror(code));
|
||||||
vmCleanup(pMgmt);
|
vmCleanup(pMgmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -683,18 +717,32 @@ static void *vmRestoreVnodeInThread(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get vnode list since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t threadNum = tsNumOfCores / 2;
|
int32_t threadNum = tsNumOfCores / 2;
|
||||||
if (threadNum < 1) threadNum = 1;
|
if (threadNum < 1) threadNum = 1;
|
||||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||||
|
|
||||||
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
||||||
|
if (threads == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t t = 0; t < threadNum; ++t) {
|
for (int32_t t = 0; t < threadNum; ++t) {
|
||||||
threads[t].threadIndex = t;
|
threads[t].threadIndex = t;
|
||||||
threads[t].pMgmt = pMgmt;
|
threads[t].pMgmt = pMgmt;
|
||||||
threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
|
threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
|
||||||
|
if (threads[t].ppVnodes == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||||
|
|
@ -717,6 +765,7 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) {
|
if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) {
|
||||||
dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno));
|
dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno));
|
||||||
|
ASSERT(errno == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
|
@ -742,6 +791,14 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return vmInitTimer(pMgmt);
|
return vmInitTimer(pMgmt);
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
for (int32_t t = 0; t < threadNum; ++t) {
|
||||||
|
SVnodeThread *pThread = &threads[t];
|
||||||
|
taosMemoryFree(pThread->ppVnodes);
|
||||||
|
}
|
||||||
|
taosMemoryFree(threads);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmStop(SVnodeMgmt *pMgmt) { vmCleanupTimer(pMgmt); }
|
static void vmStop(SVnodeMgmt *pMgmt) { vmCleanupTimer(pMgmt); }
|
||||||
|
|
|
||||||
|
|
@ -200,26 +200,33 @@ static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
|
||||||
|
*pNode = vmAcquireVnode(pMgt, vgId);
|
||||||
|
if (*pNode == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||||
|
int32_t code = 0;
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
if (pMsg->contLen < sizeof(SMsgHead)) {
|
if (pMsg->contLen < sizeof(SMsgHead)) {
|
||||||
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
||||||
pMsg->contLen);
|
pMsg->contLen);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pMsg->pCont;
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pHead->contLen = ntohl(pHead->contLen);
|
pHead->contLen = ntohl(pHead->contLen);
|
||||||
pHead->vgId = ntohl(pHead->vgId);
|
pHead->vgId = ntohl(pHead->vgId);
|
||||||
|
|
||||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
SVnodeObj *pVnode = NULL;
|
||||||
if (pVnode == NULL) {
|
code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
|
||||||
|
if (code != 0) {
|
||||||
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||||
terrno = (terrno != 0) ? terrno : -1;
|
return code;
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (qtype) {
|
switch (qtype) {
|
||||||
|
|
@ -234,49 +241,45 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
||||||
break;
|
break;
|
||||||
case STREAM_QUEUE:
|
case STREAM_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pStreamQ, pMsg);
|
code = taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||||
break;
|
break;
|
||||||
case FETCH_QUEUE:
|
case FETCH_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pFetchQ, pMsg);
|
code = taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||||
break;
|
break;
|
||||||
case WRITE_QUEUE:
|
case WRITE_QUEUE:
|
||||||
if (!vmDataSpaceSufficient(pVnode)) {
|
if (!vmDataSpaceSufficient(pVnode)) {
|
||||||
terrno = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
||||||
code = terrno;
|
|
||||||
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
||||||
terrno = TSDB_CODE_VND_NO_WRITE_AUTH;
|
code = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||||
code = terrno;
|
|
||||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
||||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
code = TSDB_CODE_VND_STOPPED;
|
||||||
code = terrno;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
case SYNC_QUEUE:
|
case SYNC_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
case SYNC_RD_QUEUE:
|
case SYNC_RD_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
case APPLY_QUEUE:
|
case APPLY_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
code = -1;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,15 +302,13 @@ int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMs
|
||||||
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
|
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
|
||||||
taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
||||||
taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
|
|
@ -317,7 +318,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
pRpc->contLen);
|
pRpc->contLen);
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
||||||
|
|
@ -326,7 +327,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
if (code) {
|
if (code) {
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pRpc->pCont;
|
SMsgHead *pHead = pRpc->pCont;
|
||||||
|
|
@ -383,6 +384,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
|
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
|
||||||
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||||
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||||
|
|
@ -398,8 +400,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
|
|
||||||
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
|
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
|
||||||
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
|
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
|
||||||
|
|
@ -428,26 +429,27 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
|
SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
|
||||||
pQPool->name = "vnode-query";
|
pQPool->name = "vnode-query";
|
||||||
pQPool->min = tsNumOfVnodeQueryThreads;
|
pQPool->min = tsNumOfVnodeQueryThreads;
|
||||||
pQPool->max = tsNumOfVnodeQueryThreads;
|
pQPool->max = tsNumOfVnodeQueryThreads;
|
||||||
if (tQueryAutoQWorkerInit(pQPool) != 0) return -1;
|
if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
|
||||||
|
|
||||||
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||||
pStreamPool->name = "vnode-stream";
|
pStreamPool->name = "vnode-stream";
|
||||||
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
||||||
if (tAutoQWorkerInit(pStreamPool) != 0) return -1;
|
if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
|
||||||
|
|
||||||
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||||
pFPool->name = "vnode-fetch";
|
pFPool->name = "vnode-fetch";
|
||||||
pFPool->max = tsNumOfVnodeFetchThreads;
|
pFPool->max = tsNumOfVnodeFetchThreads;
|
||||||
if (tWWorkerInit(pFPool) != 0) return -1;
|
if ((code = tWWorkerInit(pFPool)) != 0) return code;
|
||||||
|
|
||||||
SSingleWorkerCfg mgmtCfg = {
|
SSingleWorkerCfg mgmtCfg = {
|
||||||
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
|
if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
|
||||||
|
|
||||||
int32_t threadNum = 0;
|
int32_t threadNum = 0;
|
||||||
if (tsNumOfCores == 1) {
|
if (tsNumOfCores == 1) {
|
||||||
|
|
@ -461,7 +463,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)vmProcessMultiMgmtQueue,
|
.fp = (FItem)vmProcessMultiMgmtQueue,
|
||||||
.param = pMgmt};
|
.param = pMgmt};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg) != 0) return -1;
|
if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
|
||||||
|
|
||||||
dDebug("vnode workers are initialized");
|
dDebug("vnode workers are initialized");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
||||||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||||
int32_t dmInitVars(SDnode *pDnode);
|
int32_t dmInitVars(SDnode *pDnode);
|
||||||
|
int32_t dmInitVarsWrapper(SDnode *pDnode);
|
||||||
void dmClearVars(SDnode *pDnode);
|
void dmClearVars(SDnode *pDnode);
|
||||||
int32_t dmInitModule(SDnode *pDnode);
|
int32_t dmInitModule(SDnode *pDnode);
|
||||||
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
// clang-format off
|
||||||
#include "dmMgmt.h"
|
#include "dmMgmt.h"
|
||||||
#include "audit.h"
|
#include "audit.h"
|
||||||
#include "libs/function/tudf.h"
|
#include "libs/function/tudf.h"
|
||||||
#include "tgrant.h"
|
#include "tgrant.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#define DM_INIT_AUDIT() \
|
#define DM_INIT_AUDIT() \
|
||||||
do { \
|
do { \
|
||||||
auditCfg.port = tsMonitorPort; \
|
auditCfg.port = tsMonitorPort; \
|
||||||
auditCfg.server = tsMonitorFqdn; \
|
auditCfg.server = tsMonitorFqdn; \
|
||||||
auditCfg.comp = tsMonitorComp; \
|
auditCfg.comp = tsMonitorComp; \
|
||||||
if (auditInit(&auditCfg) != 0) { \
|
if ((code = auditInit(&auditCfg)) != 0) { \
|
||||||
return -1; \
|
return code; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
@ -35,10 +37,11 @@ static SDnode globalDnode = {0};
|
||||||
SDnode *dmInstance() { return &globalDnode; }
|
SDnode *dmInstance() { return &globalDnode; }
|
||||||
|
|
||||||
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||||
dError("env is already initialized");
|
dError("env is already initialized");
|
||||||
terrno = TSDB_CODE_REPEAT_INIT;
|
code = TSDB_CODE_REPEAT_INIT;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -58,18 +61,15 @@ static int32_t dmInitMonitor() {
|
||||||
monCfg.port = tsMonitorPort;
|
monCfg.port = tsMonitorPort;
|
||||||
monCfg.server = tsMonitorFqdn;
|
monCfg.server = tsMonitorFqdn;
|
||||||
monCfg.comp = tsMonitorComp;
|
monCfg.comp = tsMonitorComp;
|
||||||
if (monInit(&monCfg) != 0) {
|
if ((code = monInit(&monCfg)) != 0) {
|
||||||
if (terrno != 0) code = terrno;
|
dError("failed to init monitor since %s", tstrerror(code));
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) terrno = code;
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmInitAudit() {
|
static int32_t dmInitAudit() {
|
||||||
SAuditCfg auditCfg = {0};
|
SAuditCfg auditCfg = {0};
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
DM_INIT_AUDIT();
|
DM_INIT_AUDIT();
|
||||||
|
|
||||||
|
|
@ -88,27 +88,34 @@ static bool dmDataSpaceAvailable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dmCheckDiskSpace() {
|
static int32_t dmCheckDiskSpace() {
|
||||||
osUpdate();
|
osUpdate();
|
||||||
// availability
|
// availability
|
||||||
bool ret = true;
|
int32_t code = 0;
|
||||||
if (!dmDataSpaceAvailable()) {
|
if (!dmDataSpaceAvailable()) {
|
||||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
code = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
return code;
|
||||||
}
|
}
|
||||||
if (!osLogSpaceAvailable()) {
|
if (!osLogSpaceAvailable()) {
|
||||||
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
||||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
code = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
return code;
|
||||||
}
|
}
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
||||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
code = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
return code;
|
||||||
}
|
}
|
||||||
return ret;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tfsOpenWrapper(SDiskCfg *pCfg, int32_t ndisk, STfs **tfs) {
|
||||||
|
*tfs = tfsOpen(pCfg, ndisk);
|
||||||
|
if (*tfs == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t dmDiskInit() {
|
int32_t dmDiskInit() {
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
||||||
|
|
@ -120,10 +127,10 @@ int32_t dmDiskInit() {
|
||||||
numOfDisks = 1;
|
numOfDisks = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDnode->pTfs = tfsOpen(pDisks, numOfDisks);
|
int32_t code = tfsOpenWrapper(pDisks, numOfDisks, &pDnode->pTfs);
|
||||||
if (pDnode->pTfs == NULL) {
|
if (code != 0) {
|
||||||
dError("failed to init tfs since %s", terrstr());
|
dError("failed to init tfs since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -146,6 +153,12 @@ static bool dmCheckDataDirVersion() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t dmCheckDataDirVersionWrapper() {
|
||||||
|
if (!dmCheckDataDirVersion()) {
|
||||||
|
return TSDB_CODE_INVALID_DATA_FMT;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#if defined(USE_S3)
|
#if defined(USE_S3)
|
||||||
|
|
||||||
extern int32_t s3Begin();
|
extern int32_t s3Begin();
|
||||||
|
|
@ -156,17 +169,21 @@ extern int8_t tsS3Enabled;
|
||||||
|
|
||||||
int32_t dmInit() {
|
int32_t dmInit() {
|
||||||
dInfo("start to init dnode env");
|
dInfo("start to init dnode env");
|
||||||
if (dmDiskInit() != 0) return -1;
|
int32_t code = 0;
|
||||||
if (!dmCheckDataDirVersion()) return -1;
|
if ((code = dmDiskInit()) != 0) return code;
|
||||||
if (!dmCheckDiskSpace()) return -1;
|
if (!dmCheckDataDirVersion()) {
|
||||||
if (dmCheckRepeatInit(dmInstance()) != 0) return -1;
|
code = TSDB_CODE_INVALID_DATA_FMT;
|
||||||
if (dmInitSystem() != 0) return -1;
|
return code;
|
||||||
if (dmInitMonitor() != 0) return -1;
|
}
|
||||||
if (dmInitAudit() != 0) return -1;
|
if ((code = dmCheckDiskSpace()) != 0) return code;
|
||||||
if (dmInitDnode(dmInstance()) != 0) return -1;
|
if ((code = dmCheckRepeatInit(dmInstance())) != 0) return code;
|
||||||
if (InitRegexCache() != 0) return -1;
|
if ((code = dmInitSystem()) != 0) return code;
|
||||||
|
if ((code = dmInitMonitor()) != 0) return code;
|
||||||
|
if ((code = dmInitAudit()) != 0) return code;
|
||||||
|
if ((code = dmInitDnode(dmInstance())) != 0) return code;
|
||||||
|
if ((code = InitRegexCache() != 0)) return code;
|
||||||
#if defined(USE_S3)
|
#if defined(USE_S3)
|
||||||
if (s3Begin() != 0) return -1;
|
if ((code = s3Begin()) != 0) return code;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dInfo("dnode env is initialized");
|
dInfo("dnode env is initialized");
|
||||||
|
|
@ -217,6 +234,7 @@ int32_t dmRun() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||||
|
|
@ -224,19 +242,19 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
dmReleaseWrapper(pWrapper);
|
dmReleaseWrapper(pWrapper);
|
||||||
switch (ntype) {
|
switch (ntype) {
|
||||||
case MNODE:
|
case MNODE:
|
||||||
terrno = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
code = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case QNODE:
|
case QNODE:
|
||||||
terrno = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
code = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case SNODE:
|
case SNODE:
|
||||||
terrno = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
code = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
dError("failed to create node since %s", terrstr());
|
dError("failed to create node since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("start to process create-node-request");
|
dInfo("start to process create-node-request");
|
||||||
|
|
@ -244,17 +262,18 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
pWrapper = &pDnode->wrappers[ntype];
|
pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
dmReleaseWrapper(pWrapper);
|
dmReleaseWrapper(pWrapper);
|
||||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
code = terrno;
|
||||||
return -1;
|
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexLock(&pDnode->mutex);
|
taosThreadMutexLock(&pDnode->mutex);
|
||||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||||
|
|
||||||
dInfo("node:%s, start to create", pWrapper->name);
|
dInfo("node:%s, start to create", pWrapper->name);
|
||||||
int32_t code = (*pWrapper->func.createFp)(&input, pMsg);
|
code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to create since %s", pWrapper->name, tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
dInfo("node:%s, has been created", pWrapper->name);
|
dInfo("node:%s, has been created", pWrapper->name);
|
||||||
code = dmOpenNode(pWrapper);
|
code = dmOpenNode(pWrapper);
|
||||||
|
|
@ -270,12 +289,13 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||||
if (pWrapper == NULL) {
|
if (pWrapper == NULL) {
|
||||||
dError("fail to process alter node type since node not exist");
|
dError("fail to process alter node type since node not exist");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
dmReleaseWrapper(pWrapper);
|
dmReleaseWrapper(pWrapper);
|
||||||
|
|
||||||
|
|
@ -288,16 +308,16 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
dInfo("node:%s, checking node role:%d", pWrapper->name, role);
|
dInfo("node:%s, checking node role:%d", pWrapper->name, role);
|
||||||
if (role == TAOS_SYNC_ROLE_VOTER) {
|
if (role == TAOS_SYNC_ROLE_VOTER) {
|
||||||
dError("node:%s, failed to alter node type since node already is role:%d", pWrapper->name, role);
|
dError("node:%s, failed to alter node type since node already is role:%d", pWrapper->name, role);
|
||||||
terrno = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
code = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWrapper->func.isCatchUpFp != NULL) {
|
if (pWrapper->func.isCatchUpFp != NULL) {
|
||||||
dInfo("node:%s, checking node catch up", pWrapper->name);
|
dInfo("node:%s, checking node catch up", pWrapper->name);
|
||||||
if ((*pWrapper->func.isCatchUpFp)(pWrapper->pMgmt) != 1) {
|
if ((*pWrapper->func.isCatchUpFp)(pWrapper->pMgmt) != 1) {
|
||||||
terrno = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
code = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,16 +333,17 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
pWrapper = &pDnode->wrappers[ntype];
|
pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
taosThreadMutexUnlock(&pDnode->mutex);
|
taosThreadMutexUnlock(&pDnode->mutex);
|
||||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
code = terrno;
|
||||||
return -1;
|
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||||
|
|
||||||
dInfo("node:%s, start to create", pWrapper->name);
|
dInfo("node:%s, start to create", pWrapper->name);
|
||||||
int32_t code = (*pWrapper->func.createFp)(&input, pMsg);
|
code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to create since %s", pWrapper->name, tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
dInfo("node:%s, has been created", pWrapper->name);
|
dInfo("node:%s, has been created", pWrapper->name);
|
||||||
code = dmOpenNode(pWrapper);
|
code = dmOpenNode(pWrapper);
|
||||||
|
|
@ -338,35 +359,36 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmProcessDropNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
static int32_t dmProcessDropNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||||
if (pWrapper == NULL) {
|
if (pWrapper == NULL) {
|
||||||
switch (ntype) {
|
switch (ntype) {
|
||||||
case MNODE:
|
case MNODE:
|
||||||
terrno = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
code = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case QNODE:
|
case QNODE:
|
||||||
terrno = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
code = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case SNODE:
|
case SNODE:
|
||||||
terrno = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
code = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
dError("failed to drop node since %s", terrstr());
|
dError("failed to drop node since %s", tstrerror(code));
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexLock(&pDnode->mutex);
|
taosThreadMutexLock(&pDnode->mutex);
|
||||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||||
|
|
||||||
dInfo("node:%s, start to drop", pWrapper->name);
|
dInfo("node:%s, start to drop", pWrapper->name);
|
||||||
int32_t code = (*pWrapper->func.dropFp)(&input, pMsg);
|
code = (*pWrapper->func.dropFp)(&input, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to drop since %s", pWrapper->name, tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
dInfo("node:%s, has been dropped", pWrapper->name);
|
dInfo("node:%s, has been dropped", pWrapper->name);
|
||||||
pWrapper->required = false;
|
pWrapper->required = false;
|
||||||
|
|
@ -414,6 +436,4 @@ void dmReportStartup(const char *pName, const char *pDesc) {
|
||||||
|
|
||||||
int64_t dmGetClusterId() { return globalDnode.data.clusterId; }
|
int64_t dmGetClusterId() { return globalDnode.data.clusterId; }
|
||||||
|
|
||||||
bool dmReadyForTest() {
|
bool dmReadyForTest() { return dmInstance()->data.dnodeVer > 0; }
|
||||||
return dmInstance()->data.dnodeVer > 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char path[PATH_MAX + 100] = {0};
|
char path[PATH_MAX + 100] = {0};
|
||||||
|
|
||||||
if (dmInitVars(pDnode) != 0) {
|
if ((code = dmInitVarsWrapper(pDnode)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,26 +65,31 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
||||||
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
|
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
|
||||||
pWrapper->path = taosStrdup(path);
|
pWrapper->path = taosStrdup(path);
|
||||||
if (pWrapper->path == NULL) {
|
if (pWrapper->path == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pWrapper->required = dmRequireNode(pDnode, pWrapper);
|
pWrapper->required = dmRequireNode(pDnode, pWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDnode->lockfile = dmCheckRunning(tsDataDir);
|
code = dmCheckRunning(tsDataDir, &pDnode->lockfile);
|
||||||
if (pDnode->lockfile == NULL) {
|
if (code != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (dmInitModule(pDnode) != 0) {
|
|
||||||
|
if ((code = dmInitModule(pDnode)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexInit(tsNumOfCommitThreads);
|
indexInit(tsNumOfCommitThreads);
|
||||||
streamMetaInit();
|
streamMetaInit();
|
||||||
|
|
||||||
dmInitStatusClient(pDnode);
|
if ((code = dmInitStatusClient(pDnode)) != 0) {
|
||||||
dmInitSyncClient(pDnode);
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if ((code = dmInitSyncClient(pDnode)) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
dmReportStartup("dnode-transport", "initialized");
|
dmReportStartup("dnode-transport", "initialized");
|
||||||
dDebug("dnode is created, ptr:%p", pDnode);
|
dDebug("dnode is created, ptr:%p", pDnode);
|
||||||
|
|
@ -94,7 +99,7 @@ _OVER:
|
||||||
if (code != 0 && pDnode != NULL) {
|
if (code != 0 && pDnode != NULL) {
|
||||||
dmClearVars(pDnode);
|
dmClearVars(pDnode);
|
||||||
pDnode = NULL;
|
pDnode = NULL;
|
||||||
dError("failed to create dnode since %s", terrstr());
|
dError("failed to create dnode since %s", tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -122,7 +127,15 @@ void dmCleanupDnode(SDnode *pDnode) {
|
||||||
dDebug("dnode is closed, ptr:%p", pDnode);
|
dDebug("dnode is closed, ptr:%p", pDnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t dmInitVarsWrapper(SDnode *pDnode) {
|
||||||
|
int32_t code = dmInitVars(pDnode);
|
||||||
|
if (code == -1) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t dmInitVars(SDnode *pDnode) {
|
int32_t dmInitVars(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnodeData *pData = &pDnode->data;
|
SDnodeData *pData = &pDnode->data;
|
||||||
pData->dnodeId = 0;
|
pData->dnodeId = 0;
|
||||||
pData->clusterId = 0;
|
pData->clusterId = 0;
|
||||||
|
|
@ -138,21 +151,21 @@ int32_t dmInitVars(SDnode *pDnode) {
|
||||||
taosMemoryFreeClear(machineId);
|
taosMemoryFreeClear(machineId);
|
||||||
} else {
|
} else {
|
||||||
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
|
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
|
||||||
terrno = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
code = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
||||||
return -1;
|
return terrno = code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||||
if (pData->dnodeHash == NULL) {
|
if (pData->dnodeHash == NULL) {
|
||||||
dError("failed to init dnode hash");
|
dError("failed to init dnode hash");
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmReadEps(pData) != 0) {
|
if ((code = dmReadEps(pData)) != 0) {
|
||||||
dError("failed to read file since %s", terrstr());
|
dError("failed to read file since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TD_ENTERPRISE)
|
#if defined(TD_ENTERPRISE)
|
||||||
|
|
@ -274,22 +287,21 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
|
||||||
} else {
|
} else {
|
||||||
switch (pWrapper->ntype) {
|
switch (pWrapper->ntype) {
|
||||||
case MNODE:
|
case MNODE:
|
||||||
terrno = TSDB_CODE_MNODE_NOT_FOUND;
|
code = TSDB_CODE_MNODE_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
case QNODE:
|
case QNODE:
|
||||||
terrno = TSDB_CODE_QNODE_NOT_FOUND;
|
code = TSDB_CODE_QNODE_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
case SNODE:
|
case SNODE:
|
||||||
terrno = TSDB_CODE_SNODE_NOT_FOUND;
|
code = TSDB_CODE_SNODE_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
case VNODE:
|
case VNODE:
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
code = TSDB_CODE_VND_STOPPED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
code = -1;
|
|
||||||
}
|
}
|
||||||
taosThreadRwlockUnlock(&pWrapper->lock);
|
taosThreadRwlockUnlock(&pWrapper->lock);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,13 @@
|
||||||
#include "dmMgmt.h"
|
#include "dmMgmt.h"
|
||||||
|
|
||||||
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = pWrapper->pDnode;
|
SDnode *pDnode = pWrapper->pDnode;
|
||||||
|
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
code = terrno;
|
||||||
return -1;
|
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMgmtOutputOpt output = {0};
|
SMgmtOutputOpt output = {0};
|
||||||
|
|
@ -29,9 +31,9 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
|
|
||||||
dInfo("node:%s, start to open", pWrapper->name);
|
dInfo("node:%s, start to open", pWrapper->name);
|
||||||
tmsgSetDefault(&input.msgCb);
|
tmsgSetDefault(&input.msgCb);
|
||||||
if ((*pWrapper->func.openFp)(&input, &output) != 0) {
|
if ((code = (*pWrapper->func.openFp)(&input, &output)) != 0) {
|
||||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to open since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
dInfo("node:%s, has been opened", pWrapper->name);
|
dInfo("node:%s, has been opened", pWrapper->name);
|
||||||
pWrapper->deployed = true;
|
pWrapper->deployed = true;
|
||||||
|
|
@ -45,11 +47,12 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pWrapper->func.startFp != NULL) {
|
if (pWrapper->func.startFp != NULL) {
|
||||||
dDebug("node:%s, start to start", pWrapper->name);
|
dDebug("node:%s, start to start", pWrapper->name);
|
||||||
if ((*pWrapper->func.startFp)(pWrapper->pMgmt) != 0) {
|
if ((code = (*pWrapper->func.startFp)(pWrapper->pMgmt)) != 0) {
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to start since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
dDebug("node:%s, has been started", pWrapper->name);
|
dDebug("node:%s, has been started", pWrapper->name);
|
||||||
}
|
}
|
||||||
|
|
@ -85,12 +88,13 @@ void dmCloseNode(SMgmtWrapper *pWrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmOpenNodes(SDnode *pDnode) {
|
static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (!pWrapper->required) continue;
|
if (!pWrapper->required) continue;
|
||||||
if (dmOpenNode(pWrapper) != 0) {
|
if ((code = dmOpenNode(pWrapper)) != 0) {
|
||||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to open since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,12 +103,13 @@ static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmStartNodes(SDnode *pDnode) {
|
static int32_t dmStartNodes(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (!pWrapper->required) continue;
|
if (!pWrapper->required) continue;
|
||||||
if (dmStartNode(pWrapper) != 0) {
|
if ((code = dmStartNode(pWrapper)) != 0) {
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to start since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,19 +133,20 @@ static void dmCloseNodes(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmRunDnode(SDnode *pDnode) {
|
int32_t dmRunDnode(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
if (dmOpenNodes(pDnode) != 0) {
|
if ((code = dmOpenNodes(pDnode)) != 0) {
|
||||||
dError("failed to open nodes since %s", terrstr());
|
dError("failed to open nodes since %s", tstrerror(code));
|
||||||
dmCloseNodes(pDnode);
|
dmCloseNodes(pDnode);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmStartNodes(pDnode) != 0) {
|
if ((code = dmStartNodes(pDnode)) != 0) {
|
||||||
dError("failed to start nodes since %s", terrstr());
|
dError("failed to start nodes since %s", tstrerror(code));
|
||||||
dmSetStatus(pDnode, DND_STAT_STOPPED);
|
dmSetStatus(pDnode, DND_STAT_STOPPED);
|
||||||
dmStopNodes(pDnode);
|
dmStopNodes(pDnode);
|
||||||
dmCloseNodes(pDnode);
|
dmCloseNodes(pDnode);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pMsg->msgType)];
|
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pMsg->msgType)];
|
||||||
if (msgFp == NULL) {
|
if (msgFp == NULL) {
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
// terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
dGError("msg:%p, not processed since no handler, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
dGError("msg:%p, not processed since no handler, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
return -1;
|
return TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
dGTrace("msg:%p, will be processed by %s", pMsg, pWrapper->name);
|
dGTrace("msg:%p, will be processed by %s", pMsg, pWrapper->name);
|
||||||
|
|
@ -54,14 +54,15 @@ static bool dmFailFastFp(tmsg_t msgType) {
|
||||||
return msgType == TDMT_SYNC_HEARTBEAT || msgType == TDMT_SYNC_APPEND_ENTRIES;
|
return msgType == TDMT_SYNC_HEARTBEAT || msgType == TDMT_SYNC_APPEND_ENTRIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmConvertErrCode(tmsg_t msgType) {
|
static int32_t dmConvertErrCode(tmsg_t msgType, int32_t code) {
|
||||||
if (terrno != TSDB_CODE_APP_IS_STOPPING) {
|
if (code != TSDB_CODE_APP_IS_STOPPING) {
|
||||||
return;
|
return code;
|
||||||
}
|
}
|
||||||
if ((msgType > TDMT_VND_MSG_MIN && msgType < TDMT_VND_MSG_MAX) ||
|
if ((msgType > TDMT_VND_MSG_MIN && msgType < TDMT_VND_MSG_MAX) ||
|
||||||
(msgType > TDMT_SCH_MSG_MIN && msgType < TDMT_SCH_MSG_MAX)) {
|
(msgType > TDMT_SCH_MSG_MIN && msgType < TDMT_SCH_MSG_MAX)) {
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
code = TSDB_CODE_VND_STOPPED;
|
||||||
}
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) {
|
static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) {
|
||||||
SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite));
|
SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite));
|
||||||
|
|
@ -99,14 +100,14 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
|
|
||||||
int32_t svrVer = 0;
|
int32_t svrVer = 0;
|
||||||
taosVersionStrToInt(version, &svrVer);
|
taosVersionStrToInt(version, &svrVer);
|
||||||
if (0 != taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) {
|
if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) {
|
||||||
dError("Version not compatible, cli ver: %d, svr ver: %d", pRpc->info.cliVer, svrVer);
|
dError("Version not compatible, cli ver: %d, svr ver: %d", pRpc->info.cliVer, svrVer);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isForbidden = dmIsForbiddenIp(pRpc->info.forbiddenIp, pRpc->info.conn.user, pRpc->info.conn.clientIp);
|
bool isForbidden = dmIsForbiddenIp(pRpc->info.forbiddenIp, pRpc->info.conn.user, pRpc->info.conn.clientIp);
|
||||||
if (isForbidden) {
|
if (isForbidden) {
|
||||||
terrno = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
|
code = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +120,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
case TDMT_SCH_FETCH_RSP:
|
case TDMT_SCH_FETCH_RSP:
|
||||||
case TDMT_SCH_MERGE_FETCH_RSP:
|
case TDMT_SCH_MERGE_FETCH_RSP:
|
||||||
case TDMT_VND_SUBMIT_RSP:
|
case TDMT_VND_SUBMIT_RSP:
|
||||||
qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
|
code = qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
|
||||||
return;
|
return;
|
||||||
case TDMT_MND_STATUS_RSP:
|
case TDMT_MND_STATUS_RSP:
|
||||||
if (pEpSet != NULL) {
|
if (pEpSet != NULL) {
|
||||||
|
|
@ -148,32 +149,32 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (pDnode->status == DND_STAT_INIT) {
|
if (pDnode->status == DND_STAT_INIT) {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
}
|
}
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRpc->pCont == NULL && (IsReq(pRpc) || pRpc->contLen != 0)) {
|
if (pRpc->pCont == NULL && (IsReq(pRpc) || pRpc->contLen != 0)) {
|
||||||
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
||||||
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
||||||
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
||||||
terrno = pRpc->code;
|
code = pRpc->code;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHandle->defaultNtype == NODE_END) {
|
if (pHandle->defaultNtype == NODE_END) {
|
||||||
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
|
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,12 +198,12 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
|
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmMarkWrapper(pWrapper) != 0) {
|
if ((code = dmMarkWrapper(pWrapper)) != 0) {
|
||||||
pWrapper = NULL;
|
pWrapper = NULL;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
@ -221,12 +222,11 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dmConvertErrCode(pRpc->msgType);
|
code = dmConvertErrCode(pRpc->msgType, code);
|
||||||
if (terrno != 0) code = terrno;
|
|
||||||
if (pMsg) {
|
if (pMsg) {
|
||||||
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr());
|
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, terrstr());
|
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsReq(pRpc)) {
|
if (IsReq(pRpc)) {
|
||||||
|
|
@ -280,17 +280,19 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
pMsg->pCont = NULL;
|
pMsg->pCont = NULL;
|
||||||
if (pDnode->status == DND_STAT_INIT) {
|
if (pDnode->status == DND_STAT_INIT) {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
}
|
}
|
||||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), terrstr(), pMsg->info.handle);
|
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
|
||||||
return -1;
|
pMsg->info.handle);
|
||||||
|
return code;
|
||||||
} else {
|
} else {
|
||||||
pMsg->info.handle = 0;
|
pMsg->info.handle = 0;
|
||||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL);
|
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL);
|
||||||
|
|
@ -298,17 +300,19 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
pMsg->pCont = NULL;
|
pMsg->pCont = NULL;
|
||||||
if (pDnode->status == DND_STAT_INIT) {
|
if (pDnode->status == DND_STAT_INIT) {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
}
|
}
|
||||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), terrstr(), pMsg->info.handle);
|
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
|
||||||
return -1;
|
pMsg->info.handle);
|
||||||
|
return code;
|
||||||
} else {
|
} else {
|
||||||
rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL);
|
rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -426,7 +430,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) {
|
||||||
pTrans->statusRpc = rpcOpen(&rpcInit);
|
pTrans->statusRpc = rpcOpen(&rpcInit);
|
||||||
if (pTrans->statusRpc == NULL) {
|
if (pTrans->statusRpc == NULL) {
|
||||||
dError("failed to init dnode rpc status client");
|
dError("failed to init dnode rpc status client");
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode rpc status client is initialized");
|
dDebug("dnode rpc status client is initialized");
|
||||||
|
|
@ -471,7 +475,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) {
|
||||||
pTrans->syncRpc = rpcOpen(&rpcInit);
|
pTrans->syncRpc = rpcOpen(&rpcInit);
|
||||||
if (pTrans->syncRpc == NULL) {
|
if (pTrans->syncRpc == NULL) {
|
||||||
dError("failed to init dnode rpc sync client");
|
dError("failed to init dnode rpc sync client");
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode rpc sync client is initialized");
|
dDebug("dnode rpc sync client is initialized");
|
||||||
|
|
@ -521,7 +525,7 @@ int32_t dmInitServer(SDnode *pDnode) {
|
||||||
pTrans->serverRpc = rpcOpen(&rpcInit);
|
pTrans->serverRpc = rpcOpen(&rpcInit);
|
||||||
if (pTrans->serverRpc == NULL) {
|
if (pTrans->serverRpc == NULL) {
|
||||||
dError("failed to init dnode rpc server");
|
dError("failed to init dnode rpc server");
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode rpc server is initialized");
|
dDebug("dnode rpc server is initialized");
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,8 @@ void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
|
||||||
// dmFile.c
|
// dmFile.c
|
||||||
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
||||||
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
||||||
TdFilePtr dmCheckRunning(const char *dataDir);
|
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile);
|
||||||
|
//int32_t dmCheckRunningWrapper(const char *dataDir, TdFilePtr *pFile);
|
||||||
|
|
||||||
// dmodule.c
|
// dmodule.c
|
||||||
int32_t dmInitDndInfo(SDnodeData *pData);
|
int32_t dmInitDndInfo(SDnodeData *pData);
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,7 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
if (strlen(tsEncryptAlgorithm) > 0) {
|
if (strlen(tsEncryptAlgorithm) > 0) {
|
||||||
if (strcmp(tsEncryptAlgorithm, "sm4") == 0) {
|
if (strcmp(tsEncryptAlgorithm, "sm4") == 0) {
|
||||||
pData->encryptAlgorigthm = DND_CA_SM4;
|
pData->encryptAlgorigthm = DND_CA_SM4;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||||
dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm);
|
dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
@ -204,26 +203,26 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
@ -232,12 +231,11 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
|
|
||||||
pJson = tjsonParse(content);
|
pJson = tjsonParse(content);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmDecodeEps(pJson, pData) < 0) {
|
if ((code = dmDecodeEps(pJson, pData)) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,7 +249,7 @@ _OVER:
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||||
return code;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
||||||
|
|
@ -261,8 +259,8 @@ _OVER:
|
||||||
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmReadDnodePairs(pData) != 0) {
|
if ((code = dmReadDnodePairs(pData)) != 0) {
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("reset dnode list on startup");
|
dDebug("reset dnode list on startup");
|
||||||
|
|
@ -270,8 +268,8 @@ _OVER:
|
||||||
|
|
||||||
if (pData->oldDnodeEps == NULL && dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
if (pData->oldDnodeEps == NULL && dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
||||||
dError("localEp %s different with %s and need to be reconfigured", tsLocalEp, file);
|
dError("localEp %s different with %s and need to be reconfigured", tsLocalEp, file);
|
||||||
terrno = TSDB_CODE_INVALID_CFG;
|
code = TSDB_CODE_INVALID_CFG;
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -308,7 +306,7 @@ static int32_t dmEncodeEps(SJson *pJson, SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmWriteEps(SDnodeData *pData) {
|
int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
int32_t code = -1;
|
int32_t code = 0;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
SJson *pJson = NULL;
|
SJson *pJson = NULL;
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
|
|
@ -317,26 +315,30 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
// if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
||||||
|
TAOS_CHECK_GOTO(dmInitDndInfo(pData), NULL, _OVER);
|
||||||
|
|
||||||
if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||||
|
|
||||||
pData->engineVer = tsVersion;
|
pData->engineVer = tsVersion;
|
||||||
if (dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
|
||||||
|
TAOS_CHECK_GOTO(dmEncodeEps(pJson, pData), NULL, _OVER); // dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
pData->updateTime = taosGetTimestampMs();
|
pData->updateTime = taosGetTimestampMs();
|
||||||
|
|
@ -349,8 +351,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer);
|
||||||
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, terrstr(), pData->dnodeVer);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -592,28 +593,29 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dDebug("dnode file:%s not exist", file);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||||
code = 0;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -627,12 +629,13 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
|
|
||||||
pJson = tjsonParse(content);
|
pJson = tjsonParse(content);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEpPair));
|
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEpPair));
|
||||||
if (pData->oldDnodeEps == NULL) {
|
if (pData->oldDnodeEps == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
@ -640,7 +643,8 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
if (dmDecodeEpPairs(pJson, pData) < 0) {
|
if (dmDecodeEpPairs(pJson, pData) < 0) {
|
||||||
taosArrayDestroy(pData->oldDnodeEps);
|
taosArrayDestroy(pData->oldDnodeEps);
|
||||||
pData->oldDnodeEps = NULL;
|
pData->oldDnodeEps = NULL;
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
|
||||||
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -653,7 +657,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -680,8 +684,8 @@ _OVER:
|
||||||
pair->oldPort, pair->newFqdn, pair->newPort, pDnodeEp->id);
|
pair->oldPort, pair->newFqdn, pair->newPort, pDnodeEp->id);
|
||||||
taosArrayDestroy(pData->oldDnodeEps);
|
taosArrayDestroy(pData->oldDnodeEps);
|
||||||
pData->oldDnodeEps = NULL;
|
pData->oldDnodeEps = NULL;
|
||||||
terrno = TSDB_CODE_INVALID_CFG;
|
code = TSDB_CODE_INVALID_CFG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dmUtil.h"
|
|
||||||
#include "tjson.h"
|
|
||||||
#include "tgrant.h"
|
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
|
#include "dmUtil.h"
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
|
#include "tgrant.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define MAXLEN 1024
|
#define MAXLEN 1024
|
||||||
#define DM_KEY_INDICATOR "this indicator!"
|
#define DM_KEY_INDICATOR "this indicator!"
|
||||||
|
|
@ -30,7 +30,7 @@ static int32_t dmDecodeFile(SJson *pJson, bool *deployed) {
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
|
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", value, code);
|
tjsonGetInt32ValueFromDouble(pJson, "deployed", value, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
|
|
||||||
*deployed = (value != 0);
|
*deployed = (value != 0);
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -42,7 +42,11 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
char *content = NULL;
|
char *content = NULL;
|
||||||
SJson *pJson = NULL;
|
SJson *pJson = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("file:%s not exist", file);
|
dInfo("file:%s not exist", file);
|
||||||
|
|
@ -52,27 +56,27 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open file:%s since %s", file, terrstr());
|
dError("failed to open file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat file:%s since %s", file, terrstr());
|
dError("failed to fstat file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read file:%s since %s", file, terrstr());
|
dError("failed to read file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,12 +84,12 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
|
|
||||||
pJson = tjsonParse(content);
|
pJson = tjsonParse(content);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmDecodeFile(pJson, pDeployed) < 0) {
|
if (dmDecodeFile(pJson, pDeployed) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,13 +102,13 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
|
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
|
||||||
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return -1;
|
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,26 +119,57 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) {
|
||||||
if (dmEncodeFile(pJson, deployed) != 0) goto _OVER;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((code = dmEncodeFile(pJson, deployed)) != 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosCloseFile(&pFile) != 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
||||||
|
|
@ -145,43 +180,44 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write file:%s since %s, deloyed:%d", realfile, tstrerror(code), deployed);
|
||||||
dError("failed to write file:%s since %s, deloyed:%d", realfile, terrstr(), deployed);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
TdFilePtr dmCheckRunning(const char *dataDir) {
|
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
|
||||||
|
int32_t code = 0;
|
||||||
char filepath[PATH_MAX] = {0};
|
char filepath[PATH_MAX] = {0};
|
||||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
*pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
||||||
if (pFile == NULL) {
|
if (*pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open file:%s since %s", filepath, terrstr());
|
dError("failed to open file:%s since %s", filepath, tstrerror(code));
|
||||||
return NULL;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t retryTimes = 0;
|
int32_t retryTimes = 0;
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
do {
|
do {
|
||||||
ret = taosLockFile(pFile);
|
ret = taosLockFile(*pFile);
|
||||||
if (ret == 0) break;
|
if (ret == 0) break;
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
retryTimes++;
|
retryTimes++;
|
||||||
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, terrstr(), retryTimes);
|
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
|
||||||
} while (retryTimes < 12);
|
} while (retryTimes < 12);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(pFile);
|
||||||
return NULL;
|
*pFile = NULL;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
terrno = 0;
|
|
||||||
dDebug("lock file:%s to prevent repeated starts", filepath);
|
dDebug("lock file:%s to prevent repeated starts", filepath);
|
||||||
return pFile;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
||||||
|
|
@ -193,6 +229,9 @@ static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool
|
||||||
|
|
||||||
int32_t len = ENCRYPTED_LEN(sizeof(DM_KEY_INDICATOR));
|
int32_t len = ENCRYPTED_LEN(sizeof(DM_KEY_INDICATOR));
|
||||||
result = taosMemoryMalloc(len);
|
result = taosMemoryMalloc(len);
|
||||||
|
if (result == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
SCryptOpts opts;
|
SCryptOpts opts;
|
||||||
strncpy(opts.key, key, ENCRYPT_KEY_LEN);
|
strncpy(opts.key, key, ENCRYPT_KEY_LEN);
|
||||||
|
|
@ -203,13 +242,30 @@ static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool
|
||||||
CBC_Encrypt(&opts);
|
CBC_Encrypt(&opts);
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, opts.result, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, opts.result, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosCloseFile(&pFile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
encryptDebug("succeed to write checkCode file:%s", realfile);
|
encryptDebug("succeed to write checkCode file:%s", realfile);
|
||||||
|
|
||||||
|
|
@ -226,14 +282,30 @@ static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptC
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(encryptCode);
|
int32_t len = strlen(encryptCode);
|
||||||
if (taosWriteFile(pFile, encryptCode, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, encryptCode, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosCloseFile(&pFile) != 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
||||||
|
|
||||||
|
|
@ -253,26 +325,26 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to open dnode file:%s since %s", file, terrstr());
|
encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to fstat dnode file:%s since %s", file, terrstr());
|
encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size);
|
content = taosMemoryMalloc(size);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to read dnode file:%s since %s", file, terrstr());
|
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,7 +362,7 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
||||||
CBC_Decrypt(&opts);
|
CBC_Decrypt(&opts);
|
||||||
|
|
||||||
if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
|
if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
|
||||||
terrno = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
|
code = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
|
||||||
encryptError("failed to compare decrypted result");
|
encryptError("failed to compare decrypted result");
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
@ -319,39 +391,57 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
|
||||||
char checkFile[PATH_MAX] = {0};
|
char checkFile[PATH_MAX] = {0};
|
||||||
char realCheckFile[PATH_MAX] = {0};
|
char realCheckFile[PATH_MAX] = {0};
|
||||||
|
|
||||||
snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
|
int32_t nBytes = snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
|
||||||
snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
}
|
||||||
snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
|
||||||
|
|
||||||
terrno = 0;
|
nBytes = snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosMkDir(folder) != 0) {
|
if (taosMkDir(folder) != 0) {
|
||||||
encryptError("failed to create dir:%s since %s", folder, terrstr());
|
code = terrno;
|
||||||
|
encryptError("failed to create dir:%s since %s", folder, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosCheckExistFile(realCheckFile)) {
|
if (taosCheckExistFile(realCheckFile)) {
|
||||||
if(dmCompareEncryptKey(realCheckFile, key, toLogFile) != 0){
|
if ((code = dmCompareEncryptKey(realCheckFile, key, toLogFile)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(machineId = tGetMachineId())) {
|
if (!(machineId = tGetMachineId())) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generateEncryptCode(key, machineId, &encryptCode) != 0) {
|
if ((code = generateEncryptCode(key, machineId, &encryptCode)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile) != 0){
|
if ((code = dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile) != 0){
|
if ((code = dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -362,8 +452,7 @@ _OVER:
|
||||||
taosMemoryFree(encryptCode);
|
taosMemoryFree(encryptCode);
|
||||||
taosMemoryFree(machineId);
|
taosMemoryFree(machineId);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
encryptError("failed to update encrypt key since %s", tstrerror(code));
|
||||||
encryptError("failed to update encrypt key since %s", terrstr());
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#else
|
#else
|
||||||
|
|
@ -380,38 +469,40 @@ static int32_t dmReadEncryptCodeFile(char* file, char** output){
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content[size] = '\0';
|
content[size] = '\0';
|
||||||
|
|
||||||
*output = content;
|
*output = content;
|
||||||
|
content = NULL;
|
||||||
|
|
||||||
dInfo("succeed to read encryptCode file:%s", file);
|
dInfo("succeed to read encryptCode file:%s", file);
|
||||||
code = 0;
|
code = 0;
|
||||||
_OVER:
|
_OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
taosMemoryFree(content);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -425,24 +516,35 @@ int32_t dmGetEncryptKey(){
|
||||||
char *encryptKey = NULL;
|
char *encryptKey = NULL;
|
||||||
char *content = NULL;
|
char *content = NULL;
|
||||||
|
|
||||||
snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
int32_t nBytes = snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP,
|
||||||
snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
DM_ENCRYPT_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(encryptFile)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(checkFile)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
if (!taosCheckExistFile(encryptFile)) {
|
if (!taosCheckExistFile(encryptFile)) {
|
||||||
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||||
dInfo("no exist, checkCode file:%s", encryptFile);
|
dInfo("no exist, checkCode file:%s", encryptFile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmReadEncryptCodeFile(encryptFile, &content) != 0){
|
if ((code = dmReadEncryptCodeFile(encryptFile, &content)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(machineId = tGetMachineId())) {
|
if (!(machineId = tGetMachineId())) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(checkAndGetCryptKey(content, machineId, &encryptKey) != 0){
|
if ((code = checkAndGetCryptKey(content, machineId, &encryptKey)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,12 +552,12 @@ int32_t dmGetEncryptKey(){
|
||||||
taosMemoryFreeClear(content);
|
taosMemoryFreeClear(content);
|
||||||
|
|
||||||
if (encryptKey[0] == '\0') {
|
if (encryptKey[0] == '\0') {
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||||
dError("failed to read key since %s", terrstr());
|
dError("failed to read key since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmCompareEncryptKey(checkFile, encryptKey, true) != 0){
|
if ((code = dmCompareEncryptKey(checkFile, encryptKey, true)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,8 +572,7 @@ _OVER:
|
||||||
if (encryptKey != NULL) taosMemoryFree(encryptKey);
|
if (encryptKey != NULL) taosMemoryFree(encryptKey);
|
||||||
if (machineId != NULL) taosMemoryFree(machineId);
|
if (machineId != NULL) taosMemoryFree(machineId);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to get encrypt key since %s", tstrerror(code));
|
||||||
dError("failed to get encrypt key since %s", terrstr());
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -93,6 +93,7 @@ static int32_t mndFindSuperTableTagId(const SStbObj *pStb, const char *tagName,
|
||||||
}
|
}
|
||||||
|
|
||||||
int mndSetCreateIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
int mndSetCreateIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SVgObj *pVgroup = NULL;
|
SVgObj *pVgroup = NULL;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
|
@ -110,18 +111,20 @@ int mndSetCreateIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStb
|
||||||
if (pReq == NULL) {
|
if (pReq == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
action.pCont = pReq;
|
action.pCont = pReq;
|
||||||
action.contLen = contLen;
|
action.contLen = contLen;
|
||||||
action.msgType = TDMT_VND_CREATE_INDEX;
|
action.msgType = TDMT_VND_CREATE_INDEX;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +167,7 @@ _err:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int mndSetDropIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
int mndSetDropIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SVgObj *pVgroup = NULL;
|
SVgObj *pVgroup = NULL;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
|
@ -182,6 +186,8 @@ int mndSetDropIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbOb
|
||||||
if (pReq == NULL) {
|
if (pReq == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
|
|
@ -189,7 +195,7 @@ int mndSetDropIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbOb
|
||||||
action.pCont = pReq;
|
action.pCont = pReq;
|
||||||
action.contLen = len;
|
action.contLen = len;
|
||||||
action.msgType = TDMT_VND_DROP_INDEX;
|
action.msgType = TDMT_VND_DROP_INDEX;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
|
@ -198,7 +204,7 @@ int mndSetDropIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbOb
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndCleanupIdx(SMnode *pMnode) {
|
void mndCleanupIdx(SMnode *pMnode) {
|
||||||
|
|
@ -332,61 +338,91 @@ SDbObj *mndAcquireDbByIdx(SMnode *pMnode, const char *idxName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetCreateIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
int32_t mndSetCreateIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx);
|
SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendPrepareLog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetCreateIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
int32_t mndSetCreateIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndIdxActionEncode(pIdx);
|
SSdbRaw *pCommitRaw = mndIdxActionEncode(pIdx);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetAlterIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
int32_t mndSetAlterIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx);
|
SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) {
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) {
|
||||||
sdbFreeRaw(pRedoRaw);
|
sdbFreeRaw(pRedoRaw);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1;
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetAlterIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
int32_t mndSetAlterIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndIdxActionEncode(pIdx);
|
SSdbRaw *pCommitRaw = mndIdxActionEncode(pIdx);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
sdbFreeRaw(pCommitRaw);
|
if (terrno != 0) code = terrno;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||||
|
sdbFreeRaw(pCommitRaw);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateIdxVgroupRedoLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) {
|
static int32_t mndSetCreateIdxVgroupRedoLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup);
|
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup);
|
||||||
if (pVgRaw == NULL) return -1;
|
if (pVgRaw == NULL) {
|
||||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pVgRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateIdxVgroupCommitLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) {
|
static int32_t mndSetCreateIdxVgroupCommitLogs(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup);
|
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup);
|
||||||
if (pVgRaw == NULL) return -1;
|
if (pVgRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_READY) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pVgRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pVgRaw, SDB_STATUS_READY));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
|
// static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
|
||||||
|
|
@ -427,10 +463,7 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) {
|
||||||
SDbObj *pDb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
SCreateTagIndexReq createReq = {0};
|
SCreateTagIndexReq createReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateTagIdxReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSCreateTagIdxReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("idx:%s start to create", createReq.idxName);
|
mInfo("idx:%s start to create", createReq.idxName);
|
||||||
// if (mndCheckCreateIdxReq(&createReq) != 0) {
|
// if (mndCheckCreateIdxReq(&createReq) != 0) {
|
||||||
|
|
@ -439,29 +472,30 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
pDb = mndAcquireDbByStb(pMnode, createReq.stbName);
|
pDb = mndAcquireDbByStb(pMnode, createReq.stbName);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
code = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStb = mndAcquireStb(pMnode, createReq.stbName);
|
pStb = mndAcquireStb(pMnode, createReq.stbName);
|
||||||
if (pStb == NULL) {
|
if (pStb == NULL) {
|
||||||
mError("idx:%s, failed to create since stb:%s not exist", createReq.idxName, createReq.stbName);
|
mError("idx:%s, failed to create since stb:%s not exist", createReq.idxName, createReq.stbName);
|
||||||
|
code = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
SSIdx idx = {0};
|
SSIdx idx = {0};
|
||||||
if (mndAcquireGlobalIdx(pMnode, createReq.idxName, SDB_IDX, &idx) == 0) {
|
if ((code = mndAcquireGlobalIdx(pMnode, createReq.idxName, SDB_IDX, &idx)) == 0) {
|
||||||
pIdx = idx.pIdx;
|
pIdx = idx.pIdx;
|
||||||
} else {
|
} else {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (pIdx != NULL) {
|
if (pIdx != NULL) {
|
||||||
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndAddIndex(pMnode, pReq, &createReq, pDb, pStb);
|
code = mndAddIndex(pMnode, pReq, &createReq, pDb, pStb);
|
||||||
if (terrno == TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST || terrno == TSDB_CODE_MND_TAG_NOT_EXIST) {
|
if (terrno == TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST || terrno == TSDB_CODE_MND_TAG_NOT_EXIST) {
|
||||||
|
|
@ -472,32 +506,42 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
mError("stb:%s, failed to create since %s", createReq.idxName, terrstr());
|
mError("stb:%s, failed to create since %s", createReq.idxName, tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
mndReleaseStb(pMnode, pStb);
|
mndReleaseStb(pMnode, pStb);
|
||||||
mndReleaseIdx(pMnode, pIdx);
|
mndReleaseIdx(pMnode, pIdx);
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetDropIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
int32_t mndSetDropIdxPrepareLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx);
|
SSdbRaw *pRedoRaw = mndIdxActionEncode(pIdx);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendPrepareLog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetDropIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
int32_t mndSetDropIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pIdx) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndIdxActionEncode(pIdx);
|
SSdbRaw *pCommitRaw = mndIdxActionEncode(pIdx);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessGetTbIdxReq(SRpcMsg *pReq) {
|
static int32_t mndProcessGetTbIdxReq(SRpcMsg *pReq) {
|
||||||
|
|
@ -592,6 +636,7 @@ static int32_t mndCheckIndexReq(SCreateTagIndexReq *pReq) {
|
||||||
|
|
||||||
static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pOld, SStbObj *pNew, char *tagName,
|
static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pOld, SStbObj *pNew, char *tagName,
|
||||||
int on) {
|
int on) {
|
||||||
|
int32_t code = 0;
|
||||||
taosRLockLatch(&pOld->lock);
|
taosRLockLatch(&pOld->lock);
|
||||||
memcpy(pNew, pOld, sizeof(SStbObj));
|
memcpy(pNew, pOld, sizeof(SStbObj));
|
||||||
taosRUnLockLatch(&pOld->lock);
|
taosRUnLockLatch(&pOld->lock);
|
||||||
|
|
@ -604,28 +649,24 @@ static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStb
|
||||||
int8_t hasIdx = 0;
|
int8_t hasIdx = 0;
|
||||||
int32_t tag = mndFindSuperTableTagId(pOld, tagName, &hasIdx);
|
int32_t tag = mndFindSuperTableTagId(pOld, tagName, &hasIdx);
|
||||||
if (tag < 0) {
|
if (tag < 0) {
|
||||||
terrno = TSDB_CODE_MND_TAG_NOT_EXIST;
|
code = TSDB_CODE_MND_TAG_NOT_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
col_id_t colId = pOld->pTags[tag].colId;
|
col_id_t colId = pOld->pTags[tag].colId;
|
||||||
if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) {
|
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
|
||||||
return -1;
|
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
|
||||||
}
|
|
||||||
if (mndAllocStbSchemas(pOld, pNew) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
SSchema *pTag = pNew->pTags + tag;
|
SSchema *pTag = pNew->pTags + tag;
|
||||||
|
|
||||||
if (on == 1) {
|
if (on == 1) {
|
||||||
if (hasIdx && tag != 0) {
|
if (hasIdx && tag != 0) {
|
||||||
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
} else {
|
} else {
|
||||||
SSCHMEA_SET_IDX_ON(pTag);
|
SSCHMEA_SET_IDX_ON(pTag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (hasIdx == 0) {
|
if (hasIdx == 0) {
|
||||||
terrno = TSDB_CODE_MND_SMA_NOT_EXIST;
|
code = TSDB_CODE_MND_SMA_NOT_EXIST;
|
||||||
} else {
|
} else {
|
||||||
SSCHMEA_SET_IDX_OFF(pTag);
|
SSCHMEA_SET_IDX_OFF(pTag);
|
||||||
pTag->flags = 0;
|
pTag->flags = 0;
|
||||||
|
|
@ -634,11 +675,15 @@ static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStb
|
||||||
pNew->tagVer++;
|
pNew->tagVer++;
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mndStbActionEncode(pNew);
|
SSdbRaw *pCommitRaw = mndStbActionEncode(pNew);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
int32_t mndAddIndexImpl(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
int32_t mndAddIndexImpl(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
||||||
// impl later
|
// impl later
|
||||||
|
|
@ -649,17 +694,17 @@ int32_t mndAddIndexImpl(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pSt
|
||||||
|
|
||||||
// mInfo("trans:%d, used to add index to stb:%s", pTrans->id, pStb->name);
|
// mInfo("trans:%d, used to add index to stb:%s", pTrans->id, pStb->name);
|
||||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
mndTransSetSerial(pTrans);
|
mndTransSetSerial(pTrans);
|
||||||
|
|
||||||
if (mndSetCreateIdxPrepareLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateIdxPrepareLogs(pMnode, pTrans, pIdx), NULL, _OVER);
|
||||||
if (mndSetCreateIdxCommitLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateIdxCommitLogs(pMnode, pTrans, pIdx), NULL, _OVER);
|
||||||
|
|
||||||
if (mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newStb, pIdx->colName, 1) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newStb, pIdx->colName, 1), NULL, _OVER);
|
||||||
if (mndSetCreateIdxRedoActions(pMnode, pTrans, pDb, &newStb, pIdx) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateIdxRedoActions(pMnode, pTrans, pDb, &newStb, pIdx), NULL, _OVER);
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
|
|
@ -671,7 +716,7 @@ _OVER:
|
||||||
taosMemoryFree(newStb.pCmpr);
|
taosMemoryFree(newStb.pCmpr);
|
||||||
}
|
}
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
int8_t mndCheckIndexNameByTagName(SMnode *pMnode, SIdxObj *pIdxObj) {
|
int8_t mndCheckIndexNameByTagName(SMnode *pMnode, SIdxObj *pIdxObj) {
|
||||||
// build index on first tag, and no index name;
|
// build index on first tag, and no index name;
|
||||||
|
|
@ -725,25 +770,23 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re
|
||||||
int8_t hasIdx = 0;
|
int8_t hasIdx = 0;
|
||||||
int32_t tag = mndFindSuperTableTagId(pStb, req->colName, &hasIdx);
|
int32_t tag = mndFindSuperTableTagId(pStb, req->colName, &hasIdx);
|
||||||
if (tag < 0) {
|
if (tag < 0) {
|
||||||
terrno = TSDB_CODE_MND_TAG_NOT_EXIST;
|
code = TSDB_CODE_MND_TAG_NOT_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
int8_t exist = 0;
|
int8_t exist = 0;
|
||||||
if (tag == 0 && hasIdx == 1) {
|
if (tag == 0 && hasIdx == 1) {
|
||||||
exist = mndCheckIndexNameByTagName(pMnode, &idxObj);
|
exist = mndCheckIndexNameByTagName(pMnode, &idxObj);
|
||||||
if (exist) {
|
if (exist) {
|
||||||
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
} else if (hasIdx == 1) {
|
} else if (hasIdx == 1) {
|
||||||
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
col_id_t colId = pStb->pTags[tag].colId;
|
col_id_t colId = pStb->pTags[tag].colId;
|
||||||
if (mndCheckColAndTagModifiable(pMnode, pStb->name, pStb->uid, colId) != 0) {
|
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pStb->name, pStb->uid, colId));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSchema *pTag = pStb->pTags + tag;
|
// SSchema *pTag = pStb->pTags + tag;
|
||||||
// if (IS_IDX_ON(pTag)) {
|
// if (IS_IDX_ON(pTag)) {
|
||||||
|
|
@ -752,7 +795,7 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re
|
||||||
// }
|
// }
|
||||||
code = mndAddIndexImpl(pMnode, pReq, pDb, pStb, &idxObj);
|
code = mndAddIndexImpl(pMnode, pReq, pDb, pStb, &idxObj);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *pIdx) {
|
static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *pIdx) {
|
||||||
|
|
@ -763,22 +806,30 @@ static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *p
|
||||||
SStbObj newObj = {0};
|
SStbObj newObj = {0};
|
||||||
|
|
||||||
pStb = mndAcquireStb(pMnode, pIdx->stb);
|
pStb = mndAcquireStb(pMnode, pIdx->stb);
|
||||||
if (pStb == NULL) goto _OVER;
|
if (pStb == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "drop-index");
|
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "drop-index");
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
mInfo("trans:%d, used to drop idx:%s", pTrans->id, pIdx->name);
|
mInfo("trans:%d, used to drop idx:%s", pTrans->id, pIdx->name);
|
||||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
mndTransSetSerial(pTrans);
|
mndTransSetSerial(pTrans);
|
||||||
if (mndSetDropIdxPrepareLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetDropIdxPrepareLogs(pMnode, pTrans, pIdx), NULL, _OVER);
|
||||||
if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx), NULL, _OVER);
|
||||||
|
|
||||||
if (mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newObj, pIdx->colName, 0) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newObj, pIdx->colName, 0), NULL, _OVER);
|
||||||
if (mndSetDropIdxRedoActions(pMnode, pTrans, pDb, &newObj, pIdx) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetDropIdxRedoActions(pMnode, pTrans, pDb, &newObj, pIdx), NULL, _OVER);
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
|
|
@ -789,7 +840,7 @@ _OVER:
|
||||||
|
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
mndReleaseStb(pMnode, pStb);
|
mndReleaseStb(pMnode, pStb);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) {
|
int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
|
|
@ -798,13 +849,10 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) {
|
||||||
SIdxObj *pIdx = NULL;
|
SIdxObj *pIdx = NULL;
|
||||||
|
|
||||||
SDropTagIndexReq req = {0};
|
SDropTagIndexReq req = {0};
|
||||||
if (tDeserializeSDropTagIdxReq(pReq->pCont, pReq->contLen, &req) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSDropTagIdxReq(pReq->pCont, pReq->contLen, &req), NULL, _OVER);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
mInfo("idx:%s, start to drop", req.name);
|
mInfo("idx:%s, start to drop", req.name);
|
||||||
SSIdx idx = {0};
|
SSIdx idx = {0};
|
||||||
if (mndAcquireGlobalIdx(pMnode, req.name, SDB_IDX, &idx) == 0) {
|
if ((code = mndAcquireGlobalIdx(pMnode, req.name, SDB_IDX, &idx)) == 0) {
|
||||||
pIdx = idx.pIdx;
|
pIdx = idx.pIdx;
|
||||||
} else {
|
} else {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
@ -815,7 +863,7 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) {
|
||||||
code = 0;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_MND_TAG_INDEX_NOT_EXIST;
|
code = TSDB_CODE_MND_TAG_INDEX_NOT_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -823,23 +871,22 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) {
|
||||||
pDb = mndAcquireDbByIdx(pMnode, req.name);
|
pDb = mndAcquireDbByIdx(pMnode, req.name);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropIdx(pMnode, pReq, pDb, pIdx);
|
code = mndDropIdx(pMnode, pReq, pDb, pIdx);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
mError("idx:%s, failed to drop since %s", req.name, terrstr());
|
mError("idx:%s, failed to drop since %s", req.name, tstrerror(code));
|
||||||
}
|
}
|
||||||
mndReleaseIdx(pMnode, pIdx);
|
mndReleaseIdx(pMnode, pIdx);
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
static int32_t mndProcessGetIdxReq(SRpcMsg *pReq) {
|
static int32_t mndProcessGetIdxReq(SRpcMsg *pReq) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
@ -847,6 +894,7 @@ static int32_t mndProcessGetIdxReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
|
||||||
|
|
@ -856,17 +904,17 @@ int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
if (pIdx->stbUid == pStb->uid) {
|
if (pIdx->stbUid == pStb->uid) {
|
||||||
if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) {
|
if ((code = mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx)) != 0) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pIdx);
|
sdbRelease(pSdb, pIdx);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pSdb, pIdx);
|
sdbRelease(pSdb, pIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndGetIdxsByTagName(SMnode *pMnode, SStbObj *pStb, char *tagName, SIdxObj *idx) {
|
int32_t mndGetIdxsByTagName(SMnode *pMnode, SStbObj *pStb, char *tagName, SIdxObj *idx) {
|
||||||
|
|
@ -891,6 +939,7 @@ int32_t mndGetIdxsByTagName(SMnode *pMnode, SStbObj *pStb, char *tagName, SIdxOb
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int32_t mndDropIdxsByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
int32_t mndDropIdxsByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
|
||||||
|
|
@ -900,15 +949,15 @@ int32_t mndDropIdxsByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
if (pIdx->dbUid == pDb->uid) {
|
if (pIdx->dbUid == pDb->uid) {
|
||||||
if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) {
|
if ((code = mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx)) != 0) {
|
||||||
sdbRelease(pSdb, pIdx);
|
sdbRelease(pSdb, pIdx);
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pSdb, pIdx);
|
sdbRelease(pSdb, pIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) {
|
||||||
SSmaObj *pSma = mndGetIdx(pMnode, name, SDB_SMA);
|
SSmaObj *pSma = mndGetIdx(pMnode, name, SDB_SMA);
|
||||||
SIdxObj *pIdx = mndGetIdx(pMnode, name, SDB_IDX);
|
SIdxObj *pIdx = mndGetIdx(pMnode, name, SDB_IDX);
|
||||||
|
|
||||||
terrno = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if (pSma == NULL && pIdx == NULL) return 0;
|
if (pSma == NULL && pIdx == NULL) return 0;
|
||||||
|
|
||||||
|
|
@ -40,8 +40,8 @@ int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) {
|
||||||
idx->pIdx = pSma;
|
idx->pIdx = pSma;
|
||||||
} else {
|
} else {
|
||||||
mndReleaseSma(pMnode, pSma);
|
mndReleaseSma(pMnode, pSma);
|
||||||
terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST;
|
code = TSDB_CODE_MND_SMA_ALREADY_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type == SDB_IDX) {
|
if (type == SDB_IDX) {
|
||||||
|
|
@ -49,9 +49,9 @@ int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) {
|
||||||
idx->pIdx = pIdx;
|
idx->pIdx = pIdx;
|
||||||
} else {
|
} else {
|
||||||
mndReleaseIdx(pMnode, pIdx);
|
mndReleaseIdx(pMnode, pIdx);
|
||||||
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,11 @@
|
||||||
#include "systable.h"
|
#include "systable.h"
|
||||||
|
|
||||||
static int32_t mndInitInfosTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
|
static int32_t mndInitInfosTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
|
||||||
|
int32_t code = 0;
|
||||||
SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
|
SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
|
||||||
if (NULL == schema) {
|
if (NULL == schema) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < colNum; ++i) {
|
for (int32_t i = 0; i < colNum; ++i) {
|
||||||
|
|
@ -35,10 +36,11 @@ static int32_t mndInitInfosTableSchema(const SSysDbTableSchema *pSrc, int32_t co
|
||||||
}
|
}
|
||||||
|
|
||||||
*pDst = schema;
|
*pDst = schema;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndInsInitMeta(SHashObj *hash) {
|
static int32_t mndInsInitMeta(SHashObj *hash) {
|
||||||
|
int32_t code = 0;
|
||||||
STableMetaRsp meta = {0};
|
STableMetaRsp meta = {0};
|
||||||
|
|
||||||
tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName));
|
tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName));
|
||||||
|
|
@ -55,24 +57,23 @@ static int32_t mndInsInitMeta(SHashObj *hash) {
|
||||||
meta.numOfColumns = pInfosTableMeta[i].colNum;
|
meta.numOfColumns = pInfosTableMeta[i].colNum;
|
||||||
meta.sysInfo = pInfosTableMeta[i].sysInfo;
|
meta.sysInfo = pInfosTableMeta[i].sysInfo;
|
||||||
|
|
||||||
if (mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas)) {
|
TAOS_CHECK_RETURN(mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
|
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, bool sysinfo,
|
int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, bool sysinfo,
|
||||||
STableMetaRsp *pRsp) {
|
STableMetaRsp *pRsp) {
|
||||||
|
int32_t code = 0;
|
||||||
if (NULL == pMnode->infosMeta) {
|
if (NULL == pMnode->infosMeta) {
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMetaRsp *pMeta = NULL;
|
STableMetaRsp *pMeta = NULL;
|
||||||
|
|
@ -84,40 +85,41 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *
|
||||||
|
|
||||||
if (NULL == pMeta) {
|
if (NULL == pMeta) {
|
||||||
mError("invalid information schema table name:%s", tbName);
|
mError("invalid information schema table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sysinfo && pMeta->sysInfo) {
|
if (!sysinfo && pMeta->sysInfo) {
|
||||||
mError("no permission to get schema of table name:%s", tbName);
|
mError("no permission to get schema of table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_PAR_PERMISSION_DENIED;
|
code = TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pRsp = *pMeta;
|
*pRsp = *pMeta;
|
||||||
|
|
||||||
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
||||||
if (pRsp->pSchemas == NULL) {
|
if (pRsp->pSchemas == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pRsp->pSchemas = NULL;
|
pRsp->pSchemas = NULL;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
|
int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
|
||||||
|
int32_t code = 0;
|
||||||
if (NULL == pMnode->infosMeta) {
|
if (NULL == pMnode->infosMeta) {
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
|
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
|
||||||
if (NULL == pMeta) {
|
if (NULL == pMeta) {
|
||||||
mError("invalid information schema table name:%s", tbName);
|
mError("invalid information schema table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pRsp->tbName, pMeta->tbName);
|
strcpy(pRsp->tbName, pMeta->tbName);
|
||||||
|
|
@ -129,22 +131,21 @@ int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbN
|
||||||
|
|
||||||
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
||||||
if (pRsp->pSchemas == NULL) {
|
if (pRsp->pSchemas == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pRsp->pSchemas = NULL;
|
pRsp->pSchemas = NULL;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
||||||
|
|
||||||
pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
|
pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndInitInfos(SMnode *pMnode) {
|
int32_t mndInitInfos(SMnode *pMnode) {
|
||||||
pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
|
pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
|
||||||
if (pMnode->infosMeta == NULL) {
|
if (pMnode->infosMeta == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mndInsInitMeta(pMnode->infosMeta);
|
return mndInsInitMeta(pMnode->infosMeta);
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,7 @@ static inline int32_t mndAcquireRpc(SMnode *pMnode) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
taosThreadRwlockRdlock(&pMnode->lock);
|
taosThreadRwlockRdlock(&pMnode->lock);
|
||||||
if (pMnode->stopped) {
|
if (pMnode->stopped) {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
code = -1;
|
|
||||||
} else if (!mndIsLeader(pMnode)) {
|
} else if (!mndIsLeader(pMnode)) {
|
||||||
code = -1;
|
code = -1;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -63,7 +62,7 @@ static inline int32_t mndAcquireRpc(SMnode *pMnode) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
taosThreadRwlockUnlock(&pMnode->lock);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void mndReleaseRpc(SMnode *pMnode) {
|
static inline void mndReleaseRpc(SMnode *pMnode) {
|
||||||
|
|
@ -78,6 +77,7 @@ static inline void mndReleaseRpc(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *mndBuildTimerMsg(int32_t *pContLen) {
|
static void *mndBuildTimerMsg(int32_t *pContLen) {
|
||||||
|
terrno = 0;
|
||||||
SMTimerReq timerReq = {0};
|
SMTimerReq timerReq = {0};
|
||||||
|
|
||||||
int32_t contLen = tSerializeSMTimerMsg(NULL, 0, &timerReq);
|
int32_t contLen = tSerializeSMTimerMsg(NULL, 0, &timerReq);
|
||||||
|
|
@ -329,6 +329,7 @@ static int32_t minCronTime() {
|
||||||
return min <= 1 ? 2 : min;
|
return min <= 1 ? 2 : min;
|
||||||
}
|
}
|
||||||
void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
|
void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
|
||||||
|
int32_t code = 0;
|
||||||
if (sec % tsTtlPushIntervalSec == 0) {
|
if (sec % tsTtlPushIntervalSec == 0) {
|
||||||
mndPullupTtl(pMnode);
|
mndPullupTtl(pMnode);
|
||||||
}
|
}
|
||||||
|
|
@ -378,14 +379,14 @@ void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sec % (tsArbHeartBeatIntervalSec) == 0) {
|
if (sec % (tsArbHeartBeatIntervalSec) == 0) {
|
||||||
if (mndPullupArbHeartbeat(pMnode) != 0) {
|
if ((code = mndPullupArbHeartbeat(pMnode)) != 0) {
|
||||||
mError("failed to pullup arb heartbeat, since:%s", terrstr());
|
mError("failed to pullup arb heartbeat, since:%s", tstrerror(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sec % (tsArbCheckSyncIntervalSec) == 0) {
|
if (sec % (tsArbCheckSyncIntervalSec) == 0) {
|
||||||
if (mndPullupArbCheckSync(pMnode) != 0) {
|
if ((code = mndPullupArbCheckSync(pMnode)) != 0) {
|
||||||
mError("failed to pullup arb check sync, since:%s", terrstr());
|
mError("failed to pullup arb check sync, since:%s", tstrerror(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -426,17 +427,18 @@ static void *mndThreadFp(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndInitTimer(SMnode *pMnode) {
|
static int32_t mndInitTimer(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMnode->thread, &thAttr, mndThreadFp, pMnode) != 0) {
|
if ((code = taosThreadCreate(&pMnode->thread, &thAttr, mndThreadFp, pMnode)) != 0) {
|
||||||
mError("failed to create timer thread since %s", strerror(errno));
|
mError("failed to create timer thread since %s", strerror(errno));
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
tmsgReportStartup("mnode-timer", "initialized");
|
tmsgReportStartup("mnode-timer", "initialized");
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndCleanupTimer(SMnode *pMnode) {
|
static void mndCleanupTimer(SMnode *pMnode) {
|
||||||
|
|
@ -447,24 +449,26 @@ static void mndCleanupTimer(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
||||||
|
int32_t code = 0;
|
||||||
pMnode->path = taosStrdup(path);
|
pMnode->path = taosStrdup(path);
|
||||||
if (pMnode->path == NULL) {
|
if (pMnode->path == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosMkDir(pMnode->path) != 0) {
|
if (taosMkDir(pMnode->path) != 0) {
|
||||||
return -1;
|
code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndInitWal(SMnode *pMnode) {
|
static int32_t mndInitWal(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
char path[PATH_MAX + 20] = {0};
|
char path[PATH_MAX + 20] = {0};
|
||||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||||
SWalCfg cfg = {
|
SWalCfg cfg = {.vgId = 1,
|
||||||
.vgId = 1,
|
|
||||||
.fsyncPeriod = 0,
|
.fsyncPeriod = 0,
|
||||||
.rollPeriod = -1,
|
.rollPeriod = -1,
|
||||||
.segSize = -1,
|
.segSize = -1,
|
||||||
|
|
@ -472,15 +476,14 @@ static int32_t mndInitWal(SMnode *pMnode) {
|
||||||
.retentionSize = 0,
|
.retentionSize = 0,
|
||||||
.level = TAOS_WAL_FSYNC,
|
.level = TAOS_WAL_FSYNC,
|
||||||
.encryptAlgorithm = 0,
|
.encryptAlgorithm = 0,
|
||||||
.encryptKey = {0}
|
.encryptKey = {0}};
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(TD_ENTERPRISE)
|
#if defined(TD_ENTERPRISE)
|
||||||
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_MNODE_WAL) == DND_CS_MNODE_WAL){
|
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_MNODE_WAL) == DND_CS_MNODE_WAL){
|
||||||
cfg.encryptAlgorithm = (tsiEncryptScope & DND_CS_MNODE_WAL)? tsiEncryptAlgorithm : 0;
|
cfg.encryptAlgorithm = (tsiEncryptScope & DND_CS_MNODE_WAL)? tsiEncryptAlgorithm : 0;
|
||||||
if(tsEncryptKey[0] == '\0'){
|
if(tsEncryptKey[0] == '\0'){
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||||
|
|
@ -490,11 +493,13 @@ static int32_t mndInitWal(SMnode *pMnode) {
|
||||||
|
|
||||||
pMnode->pWal = walOpen(path, &cfg);
|
pMnode->pWal = walOpen(path, &cfg);
|
||||||
if (pMnode->pWal == NULL) {
|
if (pMnode->pWal == NULL) {
|
||||||
mError("failed to open wal since %s. wal:%s", terrstr(), path);
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
return -1;
|
if (terrno != 0) code = terrno;
|
||||||
|
mError("failed to open wal since %s. wal:%s", tstrerror(code), path);
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndCloseWal(SMnode *pMnode) {
|
static void mndCloseWal(SMnode *pMnode) {
|
||||||
|
|
@ -505,6 +510,7 @@ static void mndCloseWal(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndInitSdb(SMnode *pMnode) {
|
static int32_t mndInitSdb(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbOpt opt = {0};
|
SSdbOpt opt = {0};
|
||||||
opt.path = pMnode->path;
|
opt.path = pMnode->path;
|
||||||
opt.pMnode = pMnode;
|
opt.pMnode = pMnode;
|
||||||
|
|
@ -512,10 +518,12 @@ static int32_t mndInitSdb(SMnode *pMnode) {
|
||||||
|
|
||||||
pMnode->pSdb = sdbInit(&opt);
|
pMnode->pSdb = sdbInit(&opt);
|
||||||
if (pMnode->pSdb == NULL) {
|
if (pMnode->pSdb == NULL) {
|
||||||
return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndOpenSdb(SMnode *pMnode) {
|
static int32_t mndOpenSdb(SMnode *pMnode) {
|
||||||
|
|
@ -541,48 +549,47 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle
|
||||||
step.initFp = initFp;
|
step.initFp = initFp;
|
||||||
step.cleanupFp = cleanupFp;
|
step.cleanupFp = cleanupFp;
|
||||||
if (taosArrayPush(pMnode->pSteps, &step) == NULL) {
|
if (taosArrayPush(pMnode->pSteps, &step) == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndInitSteps(SMnode *pMnode) {
|
static int32_t mndInitSteps(SMnode *pMnode) {
|
||||||
if (mndAllocStep(pMnode, "mnode-wal", mndInitWal, mndCloseWal) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-wal", mndInitWal, mndCloseWal));
|
||||||
if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb));
|
||||||
if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans));
|
||||||
if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster));
|
||||||
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode));
|
||||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode));
|
||||||
if (mndAllocStep(pMnode, "mnode-snode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-snode", mndInitSnode, mndCleanupSnode));
|
||||||
if (mndAllocStep(pMnode, "mnode-arbgroup", mndInitArbGroup, mndCleanupArbGroup) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-arbgroup", mndInitArbGroup, mndCleanupArbGroup));
|
||||||
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode));
|
||||||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser));
|
||||||
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant));
|
||||||
if (mndAllocStep(pMnode, "mnode-privilege", mndInitPrivilege, mndCleanupPrivilege) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-privilege", mndInitPrivilege, mndCleanupPrivilege));
|
||||||
if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct));
|
||||||
if (mndAllocStep(pMnode, "mnode-stream", mndInitStream, mndCleanupStream) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-stream", mndInitStream, mndCleanupStream));
|
||||||
if (mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic));
|
||||||
if (mndAllocStep(pMnode, "mnode-consumer", mndInitConsumer, mndCleanupConsumer) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-consumer", mndInitConsumer, mndCleanupConsumer));
|
||||||
if (mndAllocStep(pMnode, "mnode-subscribe", mndInitSubscribe, mndCleanupSubscribe) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-subscribe", mndInitSubscribe, mndCleanupSubscribe));
|
||||||
if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup));
|
||||||
if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb));
|
||||||
if (mndAllocStep(pMnode, "mnode-sma", mndInitSma, mndCleanupSma) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-sma", mndInitSma, mndCleanupSma));
|
||||||
if (mndAllocStep(pMnode, "mnode-idx", mndInitIdx, mndCleanupIdx) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-idx", mndInitIdx, mndCleanupIdx));
|
||||||
if (mndAllocStep(pMnode, "mnode-infos", mndInitInfos, mndCleanupInfos) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-infos", mndInitInfos, mndCleanupInfos));
|
||||||
if (mndAllocStep(pMnode, "mnode-perfs", mndInitPerfs, mndCleanupPerfs) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-perfs", mndInitPerfs, mndCleanupPerfs));
|
||||||
if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb));
|
||||||
if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc));
|
||||||
if (mndAllocStep(pMnode, "mnode-view", mndInitView, mndCleanupView) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-view", mndInitView, mndCleanupView));
|
||||||
if (mndAllocStep(pMnode, "mnode-compact", mndInitCompact, mndCleanupCompact) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-compact", mndInitCompact, mndCleanupCompact));
|
||||||
if (mndAllocStep(pMnode, "mnode-compact-detail", mndInitCompactDetail, mndCleanupCompactDetail) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-compact-detail", mndInitCompactDetail, mndCleanupCompactDetail));
|
||||||
if (mndAllocStep(pMnode, "mnode-sdb", mndOpenSdb, NULL) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-sdb", mndOpenSdb, NULL));
|
||||||
if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile));
|
||||||
if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow));
|
||||||
if (mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery));
|
||||||
if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync));
|
||||||
if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1;
|
TAOS_CHECK_RETURN(mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -608,17 +615,16 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndExecSteps(SMnode *pMnode) {
|
static int32_t mndExecSteps(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t size = taosArrayGetSize(pMnode->pSteps);
|
int32_t size = taosArrayGetSize(pMnode->pSteps);
|
||||||
for (int32_t pos = 0; pos < size; pos++) {
|
for (int32_t pos = 0; pos < size; pos++) {
|
||||||
SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos);
|
SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos);
|
||||||
if (pStep->initFp == NULL) continue;
|
if (pStep->initFp == NULL) continue;
|
||||||
|
|
||||||
if ((*pStep->initFp)(pMnode) != 0) {
|
if ((code = (*pStep->initFp)(pMnode)) != 0) {
|
||||||
int32_t code = terrno;
|
mError("%s exec failed since %s, start to cleanup", pStep->name, tstrerror(code));
|
||||||
mError("%s exec failed since %s, start to cleanup", pStep->name, terrstr());
|
|
||||||
mndCleanupSteps(pMnode, pos);
|
mndCleanupSteps(pMnode, pos);
|
||||||
terrno = code;
|
TAOS_RETURN(code);
|
||||||
return -1;
|
|
||||||
} else {
|
} else {
|
||||||
mInfo("%s is initialized", pStep->name);
|
mInfo("%s is initialized", pStep->name);
|
||||||
tmsgReportStartup(pStep->name, "initialized");
|
tmsgReportStartup(pStep->name, "initialized");
|
||||||
|
|
@ -626,7 +632,7 @@ static int32_t mndExecSteps(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pMnode->clusterId = mndGetClusterId(pMnode);
|
pMnode->clusterId = mndGetClusterId(pMnode);
|
||||||
return 0;
|
TAOS_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
||||||
|
|
@ -641,6 +647,7 @@ static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
terrno = 0;
|
||||||
mInfo("start to open mnode in %s", path);
|
mInfo("start to open mnode in %s", path);
|
||||||
|
|
||||||
SMnode *pMnode = taosMemoryCalloc(1, sizeof(SMnode));
|
SMnode *pMnode = taosMemoryCalloc(1, sizeof(SMnode));
|
||||||
|
|
@ -667,7 +674,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
int32_t code = mndCreateDir(pMnode, path);
|
int32_t code = mndCreateDir(pMnode, path);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
mError("failed to open mnode since %s", terrstr());
|
mError("failed to open mnode since %s", tstrerror(code));
|
||||||
mndClose(pMnode);
|
mndClose(pMnode);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -676,7 +683,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
code = mndInitSteps(pMnode);
|
code = mndInitSteps(pMnode);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
mError("failed to open mnode since %s", terrstr());
|
mError("failed to open mnode since %s", tstrerror(code));
|
||||||
mndClose(pMnode);
|
mndClose(pMnode);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -685,7 +692,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
code = mndExecSteps(pMnode);
|
code = mndExecSteps(pMnode);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
mError("failed to open mnode since %s", terrstr());
|
mError("failed to open mnode since %s", tstrerror(code));
|
||||||
mndClose(pMnode);
|
mndClose(pMnode);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -761,45 +768,47 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
int32_t code = syncProcessMsg(pMgmt->sync, pMsg);
|
int32_t code = syncProcessMsg(pMgmt->sync, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mGError("vgId:1, failed to process sync msg:%p type:%s, errno: %s, code:0x%x", pMsg, TMSG_INFO(pMsg->msgType),
|
mGError("vgId:1, failed to process sync msg:%p type:%s, errno: %s, code:0x%x", pMsg, TMSG_INFO(pMsg->msgType),
|
||||||
terrstr(), code);
|
tstrerror(code), code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
||||||
if (!IsReq(pMsg)) return 0;
|
int32_t code = 0;
|
||||||
|
if (!IsReq(pMsg)) TAOS_RETURN(code);
|
||||||
if (pMsg->msgType == TDMT_SCH_QUERY || pMsg->msgType == TDMT_SCH_MERGE_QUERY ||
|
if (pMsg->msgType == TDMT_SCH_QUERY || pMsg->msgType == TDMT_SCH_MERGE_QUERY ||
|
||||||
pMsg->msgType == TDMT_SCH_QUERY_CONTINUE || pMsg->msgType == TDMT_SCH_QUERY_HEARTBEAT ||
|
pMsg->msgType == TDMT_SCH_QUERY_CONTINUE || pMsg->msgType == TDMT_SCH_QUERY_HEARTBEAT ||
|
||||||
pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_SCH_MERGE_FETCH || pMsg->msgType == TDMT_SCH_DROP_TASK ||
|
pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_SCH_MERGE_FETCH || pMsg->msgType == TDMT_SCH_DROP_TASK ||
|
||||||
pMsg->msgType == TDMT_SCH_TASK_NOTIFY) {
|
pMsg->msgType == TDMT_SCH_TASK_NOTIFY) {
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
taosThreadRwlockRdlock(&pMnode->lock);
|
taosThreadRwlockRdlock(&pMnode->lock);
|
||||||
if (pMnode->stopped) {
|
if (pMnode->stopped) {
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
taosThreadRwlockUnlock(&pMnode->lock);
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
SSyncState state = syncGetState(pMnode->syncMgmt.sync);
|
SSyncState state = syncGetState(pMnode->syncMgmt.sync);
|
||||||
if (terrno != 0) {
|
if (terrno != 0) {
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
taosThreadRwlockUnlock(&pMnode->lock);
|
||||||
return -1;
|
code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.state != TAOS_SYNC_STATE_LEADER) {
|
if (state.state != TAOS_SYNC_STATE_LEADER) {
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
taosThreadRwlockUnlock(&pMnode->lock);
|
||||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
code = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.restored || !pMnode->restored) {
|
if (!state.restored || !pMnode->restored) {
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
taosThreadRwlockUnlock(&pMnode->lock);
|
||||||
terrno = TSDB_CODE_SYN_RESTORING;
|
code = TSDB_CODE_SYN_RESTORING;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -811,7 +820,7 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
taosThreadRwlockUnlock(&pMnode->lock);
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (pMsg->msgType == TDMT_MND_TMQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
if (pMsg->msgType == TDMT_MND_TMQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
||||||
|
|
@ -823,19 +832,17 @@ _OVER:
|
||||||
pMsg->msgType == TDMT_MND_ARB_CHECK_SYNC_TIMER) {
|
pMsg->msgType == TDMT_MND_ARB_CHECK_SYNC_TIMER) {
|
||||||
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
||||||
pMnode->stopped, state.restored, syncStr(state.state));
|
pMnode->stopped, state.restored, syncStr(state.state));
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SEpSet epSet = {0};
|
SEpSet epSet = {0};
|
||||||
int32_t tmpCode = terrno;
|
|
||||||
mndGetMnodeEpSet(pMnode, &epSet);
|
mndGetMnodeEpSet(pMnode, &epSet);
|
||||||
terrno = tmpCode;
|
|
||||||
|
|
||||||
mGDebug(
|
mGDebug(
|
||||||
"msg:%p, type:%s failed to process since %s, mnode restored:%d stopped:%d, sync restored:%d "
|
"msg:%p, type:%s failed to process since %s, mnode restored:%d stopped:%d, sync restored:%d "
|
||||||
"role:%s, redirect numOfEps:%d inUse:%d, type:%s",
|
"role:%s, redirect numOfEps:%d inUse:%d, type:%s",
|
||||||
pMsg, TMSG_INFO(pMsg->msgType), terrstr(), pMnode->restored, pMnode->stopped, state.restored,
|
pMsg, TMSG_INFO(pMsg->msgType), tstrerror(code), pMnode->restored, pMnode->stopped, state.restored,
|
||||||
syncStr(state.state), epSet.numOfEps, epSet.inUse, TMSG_INFO(pMsg->msgType));
|
syncStr(state.state), epSet.numOfEps, epSet.inUse, TMSG_INFO(pMsg->msgType));
|
||||||
|
|
||||||
if (epSet.numOfEps <= 0) return -1;
|
if (epSet.numOfEps <= 0) return -1;
|
||||||
|
|
@ -852,7 +859,7 @@ _OVER:
|
||||||
pMsg->info.rspLen = contLen;
|
pMsg->info.rspLen = contLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo *pQueueInfo) {
|
int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo *pQueueInfo) {
|
||||||
|
|
@ -866,12 +873,12 @@ int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo* pQueueInfo) {
|
||||||
fpExt = pMnode->msgFpExt[TMSG_INDEX(pMsg->msgType)];
|
fpExt = pMnode->msgFpExt[TMSG_INDEX(pMsg->msgType)];
|
||||||
if (fpExt == NULL) {
|
if (fpExt == NULL) {
|
||||||
mGError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
mGError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckMnodeState(pMsg) != 0) return -1;
|
TAOS_CHECK_RETURN(mndCheckMnodeState(pMsg));
|
||||||
|
|
||||||
mGTrace("msg:%p, start to process in mnode, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
mGTrace("msg:%p, start to process in mnode, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
||||||
if (fp)
|
if (fp)
|
||||||
|
|
@ -885,6 +892,7 @@ int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo* pQueueInfo) {
|
||||||
} else if (code == 0) {
|
} else if (code == 0) {
|
||||||
mGTrace("msg:%p, successfully processed", pMsg);
|
mGTrace("msg:%p, successfully processed", pMsg);
|
||||||
} else {
|
} else {
|
||||||
|
//TODO removve this wrong set code
|
||||||
if (code == -1) {
|
if (code == -1) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
}
|
}
|
||||||
|
|
@ -892,7 +900,7 @@ int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo* pQueueInfo) {
|
||||||
TMSG_INFO(pMsg->msgType));
|
TMSG_INFO(pMsg->msgType));
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) {
|
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) {
|
||||||
|
|
@ -924,7 +932,8 @@ int64_t mndGenerateUid(const char *name, int32_t len) {
|
||||||
|
|
||||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||||
SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo) {
|
SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo) {
|
||||||
if (mndAcquireRpc(pMnode) != 0) return -1;
|
int32_t code = 0;
|
||||||
|
TAOS_CHECK_RETURN(mndAcquireRpc(pMnode));
|
||||||
|
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int64_t ms = taosGetTimestampMs();
|
int64_t ms = taosGetTimestampMs();
|
||||||
|
|
@ -936,7 +945,9 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
||||||
if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL ||
|
if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL ||
|
||||||
pStbInfo->stbs == NULL) {
|
pStbInfo->stbs == NULL) {
|
||||||
mndReleaseRpc(pMnode);
|
mndReleaseRpc(pMnode);
|
||||||
return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cluster info
|
// cluster info
|
||||||
|
|
@ -1062,7 +1073,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
||||||
}
|
}
|
||||||
|
|
||||||
mndReleaseRpc(pMnode);
|
mndReleaseRpc(pMnode);
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ int32_t mndInitMnode(SMnode *pMnode) {
|
||||||
void mndCleanupMnode(SMnode *pMnode) {}
|
void mndCleanupMnode(SMnode *pMnode) {}
|
||||||
|
|
||||||
SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
||||||
|
terrno = 0;
|
||||||
SMnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_MNODE, &mnodeId);
|
SMnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_MNODE, &mnodeId);
|
||||||
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||||
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
||||||
|
|
@ -82,13 +83,18 @@ void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SMnodeObj mnodeObj = {0};
|
SMnodeObj mnodeObj = {0};
|
||||||
mnodeObj.id = 1;
|
mnodeObj.id = 1;
|
||||||
mnodeObj.createdTime = taosGetTimestampMs();
|
mnodeObj.createdTime = taosGetTimestampMs();
|
||||||
mnodeObj.updateTime = mnodeObj.createdTime;
|
mnodeObj.updateTime = mnodeObj.createdTime;
|
||||||
|
|
||||||
SSdbRaw *pRaw = mndMnodeActionEncode(&mnodeObj);
|
SSdbRaw *pRaw = mndMnodeActionEncode(&mnodeObj);
|
||||||
if (pRaw == NULL) return -1;
|
if (pRaw == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
mInfo("mnode:%d, will be created when deploying, raw:%p", mnodeObj.id, pRaw);
|
mInfo("mnode:%d, will be created when deploying, raw:%p", mnodeObj.id, pRaw);
|
||||||
|
|
@ -97,25 +103,27 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
mError("mnode:%d, failed to create since %s", mnodeObj.id, terrstr());
|
mError("mnode:%d, failed to create since %s", mnodeObj.id, terrstr());
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mInfo("trans:%d, used to create mnode:%d", pTrans->id, mnodeObj.id);
|
mInfo("trans:%d, used to create mnode:%d", pTrans->id, mnodeObj.id);
|
||||||
|
|
||||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
|
||||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) {
|
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) {
|
||||||
|
|
@ -188,16 +196,19 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) {
|
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
mTrace("mnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
mTrace("mnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||||
pObj->pDnode = sdbAcquireNotReadyObj(pSdb, SDB_DNODE, &pObj->id);
|
pObj->pDnode = sdbAcquireNotReadyObj(pSdb, SDB_DNODE, &pObj->id);
|
||||||
if (pObj->pDnode == NULL) {
|
if (pObj->pDnode == NULL) {
|
||||||
mError("mnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
mError("mnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||||
return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
int32_t code = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj->syncState = TAOS_SYNC_STATE_OFFLINE;
|
pObj->syncState = TAOS_SYNC_STATE_OFFLINE;
|
||||||
mndReloadSyncConfig(pSdb->pMnode);
|
mndReloadSyncConfig(pSdb->pMnode);
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
||||||
|
|
@ -271,38 +282,59 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetRestoreCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
int32_t mndSetRestoreCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateMnodeUndoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
static int32_t mndSetCreateMnodeUndoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pUndoRaw = mndMnodeActionEncode(pObj);
|
SSdbRaw *pUndoRaw = mndMnodeActionEncode(pObj);
|
||||||
if (pUndoRaw == NULL) return -1;
|
if (pUndoRaw == NULL) {
|
||||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj);
|
SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pCreateReq, SEpSet *pCreateEpSet) {
|
static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pCreateReq, SEpSet *pCreateEpSet) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq);
|
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq);
|
||||||
void *pReq = taosMemoryMalloc(contLen);
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq);
|
tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq);
|
||||||
|
|
@ -315,15 +347,16 @@ static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *p
|
||||||
.acceptableCode = TSDB_CODE_MNODE_ALREADY_DEPLOYED,
|
.acceptableCode = TSDB_CODE_MNODE_ALREADY_DEPLOYED,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeTypeReq *pAlterMnodeTypeReq,
|
static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeTypeReq *pAlterMnodeTypeReq,
|
||||||
SEpSet *pAlterMnodeTypeEpSet) {
|
SEpSet *pAlterMnodeTypeEpSet) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq);
|
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq);
|
||||||
void *pReq = taosMemoryMalloc(contLen);
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq);
|
tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq);
|
||||||
|
|
@ -337,14 +370,15 @@ static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeType
|
||||||
.acceptableCode = TSDB_CODE_MNODE_ALREADY_IS_VOTER,
|
.acceptableCode = TSDB_CODE_MNODE_ALREADY_IS_VOTER,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pAlterReq, SEpSet *pAlterEpSet) {
|
static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pAlterReq, SEpSet *pAlterEpSet) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq);
|
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq);
|
||||||
void *pReq = taosMemoryMalloc(contLen);
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq);
|
tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq);
|
||||||
|
|
@ -357,15 +391,16 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA
|
||||||
.acceptableCode = 0,
|
.acceptableCode = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDropReq, SEpSet *pDroprEpSet) {
|
static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDropReq, SEpSet *pDroprEpSet) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq);
|
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq);
|
||||||
void *pReq = taosMemoryMalloc(contLen);
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq);
|
tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq);
|
||||||
|
|
@ -378,11 +413,11 @@ static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDrop
|
||||||
.acceptableCode = TSDB_CODE_MNODE_NOT_DEPLOYED,
|
.acceptableCode = TSDB_CODE_MNODE_NOT_DEPLOYED,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||||
|
|
@ -426,9 +461,9 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
createEpset.eps[0].port = pDnode->port;
|
createEpset.eps[0].port = pDnode->port;
|
||||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
|
|
||||||
if (mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset) != 0) return -1;
|
TAOS_CHECK_RETURN(mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetRestoreCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
int32_t mndSetRestoreCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||||
|
|
@ -474,9 +509,9 @@ int32_t mndSetRestoreCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
createEpset.eps[0].port = pDnode->port;
|
createEpset.eps[0].port = pDnode->port;
|
||||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
|
|
||||||
if (mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset) != 0) return -1;
|
TAOS_CHECK_RETURN(mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
static int32_t mndSetAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||||
|
|
@ -517,9 +552,9 @@ static int32_t mndSetAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, S
|
||||||
createEpset.eps[0].port = pDnode->port;
|
createEpset.eps[0].port = pDnode->port;
|
||||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
|
|
||||||
if (mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset) != 0) return -1;
|
TAOS_CHECK_RETURN(mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetRestoreAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
int32_t mndSetRestoreAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||||
|
|
@ -565,19 +600,23 @@ int32_t mndSetRestoreAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, S
|
||||||
createEpset.eps[0].port = pDnode->port;
|
createEpset.eps[0].port = pDnode->port;
|
||||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
|
|
||||||
if (mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset) != 0) return -1;
|
TAOS_CHECK_RETURN(mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset));
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateMnodeReq *pCreate) {
|
static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateMnodeReq *pCreate) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "create-mnode");
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "create-mnode");
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
mndTransSetSerial(pTrans);
|
mndTransSetSerial(pTrans);
|
||||||
mInfo("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
mInfo("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
||||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
SMnodeObj mnodeObj = {0};
|
SMnodeObj mnodeObj = {0};
|
||||||
mnodeObj.id = pDnode->id;
|
mnodeObj.id = pDnode->id;
|
||||||
|
|
@ -586,8 +625,8 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
||||||
mnodeObj.role = TAOS_SYNC_ROLE_LEARNER;
|
mnodeObj.role = TAOS_SYNC_ROLE_LEARNER;
|
||||||
mnodeObj.lastIndex = pMnode->applied;
|
mnodeObj.lastIndex = pMnode->applied;
|
||||||
|
|
||||||
if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj), NULL, _OVER);
|
||||||
if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj), NULL, _OVER);
|
||||||
|
|
||||||
SMnodeObj mnodeLeaderObj = {0};
|
SMnodeObj mnodeLeaderObj = {0};
|
||||||
mnodeLeaderObj.id = pDnode->id;
|
mnodeLeaderObj.id = pDnode->id;
|
||||||
|
|
@ -596,15 +635,15 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
||||||
mnodeLeaderObj.role = TAOS_SYNC_ROLE_VOTER;
|
mnodeLeaderObj.role = TAOS_SYNC_ROLE_VOTER;
|
||||||
mnodeLeaderObj.lastIndex = pMnode->applied + 1;
|
mnodeLeaderObj.lastIndex = pMnode->applied + 1;
|
||||||
|
|
||||||
if (mndSetAlterMnodeTypeRedoActions(pMnode, pTrans, pDnode, &mnodeLeaderObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetAlterMnodeTypeRedoActions(pMnode, pTrans, pDnode, &mnodeLeaderObj), NULL, _OVER);
|
||||||
if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeLeaderObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeLeaderObj), NULL, _OVER);
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
@ -614,19 +653,14 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
||||||
SDnodeObj *pDnode = NULL;
|
SDnodeObj *pDnode = NULL;
|
||||||
SMCreateMnodeReq createReq = {0};
|
SMCreateMnodeReq createReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("mnode:%d, start to create", createReq.dnodeId);
|
mInfo("mnode:%d, start to create", createReq.dnodeId);
|
||||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_MNODE) != 0) {
|
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_MNODE), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
pObj = mndAcquireMnode(pMnode, createReq.dnodeId);
|
pObj = mndAcquireMnode(pMnode, createReq.dnodeId);
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
code = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
} else if (terrno != TSDB_CODE_MND_MNODE_NOT_EXIST) {
|
} else if (terrno != TSDB_CODE_MND_MNODE_NOT_EXIST) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
@ -634,17 +668,17 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
||||||
if (pDnode == NULL) {
|
if (pDnode == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) >= 3) {
|
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) >= 3) {
|
||||||
terrno = TSDB_CODE_MND_TOO_MANY_MNODES;
|
code = TSDB_CODE_MND_TOO_MANY_MNODES;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
||||||
terrno = TSDB_CODE_DNODE_OFFLINE;
|
code = TSDB_CODE_DNODE_OFFLINE;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -665,27 +699,38 @@ _OVER:
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDropMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
static int32_t mndSetDropMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj);
|
SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj,
|
static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj,
|
||||||
bool force) {
|
bool force) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
SDDropMnodeReq dropReq = {0};
|
SDDropMnodeReq dropReq = {0};
|
||||||
|
|
@ -700,32 +745,32 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
if (totalMnodes == 2) {
|
if (totalMnodes == 2) {
|
||||||
if (force) {
|
if (force) {
|
||||||
mError("cant't force drop dnode, since a mnode on it and replica is 2");
|
mError("cant't force drop dnode, since a mnode on it and replica is 2");
|
||||||
terrno = TSDB_CODE_MNODE_ONLY_TWO_MNODE;
|
code = TSDB_CODE_MNODE_ONLY_TWO_MNODE;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
mInfo("vgId:1, has %d mnodes, exec redo log first", totalMnodes);
|
mInfo("vgId:1, has %d mnodes, exec redo log first", totalMnodes);
|
||||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj));
|
||||||
if (!force) {
|
if (!force) {
|
||||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
TAOS_CHECK_RETURN(mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet));
|
||||||
}
|
}
|
||||||
} else if (totalMnodes == 3) {
|
} else if (totalMnodes == 3) {
|
||||||
mInfo("vgId:1, has %d mnodes, exec redo action first", totalMnodes);
|
mInfo("vgId:1, has %d mnodes, exec redo action first", totalMnodes);
|
||||||
if (!force) {
|
if (!force) {
|
||||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
TAOS_CHECK_RETURN(mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet));
|
||||||
}
|
}
|
||||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj));
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
TAOS_RETURN(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force) {
|
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force) {
|
||||||
if (pObj == NULL) return 0;
|
if (pObj == NULL) return 0;
|
||||||
pObj->lastIndex = pMnode->applied;
|
pObj->lastIndex = pMnode->applied;
|
||||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj, force) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj, force));
|
||||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -734,19 +779,23 @@ static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) {
|
||||||
STrans *pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
|
|
||||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-mnode");
|
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-mnode");
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
mndTransSetSerial(pTrans);
|
mndTransSetSerial(pTrans);
|
||||||
mInfo("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
mInfo("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false), NULL, _OVER);
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
@ -755,38 +804,35 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
||||||
SMnodeObj *pObj = NULL;
|
SMnodeObj *pObj = NULL;
|
||||||
SMDropMnodeReq dropReq = {0};
|
SMDropMnodeReq dropReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("mnode:%d, start to drop", dropReq.dnodeId);
|
mInfo("mnode:%d, start to drop", dropReq.dnodeId);
|
||||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) {
|
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dropReq.dnodeId <= 0) {
|
if (dropReq.dnodeId <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
|
pObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
|
||||||
if (pObj == NULL) {
|
if (pObj == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMnode->selfDnodeId == dropReq.dnodeId) {
|
if (pMnode->selfDnodeId == dropReq.dnodeId) {
|
||||||
terrno = TSDB_CODE_MND_CANT_DROP_LEADER;
|
code = TSDB_CODE_MND_CANT_DROP_LEADER;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) {
|
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) {
|
||||||
terrno = TSDB_CODE_MND_TOO_FEW_MNODES;
|
code = TSDB_CODE_MND_TOO_FEW_MNODES;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mndIsDnodeOnline(pObj->pDnode, taosGetTimestampMs())) {
|
if (!mndIsDnodeOnline(pObj->pDnode, taosGetTimestampMs())) {
|
||||||
terrno = TSDB_CODE_DNODE_OFFLINE;
|
code = TSDB_CODE_DNODE_OFFLINE;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -805,7 +851,7 @@ _OVER:
|
||||||
|
|
||||||
mndReleaseMnode(pMnode, pObj);
|
mndReleaseMnode(pMnode, pObj);
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
|
|
@ -892,13 +938,11 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
||||||
#if 1
|
#if 1
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
|
int32_t code = 0;
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SDAlterMnodeReq alterReq = {0};
|
SDAlterMnodeReq alterReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
|
TAOS_CHECK_RETURN(tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq));
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMnodeOpt option = {.deploy = true, .numOfReplicas = alterReq.replica, .selfIndex = -1};
|
SMnodeOpt option = {.deploy = true, .numOfReplicas = alterReq.replica, .selfIndex = -1};
|
||||||
memcpy(option.replicas, alterReq.replicas, sizeof(alterReq.replicas));
|
memcpy(option.replicas, alterReq.replicas, sizeof(alterReq.replicas));
|
||||||
|
|
@ -913,9 +957,9 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndWriteFile(pMnode->path, &option) != 0) {
|
if ((code = mndWriteFile(pMnode->path, &option)) != 0) {
|
||||||
mError("failed to write mnode file since %s", terrstr());
|
mError("failed to write mnode file since %s", terrstr());
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncCfg cfg = {.replicaNum = alterReq.replica, .myIndex = -1};
|
SSyncCfg cfg = {.replicaNum = alterReq.replica, .myIndex = -1};
|
||||||
|
|
@ -939,14 +983,14 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("failed to sync reconfig since %s", terrstr());
|
mError("failed to sync reconfig since %s", terrstr());
|
||||||
} else {
|
} else {
|
||||||
mInfo("alter mnode sync success");
|
mInfo("alter mnode sync success");
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,11 @@
|
||||||
|
|
||||||
// connection/application/
|
// connection/application/
|
||||||
int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
|
int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
|
||||||
|
int32_t code = 0;
|
||||||
SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
|
SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
|
||||||
if (NULL == schema) {
|
if (NULL == schema) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < colNum; ++i) {
|
for (int32_t i = 0; i < colNum; ++i) {
|
||||||
|
|
@ -34,10 +35,11 @@ int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, S
|
||||||
}
|
}
|
||||||
|
|
||||||
*pDst = schema;
|
*pDst = schema;
|
||||||
return TSDB_CODE_SUCCESS;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndPerfsInitMeta(SHashObj *hash) {
|
int32_t mndPerfsInitMeta(SHashObj *hash) {
|
||||||
|
int32_t code = 0;
|
||||||
STableMetaRsp meta = {0};
|
STableMetaRsp meta = {0};
|
||||||
|
|
||||||
tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName));
|
tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName));
|
||||||
|
|
@ -53,56 +55,56 @@ int32_t mndPerfsInitMeta(SHashObj *hash) {
|
||||||
tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
|
tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
|
||||||
meta.numOfColumns = pSysDbTableMeta[i].colNum;
|
meta.numOfColumns = pSysDbTableMeta[i].colNum;
|
||||||
|
|
||||||
if (mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas)) {
|
TAOS_CHECK_RETURN(mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
|
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
|
int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
|
||||||
|
int32_t code = 0;
|
||||||
if (NULL == pMnode->perfsMeta) {
|
if (NULL == pMnode->perfsMeta) {
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||||
if (NULL == meta) {
|
if (NULL == meta) {
|
||||||
mError("invalid performance schema table name:%s", tbName);
|
mError("invalid performance schema table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pRsp = *meta;
|
*pRsp = *meta;
|
||||||
|
|
||||||
pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema));
|
pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema));
|
||||||
if (pRsp->pSchemas == NULL) {
|
if (pRsp->pSchemas == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pRsp->pSchemas = NULL;
|
pRsp->pSchemas = NULL;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
|
memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
|
int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
|
||||||
|
int32_t code = 0;
|
||||||
if (NULL == pMnode->perfsMeta) {
|
if (NULL == pMnode->perfsMeta) {
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMetaRsp *pMeta = taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
STableMetaRsp *pMeta = taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||||
if (NULL == pMeta) {
|
if (NULL == pMeta) {
|
||||||
mError("invalid performance schema table name:%s", tbName);
|
mError("invalid performance schema table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pRsp->tbName, pMeta->tbName);
|
strcpy(pRsp->tbName, pMeta->tbName);
|
||||||
|
|
@ -114,20 +116,21 @@ int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *t
|
||||||
|
|
||||||
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
||||||
if (pRsp->pSchemas == NULL) {
|
if (pRsp->pSchemas == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pRsp->pSchemas = NULL;
|
pRsp->pSchemas = NULL;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndInitPerfs(SMnode *pMnode) {
|
int32_t mndInitPerfs(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
pMnode->perfsMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
pMnode->perfsMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||||
if (pMnode->perfsMeta == NULL) {
|
if (pMnode->perfsMeta == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mndPerfsInitMeta(pMnode->perfsMeta);
|
return mndPerfsInitMeta(pMnode->perfsMeta);
|
||||||
|
|
|
||||||
|
|
@ -85,22 +85,23 @@ static void mndCancelGetNextApp(SMnode *pMnode, void *pIter);
|
||||||
static int32_t mndProcessSvrVerReq(SRpcMsg *pReq);
|
static int32_t mndProcessSvrVerReq(SRpcMsg *pReq);
|
||||||
|
|
||||||
int32_t mndInitProfile(SMnode *pMnode) {
|
int32_t mndInitProfile(SMnode *pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
|
||||||
// in ms
|
// in ms
|
||||||
int32_t checkTime = tsShellActivityTimer * 2 * 1000;
|
int32_t checkTime = tsShellActivityTimer * 2 * 1000;
|
||||||
pMgmt->connCache = taosCacheInit(TSDB_DATA_TYPE_UINT, checkTime, false, (__cache_free_fn_t)mndFreeConn, "conn");
|
pMgmt->connCache = taosCacheInit(TSDB_DATA_TYPE_UINT, checkTime, false, (__cache_free_fn_t)mndFreeConn, "conn");
|
||||||
if (pMgmt->connCache == NULL) {
|
if (pMgmt->connCache == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("failed to alloc profile cache since %s", terrstr());
|
mError("failed to alloc profile cache since %s", terrstr());
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->appCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, checkTime, true, (__cache_free_fn_t)mndFreeApp, "app");
|
pMgmt->appCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, checkTime, true, (__cache_free_fn_t)mndFreeApp, "app");
|
||||||
if (pMgmt->appCache == NULL) {
|
if (pMgmt->appCache == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("failed to alloc profile cache since %s", terrstr());
|
mError("failed to alloc profile cache since %s", terrstr());
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatReq);
|
||||||
|
|
@ -116,7 +117,7 @@ int32_t mndInitProfile(SMnode *pMnode) {
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndRetrieveApps);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndRetrieveApps);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndCancelGetNextApp);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndCancelGetNextApp);
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndCleanupProfile(SMnode *pMnode) {
|
void mndCleanupProfile(SMnode *pMnode) {
|
||||||
|
|
@ -384,6 +385,7 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq)
|
||||||
static void mndFreeApp(SAppObj *pApp) { mTrace("app %" PRIx64 " is destroyed", pApp->appId); }
|
static void mndFreeApp(SAppObj *pApp) { mTrace("app %" PRIx64 " is destroyed", pApp->appId); }
|
||||||
|
|
||||||
static SAppObj *mndAcquireApp(SMnode *pMnode, int64_t appId) {
|
static SAppObj *mndAcquireApp(SMnode *pMnode, int64_t appId) {
|
||||||
|
terrno = 0;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
|
||||||
SAppObj *pApp = taosCacheAcquireByKey(pMgmt->appCache, &appId, sizeof(appId));
|
SAppObj *pApp = taosCacheAcquireByKey(pMgmt->appCache, &appId, sizeof(appId));
|
||||||
|
|
@ -431,13 +433,16 @@ static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndUpdateAppInfo(SMnode *pMnode, SClientHbReq *pHbReq, SRpcConnInfo *connInfo) {
|
static int32_t mndUpdateAppInfo(SMnode *pMnode, SClientHbReq *pHbReq, SRpcConnInfo *connInfo) {
|
||||||
|
int32_t code = 0;
|
||||||
SAppHbReq *pReq = &pHbReq->app;
|
SAppHbReq *pReq = &pHbReq->app;
|
||||||
SAppObj *pApp = mndAcquireApp(pMnode, pReq->appId);
|
SAppObj *pApp = mndAcquireApp(pMnode, pReq->appId);
|
||||||
if (pApp == NULL) {
|
if (pApp == NULL) {
|
||||||
pApp = mndCreateApp(pMnode, connInfo->clientIp, pReq);
|
pApp = mndCreateApp(pMnode, connInfo->clientIp, pReq);
|
||||||
if (pApp == NULL) {
|
if (pApp == NULL) {
|
||||||
mError("failed to create new app %" PRIx64 " since %s", pReq->appId, terrstr());
|
mError("failed to create new app %" PRIx64 " since %s", pReq->appId, terrstr());
|
||||||
return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
} else {
|
} else {
|
||||||
mDebug("a new app %" PRIx64 " is created", pReq->appId);
|
mDebug("a new app %" PRIx64 " is created", pReq->appId);
|
||||||
mndReleaseApp(pMnode, pApp);
|
mndReleaseApp(pMnode, pApp);
|
||||||
|
|
@ -475,6 +480,7 @@ static int32_t mndGetOnlineDnodeNum(SMnode *pMnode, int32_t *num) {
|
||||||
|
|
||||||
static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHbReq *pHbReq,
|
static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHbReq *pHbReq,
|
||||||
SClientHbBatchRsp *pBatchRsp, SConnPreparedObj *pObj) {
|
SClientHbBatchRsp *pBatchRsp, SConnPreparedObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
SClientHbRsp hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL};
|
SClientHbRsp hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL};
|
||||||
SRpcConnInfo connInfo = pMsg->info.conn;
|
SRpcConnInfo connInfo = pMsg->info.conn;
|
||||||
|
|
@ -492,7 +498,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
||||||
pHbReq->app.pid, pHbReq->app.name, 0);
|
pHbReq->app.pid, pHbReq->app.name, 0);
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
mError("user:%s, conn:%u is freed and failed to create new since %s", connInfo.user, pBasic->connId, terrstr());
|
mError("user:%s, conn:%u is freed and failed to create new since %s", connInfo.user, pBasic->connId, terrstr());
|
||||||
return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
} else {
|
} else {
|
||||||
mDebug("user:%s, conn:%u is freed, will create a new conn:%u", connInfo.user, pBasic->connId, pConn->id);
|
mDebug("user:%s, conn:%u is freed, will create a new conn:%u", connInfo.user, pBasic->connId, pConn->id);
|
||||||
}
|
}
|
||||||
|
|
@ -501,9 +509,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
||||||
SQueryHbRspBasic *rspBasic = taosMemoryCalloc(1, sizeof(SQueryHbRspBasic));
|
SQueryHbRspBasic *rspBasic = taosMemoryCalloc(1, sizeof(SQueryHbRspBasic));
|
||||||
if (rspBasic == NULL) {
|
if (rspBasic == NULL) {
|
||||||
mndReleaseConn(pMnode, pConn, true);
|
mndReleaseConn(pMnode, pConn, true);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("user:%s, conn:%u failed to process hb while since %s", pConn->user, pBasic->connId, terrstr());
|
mError("user:%s, conn:%u failed to process hb while since %s", pConn->user, pBasic->connId, terrstr());
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
mndSaveQueryList(pConn, pBasic);
|
mndSaveQueryList(pConn, pBasic);
|
||||||
|
|
@ -539,9 +547,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
||||||
hbRsp.info = taosArrayInit(kvNum, sizeof(SKv));
|
hbRsp.info = taosArrayInit(kvNum, sizeof(SKv));
|
||||||
if (NULL == hbRsp.info) {
|
if (NULL == hbRsp.info) {
|
||||||
mError("taosArrayInit %d rsp kv failed", kvNum);
|
mError("taosArrayInit %d rsp kv failed", kvNum);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tFreeClientHbRsp(&hbRsp);
|
tFreeClientHbRsp(&hbRsp);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TD_ENTERPRISE
|
#ifdef TD_ENTERPRISE
|
||||||
|
|
@ -554,8 +562,8 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
||||||
mTrace("recv view dyn ver, bootTs:%" PRId64 ", ver:%" PRIu64, pDynViewVer->svrBootTs, pDynViewVer->dynViewVer);
|
mTrace("recv view dyn ver, bootTs:%" PRId64 ", ver:%" PRIu64, pDynViewVer->svrBootTs, pDynViewVer->dynViewVer);
|
||||||
|
|
||||||
SDynViewVersion *pRspVer = NULL;
|
SDynViewVersion *pRspVer = NULL;
|
||||||
if (0 != mndValidateDynViewVersion(pMnode, pDynViewVer, &needCheck, &pRspVer)) {
|
if (0 != (code = mndValidateDynViewVersion(pMnode, pDynViewVer, &needCheck, &pRspVer))) {
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needCheck) {
|
if (needCheck) {
|
||||||
|
|
@ -647,13 +655,14 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
||||||
|
int32_t code = 0;
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
|
|
||||||
SClientHbBatchReq batchReq = {0};
|
SClientHbBatchReq batchReq = {0};
|
||||||
if (tDeserializeSClientHbBatchReq(pReq->pCont, pReq->contLen, &batchReq) != 0) {
|
if (tDeserializeSClientHbBatchReq(pReq->pCont, pReq->contLen, &batchReq) != 0) {
|
||||||
taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq);
|
taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SConnPreparedObj obj = {0};
|
SConnPreparedObj obj = {0};
|
||||||
|
|
@ -699,31 +708,27 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
taosArrayDestroy(obj.pQnodeList);
|
taosArrayDestroy(obj.pQnodeList);
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
||||||
|
int32_t code = 0;
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
|
||||||
SKillQueryReq killReq = {0};
|
SKillQueryReq killReq = {0};
|
||||||
if (tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
TAOS_CHECK_RETURN(tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq));
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("kill query msg is received, queryId:%s", killReq.queryStrId);
|
mInfo("kill query msg is received, queryId:%s", killReq.queryStrId);
|
||||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_QUERY) != 0) {
|
TAOS_CHECK_RETURN(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_QUERY));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t connId = 0;
|
int32_t connId = 0;
|
||||||
uint64_t queryId = 0;
|
uint64_t queryId = 0;
|
||||||
char *p = strchr(killReq.queryStrId, ':');
|
char *p = strchr(killReq.queryStrId, ':');
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
mError("invalid query id %s", killReq.queryStrId);
|
mError("invalid query id %s", killReq.queryStrId);
|
||||||
terrno = TSDB_CODE_MND_INVALID_QUERY_ID;
|
code = TSDB_CODE_MND_INVALID_QUERY_ID;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
*p = 0;
|
*p = 0;
|
||||||
connId = taosStr2Int32(killReq.queryStrId, NULL, 16);
|
connId = taosStr2Int32(killReq.queryStrId, NULL, 16);
|
||||||
|
|
@ -732,40 +737,36 @@ static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
||||||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &connId, sizeof(int32_t));
|
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &connId, sizeof(int32_t));
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
mError("connId:%x, failed to kill queryId:%" PRIx64 ", conn not exist", connId, queryId);
|
mError("connId:%x, failed to kill queryId:%" PRIx64 ", conn not exist", connId, queryId);
|
||||||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
code = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
} else {
|
} else {
|
||||||
mInfo("connId:%x, queryId:%" PRIx64 " is killed by user:%s", connId, queryId, pReq->info.conn.user);
|
mInfo("connId:%x, queryId:%" PRIx64 " is killed by user:%s", connId, queryId, pReq->info.conn.user);
|
||||||
pConn->killId = queryId;
|
pConn->killId = queryId;
|
||||||
taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
|
taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessKillConnReq(SRpcMsg *pReq) {
|
static int32_t mndProcessKillConnReq(SRpcMsg *pReq) {
|
||||||
|
int32_t code = 0;
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
|
||||||
SKillConnReq killReq = {0};
|
SKillConnReq killReq = {0};
|
||||||
if (tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
TAOS_CHECK_RETURN(tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq));
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_CONN) != 0) {
|
TAOS_CHECK_RETURN(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_CONN));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &killReq.connId, sizeof(uint32_t));
|
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &killReq.connId, sizeof(uint32_t));
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
mError("connId:%u, failed to kill connection, conn not exist", killReq.connId);
|
mError("connId:%u, failed to kill connection, conn not exist", killReq.connId);
|
||||||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
code = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
} else {
|
} else {
|
||||||
mInfo("connId:%u, is killed by user:%s", killReq.connId, pReq->info.conn.user);
|
mInfo("connId:%u, is killed by user:%s", killReq.connId, pReq->info.conn.user);
|
||||||
pConn->killed = 1;
|
pConn->killed = 1;
|
||||||
taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
|
taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
|
||||||
return TSDB_CODE_SUCCESS;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,15 +138,16 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) {
|
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
mTrace("qnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
mTrace("qnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||||
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||||
if (pObj->pDnode == NULL) {
|
if (pObj->pDnode == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
mError("qnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
mError("qnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) {
|
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) {
|
||||||
|
|
@ -166,27 +167,42 @@ static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pUndoRaw = mndQnodeActionEncode(pObj);
|
SSdbRaw *pUndoRaw = mndQnodeActionEncode(pObj);
|
||||||
if (pUndoRaw == NULL) return -1;
|
if (pUndoRaw == NULL) {
|
||||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
|
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
|
||||||
|
|
@ -194,6 +210,7 @@ bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCreateQnodeReq createReq = {0};
|
SDCreateQnodeReq createReq = {0};
|
||||||
createReq.dnodeId = pDnode->id;
|
createReq.dnodeId = pDnode->id;
|
||||||
|
|
||||||
|
|
@ -212,23 +229,24 @@ int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeOb
|
||||||
action.msgType = TDMT_DND_CREATE_QNODE;
|
action.msgType = TDMT_DND_CREATE_QNODE;
|
||||||
action.acceptableCode = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
action.acceptableCode = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SDDropQnodeReq dropReq = {0};
|
SDDropQnodeReq dropReq = {0};
|
||||||
dropReq.dnodeId = pDnode->id;
|
dropReq.dnodeId = pDnode->id;
|
||||||
|
|
||||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
||||||
void *pReq = taosMemoryMalloc(contLen);
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
if (pReq == NULL) {
|
if (pReq == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||||
|
|
||||||
|
|
@ -239,12 +257,12 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
||||||
action.msgType = TDMT_DND_DROP_QNODE;
|
action.msgType = TDMT_DND_DROP_QNODE;
|
||||||
action.acceptableCode = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
action.acceptableCode = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||||
|
|
||||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendUndoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCreateQnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) {
|
static int32_t mndCreateQnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) {
|
||||||
|
|
@ -256,22 +274,26 @@ static int32_t mndCreateQnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
||||||
qnodeObj.updateTime = qnodeObj.createdTime;
|
qnodeObj.updateTime = qnodeObj.createdTime;
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-qnode");
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-qnode");
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
mndTransSetSerial(pTrans);
|
mndTransSetSerial(pTrans);
|
||||||
|
|
||||||
mInfo("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId);
|
mInfo("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId);
|
||||||
if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj), NULL, _OVER);
|
||||||
if (mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj), NULL, _OVER);
|
||||||
if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj), NULL, _OVER);
|
||||||
if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj), NULL, _OVER);
|
||||||
if (mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj), NULL, _OVER);
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
@ -281,19 +303,14 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
||||||
SDnodeObj *pDnode = NULL;
|
SDnodeObj *pDnode = NULL;
|
||||||
SMCreateQnodeReq createReq = {0};
|
SMCreateQnodeReq createReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("qnode:%d, start to create", createReq.dnodeId);
|
mInfo("qnode:%d, start to create", createReq.dnodeId);
|
||||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_QNODE) != 0) {
|
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_QNODE), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
pObj = mndAcquireQnode(pMnode, createReq.dnodeId);
|
pObj = mndAcquireQnode(pMnode, createReq.dnodeId);
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
terrno = TSDB_CODE_MND_QNODE_ALREADY_EXIST;
|
code = TSDB_CODE_MND_QNODE_ALREADY_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
} else if (terrno != TSDB_CODE_MND_QNODE_NOT_EXIST) {
|
} else if (terrno != TSDB_CODE_MND_QNODE_NOT_EXIST) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
@ -301,7 +318,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
||||||
if (pDnode == NULL) {
|
if (pDnode == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -320,34 +337,47 @@ _OVER:
|
||||||
mndReleaseQnode(pMnode, pObj);
|
mndReleaseQnode(pMnode, pObj);
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDropQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
static int32_t mndSetDropQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) {
|
||||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||||
|
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) {
|
||||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
if (terrno != 0) code = terrno;
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw))
|
||||||
|
;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED))
|
||||||
|
;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||||
|
int32_t code = 0;
|
||||||
SDDropQnodeReq dropReq = {0};
|
SDDropQnodeReq dropReq = {0};
|
||||||
dropReq.dnodeId = pDnode->id;
|
dropReq.dnodeId = pDnode->id;
|
||||||
|
|
||||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
||||||
void *pReq = taosMemoryMalloc(contLen);
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
if (pReq == NULL) {
|
if (pReq == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||||
|
|
||||||
|
|
@ -358,20 +388,20 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn
|
||||||
action.msgType = TDMT_DND_DROP_QNODE;
|
action.msgType = TDMT_DND_DROP_QNODE;
|
||||||
action.acceptableCode = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
action.acceptableCode = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force) {
|
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force) {
|
||||||
if (pObj == NULL) return 0;
|
if (pObj == NULL) return 0;
|
||||||
if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropQnodeRedoLogs(pTrans, pObj));
|
||||||
if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropQnodeCommitLogs(pTrans, pObj));
|
||||||
if (!force) {
|
if (!force) {
|
||||||
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
TAOS_CHECK_RETURN(mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -380,18 +410,22 @@ static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-qnode");
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-qnode");
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
mndTransSetSerial(pTrans);
|
mndTransSetSerial(pTrans);
|
||||||
|
|
||||||
mInfo("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id);
|
mInfo("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id);
|
||||||
if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false), NULL, _OVER);
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
||||||
|
|
@ -400,23 +434,20 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
||||||
SQnodeObj *pObj = NULL;
|
SQnodeObj *pObj = NULL;
|
||||||
SMDropQnodeReq dropReq = {0};
|
SMDropQnodeReq dropReq = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("qnode:%d, start to drop", dropReq.dnodeId);
|
mInfo("qnode:%d, start to drop", dropReq.dnodeId);
|
||||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_QNODE) != 0) {
|
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_QNODE), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dropReq.dnodeId <= 0) {
|
if (dropReq.dnodeId <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj = mndAcquireQnode(pMnode, dropReq.dnodeId);
|
pObj = mndAcquireQnode(pMnode, dropReq.dnodeId);
|
||||||
if (pObj == NULL) {
|
if (pObj == NULL) {
|
||||||
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -435,10 +466,11 @@ _OVER:
|
||||||
|
|
||||||
mndReleaseQnode(pMnode, pObj);
|
mndReleaseQnode(pMnode, pObj);
|
||||||
tFreeSDDropQnodeReq(&dropReq);
|
tFreeSDDropQnodeReq(&dropReq);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit) {
|
int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
SQnodeObj *pObj = NULL;
|
SQnodeObj *pObj = NULL;
|
||||||
|
|
@ -447,8 +479,8 @@ int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit) {
|
||||||
SArray *qnodeList = taosArrayInit(5, sizeof(SQueryNodeLoad));
|
SArray *qnodeList = taosArrayInit(5, sizeof(SQueryNodeLoad));
|
||||||
if (NULL == qnodeList) {
|
if (NULL == qnodeList) {
|
||||||
mError("failed to alloc epSet while process qnode list req");
|
mError("failed to alloc epSet while process qnode list req");
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return terrno;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
@ -484,20 +516,14 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
||||||
SQnodeListReq qlistReq = {0};
|
SQnodeListReq qlistReq = {0};
|
||||||
SQnodeListRsp qlistRsp = {0};
|
SQnodeListRsp qlistRsp = {0};
|
||||||
|
|
||||||
if (tDeserializeSQnodeListReq(pReq->pCont, pReq->contLen, &qlistReq) != 0) {
|
TAOS_CHECK_GOTO(tDeserializeSQnodeListReq(pReq->pCont, pReq->contLen, &qlistReq), NULL, _OVER);
|
||||||
mError("failed to parse qnode list req");
|
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mndCreateQnodeList(pMnode, &qlistRsp.qnodeList, qlistReq.rowNum) != 0) {
|
TAOS_CHECK_GOTO(mndCreateQnodeList(pMnode, &qlistRsp.qnodeList, qlistReq.rowNum), NULL, _OVER);
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
||||||
void *pRsp = rpcMallocCont(rspLen);
|
void *pRsp = rpcMallocCont(rspLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -509,7 +535,7 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
tFreeSQnodeListRsp(&qlistRsp);
|
tFreeSQnodeListRsp(&qlistRsp);
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndRetrieveQnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveQnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
||||||
void *pRsp = NULL;
|
void *pRsp = NULL;
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
|
|
||||||
if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
|
if ((code = tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) != 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("tDeserializeSBatchReq failed");
|
mError("tDeserializeSBatchReq failed");
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
|
@ -119,7 +119,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
||||||
MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
|
MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
mError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
mError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
taosArrayDestroy(batchRsp.pRsps);
|
taosArrayDestroy(batchRsp.pRsps);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +164,7 @@ _exit:
|
||||||
taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
|
taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
|
||||||
taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
|
taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndInitQuery(SMnode *pMnode) {
|
int32_t mndInitQuery(SMnode *pMnode) {
|
||||||
|
|
|
||||||
|
|
@ -50,17 +50,17 @@ static bool isCountWindowStreamTask(SSubplan* pPlan) {
|
||||||
|
|
||||||
int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType,
|
int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType,
|
||||||
int64_t watermark, int64_t deleteMark) {
|
int64_t watermark, int64_t deleteMark) {
|
||||||
|
int32_t code = 0;
|
||||||
SNode* pAst = NULL;
|
SNode* pAst = NULL;
|
||||||
SQueryPlan* pPlan = NULL;
|
SQueryPlan* pPlan = NULL;
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
|
||||||
|
|
||||||
if (nodesStringToNode(ast, &pAst) < 0) {
|
if (nodesStringToNode(ast, &pAst) < 0) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qSetSTableIdForRsma(pAst, uid) < 0) {
|
if (qSetSTableIdForRsma(pAst, uid) < 0) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,33 +75,33 @@ int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64
|
||||||
};
|
};
|
||||||
|
|
||||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) {
|
if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||||
if (levelNum != 1) {
|
if (levelNum != 1) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
SNodeListNode* inner = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
SNodeListNode* inner = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
||||||
|
|
||||||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||||
if (opNum != 1) {
|
if (opNum != 1) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSubplan* plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0);
|
SSubplan* plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0);
|
||||||
if (qSubPlanToString(plan, pDst, pDstLen) < 0) {
|
if (qSubPlanToString(plan, pDst, pDstLen) < 0) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
END:
|
END:
|
||||||
if (pAst) nodesDestroyNode(pAst);
|
if (pAst) nodesDestroyNode(pAst);
|
||||||
if (pPlan) nodesDestroyNode((SNode*)pPlan);
|
if (pPlan) nodesDestroyNode((SNode*)pPlan);
|
||||||
return terrno;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSetSinkTaskInfo(SStreamObj* pStream, SStreamTask* pTask) {
|
int32_t mndSetSinkTaskInfo(SStreamObj* pStream, SStreamTask* pTask) {
|
||||||
|
|
@ -127,6 +127,7 @@ int32_t mndSetSinkTaskInfo(SStreamObj* pStream, SStreamTask* pTask) {
|
||||||
|
|
||||||
int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SArray* pSinkNodeList,
|
int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SArray* pSinkNodeList,
|
||||||
SStreamTask* pTask) {
|
SStreamTask* pTask) {
|
||||||
|
int32_t code = 0;
|
||||||
bool isShuffle = false;
|
bool isShuffle = false;
|
||||||
|
|
||||||
if (pStream->fixedSinkVgId == 0) {
|
if (pStream->fixedSinkVgId == 0) {
|
||||||
|
|
@ -135,9 +136,7 @@ int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SAr
|
||||||
isShuffle = true;
|
isShuffle = true;
|
||||||
pTask->outputInfo.type = TASK_OUTPUT__SHUFFLE_DISPATCH;
|
pTask->outputInfo.type = TASK_OUTPUT__SHUFFLE_DISPATCH;
|
||||||
pTask->msgInfo.msgType = TDMT_STREAM_TASK_DISPATCH;
|
pTask->msgInfo.msgType = TDMT_STREAM_TASK_DISPATCH;
|
||||||
if (mndExtractDbInfo(pMnode, pDb, &pTask->outputInfo.shuffleDispatcher.dbInfo, NULL) < 0) {
|
TAOS_CHECK_RETURN(mndExtractDbInfo(pMnode, pDb, &pTask->outputInfo.shuffleDispatcher.dbInfo, NULL));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pMnode->pSdb, pDb);
|
sdbRelease(pMnode->pSdb, pDb);
|
||||||
|
|
@ -166,7 +165,7 @@ int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SAr
|
||||||
streamTaskSetFixedDownstreamInfo(pTask, pOneSinkTask);
|
streamTaskSetFixedDownstreamInfo(pTask, pOneSinkTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndAssignStreamTaskToVgroup(SMnode* pMnode, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) {
|
int32_t mndAssignStreamTaskToVgroup(SMnode* pMnode, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) {
|
||||||
|
|
@ -639,14 +638,15 @@ static void bindTwoLevel(SArray* tasks, int32_t begin, int32_t end) {
|
||||||
|
|
||||||
static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan* pPlan, SEpSet* pEpset, int64_t skey,
|
static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan* pPlan, SEpSet* pEpset, int64_t skey,
|
||||||
SArray* pVerList) {
|
SArray* pVerList) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb* pSdb = pMnode->pSdb;
|
SSdb* pSdb = pMnode->pSdb;
|
||||||
int32_t numOfPlanLevel = LIST_LENGTH(pPlan->pSubplans);
|
int32_t numOfPlanLevel = LIST_LENGTH(pPlan->pSubplans);
|
||||||
bool hasExtraSink = false;
|
bool hasExtraSink = false;
|
||||||
bool externalTargetDB = strcmp(pStream->sourceDb, pStream->targetDb) != 0;
|
bool externalTargetDB = strcmp(pStream->sourceDb, pStream->targetDb) != 0;
|
||||||
SDbObj* pDbObj = mndAcquireDb(pMnode, pStream->targetDb);
|
SDbObj* pDbObj = mndAcquireDb(pMnode, pStream->targetDb);
|
||||||
if (pDbObj == NULL) {
|
if (pDbObj == NULL) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool multiTarget = (pDbObj->cfg.numOfVgroups > 1);
|
bool multiTarget = (pDbObj->cfg.numOfVgroups > 1);
|
||||||
|
|
@ -670,9 +670,11 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
||||||
|
|
||||||
SSubplan* plan = getScanSubPlan(pPlan); // source plan
|
SSubplan* plan = getScanSubPlan(pPlan); // source plan
|
||||||
if (plan == NULL) {
|
if (plan == NULL) {
|
||||||
return terrno;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
int32_t code = addSourceTask(pMnode, plan, pStream, pEpset, skey, pVerList, numOfPlanLevel == 1);
|
code = addSourceTask(pMnode, plan, pStream, pEpset, skey, pVerList, numOfPlanLevel == 1);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -688,7 +690,9 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
||||||
if (numOfPlanLevel == 3) {
|
if (numOfPlanLevel == 3) {
|
||||||
plan = getAggSubPlan(pPlan, 1); // middle agg plan
|
plan = getAggSubPlan(pPlan, 1); // middle agg plan
|
||||||
if (plan == NULL) {
|
if (plan == NULL) {
|
||||||
return terrno;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
SArray** list = taosArrayGetLast(pStream->tasks);
|
SArray** list = taosArrayGetLast(pStream->tasks);
|
||||||
|
|
@ -715,7 +719,9 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
||||||
|
|
||||||
plan = getAggSubPlan(pPlan, 0);
|
plan = getAggSubPlan(pPlan, 0);
|
||||||
if (plan == NULL) {
|
if (plan == NULL) {
|
||||||
return terrno;
|
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("doScheduleStream add final agg");
|
mDebug("doScheduleStream add final agg");
|
||||||
|
|
@ -724,7 +730,7 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
||||||
addNewTaskList(pStream);
|
addNewTaskList(pStream);
|
||||||
code = addAggTask(pStream, pMnode, plan, pEpset, true);
|
code = addAggTask(pStream, pMnode, plan, pEpset, true);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
bindTwoLevel(pStream->tasks, 0, size);
|
bindTwoLevel(pStream->tasks, 0, size);
|
||||||
if (pStream->conf.fillHistory) {
|
if (pStream->conf.fillHistory) {
|
||||||
|
|
@ -735,26 +741,28 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
||||||
if (pStream->conf.fillHistory) {
|
if (pStream->conf.fillHistory) {
|
||||||
bindAggSink(pStream, pMnode, pStream->pHTasksList);
|
bindAggSink(pStream, pMnode, pStream->pHTasksList);
|
||||||
}
|
}
|
||||||
return TDB_CODE_SUCCESS;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream, int64_t skey, SArray* pVgVerList) {
|
int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream, int64_t skey, SArray* pVgVerList) {
|
||||||
|
int32_t code = 0;
|
||||||
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
|
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
|
||||||
if (pPlan == NULL) {
|
if (pPlan == NULL) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SEpSet mnodeEpset = {0};
|
SEpSet mnodeEpset = {0};
|
||||||
mndGetMnodeEpSet(pMnode, &mnodeEpset);
|
mndGetMnodeEpSet(pMnode, &mnodeEpset);
|
||||||
|
|
||||||
int32_t code = doScheduleStream(pStream, pMnode, pPlan, &mnodeEpset, skey, pVgVerList);
|
code = doScheduleStream(pStream, pMnode, pPlan, &mnodeEpset, skey, pVgVerList);
|
||||||
qDestroyQueryPlan(pPlan);
|
qDestroyQueryPlan(pPlan);
|
||||||
|
|
||||||
return code;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdb* pSdb = pMnode->pSdb;
|
SSdb* pSdb = pMnode->pSdb;
|
||||||
SVgObj* pVgroup = NULL;
|
SVgObj* pVgroup = NULL;
|
||||||
SQueryPlan* pPlan = NULL;
|
SQueryPlan* pPlan = NULL;
|
||||||
|
|
@ -763,21 +771,21 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
||||||
if (pTopic->subType == TOPIC_SUB_TYPE__COLUMN) {
|
if (pTopic->subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||||
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||||
if (pPlan == NULL) {
|
if (pPlan == NULL) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
} else if (pTopic->subType == TOPIC_SUB_TYPE__TABLE && pTopic->ast != NULL) {
|
} else if (pTopic->subType == TOPIC_SUB_TYPE__TABLE && pTopic->ast != NULL) {
|
||||||
SNode* pAst = NULL;
|
SNode* pAst = NULL;
|
||||||
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
|
if ((code = nodesStringToNode(pTopic->ast, &pAst)) != 0) {
|
||||||
mError("topic:%s, failed to create since %s", pTopic->name, terrstr());
|
mError("topic:%s, failed to create since %s", pTopic->name, terrstr());
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true};
|
SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true};
|
||||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) {
|
if ((code = qCreateQueryPlan(&cxt, &pPlan, NULL)) != 0) {
|
||||||
mError("failed to create topic:%s since %s", pTopic->name, terrstr());
|
mError("failed to create topic:%s since %s", pTopic->name, terrstr());
|
||||||
nodesDestroyNode(pAst);
|
nodesDestroyNode(pAst);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
nodesDestroyNode(pAst);
|
nodesDestroyNode(pAst);
|
||||||
}
|
}
|
||||||
|
|
@ -786,8 +794,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
||||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||||
if (levelNum != 1) {
|
if (levelNum != 1) {
|
||||||
qDestroyQueryPlan(pPlan);
|
qDestroyQueryPlan(pPlan);
|
||||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
code = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
SNodeListNode* pNodeListNode = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
SNodeListNode* pNodeListNode = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
||||||
|
|
@ -795,8 +803,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
||||||
int32_t opNum = LIST_LENGTH(pNodeListNode->pNodeList);
|
int32_t opNum = LIST_LENGTH(pNodeListNode->pNodeList);
|
||||||
if (opNum != 1) {
|
if (opNum != 1) {
|
||||||
qDestroyQueryPlan(pPlan);
|
qDestroyQueryPlan(pPlan);
|
||||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
code = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pSubplan = (SSubplan*)nodesListGetNode(pNodeListNode->pNodeList, 0);
|
pSubplan = (SSubplan*)nodesListGetNode(pNodeListNode->pNodeList, 0);
|
||||||
|
|
@ -831,13 +839,13 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
||||||
|
|
||||||
if (qSubPlanToString(pSubplan, &pSub->qmsg, &msgLen) < 0) {
|
if (qSubPlanToString(pSubplan, &pSub->qmsg, &msgLen) < 0) {
|
||||||
qDestroyQueryPlan(pPlan);
|
qDestroyQueryPlan(pPlan);
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pSub->qmsg = taosStrdup("");
|
pSub->qmsg = taosStrdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
qDestroyQueryPlan(pPlan);
|
qDestroyQueryPlan(pPlan);
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ int32_t sndBuildStreamTask(SSnode *pSnode, SStreamTask *pTask, int64_t nextProce
|
||||||
}
|
}
|
||||||
|
|
||||||
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
||||||
|
int32_t code = 0;
|
||||||
SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode));
|
SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode));
|
||||||
if (pSnode == NULL) {
|
if (pSnode == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
@ -68,12 +69,17 @@ SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
stopRsync();
|
stopRsync();
|
||||||
startRsync();
|
code = startRsync();
|
||||||
|
if (code != 0) {
|
||||||
|
terrno = code;
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
pSnode->msgCb = pOption->msgCb;
|
pSnode->msgCb = pOption->msgCb;
|
||||||
int32_t code = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE,
|
code = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE,
|
||||||
taosGetTimestampMs(), tqStartTaskCompleteCallback, &pSnode->pMeta);
|
taosGetTimestampMs(), tqStartTaskCompleteCallback, &pSnode->pMeta);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = code;
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,31 +103,31 @@ int32_t tqMetaSaveInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen, const
|
||||||
int32_t code = TDB_CODE_SUCCESS;
|
int32_t code = TDB_CODE_SUCCESS;
|
||||||
TXN* txn = NULL;
|
TXN* txn = NULL;
|
||||||
|
|
||||||
TQ_ERR_RETURN(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
TQ_ERR_GO_TO_END(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||||
TQ_ERR_RETURN(tdbTbUpsert(ttb, key, kLen, value, vLen, txn));
|
TQ_ERR_GO_TO_END(tdbTbUpsert(ttb, key, kLen, value, vLen, txn));
|
||||||
TQ_ERR_RETURN(tdbCommit(pTq->pMetaDB, txn));
|
TQ_ERR_GO_TO_END(tdbCommit(pTq->pMetaDB, txn));
|
||||||
TQ_ERR_RETURN(tdbPostCommit(pTq->pMetaDB, txn));
|
TQ_ERR_GO_TO_END(tdbPostCommit(pTq->pMetaDB, txn));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
END:
|
||||||
|
tdbAbort(pTq->pMetaDB, txn);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen) {
|
int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen) {
|
||||||
int32_t code = TDB_CODE_SUCCESS;
|
int32_t code = TDB_CODE_SUCCESS;
|
||||||
TXN* txn = NULL;
|
TXN* txn = NULL;
|
||||||
|
|
||||||
TQ_ERR_RETURN(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
TQ_ERR_GO_TO_END(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||||
TQ_ERR_RETURN(tdbTbDelete(ttb, key, kLen, txn));
|
TQ_ERR_GO_TO_END(tdbTbDelete(ttb, key, kLen, txn));
|
||||||
TQ_ERR_RETURN(tdbCommit(pTq->pMetaDB, txn));
|
TQ_ERR_GO_TO_END(tdbCommit(pTq->pMetaDB, txn));
|
||||||
TQ_ERR_RETURN(tdbPostCommit(pTq->pMetaDB, txn));
|
TQ_ERR_GO_TO_END(tdbPostCommit(pTq->pMetaDB, txn));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tqMetaTransformOffsetInfo(STQ* pTq, char* path) {
|
|
||||||
int32_t code = TDB_CODE_SUCCESS;
|
|
||||||
TQ_ERR_RETURN(tqOffsetRestoreFromFile(pTq, path));
|
|
||||||
|
|
||||||
END:
|
END:
|
||||||
|
tdbAbort(pTq->pMetaDB, txn);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -409,6 +409,7 @@ END:
|
||||||
|
|
||||||
int32_t tqMetaOpen(STQ* pTq) {
|
int32_t tqMetaOpen(STQ* pTq) {
|
||||||
char* maindb = NULL;
|
char* maindb = NULL;
|
||||||
|
char* offsetNew = NULL;
|
||||||
int32_t code = TDB_CODE_SUCCESS;
|
int32_t code = TDB_CODE_SUCCESS;
|
||||||
TQ_ERR_GO_TO_END(tqBuildFName(&maindb, pTq->path, TDB_MAINDB_NAME));
|
TQ_ERR_GO_TO_END(tqBuildFName(&maindb, pTq->path, TDB_MAINDB_NAME));
|
||||||
if(!taosCheckExistFile(maindb)){
|
if(!taosCheckExistFile(maindb)){
|
||||||
|
|
@ -416,12 +417,20 @@ int32_t tqMetaOpen(STQ* pTq) {
|
||||||
TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq));
|
TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq));
|
||||||
}else{
|
}else{
|
||||||
TQ_ERR_GO_TO_END(tqMetaTransform(pTq));
|
TQ_ERR_GO_TO_END(tqMetaTransform(pTq));
|
||||||
taosRemoveFile(maindb);
|
(void)taosRemoveFile(maindb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
|
||||||
|
if(taosCheckExistFile(offsetNew)){
|
||||||
|
TQ_ERR_GO_TO_END(tqOffsetRestoreFromFile(pTq, offsetNew));
|
||||||
|
(void)taosRemoveFile(offsetNew);
|
||||||
|
}
|
||||||
|
|
||||||
TQ_ERR_GO_TO_END(tqMetaRestoreCheckInfo(pTq));
|
TQ_ERR_GO_TO_END(tqMetaRestoreCheckInfo(pTq));
|
||||||
|
|
||||||
END:
|
END:
|
||||||
taosMemoryFree(maindb);
|
taosMemoryFree(maindb);
|
||||||
|
taosMemoryFree(offsetNew);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,13 +454,13 @@ int32_t tqMetaTransform(STQ* pTq) {
|
||||||
TQ_ERR_GO_TO_END(tqMetaTransformInfo(pTq->pMetaDB, pCheckStore, pTq->pCheckStore));
|
TQ_ERR_GO_TO_END(tqMetaTransformInfo(pTq->pMetaDB, pCheckStore, pTq->pCheckStore));
|
||||||
|
|
||||||
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
|
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
|
||||||
if(taosCheckExistFile(offset) && taosCopyFile(offset, offsetNew) < 0){
|
if(taosCheckExistFile(offset)) {
|
||||||
|
if (taosCopyFile(offset, offsetNew) < 0) {
|
||||||
tqError("copy offset file error");
|
tqError("copy offset file error");
|
||||||
}
|
} else {
|
||||||
|
|
||||||
TQ_ERR_GO_TO_END(tqMetaTransformOffsetInfo(pTq, offsetNew));
|
|
||||||
(void)taosRemoveFile(offset);
|
(void)taosRemoveFile(offset);
|
||||||
(void)taosRemoveFile(offsetNew);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
END:
|
END:
|
||||||
taosMemoryFree(offset);
|
taosMemoryFree(offset);
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
|
||||||
}
|
}
|
||||||
TQ_ERR_GO_TO_END(tqMetaSaveInfo(pTq, pTq->pOffsetStore, offset.subKey, strlen(offset.subKey), pMemBuf, size));
|
TQ_ERR_GO_TO_END(tqMetaSaveInfo(pTq, pTq->pOffsetStore, offset.subKey, strlen(offset.subKey), pMemBuf, size));
|
||||||
|
|
||||||
|
tqInfo("tq: offset restore from file to tdb, subkey:%s", offset.subKey);
|
||||||
taosMemoryFree(pMemBuf);
|
taosMemoryFree(pMemBuf);
|
||||||
pMemBuf = NULL;
|
pMemBuf = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -365,6 +365,7 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
||||||
code = streamTrySchedExec(pTask);
|
code = streamTrySchedExec(pTask);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
streamMetaReleaseTask(pStreamMeta, pTask);
|
streamMetaReleaseTask(pStreamMeta, pTask);
|
||||||
|
taosArrayDestroy(pTaskList);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,12 @@ _exit:
|
||||||
static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) {
|
static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
TdFilePtr pFD = NULL;
|
||||||
|
uint8_t *pData = NULL;
|
||||||
|
|
||||||
// encode to binary
|
// encode to binary
|
||||||
int32_t size = tsdbFSToBinary(NULL, pFS) + sizeof(TSCKSUM);
|
int32_t size = tsdbFSToBinary(NULL, pFS) + sizeof(TSCKSUM);
|
||||||
uint8_t *pData = taosMemoryMalloc(size);
|
pData = taosMemoryMalloc(size);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
@ -104,32 +106,26 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) {
|
||||||
taosCalcChecksumAppend(0, pData, size);
|
taosCalcChecksumAppend(0, pData, size);
|
||||||
|
|
||||||
// save to file
|
// save to file
|
||||||
TdFilePtr pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFD == NULL) {
|
if (pFD == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t n = taosWriteFile(pFD, pData, size);
|
int64_t n = taosWriteFile(pFD, pData, size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
taosCloseFile(&pFD);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(pFD) < 0) {
|
if (taosFsyncFile(pFD) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
taosCloseFile(&pFD);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFD);
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (pData) taosMemoryFree(pData);
|
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
|
tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
|
||||||
}
|
}
|
||||||
|
taosMemoryFree(pData);
|
||||||
|
taosCloseFile(&pFD);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,11 +176,6 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (size != tsdbLogicToFileSize(pTsdb->fs.pDelFile->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
|
||||||
// code = TSDB_CODE_FILE_CORRUPTED;
|
|
||||||
// TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SArray<SDFileSet>
|
// SArray<SDFileSet>
|
||||||
|
|
@ -327,17 +318,15 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) {
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFD);
|
|
||||||
|
|
||||||
// decode binary
|
|
||||||
code = tsdbBinaryToFS(pData, size, pFS);
|
code = tsdbBinaryToFS(pData, size, pFS);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (pData) taosMemoryFree(pData);
|
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
|
tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
|
||||||
}
|
}
|
||||||
|
taosMemoryFree(pData);
|
||||||
|
taosCloseFile(&pFD);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -383,7 +372,11 @@ static int32_t tsdbNewFileSet(STsdb *pTsdb, SDFileSet *pSetTo, SDFileSet *pSetFr
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
*pSetTo = (SDFileSet){.diskId = pSetFrom->diskId, .fid = pSetFrom->fid, .nSttF = 0};
|
*pSetTo = (SDFileSet){
|
||||||
|
.diskId = pSetFrom->diskId,
|
||||||
|
.fid = pSetFrom->fid,
|
||||||
|
.nSttF = 0,
|
||||||
|
};
|
||||||
|
|
||||||
// head
|
// head
|
||||||
pSetTo->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
pSetTo->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,9 @@ static const char *gCurrentFname[] = {
|
||||||
|
|
||||||
static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) {
|
static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) {
|
||||||
fs[0] = taosMemoryCalloc(1, sizeof(*fs[0]));
|
fs[0] = taosMemoryCalloc(1, sizeof(*fs[0]));
|
||||||
if (fs[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (fs[0] == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
fs[0]->tsdb = pTsdb;
|
fs[0]->tsdb = pTsdb;
|
||||||
tsem_init(&fs[0]->canEdit, 0, 1);
|
tsem_init(&fs[0]->canEdit, 0, 1);
|
||||||
|
|
@ -76,68 +78,74 @@ int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
|
||||||
|
|
||||||
static int32_t save_json(const cJSON *json, const char *fname) {
|
static int32_t save_json(const cJSON *json, const char *fname) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
|
char *data = NULL;
|
||||||
|
TdFilePtr fp = NULL;
|
||||||
|
|
||||||
char *data = cJSON_PrintUnformatted(json);
|
data = cJSON_PrintUnformatted(json);
|
||||||
if (data == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (data == NULL) {
|
||||||
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
TdFilePtr fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(code);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(fp, data, strlen(data)) < 0) {
|
if (taosWriteFile(fp, data, strlen(data)) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(code);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(fp) < 0) {
|
if (taosFsyncFile(fp) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(code);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&fp);
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
tsdbError("%s failed at %s:%d since %s", __func__, fname, __LINE__, tstrerror(code));
|
||||||
|
}
|
||||||
taosMemoryFree(data);
|
taosMemoryFree(data);
|
||||||
|
taosCloseFile(&fp);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t load_json(const char *fname, cJSON **json) {
|
static int32_t load_json(const char *fname, cJSON **json) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
|
|
||||||
TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ);
|
TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ);
|
||||||
if (fp == NULL) return TAOS_SYSTEM_ERROR(code);
|
if (fp == NULL) {
|
||||||
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
int64_t size;
|
int64_t size;
|
||||||
if (taosFStatFile(fp, &size, NULL) < 0) {
|
if (taosFStatFile(fp, &size, NULL) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(code);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = taosMemoryMalloc(size + 1);
|
data = taosMemoryMalloc(size + 1);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(fp, data, size) < 0) {
|
if (taosReadFile(fp, data, size) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(code);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
data[size] = '\0';
|
data[size] = '\0';
|
||||||
|
|
||||||
json[0] = cJSON_Parse(data);
|
json[0] = cJSON_Parse(data);
|
||||||
if (json[0] == NULL) {
|
if (json[0] == NULL) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
tsdbError("%s failed at %s:%d since %s", __func__, fname, __LINE__, tstrerror(code));
|
||||||
|
json[0] = NULL;
|
||||||
|
}
|
||||||
taosCloseFile(&fp);
|
taosCloseFile(&fp);
|
||||||
if (data) taosMemoryFree(data);
|
taosMemoryFree(data);
|
||||||
if (code) json[0] = NULL;
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,26 +154,25 @@ int32_t save_fs(const TFileSetArray *arr, const char *fname) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
cJSON *json = cJSON_CreateObject();
|
cJSON *json = cJSON_CreateObject();
|
||||||
if (!json) return TSDB_CODE_OUT_OF_MEMORY;
|
if (json == NULL) {
|
||||||
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
// fmtv
|
// fmtv
|
||||||
if (cJSON_AddNumberToObject(json, "fmtv", 1) == NULL) {
|
if (cJSON_AddNumberToObject(json, "fmtv", 1) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fset
|
// fset
|
||||||
cJSON *ajson = cJSON_AddArrayToObject(json, "fset");
|
cJSON *ajson = cJSON_AddArrayToObject(json, "fset");
|
||||||
if (!ajson) {
|
if (!ajson) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
const STFileSet *fset;
|
const STFileSet *fset;
|
||||||
TARRAY2_FOREACH(arr, fset) {
|
TARRAY2_FOREACH(arr, fset) {
|
||||||
cJSON *item = cJSON_CreateObject();
|
cJSON *item = cJSON_CreateObject();
|
||||||
if (!item) {
|
if (!item) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
cJSON_AddItemToArray(ajson, item);
|
cJSON_AddItemToArray(ajson, item);
|
||||||
|
|
||||||
|
|
@ -226,14 +233,17 @@ static int32_t load_fs(STsdb *pTsdb, const char *fname, TFileSetArray *arr) {
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
|
tsdbError("%s failed at %sP%d since %s, fname:%s", __func__, __FILE__, lino, tstrerror(code), fname);
|
||||||
|
}
|
||||||
|
if (json) {
|
||||||
|
cJSON_Delete(json);
|
||||||
}
|
}
|
||||||
if (json) cJSON_Delete(json);
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t apply_commit(STFileSystem *fs) {
|
static int32_t apply_commit(STFileSystem *fs) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
TFileSetArray *fsetArray1 = fs->fSetArr;
|
TFileSetArray *fsetArray1 = fs->fSetArr;
|
||||||
TFileSetArray *fsetArray2 = fs->fSetArrTmp;
|
TFileSetArray *fsetArray2 = fs->fSetArrTmp;
|
||||||
int32_t i1 = 0, i2 = 0;
|
int32_t i1 = 0, i2 = 0;
|
||||||
|
|
@ -250,15 +260,15 @@ static int32_t apply_commit(STFileSystem *fs) {
|
||||||
} else if (fset1->fid > fset2->fid) {
|
} else if (fset1->fid > fset2->fid) {
|
||||||
// create new file set with fid of fset2->fid
|
// create new file set with fid of fset2->fid
|
||||||
code = tsdbTFileSetInitCopy(fs->tsdb, fset2, &fset1);
|
code = tsdbTFileSetInitCopy(fs->tsdb, fset2, &fset1);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
code = TARRAY2_SORT_INSERT(fsetArray1, fset1, tsdbTFileSetCmprFn);
|
code = TARRAY2_SORT_INSERT(fsetArray1, fset1, tsdbTFileSetCmprFn);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
i1++;
|
i1++;
|
||||||
i2++;
|
i2++;
|
||||||
} else {
|
} else {
|
||||||
// edit
|
// edit
|
||||||
code = tsdbTFileSetApplyEdit(fs->tsdb, fset2, fset1);
|
code = tsdbTFileSetApplyEdit(fs->tsdb, fset2, fset1);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
i1++;
|
i1++;
|
||||||
i2++;
|
i2++;
|
||||||
}
|
}
|
||||||
|
|
@ -269,15 +279,19 @@ static int32_t apply_commit(STFileSystem *fs) {
|
||||||
} else {
|
} else {
|
||||||
// create new file set with fid of fset2->fid
|
// create new file set with fid of fset2->fid
|
||||||
code = tsdbTFileSetInitCopy(fs->tsdb, fset2, &fset1);
|
code = tsdbTFileSetInitCopy(fs->tsdb, fset2, &fset1);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
code = TARRAY2_SORT_INSERT(fsetArray1, fset1, tsdbTFileSetCmprFn);
|
code = TARRAY2_SORT_INSERT(fsetArray1, fset1, tsdbTFileSetCmprFn);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
i1++;
|
i1++;
|
||||||
i2++;
|
i2++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(fs->tsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t commit_edit(STFileSystem *fs) {
|
static int32_t commit_edit(STFileSystem *fs) {
|
||||||
|
|
@ -303,7 +317,8 @@ static int32_t commit_edit(STFileSystem *fs) {
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(fs->tsdb->pVnode), __func__, lino, tstrerror(code));
|
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(fs->tsdb->pVnode), __func__, __FILE__, lino,
|
||||||
|
tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
tsdbInfo("vgId:%d %s success, etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype);
|
tsdbInfo("vgId:%d %s success, etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype);
|
||||||
}
|
}
|
||||||
|
|
@ -335,7 +350,8 @@ static int32_t abort_edit(STFileSystem *fs) {
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("vgId:%d %s failed since %s", TD_VID(fs->tsdb->pVnode), __func__, tstrerror(code));
|
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(fs->tsdb->pVnode), __func__, __FILE__, lino,
|
||||||
|
tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
tsdbInfo("vgId:%d %s success, etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype);
|
tsdbInfo("vgId:%d %s success, etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype);
|
||||||
}
|
}
|
||||||
|
|
@ -360,13 +376,6 @@ static int32_t tsdbFSDoScanAndFixFile(STFileSystem *fs, const STFileObj *fobj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
/*
|
|
||||||
const char *object_name = taosDirEntryBaseName((char *)fobj->fname);
|
|
||||||
long s3_size = s3Size(object_name);
|
|
||||||
if (s3_size > 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|
@ -376,16 +385,6 @@ static int32_t tsdbFSDoScanAndFixFile(STFileSystem *fs, const STFileObj *fobj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // TODO: check file size
|
|
||||||
// int64_t fsize;
|
|
||||||
// if (taosStatFile(fobj->fname, &fsize, NULL, NULL) < 0) {
|
|
||||||
// code = TAOS_SYSTEM_ERROR(terrno);
|
|
||||||
// tsdbError("vgId:%d %s failed since file:%s stat failed, reason:%s", TD_VID(fs->tsdb->pVnode), __func__,
|
|
||||||
// fobj->fname, tstrerror(code));
|
|
||||||
// return code;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,6 +407,7 @@ static int32_t tsdbFSAddEntryToFileObjHash(STFileHash *hash, const char *fname)
|
||||||
|
|
||||||
static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) {
|
static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
char fname[TSDB_FILENAME_LEN];
|
char fname[TSDB_FILENAME_LEN];
|
||||||
|
|
||||||
// init hash table
|
// init hash table
|
||||||
|
|
@ -415,14 +415,13 @@ static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) {
|
||||||
hash->numBucket = 4096;
|
hash->numBucket = 4096;
|
||||||
hash->buckets = taosMemoryCalloc(hash->numBucket, sizeof(STFileHashEntry *));
|
hash->buckets = taosMemoryCalloc(hash->numBucket, sizeof(STFileHashEntry *));
|
||||||
if (hash->buckets == NULL) {
|
if (hash->buckets == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vnode.json
|
// vnode.json
|
||||||
current_fname(fs->tsdb, fname, TSDB_FCURRENT);
|
current_fname(fs->tsdb, fname, TSDB_FCURRENT);
|
||||||
code = tsdbFSAddEntryToFileObjHash(hash, fname);
|
code = tsdbFSAddEntryToFileObjHash(hash, fname);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// other
|
// other
|
||||||
STFileSet *fset = NULL;
|
STFileSet *fset = NULL;
|
||||||
|
|
@ -431,7 +430,7 @@ static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) {
|
||||||
for (int32_t i = 0; i < TSDB_FTYPE_MAX; i++) {
|
for (int32_t i = 0; i < TSDB_FTYPE_MAX; i++) {
|
||||||
if (fset->farr[i] != NULL) {
|
if (fset->farr[i] != NULL) {
|
||||||
code = tsdbFSAddEntryToFileObjHash(hash, fset->farr[i]->fname);
|
code = tsdbFSAddEntryToFileObjHash(hash, fset->farr[i]->fname);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,13 +440,14 @@ static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) {
|
||||||
STFileObj *fobj;
|
STFileObj *fobj;
|
||||||
TARRAY2_FOREACH(lvl->fobjArr, fobj) {
|
TARRAY2_FOREACH(lvl->fobjArr, fobj) {
|
||||||
code = tsdbFSAddEntryToFileObjHash(hash, fobj->fname);
|
code = tsdbFSAddEntryToFileObjHash(hash, fobj->fname);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(fs->tsdb->pVnode), lino, code);
|
||||||
tsdbFSDestroyFileObjHash(hash);
|
tsdbFSDestroyFileObjHash(hash);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ int32_t tsdbFSetRAWWriterOpen(SFSetRAWWriterConfig *config, SFSetRAWWriter **wri
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
writer[0] = taosMemoryCalloc(1, sizeof(SFSetRAWWriter));
|
writer[0] = taosMemoryCalloc(1, sizeof(SFSetRAWWriter));
|
||||||
if (writer[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (writer[0] == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
writer[0]->config[0] = config[0];
|
writer[0]->config[0] = config[0];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,10 @@ static int32_t tsdbFSetWriteTableDataBegin(SFSetWriter *writer, const TABLEID *t
|
||||||
writer->ctx->tbid->uid = tbid->uid;
|
writer->ctx->tbid->uid = tbid->uid;
|
||||||
|
|
||||||
code = tsdbUpdateSkmTb(writer->config->tsdb, writer->ctx->tbid, writer->skmTb);
|
code = tsdbUpdateSkmTb(writer->config->tsdb, writer->ctx->tbid, writer->skmTb);
|
||||||
|
TSDB_CHECK_CODE(code , lino, _exit);
|
||||||
|
|
||||||
code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, tbid->suid ? tbid->suid : tbid->uid, &writer->pColCmprObj);
|
code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, tbid->suid ? tbid->suid : tbid->uid, &writer->pColCmprObj);
|
||||||
// TSDB_CHECK_CODE(code, lino, _exit);
|
// TODO: TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
writer->blockDataIdx = 0;
|
writer->blockDataIdx = 0;
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(writer->blockData); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(writer->blockData); i++) {
|
||||||
|
|
@ -136,7 +137,9 @@ int32_t tsdbFSetWriterOpen(SFSetWriterConfig *config, SFSetWriter **writer) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
writer[0] = taosMemoryCalloc(1, sizeof(*writer[0]));
|
writer[0] = taosMemoryCalloc(1, sizeof(*writer[0]));
|
||||||
if (writer[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (writer[0] == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
writer[0]->config[0] = config[0];
|
writer[0]->config[0] = config[0];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4648,7 +4648,8 @@ void tsdbReaderClose2(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReader->resBlockInfo.freeBlock) {
|
if (pReader->resBlockInfo.freeBlock) {
|
||||||
pReader->resBlockInfo.pResBlock = blockDataDestroy(pReader->resBlockInfo.pResBlock);
|
blockDataDestroy(pReader->resBlockInfo.pResBlock);
|
||||||
|
pReader->resBlockInfo.pResBlock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(pSupInfo->colId);
|
taosMemoryFree(pSupInfo->colId);
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,12 @@
|
||||||
#include "cos.h"
|
#include "cos.h"
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
|
#include "tsdbDef.h"
|
||||||
#include "vnd.h"
|
#include "vnd.h"
|
||||||
|
|
||||||
static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
const char *path = pFD->path;
|
const char *path = pFD->path;
|
||||||
int32_t szPage = pFD->szPage;
|
int32_t szPage = pFD->szPage;
|
||||||
int32_t flag = pFD->flag;
|
int32_t flag = pFD->flag;
|
||||||
|
|
@ -38,70 +40,27 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
||||||
char *dot = strrchr(lc_path, '.');
|
char *dot = strrchr(lc_path, '.');
|
||||||
if (!dot) {
|
if (!dot) {
|
||||||
tsdbError("unexpected path: %s", lc_path);
|
tsdbError("unexpected path: %s", lc_path);
|
||||||
code = TAOS_SYSTEM_ERROR(ENOENT);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(ENOENT), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", pFD->lcn);
|
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", pFD->lcn);
|
||||||
|
|
||||||
pFD->pFD = taosOpenFile(lc_path, flag);
|
pFD->pFD = taosOpenFile(lc_path, flag);
|
||||||
if (pFD->pFD == NULL) {
|
if (pFD->pFD == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
// taosMemoryFree(pFD);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) {
|
if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
// taosCloseFile(&pFD->pFD);
|
|
||||||
// taosMemoryFree(pFD);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tsdbInfo("no file: %s", path);
|
tsdbInfo("no file: %s", path);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
// taosMemoryFree(pFD);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
pFD->s3File = 1;
|
pFD->s3File = 1;
|
||||||
/*
|
|
||||||
const char *object_name = taosDirEntryBaseName((char *)path);
|
|
||||||
long s3_size = 0;
|
|
||||||
if (tsS3Enabled) {
|
|
||||||
long size = s3Size(object_name);
|
|
||||||
if (size < 0) {
|
|
||||||
code = terrno = TSDB_CODE_FAILED_TO_CONNECT_S3;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
s3_size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsS3Enabled && !strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) {
|
|
||||||
#ifndef S3_BLOCK_CACHE
|
|
||||||
s3EvictCache(path, s3_size);
|
|
||||||
s3Get(object_name, path);
|
|
||||||
|
|
||||||
pFD->pFD = taosOpenFile(path, flag);
|
|
||||||
if (pFD->pFD == NULL) {
|
|
||||||
code = TAOS_SYSTEM_ERROR(ENOENT);
|
|
||||||
// taosMemoryFree(pFD);
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
pFD->pFD = (TdFilePtr)&pFD->s3File;
|
|
||||||
int32_t vid = 0;
|
|
||||||
sscanf(object_name, "v%df%dver%" PRId64 ".data", &vid, &pFD->fid, &pFD->cid);
|
|
||||||
pFD->objName = object_name;
|
|
||||||
// pFD->szFile = s3_size;
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFD->pBuf = taosMemoryCalloc(1, szPage);
|
pFD->pBuf = taosMemoryCalloc(1, szPage);
|
||||||
if (pFD->pBuf == NULL) {
|
if (pFD->pBuf == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
// taosCloseFile(&pFD->pFD);
|
|
||||||
// taosMemoryFree(pFD);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lc_size > 0) {
|
if (lc_size > 0) {
|
||||||
|
|
@ -114,11 +73,7 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
||||||
// not check file size when reading data files.
|
// not check file size when reading data files.
|
||||||
if (flag != TD_FILE_READ /* && !pFD->s3File*/) {
|
if (flag != TD_FILE_READ /* && !pFD->s3File*/) {
|
||||||
if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
|
if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
// taosMemoryFree(pFD->pBuf);
|
|
||||||
// taosCloseFile(&pFD->pFD);
|
|
||||||
// taosMemoryFree(pFD);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,12 +81,16 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
||||||
pFD->szFile = pFD->szFile / szPage;
|
pFD->szFile = pFD->szFile / szPage;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== PAGE-WISE FILE ===============
|
// =============== PAGE-WISE FILE ===============
|
||||||
int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppFD, int32_t lcn) {
|
int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppFD, int32_t lcn) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
STsdbFD *pFD = NULL;
|
STsdbFD *pFD = NULL;
|
||||||
int32_t szPage = pTsdb->pVnode->config.tsdbPageSize;
|
int32_t szPage = pTsdb->pVnode->config.tsdbPageSize;
|
||||||
|
|
||||||
|
|
@ -139,8 +98,7 @@ int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppF
|
||||||
|
|
||||||
pFD = (STsdbFD *)taosMemoryCalloc(1, sizeof(*pFD) + strlen(path) + 1);
|
pFD = (STsdbFD *)taosMemoryCalloc(1, sizeof(*pFD) + strlen(path) + 1);
|
||||||
if (pFD == NULL) {
|
if (pFD == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFD->path = (char *)&pFD[1];
|
pFD->path = (char *)&pFD[1];
|
||||||
|
|
@ -155,6 +113,9 @@ int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppF
|
||||||
*ppFD = pFD;
|
*ppFD = pFD;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,12 +133,11 @@ void tsdbCloseFile(STsdbFD **ppFD) {
|
||||||
|
|
||||||
static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *encryptKey) {
|
static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *encryptKey) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
|
|
||||||
if (!pFD->pFD) {
|
if (!pFD->pFD) {
|
||||||
code = tsdbOpenFileImpl(pFD);
|
code = tsdbOpenFileImpl(pFD);
|
||||||
if (code) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFD->pgno > 0) {
|
if (pFD->pgno > 0) {
|
||||||
|
|
@ -193,8 +153,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
|
||||||
|
|
||||||
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
|
taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
|
||||||
|
|
@ -223,8 +182,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
|
||||||
|
|
||||||
n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFD->szFile < pFD->pgno) {
|
if (pFD->szFile < pFD->pgno) {
|
||||||
|
|
@ -234,18 +192,20 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
|
||||||
pFD->pgno = 0;
|
pFD->pgno = 0;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgorithm, char *encryptKey) {
|
static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgorithm, char *encryptKey) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
|
|
||||||
// ASSERT(pgno <= pFD->szFile);
|
// ASSERT(pgno <= pFD->szFile);
|
||||||
if (!pFD->pFD) {
|
if (!pFD->pFD) {
|
||||||
code = tsdbOpenFileImpl(pFD);
|
code = tsdbOpenFileImpl(pFD);
|
||||||
if (code) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t offset = PAGE_OFFSET(pgno, pFD->szPage);
|
int64_t offset = PAGE_OFFSET(pgno, pFD->szPage);
|
||||||
|
|
@ -257,43 +217,19 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor
|
||||||
offset -= chunkoffset;
|
offset -= chunkoffset;
|
||||||
}
|
}
|
||||||
ASSERT(offset >= 0);
|
ASSERT(offset >= 0);
|
||||||
/*
|
|
||||||
if (pFD->s3File) {
|
|
||||||
LRUHandle *handle = NULL;
|
|
||||||
|
|
||||||
pFD->blkno = (pgno + tsS3BlockSize - 1) / tsS3BlockSize;
|
|
||||||
code = tsdbCacheGetBlockS3(pFD->pTsdb->bCache, pFD, &handle);
|
|
||||||
if (code != TSDB_CODE_SUCCESS || handle == NULL) {
|
|
||||||
tsdbCacheRelease(pFD->pTsdb->bCache, handle);
|
|
||||||
if (code == TSDB_CODE_SUCCESS && !handle) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *pBlock = (uint8_t *)taosLRUCacheValue(pFD->pTsdb->bCache, handle);
|
|
||||||
|
|
||||||
int64_t blk_offset = (pFD->blkno - 1) * tsS3BlockSize * pFD->szPage;
|
|
||||||
memcpy(pFD->pBuf, pBlock + (offset - blk_offset), pFD->szPage);
|
|
||||||
|
|
||||||
tsdbCacheRelease(pFD->pTsdb->bCache, handle);
|
|
||||||
} else {
|
|
||||||
*/
|
|
||||||
// seek
|
// seek
|
||||||
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read
|
// read
|
||||||
n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
} else if (n < pFD->szPage) {
|
} else if (n < pFD->szPage) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
@ -322,19 +258,22 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
|
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFD->pgno = pgno;
|
pFD->pgno = pgno;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
|
int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
|
||||||
char *encryptKey) {
|
char *encryptKey) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
||||||
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
|
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
|
||||||
int64_t bOffset = fOffset % pFD->szPage;
|
int64_t bOffset = fOffset % pFD->szPage;
|
||||||
|
|
@ -343,11 +282,11 @@ int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t
|
||||||
do {
|
do {
|
||||||
if (pFD->pgno != pgno) {
|
if (pFD->pgno != pgno) {
|
||||||
code = tsdbWriteFilePage(pFD, encryptAlgorithm, encryptKey);
|
code = tsdbWriteFilePage(pFD, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
if (pgno <= pFD->szFile) {
|
if (pgno <= pFD->szFile) {
|
||||||
code = tsdbReadFilePage(pFD, pgno, encryptAlgorithm, encryptKey);
|
code = tsdbReadFilePage(pFD, pgno, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
} else {
|
} else {
|
||||||
pFD->pgno = pgno;
|
pFD->pgno = pgno;
|
||||||
}
|
}
|
||||||
|
|
@ -362,12 +301,16 @@ int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t
|
||||||
} while (n < size);
|
} while (n < size);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbReadFileImp(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
|
static int32_t tsdbReadFileImp(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
|
||||||
char *encryptKey) {
|
char *encryptKey) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
int64_t n = 0;
|
int64_t n = 0;
|
||||||
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
||||||
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
|
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
|
||||||
|
|
@ -380,7 +323,7 @@ static int32_t tsdbReadFileImp(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int6
|
||||||
while (n < size) {
|
while (n < size) {
|
||||||
if (pFD->pgno != pgno) {
|
if (pFD->pgno != pgno) {
|
||||||
code = tsdbReadFilePage(pFD, pgno, encryptAlgorithm, encryptKey);
|
code = tsdbReadFilePage(pFD, pgno, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t nRead = TMIN(szPgCont - bOffset, size - n);
|
int64_t nRead = TMIN(szPgCont - bOffset, size - n);
|
||||||
|
|
@ -392,15 +335,20 @@ static int32_t tsdbReadFileImp(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int6
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, bool check, uint8_t **ppBlock) {
|
static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, bool check, uint8_t **ppBlock) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
SVnodeCfg *pCfg = &pFD->pTsdb->pVnode->config;
|
SVnodeCfg *pCfg = &pFD->pTsdb->pVnode->config;
|
||||||
int64_t chunksize = (int64_t)pCfg->tsdbPageSize * pCfg->s3ChunkSize;
|
int64_t chunksize = (int64_t)pCfg->tsdbPageSize * pCfg->s3ChunkSize;
|
||||||
int64_t cOffset = offset % chunksize;
|
int64_t cOffset = offset % chunksize;
|
||||||
int64_t n = 0;
|
int64_t n = 0;
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
char *object_name = taosDirEntryBaseName(pFD->path);
|
char *object_name = taosDirEntryBaseName(pFD->path);
|
||||||
char object_name_prefix[TSDB_FILENAME_LEN];
|
char object_name_prefix[TSDB_FILENAME_LEN];
|
||||||
|
|
@ -410,11 +358,13 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo
|
||||||
char *dot = strrchr(object_name_prefix, '.');
|
char *dot = strrchr(object_name_prefix, '.');
|
||||||
if (!dot) {
|
if (!dot) {
|
||||||
tsdbError("unexpected path: %s", object_name_prefix);
|
tsdbError("unexpected path: %s", object_name_prefix);
|
||||||
code = TAOS_SYSTEM_ERROR(ENOENT);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(ENOENT), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buf = taosMemoryCalloc(1, size);
|
buf = taosMemoryCalloc(1, size);
|
||||||
|
if (buf == NULL) {
|
||||||
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t chunkno = offset / chunksize + 1; n < size; ++chunkno) {
|
for (int32_t chunkno = offset / chunksize + 1; n < size; ++chunkno) {
|
||||||
int64_t nRead = TMIN(chunksize - cOffset, size - n);
|
int64_t nRead = TMIN(chunksize - cOffset, size - n);
|
||||||
|
|
@ -423,20 +373,14 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo
|
||||||
// read last chunk
|
// read last chunk
|
||||||
int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET);
|
int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
taosMemoryFree(buf);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = taosReadFile(pFD->pFD, buf + n, nRead);
|
ret = taosReadFile(pFD->pFD, buf + n, nRead);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
taosMemoryFree(buf);
|
|
||||||
goto _exit;
|
|
||||||
} else if (ret < nRead) {
|
} else if (ret < nRead) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
taosMemoryFree(buf);
|
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint8_t *pBlock = NULL;
|
uint8_t *pBlock = NULL;
|
||||||
|
|
@ -444,10 +388,7 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo
|
||||||
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - object_name_prefix), "%d.data", chunkno);
|
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - object_name_prefix), "%d.data", chunkno);
|
||||||
|
|
||||||
code = s3GetObjectBlock(object_name_prefix, cOffset, nRead, check, &pBlock);
|
code = s3GetObjectBlock(object_name_prefix, cOffset, nRead, check, &pBlock);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
taosMemoryFree(buf);
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(buf + n, pBlock, nRead);
|
memcpy(buf + n, pBlock, nRead);
|
||||||
taosMemoryFree(pBlock);
|
taosMemoryFree(pBlock);
|
||||||
|
|
@ -457,14 +398,19 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo
|
||||||
cOffset = 0;
|
cOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppBlock = buf;
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
} else {
|
||||||
|
*ppBlock = (uint8_t *)buf;
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint) {
|
static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
int64_t n = 0;
|
int64_t n = 0;
|
||||||
int32_t szPgCont = PAGE_CONTENT_SIZE(pFD->szPage);
|
int32_t szPgCont = PAGE_CONTENT_SIZE(pFD->szPage);
|
||||||
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
|
||||||
|
|
@ -486,7 +432,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64
|
||||||
if (handle) {
|
if (handle) {
|
||||||
tsdbCacheRelease(pFD->pTsdb->pgCache, handle);
|
tsdbCacheRelease(pFD->pTsdb->pgCache, handle);
|
||||||
}
|
}
|
||||||
goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
|
|
@ -499,8 +445,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
|
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFD->pgno = pgno;
|
pFD->pgno = pgno;
|
||||||
|
|
@ -525,16 +470,9 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t retrieve_size = (pgnoEnd - pgno + 1) * pFD->szPage;
|
int64_t retrieve_size = (pgnoEnd - pgno + 1) * pFD->szPage;
|
||||||
/*
|
|
||||||
code = s3GetObjectBlock(pFD->objName, retrieve_offset, retrieve_size, 1, &pBlock);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
code = tsdbReadFileBlock(pFD, retrieve_offset, retrieve_size, 1, &pBlock);
|
code = tsdbReadFileBlock(pFD, retrieve_offset, retrieve_size, 1, &pBlock);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
// 3, Store Pages in Cache
|
// 3, Store Pages in Cache
|
||||||
int nPage = pgnoEnd - pgno + 1;
|
int nPage = pgnoEnd - pgno + 1;
|
||||||
for (int i = 0; i < nPage; ++i) {
|
for (int i = 0; i < nPage; ++i) {
|
||||||
|
|
@ -550,8 +488,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
|
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pFD->pgno = pgno;
|
pFD->pgno = pgno;
|
||||||
|
|
@ -568,59 +505,72 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint,
|
int32_t tsdbReadFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint,
|
||||||
int32_t encryptAlgorithm, char *encryptKey) {
|
int32_t encryptAlgorithm, char *encryptKey) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
|
|
||||||
if (!pFD->pFD) {
|
if (!pFD->pFD) {
|
||||||
code = tsdbOpenFileImpl(pFD);
|
code = tsdbOpenFileImpl(pFD);
|
||||||
if (code) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFD->s3File && pFD->lcn > 1 /* && tsS3BlockSize < 0*/) {
|
if (pFD->s3File && pFD->lcn > 1 /* && tsS3BlockSize < 0*/) {
|
||||||
return tsdbReadFileS3(pFD, offset, pBuf, size, szHint);
|
code = tsdbReadFileS3(pFD, offset, pBuf, size, szHint);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
} else {
|
} else {
|
||||||
return tsdbReadFileImp(pFD, offset, pBuf, size, encryptAlgorithm, encryptKey);
|
code = tsdbReadFileImp(pFD, offset, pBuf, size, encryptAlgorithm, encryptKey);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadFileToBuffer(STsdbFD *pFD, int64_t offset, int64_t size, SBuffer *buffer, int64_t szHint,
|
int32_t tsdbReadFileToBuffer(STsdbFD *pFD, int64_t offset, int64_t size, SBuffer *buffer, int64_t szHint,
|
||||||
int32_t encryptAlgorithm, char *encryptKey) {
|
int32_t encryptAlgorithm, char *encryptKey) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
int32_t lino;
|
||||||
|
|
||||||
code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbReadFile(pFD, offset, (uint8_t *)tBufferGetDataEnd(buffer), size, szHint, encryptAlgorithm, encryptKey);
|
code = tsdbReadFile(pFD, offset, (uint8_t *)tBufferGetDataEnd(buffer), size, szHint, encryptAlgorithm, encryptKey);
|
||||||
if (code) return code;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
buffer->size += size;
|
buffer->size += size;
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbFsyncFile(STsdbFD *pFD, int32_t encryptAlgorithm, char *encryptKey) {
|
int32_t tsdbFsyncFile(STsdbFD *pFD, int32_t encryptAlgorithm, char *encryptKey) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
/*
|
int32_t lino;
|
||||||
if (pFD->s3File) {
|
|
||||||
tsdbWarn("%s file: %s", __func__, pFD->path);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
code = tsdbWriteFilePage(pFD, encryptAlgorithm, encryptKey);
|
code = tsdbWriteFilePage(pFD, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
if (taosFsyncFile(pFD->pFD) < 0) {
|
if (taosFsyncFile(pFD->pFD) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -635,8 +585,7 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
|
||||||
// alloc
|
// alloc
|
||||||
pReader = (SDataFReader *)taosMemoryCalloc(1, sizeof(*pReader));
|
pReader = (SDataFReader *)taosMemoryCalloc(1, sizeof(*pReader));
|
||||||
if (pReader == NULL) {
|
if (pReader == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
pReader->pTsdb = pTsdb;
|
pReader->pTsdb = pTsdb;
|
||||||
pReader->pSet = pSet;
|
pReader->pSet = pSet;
|
||||||
|
|
@ -711,22 +660,25 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) {
|
||||||
|
|
||||||
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) {
|
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
SHeadFile *pHeadFile = pReader->pSet->pHeadF;
|
SHeadFile *pHeadFile = pReader->pSet->pHeadF;
|
||||||
int64_t offset = pHeadFile->offset;
|
int64_t offset = pHeadFile->offset;
|
||||||
int64_t size = pHeadFile->size - offset;
|
int64_t size = pHeadFile->size - offset;
|
||||||
|
|
||||||
taosArrayClear(aBlockIdx);
|
taosArrayClear(aBlockIdx);
|
||||||
if (size == 0) return code;
|
if (size == 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
code = tRealloc(&pReader->aBuf[0], size);
|
code = tRealloc(&pReader->aBuf[0], size);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||||
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||||
code = tsdbReadFile(pReader->pHeadFD, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
code = tsdbReadFile(pReader->pHeadFD, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
int64_t n = 0;
|
int64_t n = 0;
|
||||||
|
|
@ -735,37 +687,39 @@ int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) {
|
||||||
n += tGetBlockIdx(pReader->aBuf[0] + n, &blockIdx);
|
n += tGetBlockIdx(pReader->aBuf[0] + n, &blockIdx);
|
||||||
|
|
||||||
if (taosArrayPush(aBlockIdx, &blockIdx) == NULL) {
|
if (taosArrayPush(aBlockIdx, &blockIdx) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSERT(n == size);
|
ASSERT(n == size);
|
||||||
|
|
||||||
return code;
|
_exit:
|
||||||
|
if (code) {
|
||||||
_err:
|
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
|
||||||
tsdbError("vgId:%d, read block idx failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk) {
|
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
SSttFile *pSttFile = pReader->pSet->aSttF[iStt];
|
SSttFile *pSttFile = pReader->pSet->aSttF[iStt];
|
||||||
int64_t offset = pSttFile->offset;
|
int64_t offset = pSttFile->offset;
|
||||||
int64_t size = pSttFile->size - offset;
|
int64_t size = pSttFile->size - offset;
|
||||||
|
|
||||||
taosArrayClear(aSttBlk);
|
taosArrayClear(aSttBlk);
|
||||||
if (size == 0) return code;
|
if (size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
code = tRealloc(&pReader->aBuf[0], size);
|
code = tRealloc(&pReader->aBuf[0], size);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||||
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||||
code = tsdbReadFile(pReader->aSttFD[iStt], offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
code = tsdbReadFile(pReader->aSttFD[iStt], offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
int64_t n = 0;
|
int64_t n = 0;
|
||||||
|
|
@ -774,46 +728,45 @@ int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk) {
|
||||||
n += tGetSttBlk(pReader->aBuf[0] + n, &sttBlk);
|
n += tGetSttBlk(pReader->aBuf[0] + n, &sttBlk);
|
||||||
|
|
||||||
if (taosArrayPush(aSttBlk, &sttBlk) == NULL) {
|
if (taosArrayPush(aSttBlk, &sttBlk) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSERT(n == size);
|
ASSERT(n == size);
|
||||||
|
|
||||||
return code;
|
_exit:
|
||||||
|
if (code) {
|
||||||
_err:
|
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
|
||||||
tsdbError("vgId:%d, read stt blk failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk) {
|
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
int64_t offset = pBlockIdx->offset;
|
int64_t offset = pBlockIdx->offset;
|
||||||
int64_t size = pBlockIdx->size;
|
int64_t size = pBlockIdx->size;
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
code = tRealloc(&pReader->aBuf[0], size);
|
code = tRealloc(&pReader->aBuf[0], size);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||||
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||||
code = tsdbReadFile(pReader->pHeadFD, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
code = tsdbReadFile(pReader->pHeadFD, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
int64_t n = tGetMapData(pReader->aBuf[0], mDataBlk);
|
int64_t n = tGetMapData(pReader->aBuf[0], mDataBlk);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _err;
|
|
||||||
}
|
}
|
||||||
ASSERT(n == size);
|
ASSERT(n == size);
|
||||||
|
|
||||||
return code;
|
_exit:
|
||||||
|
if (code) {
|
||||||
_err:
|
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
|
||||||
tsdbError("vgId:%d, read block failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -834,8 +787,7 @@ int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb
|
||||||
// alloc
|
// alloc
|
||||||
pDelFReader = (SDelFReader *)taosMemoryCalloc(1, sizeof(*pDelFReader));
|
pDelFReader = (SDelFReader *)taosMemoryCalloc(1, sizeof(*pDelFReader));
|
||||||
if (pDelFReader == NULL) {
|
if (pDelFReader == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// open impl
|
// open impl
|
||||||
|
|
@ -844,15 +796,13 @@ int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb
|
||||||
|
|
||||||
tsdbDelFileName(pTsdb, pFile, fname);
|
tsdbDelFileName(pTsdb, pFile, fname);
|
||||||
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pDelFReader->pReadH, 0);
|
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pDelFReader->pReadH, 0);
|
||||||
if (code) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
taosMemoryFree(pDelFReader);
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
*ppReader = NULL;
|
*ppReader = NULL;
|
||||||
tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
TSDB_ERROR_LOG(TD_VID(pTsdb->pVnode), lino, code);
|
||||||
|
taosMemoryFree(pDelFReader);
|
||||||
} else {
|
} else {
|
||||||
*ppReader = pDelFReader;
|
*ppReader = pDelFReader;
|
||||||
}
|
}
|
||||||
|
|
@ -881,6 +831,7 @@ int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData
|
||||||
|
|
||||||
int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer) {
|
int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
int64_t offset = pDelIdx->offset;
|
int64_t offset = pDelIdx->offset;
|
||||||
int64_t size = pDelIdx->size;
|
int64_t size = pDelIdx->size;
|
||||||
int64_t n;
|
int64_t n;
|
||||||
|
|
@ -889,13 +840,13 @@ int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelDa
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
code = tRealloc(&pReader->aBuf[0], size);
|
code = tRealloc(&pReader->aBuf[0], size);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||||
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||||
code = tsdbReadFile(pReader->pReadH, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
code = tsdbReadFile(pReader->pReadH, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// // decode
|
// // decode
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
@ -907,22 +858,22 @@ int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelDa
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (taosArrayPush(aDelData, &delData) == NULL) {
|
if (taosArrayPush(aDelData, &delData) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(n == size);
|
ASSERT(n == size);
|
||||||
|
|
||||||
return code;
|
_exit:
|
||||||
|
if (code) {
|
||||||
_err:
|
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
|
||||||
tsdbError("vgId:%d, read del data failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx) {
|
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino;
|
||||||
int32_t n;
|
int32_t n;
|
||||||
int64_t offset = pReader->fDel.offset;
|
int64_t offset = pReader->fDel.offset;
|
||||||
int64_t size = pReader->fDel.size - offset;
|
int64_t size = pReader->fDel.size - offset;
|
||||||
|
|
@ -931,13 +882,13 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx) {
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
code = tRealloc(&pReader->aBuf[0], size);
|
code = tRealloc(&pReader->aBuf[0], size);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||||
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||||
code = tsdbReadFile(pReader->pReadH, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
code = tsdbReadFile(pReader->pReadH, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
|
||||||
if (code) goto _err;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
@ -947,16 +898,15 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx) {
|
||||||
n += tGetDelIdx(pReader->aBuf[0] + n, &delIdx);
|
n += tGetDelIdx(pReader->aBuf[0] + n, &delIdx);
|
||||||
|
|
||||||
if (taosArrayPush(aDelIdx, &delIdx) == NULL) {
|
if (taosArrayPush(aDelIdx, &delIdx) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
goto _err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(n == size);
|
ASSERT(n == size);
|
||||||
|
|
||||||
return code;
|
_exit:
|
||||||
|
if (code) {
|
||||||
_err:
|
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
|
||||||
tsdbError("vgId:%d, read del idx failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,10 +190,10 @@ static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) {
|
||||||
task->prev->next = task->next;
|
task->prev->next = task->next;
|
||||||
task->next->prev = task->prev;
|
task->next->prev = task->prev;
|
||||||
if (task->cancel) {
|
if (task->cancel) {
|
||||||
taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
TAOS_UNUSED(taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
||||||
.cancel = task->cancel,
|
.cancel = task->cancel,
|
||||||
.arg = task->arg,
|
.arg = task->arg,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
vnodeAsyncTaskDone(async, task);
|
vnodeAsyncTaskDone(async, task);
|
||||||
}
|
}
|
||||||
|
|
@ -206,6 +206,9 @@ static void *vnodeAsyncLoop(void *arg) {
|
||||||
SVWorker *worker = (SVWorker *)arg;
|
SVWorker *worker = (SVWorker *)arg;
|
||||||
SVAsync *async = worker->async;
|
SVAsync *async = worker->async;
|
||||||
SArray *cancelArray = taosArrayInit(0, sizeof(SVATaskCancelInfo));
|
SArray *cancelArray = taosArrayInit(0, sizeof(SVATaskCancelInfo));
|
||||||
|
if (cancelArray == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
setThreadName(async->label);
|
setThreadName(async->label);
|
||||||
|
|
||||||
|
|
@ -466,7 +469,7 @@ int32_t vnodeAsyncOpen(int32_t numOfThreads) {
|
||||||
vnodeAsyncSetWorkers(2, numOfThreads);
|
vnodeAsyncSetWorkers(2, numOfThreads);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodeAsyncClose() {
|
int32_t vnodeAsyncClose() {
|
||||||
|
|
@ -748,10 +751,10 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) {
|
||||||
task->prev->next = task->next;
|
task->prev->next = task->next;
|
||||||
task->next->prev = task->prev;
|
task->next->prev = task->prev;
|
||||||
if (task->cancel) {
|
if (task->cancel) {
|
||||||
taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
TAOS_UNUSED(taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
||||||
.cancel = task->cancel,
|
.cancel = task->cancel,
|
||||||
.arg = task->arg,
|
.arg = task->arg,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
vnodeAsyncTaskDone(async, task);
|
vnodeAsyncTaskDone(async, task);
|
||||||
}
|
}
|
||||||
|
|
@ -763,10 +766,10 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) {
|
||||||
channel->scheduled->prev->next = channel->scheduled->next;
|
channel->scheduled->prev->next = channel->scheduled->next;
|
||||||
channel->scheduled->next->prev = channel->scheduled->prev;
|
channel->scheduled->next->prev = channel->scheduled->prev;
|
||||||
if (channel->scheduled->cancel) {
|
if (channel->scheduled->cancel) {
|
||||||
taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
TAOS_UNUSED(taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
||||||
.cancel = channel->scheduled->cancel,
|
.cancel = channel->scheduled->cancel,
|
||||||
.arg = channel->scheduled->arg,
|
.arg = channel->scheduled->arg,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
vnodeAsyncTaskDone(async, channel->scheduled);
|
vnodeAsyncTaskDone(async, channel->scheduled);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,12 @@
|
||||||
#include "vnd.h"
|
#include "vnd.h"
|
||||||
|
|
||||||
/* ------------------------ STRUCTURES ------------------------ */
|
/* ------------------------ STRUCTURES ------------------------ */
|
||||||
static int vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBufPool **ppPool) {
|
static int32_t vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBufPool **ppPool) {
|
||||||
SVBufPool *pPool;
|
SVBufPool *pPool;
|
||||||
|
|
||||||
pPool = taosMemoryMalloc(sizeof(SVBufPool) + size);
|
pPool = taosMemoryMalloc(sizeof(SVBufPool) + size);
|
||||||
if (pPool == NULL) {
|
if (pPool == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
memset(pPool, 0, sizeof(SVBufPool));
|
memset(pPool, 0, sizeof(SVBufPool));
|
||||||
|
|
||||||
|
|
@ -44,14 +43,12 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBufPoo
|
||||||
pPool->lock = taosMemoryMalloc(sizeof(TdThreadSpinlock));
|
pPool->lock = taosMemoryMalloc(sizeof(TdThreadSpinlock));
|
||||||
if (!pPool->lock) {
|
if (!pPool->lock) {
|
||||||
taosMemoryFree(pPool);
|
taosMemoryFree(pPool);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (taosThreadSpinInit(pPool->lock, 0) != 0) {
|
if (taosThreadSpinInit(pPool->lock, 0) != 0) {
|
||||||
taosMemoryFree((void *)pPool->lock);
|
taosMemoryFree((void *)pPool->lock);
|
||||||
taosMemoryFree(pPool);
|
taosMemoryFree(pPool);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
return terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pPool->lock = NULL;
|
pPool->lock = NULL;
|
||||||
|
|
@ -77,10 +74,11 @@ int vnodeOpenBufPool(SVnode *pVnode) {
|
||||||
|
|
||||||
for (int i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
|
for (int i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
|
||||||
// create pool
|
// create pool
|
||||||
if (vnodeBufPoolCreate(pVnode, i, size, &pVnode->aBufPool[i])) {
|
int32_t code;
|
||||||
|
if ((code = vnodeBufPoolCreate(pVnode, i, size, &pVnode->aBufPool[i]))) {
|
||||||
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
|
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
vnodeCloseBufPool(pVnode);
|
vnodeCloseBufPool(pVnode);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to free list
|
// add to free list
|
||||||
|
|
@ -274,8 +272,6 @@ _exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodeBufPoolRegisterQuery(SVBufPool *pPool, SQueryNode *pQNode) {
|
int32_t vnodeBufPoolRegisterQuery(SVBufPool *pPool, SQueryNode *pQNode) {
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
taosThreadMutexLock(&pPool->mutex);
|
taosThreadMutexLock(&pPool->mutex);
|
||||||
|
|
||||||
pQNode->pNext = pPool->qList.pNext;
|
pQNode->pNext = pPool->qList.pNext;
|
||||||
|
|
@ -285,9 +281,7 @@ int32_t vnodeBufPoolRegisterQuery(SVBufPool *pPool, SQueryNode *pQNode) {
|
||||||
pPool->nQuery++;
|
pPool->nQuery++;
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pPool->mutex);
|
taosThreadMutexUnlock(&pPool->mutex);
|
||||||
|
return 0;
|
||||||
_exit:
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeBufPoolDeregisterQuery(SVBufPool *pPool, SQueryNode *pQNode, bool proactive) {
|
void vnodeBufPoolDeregisterQuery(SVBufPool *pPool, SQueryNode *pQNode, bool proactive) {
|
||||||
|
|
|
||||||
|
|
@ -394,8 +394,7 @@ int vnodeValidateTableHash(SVnode *pVnode, char *tableFName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashValue < pVnode->config.hashBegin || hashValue > pVnode->config.hashEnd) {
|
if (hashValue < pVnode->config.hashBegin || hashValue > pVnode->config.hashEnd) {
|
||||||
terrno = TSDB_CODE_VND_HASH_MISMATCH;
|
return terrno = TSDB_CODE_VND_HASH_MISMATCH;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -19,31 +19,19 @@
|
||||||
static volatile int32_t VINIT = 0;
|
static volatile int32_t VINIT = 0;
|
||||||
|
|
||||||
int vnodeInit(int nthreads) {
|
int vnodeInit(int nthreads) {
|
||||||
int32_t init;
|
if (atomic_val_compare_exchange_32(&VINIT, 0, 1)) {
|
||||||
|
|
||||||
init = atomic_val_compare_exchange_32(&VINIT, 0, 1);
|
|
||||||
if (init) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vnodeAsyncOpen(nthreads) != 0) {
|
TAOS_CHECK_RETURN(vnodeAsyncOpen(nthreads));
|
||||||
return -1;
|
TAOS_CHECK_RETURN(walInit());
|
||||||
}
|
|
||||||
|
|
||||||
if (walInit() < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeCleanup() {
|
void vnodeCleanup() {
|
||||||
int32_t init = atomic_val_compare_exchange_32(&VINIT, 1, 0);
|
if (atomic_val_compare_exchange_32(&VINIT, 1, 0) == 0) return;
|
||||||
if (init == 0) return;
|
|
||||||
|
|
||||||
// set stop
|
|
||||||
vnodeAsyncClose();
|
vnodeAsyncClose();
|
||||||
|
|
||||||
walCleanUp();
|
walCleanUp();
|
||||||
smaCleanUp();
|
smaCleanUp();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,8 @@ int32_t ctgGetTbTag(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName,
|
||||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* pJson = parseTagDatatoJson(pTag);
|
char* pJson = NULL;
|
||||||
|
parseTagDatatoJson(pTag, &pJson);
|
||||||
STagVal tagVal;
|
STagVal tagVal;
|
||||||
tagVal.cid = 0;
|
tagVal.cid = 0;
|
||||||
tagVal.type = TSDB_DATA_TYPE_JSON;
|
tagVal.type = TSDB_DATA_TYPE_JSON;
|
||||||
|
|
|
||||||
|
|
@ -2079,7 +2079,8 @@ int32_t ctgHandleGetTbTagRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf*
|
||||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* pJson = parseTagDatatoJson(pTag);
|
char* pJson = NULL;
|
||||||
|
parseTagDatatoJson(pTag, &pJson);
|
||||||
STagVal tagVal;
|
STagVal tagVal;
|
||||||
tagVal.cid = 0;
|
tagVal.cid = 0;
|
||||||
tagVal.type = TSDB_DATA_TYPE_JSON;
|
tagVal.type = TSDB_DATA_TYPE_JSON;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -23,6 +23,15 @@
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tgrant.h"
|
#include "tgrant.h"
|
||||||
|
|
||||||
|
#define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \
|
||||||
|
do { \
|
||||||
|
int _code = colDataSetVal(pCol, rows, buf, isNull);\
|
||||||
|
if (TSDB_CODE_SUCCESS != _code) { \
|
||||||
|
terrno = _code; \
|
||||||
|
return _code; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
extern SConfig* tsCfg;
|
extern SConfig* tsCfg;
|
||||||
|
|
||||||
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
|
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
|
||||||
|
|
@ -100,7 +109,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pOutput = pBlock;
|
*pOutput = pBlock;
|
||||||
} else {
|
} else {
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +117,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
||||||
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta,
|
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta,
|
||||||
int8_t biMode) {
|
int8_t biMode) {
|
||||||
int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
|
int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
|
||||||
blockDataEnsureCapacity(pBlock, blockCap);
|
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, blockCap));
|
||||||
pBlock->info.rows = 0;
|
pBlock->info.rows = 0;
|
||||||
|
|
||||||
// field
|
// field
|
||||||
|
|
@ -138,11 +147,12 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
STR_TO_VARSTR(buf, pMeta->schema[i].name);
|
STR_TO_VARSTR(buf, pMeta->schema[i].name);
|
||||||
colDataSetVal(pCol1, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
|
||||||
|
|
||||||
STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name);
|
STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name);
|
||||||
colDataSetVal(pCol2, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
|
||||||
int32_t bytes = getSchemaBytes(pMeta->schema + i);
|
int32_t bytes = getSchemaBytes(pMeta->schema + i);
|
||||||
colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||||
if (TSDB_VIEW_TABLE != pMeta->tableType) {
|
if (TSDB_VIEW_TABLE != pMeta->tableType) {
|
||||||
if (i >= pMeta->tableInfo.numOfColumns) {
|
if (i >= pMeta->tableInfo.numOfColumns) {
|
||||||
STR_TO_VARSTR(buf, "TAG");
|
STR_TO_VARSTR(buf, "TAG");
|
||||||
|
|
@ -155,22 +165,22 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
||||||
} else {
|
} else {
|
||||||
STR_TO_VARSTR(buf, "VIEW COL");
|
STR_TO_VARSTR(buf, "VIEW COL");
|
||||||
}
|
}
|
||||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
|
||||||
if (useCompress(pMeta->tableType) && pMeta->schemaExt) {
|
if (useCompress(pMeta->tableType) && pMeta->schemaExt) {
|
||||||
if (i < pMeta->tableInfo.numOfColumns) {
|
if (i < pMeta->tableInfo.numOfColumns) {
|
||||||
STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
|
STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
|
||||||
colDataSetVal(pCol5, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
|
||||||
STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress)));
|
STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress)));
|
||||||
colDataSetVal(pCol6, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
|
||||||
STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress)));
|
STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress)));
|
||||||
colDataSetVal(pCol7, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
|
||||||
} else {
|
} else {
|
||||||
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
||||||
colDataSetVal(pCol5, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
|
||||||
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
||||||
colDataSetVal(pCol6, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
|
||||||
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
||||||
colDataSetVal(pCol7, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,13 +190,13 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
||||||
}
|
}
|
||||||
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
|
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
|
||||||
STR_TO_VARSTR(buf, "tbname");
|
STR_TO_VARSTR(buf, "tbname");
|
||||||
colDataSetVal(pCol1, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
|
||||||
STR_TO_VARSTR(buf, "VARCHAR");
|
STR_TO_VARSTR(buf, "VARCHAR");
|
||||||
colDataSetVal(pCol2, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
|
||||||
int32_t bytes = TSDB_TABLE_NAME_LEN - 1;
|
int32_t bytes = TSDB_TABLE_NAME_LEN - 1;
|
||||||
colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||||
STR_TO_VARSTR(buf, "TAG");
|
STR_TO_VARSTR(buf, "TAG");
|
||||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
|
||||||
++(pBlock->info.rows);
|
++(pBlock->info.rows);
|
||||||
}
|
}
|
||||||
if (pBlock->info.rows <= 0) {
|
if (pBlock->info.rows <= 0) {
|
||||||
|
|
@ -212,7 +222,7 @@ static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp**
|
||||||
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
|
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +244,7 @@ static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pOutput = pBlock;
|
*pOutput = pBlock;
|
||||||
} else {
|
} else {
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -264,13 +274,17 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* buildRetension(SArray* pRetension) {
|
static int32_t buildRetension(SArray* pRetension, char **ppRetentions ) {
|
||||||
size_t size = taosArrayGetSize(pRetension);
|
size_t size = taosArrayGetSize(pRetension);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return NULL;
|
*ppRetentions = NULL;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* p1 = taosMemoryCalloc(1, 100);
|
char* p1 = taosMemoryCalloc(1, 100);
|
||||||
|
if(NULL == p1) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
|
|
||||||
for (int32_t i = 0; i < size; ++i) {
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
|
|
@ -288,7 +302,8 @@ static char* buildRetension(SArray* pRetension) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p1;
|
*ppRetentions = p1;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* cacheModelStr(int8_t cacheModel) {
|
static const char* cacheModelStr(int8_t cacheModel) {
|
||||||
|
|
@ -319,14 +334,14 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
|
||||||
return TSDB_CACHE_MODEL_NONE_STR;
|
return TSDB_CACHE_MODEL_NONE_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
||||||
blockDataEnsureCapacity(pBlock, 1);
|
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||||
pBlock->info.rows = 1;
|
pBlock->info.rows = 1;
|
||||||
|
|
||||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
char buf1[SHOW_CREATE_DB_RESULT_FIELD1_LEN] = {0};
|
char buf1[SHOW_CREATE_DB_RESULT_FIELD1_LEN] = {0};
|
||||||
STR_TO_VARSTR(buf1, dbName);
|
STR_TO_VARSTR(buf1, dbName);
|
||||||
colDataSetVal(pCol1, 0, buf1, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol1, 0, buf1, false);
|
||||||
|
|
||||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||||
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
|
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
|
||||||
|
|
@ -347,7 +362,8 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* retentions = buildRetension(pCfg->pRetensions);
|
char* pRetentions = NULL;
|
||||||
|
QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions));
|
||||||
int32_t dbFNameLen = strlen(dbFName);
|
int32_t dbFNameLen = strlen(dbFName);
|
||||||
int32_t hashPrefix = 0;
|
int32_t hashPrefix = 0;
|
||||||
if (pCfg->hashPrefix > 0) {
|
if (pCfg->hashPrefix > 0) {
|
||||||
|
|
@ -374,28 +390,30 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
|
||||||
pCfg->keepTimeOffset, encryptAlgorithmStr(pCfg->encryptAlgorithm), pCfg->s3ChunkSize,
|
pCfg->keepTimeOffset, encryptAlgorithmStr(pCfg->encryptAlgorithm), pCfg->s3ChunkSize,
|
||||||
pCfg->s3KeepLocal, pCfg->s3Compact);
|
pCfg->s3KeepLocal, pCfg->s3Compact);
|
||||||
|
|
||||||
if (retentions) {
|
if (pRetentions) {
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions);
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", pRetentions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(retentions);
|
taosMemoryFree(pRetentions);
|
||||||
|
|
||||||
(varDataLen(buf2)) = len;
|
(varDataLen(buf2)) = len;
|
||||||
|
|
||||||
colDataSetVal(pCol2, 0, buf2, false);
|
COL_DATA_SET_VAL_AND_CHECK(pCol2, 0, buf2, false);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
SSDataBlock* pBlock = NULL;
|
SSDataBlock* pBlock = NULL;
|
||||||
int32_t code = buildCreateDBResultDataBlock(&pBlock);
|
int32_t code = buildCreateDBResultDataBlock(&pBlock);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg);
|
code = setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
|
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
|
||||||
}
|
}
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -415,7 +433,7 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pOutput = pBlock;
|
*pOutput = pBlock;
|
||||||
} else {
|
} else {
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -436,7 +454,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pOutput = pBlock;
|
*pOutput = pBlock;
|
||||||
} else {
|
} else {
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -494,6 +512,7 @@ void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SArray* pTagVals = NULL;
|
SArray* pTagVals = NULL;
|
||||||
STag* pTag = (STag*)pCfg->pTags;
|
STag* pTag = (STag*)pCfg->pTags;
|
||||||
|
|
||||||
|
|
@ -503,20 +522,15 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tTagIsJson(pTag)) {
|
if (tTagIsJson(pTag)) {
|
||||||
char* pJson = parseTagDatatoJson(pTag);
|
char* pJson = NULL;
|
||||||
if (pJson) {
|
parseTagDatatoJson(pTag, &pJson);
|
||||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
||||||
taosMemoryFree(pJson);
|
taosMemoryFree(pJson);
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tTagToValArray((const STag*)pCfg->pTags, &pTagVals);
|
QRY_ERR_RET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals));
|
||||||
if (code) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t valueNum = taosArrayGetSize(pTagVals);
|
int16_t valueNum = taosArrayGetSize(pTagVals);
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
int32_t j = 0;
|
int32_t j = 0;
|
||||||
|
|
@ -534,16 +548,18 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
||||||
if (pSchema->colId > pTagVal->cid) {
|
if (pSchema->colId > pTagVal->cid) {
|
||||||
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
|
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
|
||||||
taosArrayDestroy(pTagVals);
|
code = TSDB_CODE_APP_ERROR;
|
||||||
return TSDB_CODE_APP_ERROR;
|
TAOS_CHECK_ERRNO(code);
|
||||||
} else if (pSchema->colId == pTagVal->cid) {
|
} else if (pSchema->colId == pTagVal->cid) {
|
||||||
char type = pTagVal->type;
|
char type = pTagVal->type;
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(type)) {
|
if (IS_VAR_DATA_TYPE(type)) {
|
||||||
dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
||||||
|
TAOS_CHECK_ERRNO(code);
|
||||||
} else {
|
} else {
|
||||||
dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen);
|
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen);
|
||||||
|
TAOS_CHECK_ERRNO(code);
|
||||||
}
|
}
|
||||||
*len += tlen;
|
*len += tlen;
|
||||||
j++;
|
j++;
|
||||||
|
|
@ -580,9 +596,10 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
taosArrayDestroy(pTagVals);
|
taosArrayDestroy(pTagVals);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) {
|
void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) {
|
||||||
|
|
@ -647,20 +664,19 @@ void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg*
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg) {
|
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg) {
|
||||||
int32_t code = 0;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
blockDataEnsureCapacity(pBlock, 1);
|
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||||
pBlock->info.rows = 1;
|
pBlock->info.rows = 1;
|
||||||
|
|
||||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
char buf1[SHOW_CREATE_TB_RESULT_FIELD1_LEN] = {0};
|
char buf1[SHOW_CREATE_TB_RESULT_FIELD1_LEN] = {0};
|
||||||
STR_TO_VARSTR(buf1, tbName);
|
STR_TO_VARSTR(buf1, tbName);
|
||||||
colDataSetVal(pCol1, 0, buf1, false);
|
QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
|
||||||
|
|
||||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||||
char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN);
|
char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN);
|
||||||
if (NULL == buf2) {
|
if (NULL == buf2) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
|
|
@ -677,10 +693,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
|
||||||
appendTagNameFields(buf2, &len, pCfg);
|
appendTagNameFields(buf2, &len, pCfg);
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS (");
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS (");
|
||||||
code = appendTagValues(buf2, &len, pCfg);
|
code = appendTagValues(buf2, &len, pCfg);
|
||||||
if (code) {
|
TAOS_CHECK_ERRNO(code);
|
||||||
taosMemoryFree(buf2);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")");
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")");
|
||||||
appendTableOptions(buf2, &len, pDbCfg, pCfg);
|
appendTableOptions(buf2, &len, pDbCfg, pCfg);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -692,29 +705,30 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
|
||||||
|
|
||||||
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
||||||
|
|
||||||
colDataSetVal(pCol2, 0, buf2, false);
|
code = colDataSetVal(pCol2, 0, buf2, false);
|
||||||
|
TAOS_CHECK_ERRNO(code);
|
||||||
|
|
||||||
|
_exit:
|
||||||
taosMemoryFree(buf2);
|
taosMemoryFree(buf2);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
|
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
blockDataEnsureCapacity(pBlock, 1);
|
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||||
pBlock->info.rows = 1;
|
pBlock->info.rows = 1;
|
||||||
|
|
||||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
|
char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
|
||||||
snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
|
snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
|
||||||
varDataSetLen(buf1, strlen(varDataVal(buf1)));
|
varDataSetLen(buf1, strlen(varDataVal(buf1)));
|
||||||
colDataSetVal(pCol1, 0, buf1, false);
|
QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
|
||||||
|
|
||||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||||
char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
|
char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
|
||||||
if (NULL == buf2) {
|
if (NULL == buf2) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SViewMeta* pMeta = pStmt->pViewMeta;
|
SViewMeta* pMeta = pStmt->pViewMeta;
|
||||||
|
|
@ -723,11 +737,10 @@ static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreate
|
||||||
pStmt->dbName, pStmt->viewName, pMeta->querySql);
|
pStmt->dbName, pStmt->viewName, pMeta->querySql);
|
||||||
int32_t len = strlen(varDataVal(buf2));
|
int32_t len = strlen(varDataVal(buf2));
|
||||||
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
||||||
colDataSetVal(pCol2, 0, buf2, false);
|
code = colDataSetVal(pCol2, 0, buf2, false);
|
||||||
|
|
||||||
taosMemoryFree(buf2);
|
taosMemoryFree(buf2);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
|
|
@ -739,7 +752,7 @@ static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRs
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
|
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
|
||||||
}
|
}
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -832,23 +845,39 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) {
|
||||||
pBlock->info.hasVarCol = true;
|
pBlock->info.hasVarCol = true;
|
||||||
|
|
||||||
pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData));
|
pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData));
|
||||||
|
if (NULL == pBlock->pDataBlock) {
|
||||||
|
taosMemoryFree(pBlock);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
SColumnInfoData infoData = {0};
|
SColumnInfoData infoData = {0};
|
||||||
|
|
||||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN;
|
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN;
|
||||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN;
|
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN;
|
||||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||||
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN;
|
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN;
|
||||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
*pOutput = pBlock;
|
*pOutput = pBlock;
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
|
_exit:
|
||||||
|
if(terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
taosMemoryFree(pBlock);
|
||||||
|
taosArrayDestroy(pBlock->pDataBlock);
|
||||||
|
}
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
||||||
|
|
@ -860,7 +889,7 @@ static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
|
code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
|
||||||
}
|
}
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -881,14 +910,14 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p
|
||||||
infoData.info.type = pExpr->resType.type;
|
infoData.info.type = pExpr->resType.type;
|
||||||
infoData.info.bytes = pExpr->resType.bytes;
|
infoData.info.bytes = pExpr->resType.bytes;
|
||||||
}
|
}
|
||||||
blockDataAppendColInfo(pBlock, &infoData);
|
QRY_ERR_RET(blockDataAppendColInfo(pBlock, &infoData));
|
||||||
}
|
}
|
||||||
*pOutput = pBlock;
|
*pOutput = pBlock;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
||||||
blockDataEnsureCapacity(pBlock, 1);
|
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||||
|
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
SNode* pProj = NULL;
|
SNode* pProj = NULL;
|
||||||
|
|
@ -897,9 +926,9 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
||||||
return TSDB_CODE_PAR_INVALID_SELECTED_EXPR;
|
return TSDB_CODE_PAR_INVALID_SELECTED_EXPR;
|
||||||
} else {
|
} else {
|
||||||
if (((SValueNode*)pProj)->isNull) {
|
if (((SValueNode*)pProj)->isNull) {
|
||||||
colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true);
|
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true));
|
||||||
} else {
|
} else {
|
||||||
colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false);
|
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -917,7 +946,7 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
|
code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
|
||||||
}
|
}
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -930,7 +959,7 @@ static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp*
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
|
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
|
||||||
}
|
}
|
||||||
blockDataDestroy(pBlock);
|
(void)blockDataDestroy(pBlock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx);
|
if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno;
|
||||||
} else {
|
} else {
|
||||||
for (int32_t i = 0; i < group->nodeNum; ++i) {
|
for (int32_t i = 0; i < group->nodeNum; ++i) {
|
||||||
rsp = taosArrayGet(group->nodeExecInfo, i);
|
rsp = taosArrayGet(group->nodeExecInfo, i);
|
||||||
|
|
@ -208,7 +208,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx);
|
if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1920,6 +1920,7 @@ _return:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
|
int32_t code = 0;
|
||||||
SExplainCtx *pCtx = (SExplainCtx *)ctx;
|
SExplainCtx *pCtx = (SExplainCtx *)ctx;
|
||||||
int32_t rowNum = taosArrayGetSize(pCtx->rows);
|
int32_t rowNum = taosArrayGetSize(pCtx->rows);
|
||||||
if (rowNum <= 0) {
|
if (rowNum <= 0) {
|
||||||
|
|
@ -1929,14 +1930,14 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
|
|
||||||
SSDataBlock *pBlock = createDataBlock();
|
SSDataBlock *pBlock = createDataBlock();
|
||||||
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, TSDB_EXPLAIN_RESULT_ROW_SIZE, 1);
|
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, TSDB_EXPLAIN_RESULT_ROW_SIZE, 1);
|
||||||
blockDataAppendColInfo(pBlock, &infoData);
|
QRY_ERR_JRET(blockDataAppendColInfo(pBlock, &infoData));
|
||||||
blockDataEnsureCapacity(pBlock, rowNum);
|
QRY_ERR_JRET(blockDataEnsureCapacity(pBlock, rowNum));
|
||||||
|
|
||||||
SColumnInfoData *pInfoData = taosArrayGet(pBlock->pDataBlock, 0);
|
SColumnInfoData *pInfoData = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
|
|
||||||
for (int32_t i = 0; i < rowNum; ++i) {
|
for (int32_t i = 0; i < rowNum; ++i) {
|
||||||
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
||||||
colDataSetVal(pInfoData, i, row->buf, false);
|
QRY_ERR_JRET(colDataSetVal(pInfoData, i, row->buf, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->info.rows = rowNum;
|
pBlock->info.rows = rowNum;
|
||||||
|
|
@ -1946,8 +1947,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
||||||
if (NULL == rsp) {
|
if (NULL == rsp) {
|
||||||
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
||||||
blockDataDestroy(pBlock);
|
QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp->completed = 1;
|
rsp->completed = 1;
|
||||||
|
|
@ -1961,10 +1961,11 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
|
|
||||||
SET_PAYLOAD_LEN(rsp->data, len, len);
|
SET_PAYLOAD_LEN(rsp->data, len, len);
|
||||||
|
|
||||||
|
_return:
|
||||||
blockDataDestroy(pBlock);
|
blockDataDestroy(pBlock);
|
||||||
|
|
||||||
*pRsp = rsp;
|
*pRsp = rsp;
|
||||||
return TSDB_CODE_SUCCESS;
|
QRY_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) {
|
int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) {
|
||||||
|
|
@ -2099,32 +2100,30 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t
|
||||||
group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp));
|
group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp));
|
||||||
if (NULL == group->nodeExecInfo) {
|
if (NULL == group->nodeExecInfo) {
|
||||||
qError("taosArrayInit %d explainExecInfo failed", group->nodeNum);
|
qError("taosArrayInit %d explainExecInfo failed", group->nodeNum);
|
||||||
tFreeSExplainRsp(pRspMsg);
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
taosWUnLockLatch(&group->lock);
|
TAOS_CHECK_ERRNO(code);
|
||||||
|
|
||||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group->physiPlanExecNum = pRspMsg->numOfPlans;
|
group->physiPlanExecNum = pRspMsg->numOfPlans;
|
||||||
} else if (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum) {
|
} else if (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum) {
|
||||||
qError("group execInfo already full, size:%d, nodeNum:%d", (int32_t)taosArrayGetSize(group->nodeExecInfo),
|
qError("group execInfo already full, size:%d, nodeNum:%d", (int32_t)taosArrayGetSize(group->nodeExecInfo),
|
||||||
group->nodeNum);
|
group->nodeNum);
|
||||||
tFreeSExplainRsp(pRspMsg);
|
code = TSDB_CODE_APP_ERROR;
|
||||||
taosWUnLockLatch(&group->lock);
|
TAOS_CHECK_ERRNO(code);
|
||||||
|
|
||||||
QRY_ERR_RET(TSDB_CODE_APP_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group->physiPlanExecNum != pRspMsg->numOfPlans) {
|
if (group->physiPlanExecNum != pRspMsg->numOfPlans) {
|
||||||
qError("physiPlanExecNum %d mismatch with others %d in group %d", pRspMsg->numOfPlans, group->physiPlanExecNum,
|
qError("physiPlanExecNum %d mismatch with others %d in group %d", pRspMsg->numOfPlans, group->physiPlanExecNum,
|
||||||
groupId);
|
groupId);
|
||||||
tFreeSExplainRsp(pRspMsg);
|
code = TSDB_CODE_APP_ERROR;
|
||||||
taosWUnLockLatch(&group->lock);
|
TAOS_CHECK_ERRNO(code);
|
||||||
|
|
||||||
QRY_ERR_RET(TSDB_CODE_APP_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(group->nodeExecInfo, pRspMsg);
|
if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL)
|
||||||
|
{
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
TAOS_CHECK_ERRNO(code);
|
||||||
|
}
|
||||||
|
|
||||||
groupDone = (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum);
|
groupDone = (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum);
|
||||||
|
|
||||||
|
|
@ -2140,6 +2139,11 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
tFreeSExplainRsp(pRspMsg);
|
||||||
|
taosWUnLockLatch(&group->lock);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) {
|
int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) {
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
|
||||||
|
|
||||||
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowEntryInfoOffset, SFunctionStateStore* pStore);
|
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowEntryInfoOffset, SFunctionStateStore* pStore);
|
||||||
void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols, bool outputEveryColumn);
|
void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols, bool outputEveryColumn);
|
||||||
void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow);
|
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow);
|
||||||
|
|
||||||
SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode);
|
SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode);
|
||||||
SColumn extractColumnFromColumnNode(SColumnNode* pColNode);
|
SColumn extractColumnFromColumnNode(SColumnNode* pColNode);
|
||||||
|
|
|
||||||
|
|
@ -834,7 +834,7 @@ void doBuildResultDatablock(struct SOperatorInfo* pOperator, SOptrBasicInfo* pbI
|
||||||
/**
|
/**
|
||||||
* @brief copydata from hash table, instead of copying from SGroupResInfo's pRow
|
* @brief copydata from hash table, instead of copying from SGroupResInfo's pRow
|
||||||
*/
|
*/
|
||||||
int32_t doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
||||||
SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup);
|
SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup);
|
||||||
|
|
||||||
bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo);
|
bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo);
|
||||||
|
|
@ -855,17 +855,20 @@ int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* de
|
||||||
|
|
||||||
extern void doDestroyExchangeOperatorInfo(void* param);
|
extern void doDestroyExchangeOperatorInfo(void* param);
|
||||||
|
|
||||||
int32_t doFilterImpl(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo, SColumnInfoData** pResCol);
|
int32_t doFilterImpl(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo,
|
||||||
|
SColumnInfoData** pResCol);
|
||||||
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo);
|
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo);
|
||||||
int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock,
|
int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock,
|
||||||
int32_t rows, SExecTaskInfo* pTask, STableMetaCacheInfo* pCache);
|
int32_t rows, SExecTaskInfo* pTask, STableMetaCacheInfo* pCache);
|
||||||
|
|
||||||
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
|
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
|
||||||
void setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, const char* name);
|
int32_t setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId,
|
||||||
void setVgIdColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, int32_t vgId);
|
const char* name);
|
||||||
void setVgVerColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, int64_t vgVer);
|
int32_t setVgIdColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, int32_t vgId);
|
||||||
|
int32_t setVgVerColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, int64_t vgVer);
|
||||||
|
|
||||||
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset);
|
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
||||||
|
int32_t* rowEntryInfoOffset);
|
||||||
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||||
|
|
||||||
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
|
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
|
||||||
|
|
@ -875,7 +878,8 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
|
||||||
int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
|
int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
|
||||||
int32_t numOfOutput, SArray* pPseudoList);
|
int32_t numOfOutput, SArray* pPseudoList);
|
||||||
|
|
||||||
void setInputDataBlock(SExprSupp* pExprSupp, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol);
|
int32_t setInputDataBlock(SExprSupp* pExprSupp, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
|
||||||
|
bool createDummyCol);
|
||||||
|
|
||||||
int32_t checkForQueryBuf(size_t numOfTables);
|
int32_t checkForQueryBuf(size_t numOfTables);
|
||||||
|
|
||||||
|
|
@ -894,8 +898,8 @@ bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup);
|
||||||
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup);
|
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup);
|
||||||
bool isDeletedStreamWindow(STimeWindow* pWin, uint64_t groupId, void* pState, STimeWindowAggSupp* pTwSup,
|
bool isDeletedStreamWindow(STimeWindow* pWin, uint64_t groupId, void* pState, STimeWindowAggSupp* pTwSup,
|
||||||
SStateStore* pStore);
|
SStateStore* pStore);
|
||||||
void appendDataToSpecialBlock(SSDataBlock* pBlock, TSKEY* pStartTs, TSKEY* pEndTs, uint64_t* pUid,
|
int32_t appendDataToSpecialBlock(SSDataBlock* pBlock, TSKEY* pStartTs, TSKEY* pEndTs, uint64_t* pUid, uint64_t* pGp,
|
||||||
uint64_t* pGp, void* pTbName);
|
void* pTbName);
|
||||||
|
|
||||||
uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t rowId);
|
uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t rowId);
|
||||||
|
|
||||||
|
|
@ -906,7 +910,7 @@ bool groupbyTbname(SNodeList* pGroupList);
|
||||||
void getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
|
void getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
|
||||||
int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int32_t pos, int32_t order,
|
int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int32_t pos, int32_t order,
|
||||||
int64_t* pData);
|
int64_t* pData);
|
||||||
void appendCreateTableRow(void* pState, SExprSupp* pTableSup, SExprSupp* pTagSup, uint64_t groupId,
|
int32_t appendCreateTableRow(void* pState, SExprSupp* pTableSup, SExprSupp* pTagSup, uint64_t groupId,
|
||||||
SSDataBlock* pSrcBlock, int32_t rowId, SSDataBlock* pDestBlock, SStateStore* pAPI);
|
SSDataBlock* pSrcBlock, int32_t rowId, SSDataBlock* pDestBlock, SStateStore* pAPI);
|
||||||
|
|
||||||
SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag);
|
SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag);
|
||||||
|
|
@ -929,12 +933,13 @@ int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, SExprSupp* pExpSup, i
|
||||||
SStreamState* pState, int32_t keySize, int16_t keyType, SStateStore* pStore,
|
SStreamState* pState, int32_t keySize, int16_t keyType, SStateStore* pStore,
|
||||||
SReadHandle* pHandle, STimeWindowAggSupp* pTwAggSup, const char* taskIdStr,
|
SReadHandle* pHandle, STimeWindowAggSupp* pTwAggSup, const char* taskIdStr,
|
||||||
SStorageAPI* pApi, int32_t tsIndex);
|
SStorageAPI* pApi, int32_t tsIndex);
|
||||||
int32_t initDownStream(struct SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, uint16_t type, int32_t tsColIndex,
|
int32_t initDownStream(struct SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, uint16_t type,
|
||||||
STimeWindowAggSupp* pTwSup, struct SSteamOpBasicInfo* pBasic);
|
int32_t tsColIndex, STimeWindowAggSupp* pTwSup, struct SSteamOpBasicInfo* pBasic);
|
||||||
void getMaxTsWins(const SArray* pAllWins, SArray* pMaxWins);
|
int32_t getMaxTsWins(const SArray* pAllWins, SArray* pMaxWins);
|
||||||
void initGroupResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList);
|
void initGroupResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList);
|
||||||
void getSessionHashKey(const SSessionKey* pKey, SSessionKey* pHashKey);
|
void getSessionHashKey(const SSessionKey* pKey, SSessionKey* pHashKey);
|
||||||
void deleteSessionWinState(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SSHashObj* pMapUpdate, SSHashObj* pMapDelete, SSHashObj* pPkDelete, bool needAdd);
|
int32_t deleteSessionWinState(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SSHashObj* pMapUpdate,
|
||||||
|
SSHashObj* pMapDelete, SSHashObj* pPkDelete, bool needAdd);
|
||||||
int32_t getAllSessionWindow(SSHashObj* pHashMap, SSHashObj* pStUpdated);
|
int32_t getAllSessionWindow(SSHashObj* pHashMap, SSHashObj* pStUpdated);
|
||||||
int32_t closeSessionWindow(SSHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SSHashObj* pClosed);
|
int32_t closeSessionWindow(SSHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SSHashObj* pClosed);
|
||||||
int32_t copyUpdateResult(SSHashObj** ppWinUpdated, SArray* pUpdated, __compar_fn_t compar);
|
int32_t copyUpdateResult(SSHashObj** ppWinUpdated, SArray* pUpdated, __compar_fn_t compar);
|
||||||
|
|
@ -943,22 +948,24 @@ void removeSessionDeleteResults(SSHashObj* pHashMap, SArray* pWins);
|
||||||
int32_t doOneWindowAggImpl(SColumnInfoData* pTimeWindowData, SResultWindowInfo* pCurWin, SResultRow** pResult,
|
int32_t doOneWindowAggImpl(SColumnInfoData* pTimeWindowData, SResultWindowInfo* pCurWin, SResultRow** pResult,
|
||||||
int32_t startIndex, int32_t winRows, int32_t rows, int32_t numOutput,
|
int32_t startIndex, int32_t winRows, int32_t rows, int32_t numOutput,
|
||||||
struct SOperatorInfo* pOperator, int64_t winDelta);
|
struct SOperatorInfo* pOperator, int64_t winDelta);
|
||||||
int32_t setSessionWinOutputInfo(SSHashObj* pStUpdated, SResultWindowInfo* pWinInfo);
|
void setSessionWinOutputInfo(SSHashObj* pStUpdated, SResultWindowInfo* pWinInfo);
|
||||||
int32_t saveSessionOutputBuf(SStreamAggSupporter* pAggSup, SResultWindowInfo* pWinInfo);
|
int32_t saveSessionOutputBuf(SStreamAggSupporter* pAggSup, SResultWindowInfo* pWinInfo);
|
||||||
int32_t saveResult(SResultWindowInfo winInfo, SSHashObj* pStUpdated);
|
int32_t saveResult(SResultWindowInfo winInfo, SSHashObj* pStUpdated);
|
||||||
void saveDeleteRes(SSHashObj* pStDelete, SSessionKey key);
|
int32_t saveDeleteRes(SSHashObj* pStDelete, SSessionKey key);
|
||||||
void removeSessionResult(SStreamAggSupporter* pAggSup, SSHashObj* pHashMap, SSHashObj* pResMap, SSessionKey* pKey);
|
void removeSessionResult(SStreamAggSupporter* pAggSup, SSHashObj* pHashMap, SSHashObj* pResMap, SSessionKey* pKey);
|
||||||
void doBuildDeleteDataBlock(struct SOperatorInfo* pOp, SSHashObj* pStDeleted, SSDataBlock* pBlock, void** Ite);
|
void doBuildDeleteDataBlock(struct SOperatorInfo* pOp, SSHashObj* pStDeleted, SSDataBlock* pBlock, void** Ite);
|
||||||
void doBuildSessionResult(struct SOperatorInfo* pOperator, void* pState, SGroupResInfo* pGroupResInfo, SSDataBlock* pBlock);
|
void doBuildSessionResult(struct SOperatorInfo* pOperator, void* pState, SGroupResInfo* pGroupResInfo,
|
||||||
void getSessionWindowInfoByKey(SStreamAggSupporter* pAggSup, SSessionKey* pKey, SResultWindowInfo* pWinInfo);
|
SSDataBlock* pBlock);
|
||||||
|
int32_t getSessionWindowInfoByKey(SStreamAggSupporter* pAggSup, SSessionKey* pKey, SResultWindowInfo* pWinInfo);
|
||||||
void getNextSessionWinInfo(SStreamAggSupporter* pAggSup, SSHashObj* pStUpdated, SResultWindowInfo* pCurWin,
|
void getNextSessionWinInfo(SStreamAggSupporter* pAggSup, SSHashObj* pStUpdated, SResultWindowInfo* pCurWin,
|
||||||
SResultWindowInfo* pNextWin);
|
SResultWindowInfo* pNextWin);
|
||||||
void compactTimeWindow(SExprSupp* pSup, SStreamAggSupporter* pAggSup, STimeWindowAggSupp* pTwAggSup,
|
int32_t compactTimeWindow(SExprSupp* pSup, SStreamAggSupporter* pAggSup, STimeWindowAggSupp* pTwAggSup,
|
||||||
SExecTaskInfo* pTaskInfo, SResultWindowInfo* pCurWin, SResultWindowInfo* pNextWin,
|
SExecTaskInfo* pTaskInfo, SResultWindowInfo* pCurWin, SResultWindowInfo* pNextWin,
|
||||||
SSHashObj* pStUpdated, SSHashObj* pStDeleted, bool addGap);
|
SSHashObj* pStUpdated, SSHashObj* pStDeleted, bool addGap);
|
||||||
int32_t releaseOutputBuf(void* pState, SRowBuffPos* pPos, SStateStore* pAPI);
|
void releaseOutputBuf(void* pState, SRowBuffPos* pPos, SStateStore* pAPI);
|
||||||
void resetWinRange(STimeWindow* winRange);
|
void resetWinRange(STimeWindow* winRange);
|
||||||
bool checkExpiredData(SStateStore* pAPI, SUpdateInfo* pUpdateInfo, STimeWindowAggSupp* pTwSup, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
bool checkExpiredData(SStateStore* pAPI, SUpdateInfo* pUpdateInfo, STimeWindowAggSupp* pTwSup, uint64_t tableId,
|
||||||
|
TSKEY ts, void* pPkVal, int32_t len);
|
||||||
int64_t getDeleteMark(SWindowPhysiNode* pWinPhyNode, int64_t interval);
|
int64_t getDeleteMark(SWindowPhysiNode* pWinPhyNode, int64_t interval);
|
||||||
void resetUnCloseSessionWinInfo(SSHashObj* winMap);
|
void resetUnCloseSessionWinInfo(SSHashObj* winMap);
|
||||||
void setStreamOperatorCompleted(struct SOperatorInfo* pOperator);
|
void setStreamOperatorCompleted(struct SOperatorInfo* pOperator);
|
||||||
|
|
@ -980,25 +987,23 @@ void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
|
||||||
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree);
|
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree);
|
||||||
SSDataBlock* getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam);
|
SSDataBlock* getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam);
|
||||||
void getCountWinRange(SStreamAggSupporter* pAggSup, const SSessionKey* pKey, EStreamType mode, SSessionKey* pDelRange);
|
void getCountWinRange(SStreamAggSupporter* pAggSup, const SSessionKey* pKey, EStreamType mode, SSessionKey* pDelRange);
|
||||||
bool doDeleteSessionWindow(SStreamAggSupporter* pAggSup, SSessionKey* pKey);
|
void doDeleteSessionWindow(SStreamAggSupporter* pAggSup, SSessionKey* pKey);
|
||||||
|
|
||||||
void saveDeleteInfo(SArray* pWins, SSessionKey key);
|
int32_t saveDeleteInfo(SArray* pWins, SSessionKey key);
|
||||||
void removeSessionResults(SStreamAggSupporter* pAggSup, SSHashObj* pHashMap, SArray* pWins);
|
void removeSessionResults(SStreamAggSupporter* pAggSup, SSHashObj* pHashMap, SArray* pWins);
|
||||||
void copyDeleteWindowInfo(SArray* pResWins, SSHashObj* pStDeleted);
|
int32_t copyDeleteWindowInfo(SArray* pResWins, SSHashObj* pStDeleted);
|
||||||
void copyDeleteSessionKey(SSHashObj* source, SSHashObj* dest);
|
int32_t copyDeleteSessionKey(SSHashObj* source, SSHashObj* dest);
|
||||||
|
|
||||||
bool inSlidingWindow(SInterval* pInterval, STimeWindow* pWin, SDataBlockInfo* pBlockInfo);
|
bool inSlidingWindow(SInterval* pInterval, STimeWindow* pWin, SDataBlockInfo* pBlockInfo);
|
||||||
bool inCalSlidingWindow(SInterval* pInterval, STimeWindow* pWin, TSKEY calStart, TSKEY calEnd, EStreamType blockType);
|
bool inCalSlidingWindow(SInterval* pInterval, STimeWindow* pWin, TSKEY calStart, TSKEY calEnd, EStreamType blockType);
|
||||||
bool compareVal(const char* v, const SStateKeys* pKey);
|
bool compareVal(const char* v, const SStateKeys* pKey);
|
||||||
bool inWinRange(STimeWindow* range, STimeWindow* cur);
|
bool inWinRange(STimeWindow* range, STimeWindow* cur);
|
||||||
void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SArray* result);
|
int32_t doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SArray* result);
|
||||||
|
|
||||||
int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo,
|
int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo,
|
||||||
TSKEY* primaryKeys, int32_t prevPosition, int32_t order);
|
TSKEY* primaryKeys, int32_t prevPosition, int32_t order);
|
||||||
void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status);
|
void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNo
|
||||||
int32_t order, const char* id);
|
int32_t order, const char* id);
|
||||||
|
|
||||||
void* taosDestroyFillInfo(struct SFillInfo* pFillInfo);
|
void* taosDestroyFillInfo(struct SFillInfo* pFillInfo);
|
||||||
int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity);
|
void taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity);
|
||||||
int64_t getFillInfoStart(struct SFillInfo* pFillInfo);
|
int64_t getFillInfoStart(struct SFillInfo* pFillInfo);
|
||||||
|
|
||||||
bool fillIfWindowPseudoColumn(SFillInfo* pFillInfo, SFillColInfo* pCol, SColumnInfoData* pDstColInfoData,
|
bool fillIfWindowPseudoColumn(SFillInfo* pFillInfo, SFillColInfo* pCol, SColumnInfoData* pDstColInfoData,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
|
|
||||||
#include "executorInt.h"
|
#include "executorInt.h"
|
||||||
|
#include "index.h"
|
||||||
#include "operator.h"
|
#include "operator.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "querytask.h"
|
#include "querytask.h"
|
||||||
|
|
@ -29,7 +30,6 @@
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
#include "index.h"
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool hasAgg;
|
bool hasAgg;
|
||||||
|
|
@ -166,6 +166,8 @@ void destroyAggOperatorInfo(void* param) {
|
||||||
* if false, fill results of ONE GROUP
|
* if false, fill results of ONE GROUP
|
||||||
* */
|
* */
|
||||||
static bool nextGroupedResult(SOperatorInfo* pOperator) {
|
static bool nextGroupedResult(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
SAggOperatorInfo* pAggInfo = pOperator->info;
|
SAggOperatorInfo* pAggInfo = pOperator->info;
|
||||||
|
|
||||||
|
|
@ -175,7 +177,6 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) {
|
||||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||||
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
|
||||||
int32_t order = pAggInfo->binfo.inputTsOrder;
|
int32_t order = pAggInfo->binfo.inputTsOrder;
|
||||||
SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
|
SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
|
||||||
|
|
||||||
|
|
@ -183,11 +184,10 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) {
|
||||||
pAggInfo->pNewGroupBlock = NULL;
|
pAggInfo->pNewGroupBlock = NULL;
|
||||||
tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
|
tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
|
||||||
setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
|
setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
|
||||||
setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
|
||||||
code = doAggregateImpl(pOperator, pSup->pCtx);
|
code = doAggregateImpl(pOperator, pSup->pCtx);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
T_LONG_JMP(pTaskInfo->env, code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
bool blockAllocated = false;
|
bool blockAllocated = false;
|
||||||
|
|
@ -222,7 +222,9 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
// the pDataBlock are always the same one, no need to call this again
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
|
setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
|
||||||
setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
|
code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
code = doAggregateImpl(pOperator, pSup->pCtx);
|
code = doAggregateImpl(pOperator, pSup->pCtx);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
|
destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
|
||||||
|
|
@ -238,6 +240,13 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
|
initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
pTaskInfo->code = code;
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return pBlock != NULL;
|
return pBlock != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,7 +345,6 @@ static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBloc
|
||||||
colInfo.info.type = TSDB_DATA_TYPE_NULL;
|
colInfo.info.type = TSDB_DATA_TYPE_NULL;
|
||||||
colInfo.info.bytes = 1;
|
colInfo.info.bytes = 1;
|
||||||
|
|
||||||
|
|
||||||
SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
|
SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
|
||||||
for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
|
for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
|
||||||
SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
|
SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
|
||||||
|
|
@ -395,8 +403,9 @@ void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uin
|
||||||
SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
|
SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
|
||||||
int32_t* rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
|
int32_t* rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
|
||||||
|
|
||||||
SResultRow* pResultRow = doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId,
|
SResultRow* pResultRow =
|
||||||
sizeof(groupId), true, groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
|
doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
|
||||||
|
groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
|
||||||
/*
|
/*
|
||||||
* not assign result buffer yet, add new result buffer
|
* not assign result buffer yet, add new result buffer
|
||||||
* all group belong to one result set, and each group result has different group id so set the id to be one
|
* all group belong to one result set, and each group result has different group id so set the id to be one
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,7 @@ void destroyCountWindowOperatorInfo(void* param) {
|
||||||
taosMemoryFreeClear(param);
|
taosMemoryFreeClear(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearWinStateBuff(SCountWindowResult* pBuff) {
|
static void clearWinStateBuff(SCountWindowResult* pBuff) { pBuff->winRows = 0; }
|
||||||
pBuff->winRows = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SCountWindowResult* getCountWinStateInfo(SCountWindowSupp* pCountSup) {
|
static SCountWindowResult* getCountWinStateInfo(SCountWindowSupp* pCountSup) {
|
||||||
SCountWindowResult* pBuffInfo = taosArrayGet(pCountSup->pWinStates, pCountSup->stateIndex);
|
SCountWindowResult* pBuffInfo = taosArrayGet(pCountSup->pWinStates, pCountSup->stateIndex);
|
||||||
|
|
@ -76,7 +74,8 @@ static SCountWindowResult* getCountWinStateInfo(SCountWindowSupp* pCountSup) {
|
||||||
return pBuffInfo;
|
return pBuffInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SCountWindowResult* setCountWindowOutputBuff(SExprSupp* pExprSup, SCountWindowSupp* pCountSup, SResultRow** pResult) {
|
static SCountWindowResult* setCountWindowOutputBuff(SExprSupp* pExprSup, SCountWindowSupp* pCountSup,
|
||||||
|
SResultRow** pResult) {
|
||||||
SCountWindowResult* pBuff = getCountWinStateInfo(pCountSup);
|
SCountWindowResult* pBuff = getCountWinStateInfo(pCountSup);
|
||||||
(*pResult) = &pBuff->row;
|
(*pResult) = &pBuff->row;
|
||||||
setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
|
setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
|
||||||
|
|
@ -136,12 +135,13 @@ int32_t doCountWindowAggImpl(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buildCountResult(SExprSupp* pExprSup, SCountWindowSupp* pCountSup, SExecTaskInfo* pTaskInfo, SFilterInfo* pFilterInfo, SSDataBlock* pBlock) {
|
static void buildCountResult(SExprSupp* pExprSup, SCountWindowSupp* pCountSup, SExecTaskInfo* pTaskInfo,
|
||||||
|
SFilterInfo* pFilterInfo, SSDataBlock* pBlock) {
|
||||||
SResultRow* pResultRow = NULL;
|
SResultRow* pResultRow = NULL;
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pCountSup->pWinStates); i++) {
|
for (int32_t i = 0; i < taosArrayGetSize(pCountSup->pWinStates); i++) {
|
||||||
SCountWindowResult* pBuff = setCountWindowOutputBuff(pExprSup, pCountSup, &pResultRow);
|
SCountWindowResult* pBuff = setCountWindowOutputBuff(pExprSup, pCountSup, &pResultRow);
|
||||||
if (pBuff->winRows == 0) {
|
if (pBuff->winRows == 0) {
|
||||||
continue;;
|
continue;
|
||||||
}
|
}
|
||||||
doUpdateNumOfRows(pExprSup->pCtx, pResultRow, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
|
doUpdateNumOfRows(pExprSup->pCtx, pResultRow, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
|
||||||
copyResultrowToDataBlock(pExprSup->pExprInfo, pExprSup->numOfExprs, pResultRow, pExprSup->pCtx, pBlock,
|
copyResultrowToDataBlock(pExprSup->pExprInfo, pExprSup->numOfExprs, pResultRow, pExprSup->pCtx, pBlock,
|
||||||
|
|
@ -154,6 +154,8 @@ static void buildCountResult(SExprSupp* pExprSup, SCountWindowSupp* pCountSup, S
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SCountWindowOperatorInfo* pInfo = pOperator->info;
|
SCountWindowOperatorInfo* pInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
SExprSupp* pExprSup = &pOperator->exprSupp;
|
SExprSupp* pExprSup = &pOperator->exprSupp;
|
||||||
|
|
@ -170,8 +172,11 @@ static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pRes->info.scanFlag = pBlock->info.scanFlag;
|
pRes->info.scanFlag = pBlock->info.scanFlag;
|
||||||
setInputDataBlock(pExprSup, pBlock, order, MAIN_SCAN, true);
|
code = setInputDataBlock(pExprSup, pBlock, order, MAIN_SCAN, true);
|
||||||
blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||||
|
|
@ -196,11 +201,19 @@ static SSDataBlock* countWindowAggregate(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCountResult(pExprSup, &pInfo->countSup, pTaskInfo, pOperator->exprSupp.pFilterInfo, pRes);
|
buildCountResult(pExprSup, &pInfo->countSup, pTaskInfo, pOperator->exprSupp.pFilterInfo, pRes);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return pRes->info.rows == 0 ? NULL : pRes;
|
return pRes->info.rows == 0 ? NULL : pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode,
|
SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SCountWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SCountWindowOperatorInfo));
|
SCountWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SCountWindowOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
|
@ -209,7 +222,6 @@ SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
|
|
||||||
pOperator->exprSupp.hasWindowOrGroup = true;
|
pOperator->exprSupp.hasWindowOrGroup = true;
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
|
||||||
SCountWinodwPhysiNode* pCountWindowNode = (SCountWinodwPhysiNode*)physiNode;
|
SCountWinodwPhysiNode* pCountWindowNode = (SCountWinodwPhysiNode*)physiNode;
|
||||||
|
|
||||||
pInfo->tsSlotId = ((SColumnNode*)pCountWindowNode->window.pTspk)->slotId;
|
pInfo->tsSlotId = ((SColumnNode*)pCountWindowNode->window.pTspk)->slotId;
|
||||||
|
|
@ -218,9 +230,7 @@ SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
int32_t numOfScalarExpr = 0;
|
int32_t numOfScalarExpr = 0;
|
||||||
SExprInfo* pScalarExprInfo = createExprInfo(pCountWindowNode->window.pExprs, NULL, &numOfScalarExpr);
|
SExprInfo* pScalarExprInfo = createExprInfo(pCountWindowNode->window.pExprs, NULL, &numOfScalarExpr);
|
||||||
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
|
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t keyBufSize = 0;
|
size_t keyBufSize = 0;
|
||||||
|
|
@ -230,9 +240,7 @@ SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
|
|
||||||
code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
|
code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
|
||||||
pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
|
pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSDataBlock* pResBlock = createDataBlockFromDescNode(pCountWindowNode->window.node.pOutputDataBlockDesc);
|
SSDataBlock* pResBlock = createDataBlockFromDescNode(pCountWindowNode->window.node.pOutputDataBlockDesc);
|
||||||
blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity);
|
blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity);
|
||||||
|
|
@ -257,11 +265,10 @@ SOperatorInfo* createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
pInfo->countSup.stateIndex = 0;
|
pInfo->countSup.stateIndex = 0;
|
||||||
|
|
||||||
code = filterInitFromNode((SNode*)pCountWindowNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
code = filterInitFromNode((SNode*)pCountWindowNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
code = initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
setOperatorInfo(pOperator, "CountWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT, true, OP_NOT_OPENED, pInfo,
|
setOperatorInfo(pOperator, "CountWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT, true, OP_NOT_OPENED, pInfo,
|
||||||
pTaskInfo);
|
pTaskInfo);
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ static void doKeepTuple(SWindowRowsSup* pRowSup, int64_t ts, uint64_t groupId) {
|
||||||
|
|
||||||
SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode,
|
SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SEventWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SEventWindowOperatorInfo));
|
SEventWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SEventWindowOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
|
@ -71,29 +73,21 @@ SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
SEventWinodwPhysiNode* pEventWindowNode = (SEventWinodwPhysiNode*)physiNode;
|
SEventWinodwPhysiNode* pEventWindowNode = (SEventWinodwPhysiNode*)physiNode;
|
||||||
|
|
||||||
int32_t tsSlotId = ((SColumnNode*)pEventWindowNode->window.pTspk)->slotId;
|
int32_t tsSlotId = ((SColumnNode*)pEventWindowNode->window.pTspk)->slotId;
|
||||||
int32_t code = filterInitFromNode((SNode*)pEventWindowNode->pStartCond, &pInfo->pStartCondInfo, 0);
|
code = filterInitFromNode((SNode*)pEventWindowNode->pStartCond, &pInfo->pStartCondInfo, 0);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = filterInitFromNode((SNode*)pEventWindowNode->pEndCond, &pInfo->pEndCondInfo, 0);
|
code = filterInitFromNode((SNode*)pEventWindowNode->pEndCond, &pInfo->pEndCondInfo, 0);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pEventWindowNode->window.pExprs != NULL) {
|
if (pEventWindowNode->window.pExprs != NULL) {
|
||||||
int32_t numOfScalarExpr = 0;
|
int32_t numOfScalarExpr = 0;
|
||||||
SExprInfo* pScalarExprInfo = createExprInfo(pEventWindowNode->window.pExprs, NULL, &numOfScalarExpr);
|
SExprInfo* pScalarExprInfo = createExprInfo(pEventWindowNode->window.pExprs, NULL, &numOfScalarExpr);
|
||||||
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
|
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code = filterInitFromNode((SNode*)pEventWindowNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
code = filterInitFromNode((SNode*)pEventWindowNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
||||||
|
|
||||||
|
|
@ -103,12 +97,13 @@ SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
|
|
||||||
code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
|
code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
|
||||||
pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
|
pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSDataBlock* pResBlock = createDataBlockFromDescNode(pEventWindowNode->window.node.pOutputDataBlockDesc);
|
SSDataBlock* pResBlock = createDataBlockFromDescNode(pEventWindowNode->window.node.pOutputDataBlockDesc);
|
||||||
blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity);
|
QUERY_CHECK_NULL(pResBlock, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
code = blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
initBasicInfo(&pInfo->binfo, pResBlock);
|
initBasicInfo(&pInfo->binfo, pResBlock);
|
||||||
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
|
|
@ -118,7 +113,8 @@ SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNo
|
||||||
pInfo->twAggSup = (STimeWindowAggSupp){.waterMark = pEventWindowNode->window.watermark,
|
pInfo->twAggSup = (STimeWindowAggSupp){.waterMark = pEventWindowNode->window.watermark,
|
||||||
.calTrigger = pEventWindowNode->window.triggerType};
|
.calTrigger = pEventWindowNode->window.triggerType};
|
||||||
|
|
||||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
code = initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
pInfo->tsSlotId = tsSlotId;
|
pInfo->tsSlotId = tsSlotId;
|
||||||
|
|
||||||
|
|
@ -173,6 +169,8 @@ void destroyEWindowOperatorInfo(void* param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SEventWindowOperatorInfo* pInfo = pOperator->info;
|
SEventWindowOperatorInfo* pInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
|
@ -191,8 +189,11 @@ static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pRes->info.scanFlag = pBlock->info.scanFlag;
|
pRes->info.scanFlag = pBlock->info.scanFlag;
|
||||||
setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true);
|
code = setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true);
|
||||||
blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||||
|
|
@ -210,6 +211,11 @@ static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return pRes->info.rows == 0 ? NULL : pRes;
|
return pRes->info.rows == 0 ? NULL : pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -607,7 +607,7 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pCo
|
||||||
blockDataAppendColInfo(pBlock, &idata);
|
blockDataAppendColInfo(pBlock, &idata);
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDecode(pBlock, pStart);
|
(void) blockDecode(pBlock, pStart);
|
||||||
blockDataEnsureCapacity(pRes, pBlock->info.rows);
|
blockDataEnsureCapacity(pRes, pBlock->info.rows);
|
||||||
|
|
||||||
// data from mnode
|
// data from mnode
|
||||||
|
|
|
||||||
|
|
@ -2021,18 +2021,27 @@ uint64_t tableListGetTableGroupId(const STableListInfo* pTableList, uint64_t tab
|
||||||
|
|
||||||
// TODO handle the group offset info, fix it, the rule of group output will be broken by this function
|
// TODO handle the group offset info, fix it, the rule of group output will be broken by this function
|
||||||
int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid) {
|
int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
if (pTableList->map == NULL) {
|
if (pTableList->map == NULL) {
|
||||||
pTableList->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
pTableList->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||||
|
QUERY_CHECK_NULL(pTableList->map, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableKeyInfo keyInfo = {.uid = uid, .groupId = gid};
|
STableKeyInfo keyInfo = {.uid = uid, .groupId = gid};
|
||||||
taosArrayPush(pTableList->pTableList, &keyInfo);
|
void* tmp = taosArrayPush(pTableList->pTableList, &keyInfo);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1;
|
int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1;
|
||||||
taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot));
|
code = taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot));
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1);
|
qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1);
|
||||||
return TSDB_CODE_SUCCESS;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo,
|
int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo,
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@
|
||||||
|
|
||||||
#include "executor.h"
|
#include "executor.h"
|
||||||
#include "executorInt.h"
|
#include "executorInt.h"
|
||||||
#include "trpc.h"
|
|
||||||
#include "wal.h"
|
|
||||||
#include "operator.h"
|
#include "operator.h"
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
#include "querytask.h"
|
#include "querytask.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
|
#include "trpc.h"
|
||||||
#include "tudf.h"
|
#include "tudf.h"
|
||||||
|
#include "wal.h"
|
||||||
|
|
||||||
#include "storageapi.h"
|
#include "storageapi.h"
|
||||||
|
|
||||||
|
|
@ -31,15 +31,17 @@ int32_t exchangeObjRefPool = -1;
|
||||||
|
|
||||||
static void cleanupRefPool() {
|
static void cleanupRefPool() {
|
||||||
int32_t ref = atomic_val_compare_exchange_32(&exchangeObjRefPool, exchangeObjRefPool, 0);
|
int32_t ref = atomic_val_compare_exchange_32(&exchangeObjRefPool, exchangeObjRefPool, 0);
|
||||||
taosCloseRef(ref);
|
(void)taosCloseRef(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initRefPool() {
|
static void initRefPool() {
|
||||||
exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo);
|
exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo);
|
||||||
atexit(cleanupRefPool);
|
(void)atexit(cleanupRefPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
|
static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
if (pOperator->numOfDownstream == 0) {
|
if (pOperator->numOfDownstream == 0) {
|
||||||
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
|
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
|
||||||
|
|
@ -60,33 +62,44 @@ static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOf
|
||||||
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; i++) {
|
for (int32_t i = 0; i < numOfBlocks; i++) {
|
||||||
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||||
taosArrayPush(pInfo->pBlockLists, pReq);
|
void* tmp = taosArrayPush(pInfo->pBlockLists, pReq);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
taosArrayPush(pInfo->pBlockLists, &input);
|
void* tmp = taosArrayPush(pInfo->pBlockLists, &input);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||||
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
||||||
SPackedData tmp = {.pDataBlock = pDataBlock};
|
SPackedData tmp = {.pDataBlock = pDataBlock};
|
||||||
taosArrayPush(pInfo->pBlockLists, &tmp);
|
void* tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
|
||||||
|
QUERY_CHECK_NULL(tmpItem, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
||||||
} else if (type == STREAM_INPUT__CHECKPOINT) {
|
} else if (type == STREAM_INPUT__CHECKPOINT) {
|
||||||
SPackedData tmp = {.pDataBlock = input};
|
SPackedData tmp = {.pDataBlock = input};
|
||||||
taosArrayPush(pInfo->pBlockLists, &tmp);
|
void* tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
|
||||||
|
QUERY_CHECK_NULL(tmpItem, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
pInfo->blockType = STREAM_INPUT__CHECKPOINT;
|
pInfo->blockType = STREAM_INPUT__CHECKPOINT;
|
||||||
} else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
|
} else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||||
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||||
taosArrayPush(pInfo->pBlockLists, pReq);
|
void* tmp = taosArrayPush(pInfo->pBlockLists, pReq);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doSetStreamOpOpen(SOperatorInfo* pOperator, char* id) {
|
static int32_t doSetStreamOpOpen(SOperatorInfo* pOperator, char* id) {
|
||||||
|
|
@ -124,7 +137,10 @@ void resetTaskInfo(qTaskInfo_t tinfo) {
|
||||||
clearStreamBlock(pTaskInfo->pRoot);
|
clearStreamBlock(pTaskInfo->pRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, const char* id) {
|
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type,
|
||||||
|
const char* id) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
if (pOperator->numOfDownstream == 0) {
|
if (pOperator->numOfDownstream == 0) {
|
||||||
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
|
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
|
||||||
|
|
@ -147,24 +163,30 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
||||||
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; i++) {
|
for (int32_t i = 0; i < numOfBlocks; i++) {
|
||||||
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||||
taosArrayPush(pInfo->pBlockLists, pReq);
|
void* tmp = taosArrayPush(pInfo->pBlockLists, pReq);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
taosArrayPush(pInfo->pBlockLists, input);
|
void* tmp = taosArrayPush(pInfo->pBlockLists, input);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||||
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
||||||
SPackedData tmp = {.pDataBlock = pDataBlock};
|
SPackedData tmp = {.pDataBlock = pDataBlock};
|
||||||
taosArrayPush(pInfo->pBlockLists, &tmp);
|
void* tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
|
||||||
|
QUERY_CHECK_NULL(tmpItem, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
||||||
} else if (type == STREAM_INPUT__CHECKPOINT_TRIGGER) {
|
} else if (type == STREAM_INPUT__CHECKPOINT_TRIGGER) {
|
||||||
SPackedData tmp = {.pDataBlock = input};
|
SPackedData tmp = {.pDataBlock = input};
|
||||||
taosArrayPush(pInfo->pBlockLists, &tmp);
|
void* tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
|
||||||
|
QUERY_CHECK_NULL(tmpItem, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
pInfo->blockType = STREAM_INPUT__CHECKPOINT;
|
pInfo->blockType = STREAM_INPUT__CHECKPOINT;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
@ -172,6 +194,12 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void doSetTaskId(SOperatorInfo* pOperator, SStorageAPI* pAPI) {
|
void doSetTaskId(SOperatorInfo* pOperator, SStorageAPI* pAPI) {
|
||||||
|
|
@ -330,16 +358,25 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers, int32_t v
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
qStreamInfoResetTimewindowFilter(pTaskInfo);
|
code = qStreamInfoResetTimewindowFilter(pTaskInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
nodesDestroyNode((SNode*)pPlan);
|
||||||
|
qDestroyTask(pTaskInfo);
|
||||||
|
terrno = code;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return pTaskInfo;
|
return pTaskInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SArray* filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const SArray* tableIdList, const char* idstr,
|
static int32_t filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const SArray* tableIdList, const char* idstr,
|
||||||
SStorageAPI* pAPI) {
|
SStorageAPI* pAPI, SArray** ppArrayRes) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
|
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
|
||||||
int32_t numOfUids = taosArrayGetSize(tableIdList);
|
int32_t numOfUids = taosArrayGetSize(tableIdList);
|
||||||
if (numOfUids == 0) {
|
if (numOfUids == 0) {
|
||||||
return qa;
|
(*ppArrayRes) = qa;
|
||||||
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
|
STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
|
||||||
|
|
@ -395,11 +432,18 @@ static SArray* filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const S
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle multiple partition
|
// handle multiple partition
|
||||||
taosArrayPush(qa, id);
|
void* tmp = taosArrayPush(qa, id);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
pAPI->metaReaderFn.clearReader(&mr);
|
pAPI->metaReaderFn.clearReader(&mr);
|
||||||
return qa;
|
(*ppArrayRes) = qa;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
|
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
|
||||||
|
|
@ -416,7 +460,12 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI
|
||||||
SStreamScanInfo* pScanInfo = pInfo->info;
|
SStreamScanInfo* pScanInfo = pInfo->info;
|
||||||
|
|
||||||
if (isAdd) { // add new table id
|
if (isAdd) { // add new table id
|
||||||
SArray* qa = filterUnqualifiedTables(pScanInfo, tableIdList, id, &pTaskInfo->storageAPI);
|
SArray* qa = NULL;
|
||||||
|
code = filterUnqualifiedTables(pScanInfo, tableIdList, id, &pTaskInfo->storageAPI, &qa);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
taosArrayDestroy(qa);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
int32_t numOfQualifiedTables = taosArrayGetSize(qa);
|
int32_t numOfQualifiedTables = taosArrayGetSize(qa);
|
||||||
qDebug("%d qualified child tables added into stream scanner, %s", numOfQualifiedTables, id);
|
qDebug("%d qualified child tables added into stream scanner, %s", numOfQualifiedTables, id);
|
||||||
code = pTaskInfo->storageAPI.tqReaderFn.tqReaderAddTables(pScanInfo->tqReader, qa);
|
code = pTaskInfo->storageAPI.tqReaderFn.tqReaderAddTables(pScanInfo->tqReader, qa);
|
||||||
|
|
@ -459,7 +508,13 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId);
|
code = tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
taosMemoryFree(keyBuf);
|
||||||
|
taosArrayDestroy(qa);
|
||||||
|
taosWUnLockLatch(&pTaskInfo->lock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosWUnLockLatch(&pTaskInfo->lock);
|
taosWUnLockLatch(&pTaskInfo->lock);
|
||||||
|
|
@ -509,9 +564,7 @@ int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* table
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool qIsDynamicExecTask(qTaskInfo_t tinfo) {
|
bool qIsDynamicExecTask(qTaskInfo_t tinfo) { return ((SExecTaskInfo*)tinfo)->dynamicTask; }
|
||||||
return ((SExecTaskInfo*)tinfo)->dynamicTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyOperatorParam(SOperatorParam* pParam) {
|
void destroyOperatorParam(SOperatorParam* pParam) {
|
||||||
if (NULL == pParam) {
|
if (NULL == pParam) {
|
||||||
|
|
@ -531,7 +584,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
||||||
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
|
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
|
||||||
EOPTR_EXEC_MODEL model) {
|
EOPTR_EXEC_MODEL model) {
|
||||||
SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo;
|
SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo;
|
||||||
taosThreadOnce(&initPoolOnce, initRefPool);
|
(void)taosThreadOnce(&initPoolOnce, initRefPool);
|
||||||
|
|
||||||
qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId);
|
qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId);
|
||||||
|
|
||||||
|
|
@ -575,6 +628,8 @@ static void freeBlock(void* param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal) {
|
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
int64_t threadId = taosGetSelfPthreadId();
|
int64_t threadId = taosGetSelfPthreadId();
|
||||||
|
|
||||||
|
|
@ -605,7 +660,7 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo
|
||||||
int32_t ret = setjmp(pTaskInfo->env);
|
int32_t ret = setjmp(pTaskInfo->env);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
pTaskInfo->code = ret;
|
pTaskInfo->code = ret;
|
||||||
cleanUpUdfs();
|
(void)cleanUpUdfs();
|
||||||
|
|
||||||
qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
|
qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
|
||||||
atomic_store_64(&pTaskInfo->owner, 0);
|
atomic_store_64(&pTaskInfo->owner, 0);
|
||||||
|
|
@ -640,18 +695,21 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo
|
||||||
SSDataBlock* p = NULL;
|
SSDataBlock* p = NULL;
|
||||||
if (blockIndex >= taosArrayGetSize(pTaskInfo->pResultBlockList)) {
|
if (blockIndex >= taosArrayGetSize(pTaskInfo->pResultBlockList)) {
|
||||||
SSDataBlock* p1 = createOneDataBlock(pRes, true);
|
SSDataBlock* p1 = createOneDataBlock(pRes, true);
|
||||||
taosArrayPush(pTaskInfo->pResultBlockList, &p1);
|
void* tmp = taosArrayPush(pTaskInfo->pResultBlockList, &p1);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
p = p1;
|
p = p1;
|
||||||
} else {
|
} else {
|
||||||
p = *(SSDataBlock**)taosArrayGet(pTaskInfo->pResultBlockList, blockIndex);
|
p = *(SSDataBlock**)taosArrayGet(pTaskInfo->pResultBlockList, blockIndex);
|
||||||
copyDataBlock(p, pRes);
|
code = copyDataBlock(p, pRes);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
blockIndex += 1;
|
blockIndex += 1;
|
||||||
|
|
||||||
current += p->info.rows;
|
current += p->info.rows;
|
||||||
ASSERT(p->info.rows > 0 || p->info.type == STREAM_CHECKPOINT);
|
ASSERT(p->info.rows > 0 || p->info.type == STREAM_CHECKPOINT);
|
||||||
taosArrayPush(pResList, &p);
|
void* tmp = taosArrayPush(pResList, &p);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
if (current >= rowsThreshold) {
|
if (current >= rowsThreshold) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -671,7 +729,9 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo
|
||||||
*useconds = pTaskInfo->cost.elapsedTime;
|
*useconds = pTaskInfo->cost.elapsedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanUpUdfs();
|
_end:
|
||||||
|
|
||||||
|
(void)cleanUpUdfs();
|
||||||
|
|
||||||
uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
|
uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
|
||||||
qDebug("%s task suspended, %d rows in %d blocks returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
|
qDebug("%s task suspended, %d rows in %d blocks returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
|
||||||
|
|
@ -730,7 +790,7 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
|
||||||
int32_t ret = setjmp(pTaskInfo->env);
|
int32_t ret = setjmp(pTaskInfo->env);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
pTaskInfo->code = ret;
|
pTaskInfo->code = ret;
|
||||||
cleanUpUdfs();
|
(void)cleanUpUdfs();
|
||||||
qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
|
qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
|
||||||
atomic_store_64(&pTaskInfo->owner, 0);
|
atomic_store_64(&pTaskInfo->owner, 0);
|
||||||
return pTaskInfo->code;
|
return pTaskInfo->code;
|
||||||
|
|
@ -748,7 +808,8 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
|
||||||
*useconds = pTaskInfo->cost.elapsedTime;
|
*useconds = pTaskInfo->cost.elapsedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanUpUdfs();
|
int32_t tmpRes = cleanUpUdfs();
|
||||||
|
qTrace("%s at line %d res:%d", __func__, __LINE__, tmpRes);
|
||||||
|
|
||||||
int32_t current = (*pRes != NULL) ? (*pRes)->info.rows : 0;
|
int32_t current = (*pRes != NULL) ? (*pRes)->info.rows : 0;
|
||||||
uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
|
uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
|
||||||
|
|
@ -762,9 +823,13 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
|
||||||
|
|
||||||
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
|
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
|
||||||
taosWLockLatch(&pTaskInfo->stopInfo.lock);
|
taosWLockLatch(&pTaskInfo->stopInfo.lock);
|
||||||
taosArrayPush(pTaskInfo->stopInfo.pStopInfo, pInfo);
|
void* tmp = taosArrayPush(pTaskInfo->stopInfo.pStopInfo, pInfo);
|
||||||
taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
|
taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
|
||||||
|
|
||||||
|
if (!tmp) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -798,8 +863,8 @@ void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
|
||||||
SExchangeOpStopInfo* pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
|
SExchangeOpStopInfo* pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
|
||||||
SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
|
SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
|
||||||
if (pExchangeInfo) {
|
if (pExchangeInfo) {
|
||||||
tsem_post(&pExchangeInfo->ready);
|
(void)tsem_post(&pExchangeInfo->ready);
|
||||||
taosReleaseRef(exchangeObjRefPool, pStop->refId);
|
(void)taosReleaseRef(exchangeObjRefPool, pStop->refId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -917,8 +982,8 @@ int32_t qStreamSourceScanParamForHistoryScanStep1(qTaskInfo_t tinfo, SVersionRan
|
||||||
pStreamInfo->fillHistoryWindow = *pWindow;
|
pStreamInfo->fillHistoryWindow = *pWindow;
|
||||||
pStreamInfo->recoverStep = STREAM_RECOVER_STEP__PREPARE1;
|
pStreamInfo->recoverStep = STREAM_RECOVER_STEP__PREPARE1;
|
||||||
|
|
||||||
qDebug("%s step 1. set param for stream scanner for scan-history data, verRange:%" PRId64 " - %" PRId64 ", window:%" PRId64
|
qDebug("%s step 1. set param for stream scanner for scan-history data, verRange:%" PRId64 " - %" PRId64
|
||||||
" - %" PRId64,
|
", window:%" PRId64 " - %" PRId64,
|
||||||
GET_TASKID(pTaskInfo), pStreamInfo->fillHistoryVer.minVer, pStreamInfo->fillHistoryVer.maxVer, pWindow->skey,
|
GET_TASKID(pTaskInfo), pStreamInfo->fillHistoryVer.minVer, pStreamInfo->fillHistoryVer.maxVer, pWindow->skey,
|
||||||
pWindow->ekey);
|
pWindow->ekey);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -955,7 +1020,8 @@ int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo) {
|
||||||
while (1) {
|
while (1) {
|
||||||
int32_t type = pOperator->operatorType;
|
int32_t type = pOperator->operatorType;
|
||||||
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
|
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
|
||||||
type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL) {
|
type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL ||
|
||||||
|
type == QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL) {
|
||||||
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
||||||
STimeWindowAggSupp* pSup = &pInfo->twAggSup;
|
STimeWindowAggSupp* pSup = &pInfo->twAggSup;
|
||||||
|
|
||||||
|
|
@ -1137,6 +1203,7 @@ void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
|
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
SStorageAPI* pAPI = &pTaskInfo->storageAPI;
|
SStorageAPI* pAPI = &pTaskInfo->storageAPI;
|
||||||
|
|
||||||
|
|
@ -1249,8 +1316,17 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
qDebug("tsdb reader created with offset(snapshot) uid:%" PRId64 " ts:%" PRId64 " table index:%d, total:%d, %s",
|
qDebug("tsdb reader created with offset(snapshot) uid:%" PRId64 " ts:%" PRId64 " table index:%d, total:%d, %s",
|
||||||
uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
|
uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
|
||||||
} else {
|
} else {
|
||||||
pTaskInfo->storageAPI.tsdReader.tsdSetQueryTableList(pScanBaseInfo->dataReader, &keyInfo, 1);
|
code = pTaskInfo->storageAPI.tsdReader.tsdSetQueryTableList(pScanBaseInfo->dataReader, &keyInfo, 1);
|
||||||
pTaskInfo->storageAPI.tsdReader.tsdReaderResetStatus(pScanBaseInfo->dataReader, &pScanBaseInfo->cond);
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = pTaskInfo->storageAPI.tsdReader.tsdReaderResetStatus(pScanBaseInfo->dataReader, &pScanBaseInfo->cond);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
qDebug("tsdb reader offset seek snapshot to uid:%" PRId64 " ts %" PRId64 " table index:%d numOfTable:%d, %s",
|
qDebug("tsdb reader offset seek snapshot to uid:%" PRId64 " ts %" PRId64 " table index:%d numOfTable:%d, %s",
|
||||||
uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
|
uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
|
||||||
}
|
}
|
||||||
|
|
@ -1289,20 +1365,32 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
}
|
}
|
||||||
|
|
||||||
pAPI->snapshotFn.taosXSetTablePrimaryKey(sContext, mtInfo.uid);
|
pAPI->snapshotFn.taosXSetTablePrimaryKey(sContext, mtInfo.uid);
|
||||||
initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
|
code = initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
if (pAPI->snapshotFn.taosXGetTablePrimaryKey(sContext)) {
|
if (pAPI->snapshotFn.taosXGetTablePrimaryKey(sContext)) {
|
||||||
pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts;
|
pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts;
|
||||||
} else {
|
} else {
|
||||||
pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts + 1;
|
pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tableListAddTableInfo(pTableListInfo, mtInfo.uid, 0);
|
code = tableListAddTableInfo(pTableListInfo, mtInfo.uid, 0);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
STableKeyInfo* pList = tableListGetInfo(pTableListInfo, 0);
|
STableKeyInfo* pList = tableListGetInfo(pTableListInfo, 0);
|
||||||
int32_t size = tableListGetSize(pTableListInfo);
|
int32_t size = tableListGetSize(pTableListInfo);
|
||||||
|
|
||||||
pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size, NULL,
|
code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size,
|
||||||
(void**)&pInfo->dataReader, NULL, NULL);
|
NULL, (void**)&pInfo->dataReader, NULL, NULL);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
|
cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
|
||||||
strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName);
|
strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName);
|
||||||
|
|
@ -1353,12 +1441,14 @@ void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
(void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
destroySendMsgInfo(pSendInfo);
|
destroySendMsgInfo(pSendInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
|
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExecTaskInfo* pTaskInfo = tinfo;
|
SExecTaskInfo* pTaskInfo = tinfo;
|
||||||
SArray* plist = getTableListInfo(pTaskInfo);
|
SArray* plist = getTableListInfo(pTaskInfo);
|
||||||
|
|
||||||
|
|
@ -1366,30 +1456,50 @@ SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
|
||||||
STableListInfo* pTableListInfo = taosArrayGetP(plist, 0);
|
STableListInfo* pTableListInfo = taosArrayGetP(plist, 0);
|
||||||
|
|
||||||
SArray* pUidList = taosArrayInit(10, sizeof(uint64_t));
|
SArray* pUidList = taosArrayInit(10, sizeof(uint64_t));
|
||||||
|
QUERY_CHECK_NULL(pUidList, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
int32_t numOfTables = tableListGetSize(pTableListInfo);
|
int32_t numOfTables = tableListGetSize(pTableListInfo);
|
||||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||||
STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
|
STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
|
||||||
taosArrayPush(pUidList, &pKeyInfo->uid);
|
void* tmp = taosArrayPush(pUidList, &pKeyInfo->uid);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(plist);
|
taosArrayDestroy(plist);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return pUidList;
|
return pUidList;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
|
static void extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
SStreamScanInfo* pScanInfo = pOperator->info;
|
SStreamScanInfo* pScanInfo = pOperator->info;
|
||||||
STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
|
STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
|
||||||
taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
|
void* tmp = taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||||
STableScanInfo* pScanInfo = pOperator->info;
|
STableScanInfo* pScanInfo = pOperator->info;
|
||||||
taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
|
void* tmp = taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
} else {
|
} else {
|
||||||
if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
|
if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
|
||||||
extractTableList(pList, pOperator->pDownstream[0]);
|
extractTableList(pList, pOperator->pDownstream[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo) {
|
SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo) {
|
||||||
|
|
|
||||||
|
|
@ -72,14 +72,14 @@ static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
|
||||||
#define realloc u_realloc
|
#define realloc u_realloc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExpr, SSDataBlock* pBlock);
|
static int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExpr, SSDataBlock* pBlock);
|
||||||
|
|
||||||
static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size);
|
static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size);
|
||||||
static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag);
|
static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag);
|
||||||
|
|
||||||
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
|
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
|
||||||
bool createDummyCol);
|
bool createDummyCol);
|
||||||
static int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
static void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
||||||
SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup);
|
SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup);
|
||||||
|
|
||||||
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
|
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
|
||||||
|
|
@ -192,8 +192,12 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
|
||||||
|
|
||||||
// add a new result set for a new group
|
// add a new result set for a new group
|
||||||
SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
|
SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
|
||||||
tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
|
int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
|
||||||
sizeof(SResultRowPosition));
|
sizeof(SResultRowPosition));
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. set the new time window to be the new active time window
|
// 2. set the new time window to be the new active time window
|
||||||
|
|
@ -209,11 +213,14 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
|
||||||
}
|
}
|
||||||
|
|
||||||
// query_range_start, query_range_end, window_duration, window_start, window_end
|
// query_range_start, query_range_end, window_duration, window_start, window_end
|
||||||
void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
|
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
|
||||||
pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
|
pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
pColData->info.bytes = sizeof(int64_t);
|
pColData->info.bytes = sizeof(int64_t);
|
||||||
|
|
||||||
colInfoDataEnsureCapacity(pColData, 5, false);
|
int32_t code = colInfoDataEnsureCapacity(pColData, 5, false);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
colDataSetInt64(pColData, 0, &pQueryWindow->skey);
|
colDataSetInt64(pColData, 0, &pQueryWindow->skey);
|
||||||
colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
|
colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
|
||||||
|
|
||||||
|
|
@ -221,35 +228,46 @@ void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow
|
||||||
colDataSetInt64(pColData, 2, &interval); // this value may be variable in case of 'n' and 'y'.
|
colDataSetInt64(pColData, 2, &interval); // this value may be variable in case of 'n' and 'y'.
|
||||||
colDataSetInt64(pColData, 3, &pQueryWindow->skey);
|
colDataSetInt64(pColData, 3, &pQueryWindow->skey);
|
||||||
colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
|
colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
|
static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SqlFunctionCtx* pCtx = pExprSup->pCtx;
|
SqlFunctionCtx* pCtx = pExprSup->pCtx;
|
||||||
for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
|
for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
|
||||||
pCtx[i].order = order;
|
pCtx[i].order = order;
|
||||||
pCtx[i].input.numOfRows = pBlock->info.rows;
|
pCtx[i].input.numOfRows = pBlock->info.rows;
|
||||||
setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
|
code = setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
pCtx[i].pSrcBlock = pBlock;
|
pCtx[i].pSrcBlock = pBlock;
|
||||||
pCtx[i].scanFlag = scanFlag;
|
pCtx[i].scanFlag = scanFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol) {
|
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
|
||||||
|
bool createDummyCol) {
|
||||||
if (pBlock->pBlockAgg != NULL) {
|
if (pBlock->pBlockAgg != NULL) {
|
||||||
doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
|
return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
|
||||||
} else {
|
} else {
|
||||||
doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
|
return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
|
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
|
||||||
int32_t numOfRows) {
|
int32_t numOfRows) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SColumnInfoData* pColInfo = NULL;
|
SColumnInfoData* pColInfo = NULL;
|
||||||
if (pInput->pData[paramIndex] == NULL) {
|
if (pInput->pData[paramIndex] == NULL) {
|
||||||
pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
|
pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
|
||||||
if (pColInfo == NULL) {
|
QUERY_CHECK_NULL(pColInfo, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the correct column info (data type and bytes)
|
// Set the correct column info (data type and bytes)
|
||||||
pColInfo->info.type = pFuncParam->param.nType;
|
pColInfo->info.type = pFuncParam->param.nType;
|
||||||
|
|
@ -260,7 +278,8 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc
|
||||||
pColInfo = pInput->pData[paramIndex];
|
pColInfo = pInput->pData[paramIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
|
code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
int8_t type = pFuncParam->param.nType;
|
int8_t type = pFuncParam->param.nType;
|
||||||
if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
|
if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
|
||||||
|
|
@ -277,12 +296,17 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc
|
||||||
char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
|
char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
|
||||||
STR_WITH_SIZE_TO_VARSTR(tmp, pFuncParam->param.pz, pFuncParam->param.nLen);
|
STR_WITH_SIZE_TO_VARSTR(tmp, pFuncParam->param.pz, pFuncParam->param.nLen);
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
colDataSetVal(pColInfo, i, tmp, false);
|
code = colDataSetVal(pColInfo, i, tmp, false);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
taosMemoryFree(tmp);
|
taosMemoryFree(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
|
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
|
||||||
|
|
@ -419,7 +443,9 @@ static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SF
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
|
int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
int32_t numOfRows = pBlock->info.rows;
|
int32_t numOfRows = pBlock->info.rows;
|
||||||
|
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
|
@ -443,12 +469,19 @@ void setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pB
|
||||||
// the data in the corresponding SColumnInfoData will not be used.
|
// the data in the corresponding SColumnInfoData will not be used.
|
||||||
pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
|
pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
||||||
doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
|
code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pInput->colDataSMAIsSet = false;
|
pInput->colDataSMAIsSet = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -468,7 +501,8 @@ STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset) {
|
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
||||||
|
int32_t* rowEntryInfoOffset) {
|
||||||
bool init = false;
|
bool init = false;
|
||||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||||
pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
|
pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
|
||||||
|
|
@ -517,6 +551,8 @@ void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
|
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
if (pFilterInfo == NULL || pBlock->info.rows == 0) {
|
if (pFilterInfo == NULL || pBlock->info.rows == 0) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -524,16 +560,12 @@ int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* p
|
||||||
SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
|
SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
|
||||||
SColumnInfoData* p = NULL;
|
SColumnInfoData* p = NULL;
|
||||||
|
|
||||||
int32_t code = filterSetDataFromSlotId(pFilterInfo, ¶m1);
|
code = filterSetDataFromSlotId(pFilterInfo, ¶m1);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _err);
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t status = 0;
|
int32_t status = 0;
|
||||||
code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
|
code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _err);
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
extractQualifiedTupleByFilterResult(pBlock, p, status);
|
extractQualifiedTupleByFilterResult(pBlock, p, status);
|
||||||
|
|
||||||
|
|
@ -544,7 +576,8 @@ int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* p
|
||||||
if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
|
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
|
||||||
if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
|
code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -598,6 +631,8 @@ void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExpr
|
||||||
|
|
||||||
void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
|
void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
|
||||||
SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
|
SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
for (int32_t j = 0; j < numOfExprs; ++j) {
|
for (int32_t j = 0; j < numOfExprs; ++j) {
|
||||||
int32_t slotId = pExprInfo[j].base.resSchema.slotId;
|
int32_t slotId = pExprInfo[j].base.resSchema.slotId;
|
||||||
|
|
||||||
|
|
@ -611,11 +646,13 @@ void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
|
code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
|
||||||
int32_t code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
if (TAOS_FAILED(code)) {
|
|
||||||
qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
|
int32_t winCode = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
|
||||||
T_LONG_JMP(pTaskInfo->env, code);
|
if (TAOS_FAILED(winCode)) {
|
||||||
|
qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(winCode));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, winCode);
|
||||||
}
|
}
|
||||||
} else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
} else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
@ -625,10 +662,17 @@ void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultR
|
||||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
char* in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
|
char* in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
|
||||||
for (int32_t k = 0; k < pRow->numOfRows; ++k) {
|
for (int32_t k = 0; k < pRow->numOfRows; ++k) {
|
||||||
colDataSetVal(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
|
code = colDataSetVal(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo refactor. SResultRow has direct pointer in miainfo
|
// todo refactor. SResultRow has direct pointer in miainfo
|
||||||
|
|
@ -671,9 +715,10 @@ int32_t finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPos
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
||||||
SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold,
|
SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup) {
|
||||||
bool ignoreGroup) {
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExprInfo* pExprInfo = pSup->pExprInfo;
|
SExprInfo* pExprInfo = pSup->pExprInfo;
|
||||||
int32_t numOfExprs = pSup->numOfExprs;
|
int32_t numOfExprs = pSup->numOfExprs;
|
||||||
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
||||||
|
|
@ -724,7 +769,8 @@ int32_t doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock,
|
||||||
|
|
||||||
if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
|
if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
|
||||||
uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
|
uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
|
||||||
blockDataEnsureCapacity(pBlock, newSize);
|
code = blockDataEnsureCapacity(pBlock, newSize);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
|
qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
|
||||||
pBlock->info.capacity, GET_TASKID(pTaskInfo));
|
pBlock->info.capacity, GET_TASKID(pTaskInfo));
|
||||||
// todo set the pOperator->resultInfo size
|
// todo set the pOperator->resultInfo size
|
||||||
|
|
@ -746,12 +792,20 @@ int32_t doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock,
|
||||||
qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
|
qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
|
||||||
pBlock->info.id.groupId);
|
pBlock->info.id.groupId);
|
||||||
pBlock->info.dataLoad = 1;
|
pBlock->info.dataLoad = 1;
|
||||||
blockDataUpdateTsWindow(pBlock, 0);
|
code = blockDataUpdateTsWindow(pBlock, 0);
|
||||||
return 0;
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
|
||||||
SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup) {
|
SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExprInfo* pExprInfo = pSup->pExprInfo;
|
SExprInfo* pExprInfo = pSup->pExprInfo;
|
||||||
int32_t numOfExprs = pSup->numOfExprs;
|
int32_t numOfExprs = pSup->numOfExprs;
|
||||||
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
||||||
|
|
@ -792,7 +846,8 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprS
|
||||||
|
|
||||||
if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
|
if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
|
||||||
uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
|
uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
|
||||||
blockDataEnsureCapacity(pBlock, newSize);
|
code = blockDataEnsureCapacity(pBlock, newSize);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
|
qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
|
||||||
pBlock->info.capacity, GET_TASKID(pTaskInfo));
|
pBlock->info.capacity, GET_TASKID(pTaskInfo));
|
||||||
// todo set the pOperator->resultInfo size
|
// todo set the pOperator->resultInfo size
|
||||||
|
|
@ -811,8 +866,14 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprS
|
||||||
qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
|
qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
|
||||||
pBlock->info.id.groupId);
|
pBlock->info.id.groupId);
|
||||||
pBlock->info.dataLoad = 1;
|
pBlock->info.dataLoad = 1;
|
||||||
blockDataUpdateTsWindow(pBlock, 0);
|
code = blockDataUpdateTsWindow(pBlock, 0);
|
||||||
return 0;
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
|
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
|
||||||
|
|
@ -909,9 +970,9 @@ void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
|
||||||
initResultRowInfo(&pInfo->resultRowInfo);
|
initResultRowInfo(&pInfo->resultRowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
|
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
|
||||||
if (pCtx == NULL) {
|
if (pCtx == NULL) {
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||||
|
|
@ -939,7 +1000,7 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFreeClear(pCtx);
|
taosMemoryFreeClear(pCtx);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
|
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
|
||||||
|
|
@ -970,7 +1031,10 @@ void cleanupExprSupp(SExprSupp* pSupp) {
|
||||||
taosMemoryFree(pSupp->rowEntryInfoOffset);
|
taosMemoryFree(pSupp->rowEntryInfoOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupBasicInfo(SOptrBasicInfo* pInfo) { pInfo->pRes = blockDataDestroy(pInfo->pRes); }
|
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
|
||||||
|
blockDataDestroy(pInfo->pRes);
|
||||||
|
pInfo->pRes = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
bool groupbyTbname(SNodeList* pGroupList) {
|
bool groupbyTbname(SNodeList* pGroupList) {
|
||||||
bool bytbname = false;
|
bool bytbname = false;
|
||||||
|
|
@ -1019,7 +1083,12 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo*
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||||
STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
|
STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
|
||||||
taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
void* tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
||||||
|
if (!tmp) {
|
||||||
|
taosArrayDestroy(pDeleterParam->pUidList);
|
||||||
|
taosMemoryFree(pDeleterParam);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*pParam = pDeleterParam;
|
*pParam = pDeleterParam;
|
||||||
|
|
@ -1077,25 +1146,15 @@ void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
|
||||||
freeOperatorParamImpl(pParam, OP_GET_PARAM);
|
freeOperatorParamImpl(pParam, OP_GET_PARAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) {
|
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
|
||||||
freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) {
|
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
|
||||||
freeOperatorParamImpl(pParam, OP_GET_PARAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) {
|
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
|
||||||
freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) {
|
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
|
||||||
freeOperatorParamImpl(pParam, OP_GET_PARAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) {
|
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
|
||||||
freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
|
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
|
||||||
STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
|
STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
|
||||||
|
|
@ -1103,10 +1162,7 @@ void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
|
||||||
freeOperatorParamImpl(pParam, OP_GET_PARAM);
|
freeOperatorParamImpl(pParam, OP_GET_PARAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) {
|
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
|
||||||
freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
|
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
|
||||||
if (NULL == pParam) {
|
if (NULL == pParam) {
|
||||||
|
|
@ -1166,11 +1222,12 @@ void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE SSDataBlock* getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx,
|
||||||
FORCE_INLINE SSDataBlock* getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam) {
|
bool clearParam) {
|
||||||
if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
|
if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
|
||||||
qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
|
qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
|
||||||
SSDataBlock* pBlock = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx], pOperator->pDownstreamGetParams[idx]);
|
SSDataBlock* pBlock = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
|
||||||
|
pOperator->pDownstreamGetParams[idx]);
|
||||||
if (clearParam) {
|
if (clearParam) {
|
||||||
freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
|
freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
|
||||||
pOperator->pDownstreamGetParams[idx] = NULL;
|
pOperator->pDownstreamGetParams[idx] = NULL;
|
||||||
|
|
@ -1181,7 +1238,6 @@ FORCE_INLINE SSDataBlock* getNextBlockFromDownstreamImpl(struct SOperatorInfo* p
|
||||||
return pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx]);
|
return pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool compareVal(const char* v, const SStateKeys* pKey) {
|
bool compareVal(const char* v, const SStateKeys* pKey) {
|
||||||
if (IS_VAR_DATA_TYPE(pKey->type)) {
|
if (IS_VAR_DATA_TYPE(pKey->type)) {
|
||||||
if (varDataLen(v) != varDataLen(pKey->pData)) {
|
if (varDataLen(v) != varDataLen(pKey->pData)) {
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
|
#include "operator.h"
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
|
#include "querytask.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tfill.h"
|
#include "tfill.h"
|
||||||
#include "operator.h"
|
|
||||||
#include "querytask.h"
|
|
||||||
|
|
||||||
typedef struct STimeRange {
|
typedef struct STimeRange {
|
||||||
TSKEY skey;
|
TSKEY skey;
|
||||||
|
|
@ -75,7 +75,8 @@ static void doHandleRemainBlockForNewGroupImpl(SOperatorInfo* pOperator, SFillOp
|
||||||
|
|
||||||
revisedFillStartKey(pInfo, pInfo->existNewGroupBlock, order);
|
revisedFillStartKey(pInfo, pInfo->existNewGroupBlock, order);
|
||||||
|
|
||||||
int64_t ts = (order == TSDB_ORDER_ASC)? pInfo->existNewGroupBlock->info.window.ekey:pInfo->existNewGroupBlock->info.window.skey;
|
int64_t ts = (order == TSDB_ORDER_ASC) ? pInfo->existNewGroupBlock->info.window.ekey
|
||||||
|
: pInfo->existNewGroupBlock->info.window.skey;
|
||||||
taosFillSetStartInfo(pInfo->pFillInfo, pInfo->pRes->info.rows, ts);
|
taosFillSetStartInfo(pInfo->pFillInfo, pInfo->pRes->info.rows, ts);
|
||||||
|
|
||||||
taosFillSetInputDataBlock(pInfo->pFillInfo, pInfo->pRes);
|
taosFillSetInputDataBlock(pInfo->pFillInfo, pInfo->pRes);
|
||||||
|
|
@ -92,6 +93,7 @@ static void doHandleRemainBlockForNewGroupImpl(SOperatorInfo* pOperator, SFillOp
|
||||||
|
|
||||||
static void doHandleRemainBlockFromNewGroup(SOperatorInfo* pOperator, SFillOperatorInfo* pInfo,
|
static void doHandleRemainBlockFromNewGroup(SOperatorInfo* pOperator, SFillOperatorInfo* pInfo,
|
||||||
SResultInfo* pResultInfo, int32_t order) {
|
SResultInfo* pResultInfo, int32_t order) {
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
if (taosFillHasMoreResults(pInfo->pFillInfo)) {
|
if (taosFillHasMoreResults(pInfo->pFillInfo)) {
|
||||||
int32_t numOfResultRows = pResultInfo->capacity - pInfo->pFinalRes->info.rows;
|
int32_t numOfResultRows = pResultInfo->capacity - pInfo->pFinalRes->info.rows;
|
||||||
taosFillResultDataBlock(pInfo->pFillInfo, pInfo->pFinalRes, numOfResultRows);
|
taosFillResultDataBlock(pInfo->pFillInfo, pInfo->pFinalRes, numOfResultRows);
|
||||||
|
|
@ -106,18 +108,32 @@ static void doHandleRemainBlockFromNewGroup(SOperatorInfo* pOperator, SFillOpera
|
||||||
}
|
}
|
||||||
|
|
||||||
void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
|
void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
SFillOperatorInfo* pInfo = pOperator->info;
|
SFillOperatorInfo* pInfo = pOperator->info;
|
||||||
SExprSupp* pSup = &pOperator->exprSupp;
|
SExprSupp* pSup = &pOperator->exprSupp;
|
||||||
setInputDataBlock(pSup, pBlock, order, scanFlag, false);
|
code = setInputDataBlock(pSup, pBlock, order, scanFlag, false);
|
||||||
projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, NULL);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
// reset the row value before applying the no-fill functions to the input data block, which is "pBlock" in this case.
|
// reset the row value before applying the no-fill functions to the input data block, which is "pBlock" in this case.
|
||||||
pInfo->pRes->info.rows = 0;
|
pInfo->pRes->info.rows = 0;
|
||||||
SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp;
|
SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp;
|
||||||
setInputDataBlock(pNoFillSupp, pBlock, order, scanFlag, false);
|
code = setInputDataBlock(pNoFillSupp, pBlock, order, scanFlag, false);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
projectApplyFunctions(pNoFillSupp->pExprInfo, pInfo->pRes, pBlock, pNoFillSupp->pCtx, pNoFillSupp->numOfExprs, NULL);
|
code = projectApplyFunctions(pNoFillSupp->pExprInfo, pInfo->pRes, pBlock, pNoFillSupp->pCtx, pNoFillSupp->numOfExprs,
|
||||||
|
NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
pInfo->pRes->info.id.groupId = pBlock->info.id.groupId;
|
pInfo->pRes->info.id.groupId = pBlock->info.id.groupId;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillResetPrevForNewGroup(SFillInfo* pFillInfo) {
|
static void fillResetPrevForNewGroup(SFillInfo* pFillInfo) {
|
||||||
|
|
@ -180,6 +196,8 @@ static void revisedFillStartKey(SFillOperatorInfo* pInfo, SSDataBlock* pBlock, i
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) {
|
static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SFillOperatorInfo* pInfo = pOperator->info;
|
SFillOperatorInfo* pInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
|
@ -219,11 +237,14 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) {
|
||||||
} else {
|
} else {
|
||||||
pResBlock->info.scanFlag = pBlock->info.scanFlag;
|
pResBlock->info.scanFlag = pBlock->info.scanFlag;
|
||||||
pBlock->info.dataLoad = 1;
|
pBlock->info.dataLoad = 1;
|
||||||
blockDataUpdateTsWindow(pBlock, pInfo->primarySrcSlotId);
|
code = blockDataUpdateTsWindow(pBlock, pInfo->primarySrcSlotId);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
blockDataCleanup(pInfo->pRes);
|
blockDataCleanup(pInfo->pRes);
|
||||||
blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
|
code = blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
|
||||||
blockDataEnsureCapacity(pInfo->pFinalRes, pBlock->info.rows);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
code = blockDataEnsureCapacity(pInfo->pFinalRes, pBlock->info.rows);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
doApplyScalarCalculation(pOperator, pBlock, order, pBlock->info.scanFlag);
|
doApplyScalarCalculation(pOperator, pBlock, order, pBlock->info.scanFlag);
|
||||||
|
|
||||||
if (pInfo->curGroupId == 0 || (pInfo->curGroupId == pInfo->pRes->info.id.groupId)) {
|
if (pInfo->curGroupId == 0 || (pInfo->curGroupId == pInfo->pRes->info.id.groupId)) {
|
||||||
|
|
@ -276,6 +297,13 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
||||||
|
|
@ -294,7 +322,11 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
doFilter(fillResult, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo);
|
int32_t code = doFilter(fillResult, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
if (fillResult->info.rows > 0) {
|
if (fillResult->info.rows > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -310,8 +342,10 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
||||||
void destroyFillOperatorInfo(void* param) {
|
void destroyFillOperatorInfo(void* param) {
|
||||||
SFillOperatorInfo* pInfo = (SFillOperatorInfo*)param;
|
SFillOperatorInfo* pInfo = (SFillOperatorInfo*)param;
|
||||||
pInfo->pFillInfo = taosDestroyFillInfo(pInfo->pFillInfo);
|
pInfo->pFillInfo = taosDestroyFillInfo(pInfo->pFillInfo);
|
||||||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
blockDataDestroy(pInfo->pRes);
|
||||||
pInfo->pFinalRes = blockDataDestroy(pInfo->pFinalRes);
|
pInfo->pRes = NULL;
|
||||||
|
blockDataDestroy(pInfo->pFinalRes);
|
||||||
|
pInfo->pFinalRes = NULL;
|
||||||
|
|
||||||
cleanupExprSupp(&pInfo->noFillExprSupp);
|
cleanupExprSupp(&pInfo->noFillExprSupp);
|
||||||
|
|
||||||
|
|
@ -407,7 +441,8 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = initExprSupp(pNoFillSupp, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs, &pTaskInfo->storageAPI.functionStore);
|
code =
|
||||||
|
initExprSupp(pNoFillSupp, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
@ -423,7 +458,10 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
||||||
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
||||||
|
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
code = initExprSupp(&pOperator->exprSupp, pExprInfo, pInfo->numOfExpr, &pTaskInfo->storageAPI.functionStore);
|
code = initExprSupp(&pOperator->exprSupp, pExprInfo, pInfo->numOfExpr, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
|
|
@ -444,7 +482,10 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->pFinalRes = createOneDataBlock(pInfo->pRes, false);
|
pInfo->pFinalRes = createOneDataBlock(pInfo->pRes, false);
|
||||||
blockDataEnsureCapacity(pInfo->pFinalRes, pOperator->resultInfo.capacity);
|
code = blockDataEnsureCapacity(pInfo->pFinalRes, pOperator->resultInfo.capacity);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
code = filterInitFromNode((SNode*)pPhyFillNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
code = filterInitFromNode((SNode*)pPhyFillNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
@ -453,8 +494,8 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
||||||
|
|
||||||
setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||||
pOperator->exprSupp.numOfExprs = pInfo->numOfExpr;
|
pOperator->exprSupp.numOfExprs = pInfo->numOfExpr;
|
||||||
pOperator->fpSet =
|
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doFill, NULL, destroyFillOperatorInfo, optrDefaultBufFn, NULL,
|
||||||
createOperatorFpSet(optrDummyOpenFn, doFill, NULL, destroyFillOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
optrDefaultGetNextExtFn, NULL);
|
||||||
|
|
||||||
code = appendDownstream(pOperator, &downstream, 1);
|
code = appendDownstream(pOperator, &downstream, 1);
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ static void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDa
|
||||||
static int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity);
|
static int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity);
|
||||||
static int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo, int32_t numOfCols, char* pData,
|
static int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo, int32_t numOfCols, char* pData,
|
||||||
int32_t bytes, uint64_t groupId, SDiskbasedBuf* pBuf, SAggSupporter* pAggSup);
|
int32_t bytes, uint64_t groupId, SDiskbasedBuf* pBuf, SAggSupporter* pAggSup);
|
||||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
static int32_t extractColumnInfo(SNodeList* pNodeList, SArray** pArrayRes);
|
||||||
|
|
||||||
static void freeGroupKey(void* param) {
|
static void freeGroupKey(void* param) {
|
||||||
SGroupKeys* pKey = (SGroupKeys*)param;
|
SGroupKeys* pKey = (SGroupKeys*)param;
|
||||||
|
|
@ -111,7 +111,10 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char**
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush((*pGroupColVals), &key);
|
void* tmp = taosArrayPush((*pGroupColVals), &key);
|
||||||
|
if (!tmp) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols;
|
int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols;
|
||||||
|
|
@ -349,12 +352,16 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* buildGroupResultDataBlock(SOperatorInfo* pOperator) {
|
static SSDataBlock* buildGroupResultDataBlock(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
||||||
|
|
||||||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||||
doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL);
|
code = doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
if (!hasRemainResults(&pInfo->groupResInfo)) {
|
if (!hasRemainResults(&pInfo->groupResInfo)) {
|
||||||
setOperatorCompleted(pOperator);
|
setOperatorCompleted(pOperator);
|
||||||
|
|
@ -367,6 +374,12 @@ static SSDataBlock* buildGroupResultDataBlock(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pOperator->resultInfo.totalRows += pRes->info.rows;
|
pOperator->resultInfo.totalRows += pRes->info.rows;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return (pRes->info.rows == 0) ? NULL : pRes;
|
return (pRes->info.rows == 0) ? NULL : pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,6 +425,9 @@ void doBuildResultDatablockByHash(SOperatorInfo* pOperator, SOptrBasicInfo* pbIn
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* buildGroupResultDataBlockByHash(SOperatorInfo* pOperator) {
|
static SSDataBlock* buildGroupResultDataBlockByHash(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
||||||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||||
|
|
||||||
|
|
@ -419,7 +435,9 @@ static SSDataBlock* buildGroupResultDataBlockByHash(SOperatorInfo* pOperator) {
|
||||||
while (1) {
|
while (1) {
|
||||||
doBuildResultDatablockByHash(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
doBuildResultDatablockByHash(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||||
|
|
||||||
doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL);
|
code = doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
if (!hasRemainResultByHash(pOperator)) {
|
if (!hasRemainResultByHash(pOperator)) {
|
||||||
setOperatorCompleted(pOperator);
|
setOperatorCompleted(pOperator);
|
||||||
// clean hash after completed
|
// clean hash after completed
|
||||||
|
|
@ -433,6 +451,12 @@ static SSDataBlock* buildGroupResultDataBlockByHash(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pOperator->resultInfo.totalRows += pRes->info.rows;
|
pOperator->resultInfo.totalRows += pRes->info.rows;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return (pRes->info.rows == 0) ? NULL : pRes;
|
return (pRes->info.rows == 0) ? NULL : pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,6 +465,8 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
||||||
|
|
@ -462,15 +488,14 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||||
pInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
|
pInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
|
||||||
|
|
||||||
// the pDataBlock are always the same one, no need to call this again
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
setInputDataBlock(&pOperator->exprSupp, pBlock, order, pBlock->info.scanFlag, true);
|
code = setInputDataBlock(&pOperator->exprSupp, pBlock, order, pBlock->info.scanFlag, true);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||||
pTaskInfo->code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||||
pInfo->scalarSup.numOfExprs, NULL);
|
pInfo->scalarSup.numOfExprs, NULL);
|
||||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doHashGroupbyAgg(pOperator, pBlock);
|
doHashGroupbyAgg(pOperator, pBlock);
|
||||||
|
|
@ -491,11 +516,19 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||||
pGroupResInfo->dataPos = NULL;
|
pGroupResInfo->dataPos = NULL;
|
||||||
|
|
||||||
pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0;
|
pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
pTaskInfo->code = code;
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
return buildGroupResultDataBlockByHash(pOperator);
|
return buildGroupResultDataBlockByHash(pOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo) {
|
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo));
|
SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
|
@ -514,32 +547,28 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode*
|
||||||
pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr);
|
pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->pGroupCols = extractColumnInfo(pAggNode->pGroupKeys);
|
pInfo->pGroupCols = NULL;
|
||||||
|
code = extractColumnInfo(pAggNode->pGroupKeys, &pInfo->pGroupCols);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
|
code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
code = blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num);
|
SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num);
|
||||||
code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, pInfo->groupKeyLen, pTaskInfo->id.str,
|
code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, pInfo->groupKeyLen, pTaskInfo->id.str,
|
||||||
pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
|
pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
setOperatorInfo(pOperator, "GroupbyAggOperator", 0, true, OP_NOT_OPENED, pInfo, pTaskInfo);
|
setOperatorInfo(pOperator, "GroupbyAggOperator", 0, true, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||||
|
|
@ -551,9 +580,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode*
|
||||||
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, hashGroupbyAggregate, NULL, destroyGroupOperatorInfo,
|
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, hashGroupbyAggregate, NULL, destroyGroupOperatorInfo,
|
||||||
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
||||||
code = appendDownstream(pOperator, &downstream, 1);
|
code = appendDownstream(pOperator, &downstream, 1);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
|
|
@ -567,6 +594,8 @@ _error:
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* createBlockDataNotLoaded(const SOperatorInfo* pOperator, SSDataBlock* pDataBlock) {
|
SSDataBlock* createBlockDataNotLoaded(const SOperatorInfo* pOperator, SSDataBlock* pDataBlock) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
if (pDataBlock == NULL) {
|
if (pDataBlock == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -595,27 +624,33 @@ SSDataBlock* createBlockDataNotLoaded(const SOperatorInfo* pOperator, SSDataBloc
|
||||||
int32_t slotId = pExpr->base.pParam[0].pCol->slotId;
|
int32_t slotId = pExpr->base.pParam[0].pCol->slotId;
|
||||||
SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, slotId);
|
SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, slotId);
|
||||||
SColumnInfoData colInfo = {.hasNull = true, .info = pSrc->info};
|
SColumnInfoData colInfo = {.hasNull = true, .info = pSrc->info};
|
||||||
blockDataAppendColInfo(pDstBlock, &colInfo);
|
code = blockDataAppendColInfo(pDstBlock, &colInfo);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
SColumnInfoData* pDst = taosArrayGet(pDstBlock->pDataBlock, i);
|
SColumnInfoData* pDst = taosArrayGet(pDstBlock->pDataBlock, i);
|
||||||
if (pDataBlock->pBlockAgg && pDataBlock->pBlockAgg[slotId].colId != -1) {
|
if (pDataBlock->pBlockAgg && pDataBlock->pBlockAgg[slotId].colId != -1) {
|
||||||
pDstBlock->pBlockAgg[i] = pDataBlock->pBlockAgg[slotId];
|
pDstBlock->pBlockAgg[i] = pDataBlock->pBlockAgg[slotId];
|
||||||
} else {
|
} else {
|
||||||
int32_t code = doEnsureCapacity(pDst, &pDstBlock->info, pDataBlock->info.rows, false);
|
code = doEnsureCapacity(pDst, &pDstBlock->info, pDataBlock->info.rows, false);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
code = colDataAssign(pDst, pSrc, pDataBlock->info.rows, &pDataBlock->info);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
terrno = code;
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
blockDataDestroy(pDstBlock);
|
blockDataDestroy(pDstBlock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
colDataAssign(pDst, pSrc, pDataBlock->info.rows, &pDataBlock->info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pDstBlock;
|
return pDstBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SPartitionOperatorInfo* pInfo = pOperator->info;
|
SPartitionOperatorInfo* pInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
|
@ -709,24 +744,37 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
||||||
}
|
}
|
||||||
if (pGroupInfo->blockForNotLoaded == NULL) {
|
if (pGroupInfo->blockForNotLoaded == NULL) {
|
||||||
pGroupInfo->blockForNotLoaded = taosArrayInit(0, sizeof(SSDataBlock*));
|
pGroupInfo->blockForNotLoaded = taosArrayInit(0, sizeof(SSDataBlock*));
|
||||||
|
QUERY_CHECK_NULL(pGroupInfo->blockForNotLoaded, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
pGroupInfo->offsetForNotLoaded = 0;
|
pGroupInfo->offsetForNotLoaded = 0;
|
||||||
}
|
}
|
||||||
dataNotLoadBlock->info.id.groupId = pGroupInfo->groupId;
|
dataNotLoadBlock->info.id.groupId = pGroupInfo->groupId;
|
||||||
dataNotLoadBlock->info.dataLoad = 0;
|
dataNotLoadBlock->info.dataLoad = 0;
|
||||||
taosArrayPush(pGroupInfo->blockForNotLoaded, &dataNotLoadBlock);
|
void* tmp = taosArrayPush(pGroupInfo->blockForNotLoaded, &dataNotLoadBlock);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDataGroupInfo** pGroupInfo, int32_t len) {
|
void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDataGroupInfo** pGroupInfo, int32_t len) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SDataGroupInfo* p = taosHashGet(pInfo->pGroupSet, pInfo->keyBuf, len);
|
SDataGroupInfo* p = taosHashGet(pInfo->pGroupSet, pInfo->keyBuf, len);
|
||||||
|
|
||||||
void* pPage = NULL;
|
void* pPage = NULL;
|
||||||
if (p == NULL) { // it is a new group
|
if (p == NULL) { // it is a new group
|
||||||
SDataGroupInfo gi = {0};
|
SDataGroupInfo gi = {0};
|
||||||
gi.pPageList = taosArrayInit(100, sizeof(int32_t));
|
gi.pPageList = taosArrayInit(100, sizeof(int32_t));
|
||||||
taosHashPut(pInfo->pGroupSet, pInfo->keyBuf, len, &gi, sizeof(SDataGroupInfo));
|
QUERY_CHECK_NULL(gi.pPageList, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
code = taosHashPut(pInfo->pGroupSet, pInfo->keyBuf, len, &gi, sizeof(SDataGroupInfo));
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
p = taosHashGet(pInfo->pGroupSet, pInfo->keyBuf, len);
|
p = taosHashGet(pInfo->pGroupSet, pInfo->keyBuf, len);
|
||||||
|
|
||||||
|
|
@ -736,7 +784,9 @@ void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDataGroupInf
|
||||||
return pPage;
|
return pPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(p->pPageList, &pageId);
|
void* tmp = taosArrayPush(p->pPageList, &pageId);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
*(int32_t*)pPage = 0;
|
*(int32_t*)pPage = 0;
|
||||||
} else {
|
} else {
|
||||||
int32_t* curId = taosArrayGetLast(p->pPageList);
|
int32_t* curId = taosArrayGetLast(p->pPageList);
|
||||||
|
|
@ -759,12 +809,21 @@ void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDataGroupInf
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(p->pPageList, &pageId);
|
void* tmp = taosArrayPush(p->pPageList, &pageId);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
memset(pPage, 0, getBufPageSize(pInfo->pBuf));
|
memset(pPage, 0, getBufPageSize(pInfo->pBuf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*pGroupInfo = p;
|
*pGroupInfo = p;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return pPage;
|
return pPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -832,6 +891,8 @@ static SSDataBlock* buildPartitionResultForNotLoadBlock(SDataGroupInfo* pGroupIn
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) {
|
static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SPartitionOperatorInfo* pInfo = pOperator->info;
|
SPartitionOperatorInfo* pInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
|
@ -877,8 +938,11 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) {
|
||||||
return buildPartitionResult(pOperator);
|
return buildPartitionResult(pOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->rowCapacity);
|
code = blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->rowCapacity);
|
||||||
blockDataFromBuf1(pInfo->binfo.pRes, page, pInfo->rowCapacity);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
code = blockDataFromBuf1(pInfo->binfo.pRes, page, pInfo->rowCapacity);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
pInfo->pageIndex += 1;
|
pInfo->pageIndex += 1;
|
||||||
releaseBufPage(pInfo->pBuf, page);
|
releaseBufPage(pInfo->pBuf, page);
|
||||||
|
|
@ -891,13 +955,21 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
if (pInfo->pOrderInfoArr) {
|
if (pInfo->pOrderInfoArr) {
|
||||||
pInfo->binfo.pRes->info.rows += pInfo->remainRows;
|
pInfo->binfo.pRes->info.rows += pInfo->remainRows;
|
||||||
blockDataTrimFirstRows(pInfo->binfo.pRes, pInfo->orderedRows);
|
code = blockDataTrimFirstRows(pInfo->binfo.pRes, pInfo->orderedRows);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
pInfo->orderedRows = blockDataGetSortedRows(pInfo->binfo.pRes, pInfo->pOrderInfoArr);
|
pInfo->orderedRows = blockDataGetSortedRows(pInfo->binfo.pRes, pInfo->pOrderInfoArr);
|
||||||
pInfo->remainRows = pInfo->binfo.pRes->info.rows - pInfo->orderedRows;
|
pInfo->remainRows = pInfo->binfo.pRes->info.rows - pInfo->orderedRows;
|
||||||
pInfo->binfo.pRes->info.rows = pInfo->orderedRows;
|
pInfo->binfo.pRes->info.rows = pInfo->orderedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDataUpdateTsWindow(pInfo->binfo.pRes, 0);
|
code = blockDataUpdateTsWindow(pInfo->binfo.pRes, 0);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
|
|
||||||
pOperator->resultInfo.totalRows += pInfo->binfo.pRes->info.rows;
|
pOperator->resultInfo.totalRows += pInfo->binfo.pRes->info.rows;
|
||||||
return pInfo->binfo.pRes;
|
return pInfo->binfo.pRes;
|
||||||
|
|
@ -908,8 +980,9 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
SPartitionOperatorInfo* pInfo = pOperator->info;
|
SPartitionOperatorInfo* pInfo = pOperator->info;
|
||||||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||||
|
|
||||||
|
|
@ -948,7 +1021,8 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
||||||
void* pGroupIter = taosHashIterate(pInfo->pGroupSet, NULL);
|
void* pGroupIter = taosHashIterate(pInfo->pGroupSet, NULL);
|
||||||
while (pGroupIter != NULL) {
|
while (pGroupIter != NULL) {
|
||||||
SDataGroupInfo* pGroupInfo = pGroupIter;
|
SDataGroupInfo* pGroupInfo = pGroupIter;
|
||||||
taosArrayPush(groupArray, pGroupInfo);
|
void* tmp = taosArrayPush(groupArray, pGroupInfo);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
pGroupIter = taosHashIterate(pInfo->pGroupSet, pGroupIter);
|
pGroupIter = taosHashIterate(pInfo->pGroupSet, pGroupIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -960,7 +1034,15 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
||||||
pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0;
|
pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0;
|
||||||
|
|
||||||
pOperator->status = OP_RES_TO_RETURN;
|
pOperator->status = OP_RES_TO_RETURN;
|
||||||
blockDataEnsureCapacity(pRes, 4096);
|
code = blockDataEnsureCapacity(pRes, 4096);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
|
}
|
||||||
|
|
||||||
return buildPartitionResult(pOperator);
|
return buildPartitionResult(pOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1002,6 +1084,8 @@ static void destroyPartitionOperatorInfo(void* param) {
|
||||||
|
|
||||||
SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode,
|
SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SPartitionOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SPartitionOperatorInfo));
|
SPartitionOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SPartitionOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
|
@ -1022,7 +1106,8 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
pTaskInfo->code = terrno;
|
pTaskInfo->code = terrno;
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
taosArrayPush(pInfo->pOrderInfoArr, &order);
|
void* tmp = taosArrayPush(pInfo->pOrderInfoArr, &order);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pPartNode->pExprs != NULL) {
|
if (pPartNode->pExprs != NULL) {
|
||||||
|
|
@ -1048,7 +1133,7 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
uint32_t defaultBufsz = 0;
|
uint32_t defaultBufsz = 0;
|
||||||
|
|
||||||
pInfo->binfo.pRes = createDataBlockFromDescNode(pPartNode->node.pOutputDataBlockDesc);
|
pInfo->binfo.pRes = createDataBlockFromDescNode(pPartNode->node.pOutputDataBlockDesc);
|
||||||
int32_t code = getBufferPgSize(pInfo->binfo.pRes->info.rowSize, &defaultPgsz, &defaultBufsz);
|
code = getBufferPgSize(pInfo->binfo.pRes->info.rowSize, &defaultPgsz, &defaultBufsz);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
terrno = code;
|
terrno = code;
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
|
|
@ -1069,7 +1154,8 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->rowCapacity = blockDataGetCapacityInRow(pInfo->binfo.pRes, getBufPageSize(pInfo->pBuf),
|
pInfo->rowCapacity =
|
||||||
|
blockDataGetCapacityInRow(pInfo->binfo.pRes, getBufPageSize(pInfo->pBuf),
|
||||||
blockDataGetSerialMetaSize(taosArrayGetSize(pInfo->binfo.pRes->pDataBlock)));
|
blockDataGetSerialMetaSize(taosArrayGetSize(pInfo->binfo.pRes->pDataBlock)));
|
||||||
pInfo->columnOffset = setupColumnOffset(pInfo->binfo.pRes, pInfo->rowCapacity);
|
pInfo->columnOffset = setupColumnOffset(pInfo->binfo.pRes, pInfo->rowCapacity);
|
||||||
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
||||||
|
|
@ -1084,8 +1170,8 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||||
|
|
||||||
pOperator->fpSet =
|
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, hashPartition, NULL, destroyPartitionOperatorInfo,
|
||||||
createOperatorFpSet(optrDummyOpenFn, hashPartition, NULL, destroyPartitionOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
||||||
|
|
||||||
code = appendDownstream(pOperator, &downstream, 1);
|
code = appendDownstream(pOperator, &downstream, 1);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
@ -1100,6 +1186,7 @@ _error:
|
||||||
if (pInfo != NULL) {
|
if (pInfo != NULL) {
|
||||||
destroyPartitionOperatorInfo(pInfo);
|
destroyPartitionOperatorInfo(pInfo);
|
||||||
}
|
}
|
||||||
|
pTaskInfo->code = code;
|
||||||
taosMemoryFreeClear(pOperator);
|
taosMemoryFreeClear(pOperator);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1110,8 +1197,8 @@ int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo,
|
||||||
SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo;
|
SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo;
|
||||||
SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
|
SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
|
||||||
|
|
||||||
SResultRow* pResultRow =
|
SResultRow* pResultRow = doSetResultOutBufByKey(pBuf, pResultRowInfo, (char*)pData, bytes, true, groupId, pTaskInfo,
|
||||||
doSetResultOutBufByKey(pBuf, pResultRowInfo, (char*)pData, bytes, true, groupId, pTaskInfo, false, pAggSup, false);
|
false, pAggSup, false);
|
||||||
|
|
||||||
return setResultRowInitCtx(pResultRow, pCtx, numOfCols, pOperator->exprSupp.rowEntryInfoOffset);
|
return setResultRowInitCtx(pResultRow, pCtx, numOfCols, pOperator->exprSupp.rowEntryInfoOffset);
|
||||||
}
|
}
|
||||||
|
|
@ -1134,6 +1221,8 @@ static bool hasRemainPartion(SStreamPartitionOperatorInfo* pInfo) { return pInfo
|
||||||
static bool hasRemainTbName(SStreamPartitionOperatorInfo* pInfo) { return pInfo->pTbNameIte != NULL; }
|
static bool hasRemainTbName(SStreamPartitionOperatorInfo* pInfo) { return pInfo->pTbNameIte != NULL; }
|
||||||
|
|
||||||
static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
|
static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SStorageAPI* pAPI = &pOperator->pTaskInfo->storageAPI;
|
SStorageAPI* pAPI = &pOperator->pTaskInfo->storageAPI;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
|
@ -1153,14 +1242,20 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
|
||||||
bool isNull = colDataIsNull(pSrcCol, pSrc->info.rows, rowIndex, NULL);
|
bool isNull = colDataIsNull(pSrcCol, pSrc->info.rows, rowIndex, NULL);
|
||||||
char* pSrcData = NULL;
|
char* pSrcData = NULL;
|
||||||
if (!isNull) pSrcData = colDataGetData(pSrcCol, rowIndex);
|
if (!isNull) pSrcData = colDataGetData(pSrcCol, rowIndex);
|
||||||
colDataSetVal(pDestCol, pDest->info.rows, pSrcData, isNull);
|
code = colDataSetVal(pDestCol, pDest->info.rows, pSrcData, isNull);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
pDest->info.rows++;
|
pDest->info.rows++;
|
||||||
}
|
}
|
||||||
pDest->info.parTbName[0] = 0;
|
pDest->info.parTbName[0] = 0;
|
||||||
if (pInfo->tbnameCalSup.numOfExprs > 0) {
|
if (pInfo->tbnameCalSup.numOfExprs > 0) {
|
||||||
void* tbname = NULL;
|
void* tbname = NULL;
|
||||||
if (pAPI->stateStore.streamStateGetParName(pOperator->pTaskInfo->streamInfo.pState, pParInfo->groupId, &tbname, false) == 0) {
|
int32_t winCode = TSDB_CODE_SUCCESS;
|
||||||
|
code = pAPI->stateStore.streamStateGetParName(pOperator->pTaskInfo->streamInfo.pState, pParInfo->groupId, &tbname,
|
||||||
|
false, &winCode);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
if (winCode == TSDB_CODE_SUCCESS) {
|
||||||
memcpy(pDest->info.parTbName, tbname, TSDB_TABLE_NAME_LEN);
|
memcpy(pDest->info.parTbName, tbname, TSDB_TABLE_NAME_LEN);
|
||||||
pAPI->stateStore.streamStateFreeVal(tbname);
|
pAPI->stateStore.streamStateFreeVal(tbname);
|
||||||
}
|
}
|
||||||
|
|
@ -1169,25 +1264,42 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
|
||||||
pParInfo->rowIds = NULL;
|
pParInfo->rowIds = NULL;
|
||||||
pDest->info.dataLoad = 1;
|
pDest->info.dataLoad = 1;
|
||||||
|
|
||||||
blockDataUpdateTsWindow(pDest, pInfo->tsColIndex);
|
code = blockDataUpdateTsWindow(pDest, pInfo->tsColIndex);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
pDest->info.id.groupId = pParInfo->groupId;
|
pDest->info.id.groupId = pParInfo->groupId;
|
||||||
pOperator->resultInfo.totalRows += pDest->info.rows;
|
pOperator->resultInfo.totalRows += pDest->info.rows;
|
||||||
pInfo->parIte = taosHashIterate(pInfo->pPartitions, pInfo->parIte);
|
pInfo->parIte = taosHashIterate(pInfo->pPartitions, pInfo->parIte);
|
||||||
ASSERT(pDest->info.rows > 0);
|
ASSERT(pDest->info.rows > 0);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
blockDataCleanup(pDest);
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
printDataBlock(pDest, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
printDataBlock(pDest, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||||
return pDest;
|
return pDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendCreateTableRow(void* pState, SExprSupp* pTableSup, SExprSupp* pTagSup, uint64_t groupId,
|
int32_t appendCreateTableRow(void* pState, SExprSupp* pTableSup, SExprSupp* pTagSup, uint64_t groupId,
|
||||||
SSDataBlock* pSrcBlock, int32_t rowId, SSDataBlock* pDestBlock, SStateStore* pAPI) {
|
SSDataBlock* pSrcBlock, int32_t rowId, SSDataBlock* pDestBlock, SStateStore* pAPI) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
void* pValue = NULL;
|
void* pValue = NULL;
|
||||||
if (pAPI->streamStateGetParName(pState, groupId, &pValue, true) != 0) {
|
int32_t winCode = TSDB_CODE_SUCCESS;
|
||||||
|
code = pAPI->streamStateGetParName(pState, groupId, &pValue, true, &winCode);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
if (winCode != TSDB_CODE_SUCCESS) {
|
||||||
SSDataBlock* pTmpBlock = blockCopyOneRow(pSrcBlock, rowId);
|
SSDataBlock* pTmpBlock = blockCopyOneRow(pSrcBlock, rowId);
|
||||||
memset(pTmpBlock->info.parTbName, 0, TSDB_TABLE_NAME_LEN);
|
memset(pTmpBlock->info.parTbName, 0, TSDB_TABLE_NAME_LEN);
|
||||||
pTmpBlock->info.id.groupId = groupId;
|
pTmpBlock->info.id.groupId = groupId;
|
||||||
char* tbName = pSrcBlock->info.parTbName;
|
char* tbName = pSrcBlock->info.parTbName;
|
||||||
if (pTableSup->numOfExprs > 0) {
|
if (pTableSup->numOfExprs > 0) {
|
||||||
projectApplyFunctions(pTableSup->pExprInfo, pDestBlock, pTmpBlock, pTableSup->pCtx, pTableSup->numOfExprs, NULL);
|
code = projectApplyFunctions(pTableSup->pExprInfo, pDestBlock, pTmpBlock, pTableSup->pCtx, pTableSup->numOfExprs,
|
||||||
|
NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
SColumnInfoData* pTbCol = taosArrayGet(pDestBlock->pDataBlock, UD_TABLE_NAME_COLUMN_INDEX);
|
SColumnInfoData* pTbCol = taosArrayGet(pDestBlock->pDataBlock, UD_TABLE_NAME_COLUMN_INDEX);
|
||||||
memset(tbName, 0, TSDB_TABLE_NAME_LEN);
|
memset(tbName, 0, TSDB_TABLE_NAME_LEN);
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
|
|
@ -1198,7 +1310,8 @@ void appendCreateTableRow(void* pState, SExprSupp* pTableSup, SExprSupp* pTagSup
|
||||||
void* pData = colDataGetData(pTbCol, pDestBlock->info.rows - 1);
|
void* pData = colDataGetData(pTbCol, pDestBlock->info.rows - 1);
|
||||||
len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN - 1);
|
len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN - 1);
|
||||||
memcpy(tbName, varDataVal(pData), len);
|
memcpy(tbName, varDataVal(pData), len);
|
||||||
pAPI->streamStatePutParName(pState, groupId, tbName);
|
code = pAPI->streamStatePutParName(pState, groupId, tbName);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
memcpy(pTmpBlock->info.parTbName, tbName, len);
|
memcpy(pTmpBlock->info.parTbName, tbName, len);
|
||||||
pDestBlock->info.rows--;
|
pDestBlock->info.rows--;
|
||||||
|
|
@ -1209,45 +1322,63 @@ void appendCreateTableRow(void* pState, SExprSupp* pTableSup, SExprSupp* pTagSup
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTagSup->numOfExprs > 0) {
|
if (pTagSup->numOfExprs > 0) {
|
||||||
projectApplyFunctions(pTagSup->pExprInfo, pDestBlock, pTmpBlock, pTagSup->pCtx, pTagSup->numOfExprs, NULL);
|
code = projectApplyFunctions(pTagSup->pExprInfo, pDestBlock, pTmpBlock, pTagSup->pCtx, pTagSup->numOfExprs, NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
pDestBlock->info.rows--;
|
pDestBlock->info.rows--;
|
||||||
} else {
|
} else {
|
||||||
memcpy(pDestBlock->info.parTbName, pTmpBlock->info.parTbName, TSDB_TABLE_NAME_LEN);
|
memcpy(pDestBlock->info.parTbName, pTmpBlock->info.parTbName, TSDB_TABLE_NAME_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* pGpIdCol = taosArrayGet(pDestBlock->pDataBlock, UD_GROUPID_COLUMN_INDEX);
|
void* pGpIdCol = taosArrayGet(pDestBlock->pDataBlock, UD_GROUPID_COLUMN_INDEX);
|
||||||
colDataSetVal(pGpIdCol, pDestBlock->info.rows, (const char*)&groupId, false);
|
code = colDataSetVal(pGpIdCol, pDestBlock->info.rows, (const char*)&groupId, false);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
pDestBlock->info.rows++;
|
pDestBlock->info.rows++;
|
||||||
blockDataDestroy(pTmpBlock);
|
blockDataDestroy(pTmpBlock);
|
||||||
} else {
|
} else {
|
||||||
memcpy(pSrcBlock->info.parTbName, pValue, TSDB_TABLE_NAME_LEN);
|
memcpy(pSrcBlock->info.parTbName, pValue, TSDB_TABLE_NAME_LEN);
|
||||||
}
|
}
|
||||||
pAPI->streamStateFreeVal(pValue);
|
pAPI->streamStateFreeVal(pValue);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* buildStreamCreateTableResult(SOperatorInfo* pOperator) {
|
static int32_t buildStreamCreateTableResult(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SExecTaskInfo* pTask = pOperator->pTaskInfo;
|
SExecTaskInfo* pTask = pOperator->pTaskInfo;
|
||||||
|
|
||||||
SStreamPartitionOperatorInfo* pInfo = pOperator->info;
|
SStreamPartitionOperatorInfo* pInfo = pOperator->info;
|
||||||
|
SSDataBlock* pSrc = pInfo->pInputDataBlock;
|
||||||
if ((pInfo->tbnameCalSup.numOfExprs == 0 && pInfo->tagCalSup.numOfExprs == 0) ||
|
if ((pInfo->tbnameCalSup.numOfExprs == 0 && pInfo->tagCalSup.numOfExprs == 0) ||
|
||||||
taosHashGetSize(pInfo->pPartitions) == 0) {
|
taosHashGetSize(pInfo->pPartitions) == 0) {
|
||||||
return NULL;
|
goto _end;
|
||||||
}
|
}
|
||||||
blockDataCleanup(pInfo->pCreateTbRes);
|
blockDataCleanup(pInfo->pCreateTbRes);
|
||||||
blockDataEnsureCapacity(pInfo->pCreateTbRes, taosHashGetSize(pInfo->pPartitions));
|
code = blockDataEnsureCapacity(pInfo->pCreateTbRes, taosHashGetSize(pInfo->pPartitions));
|
||||||
SSDataBlock* pSrc = pInfo->pInputDataBlock;
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
if (pInfo->pTbNameIte != NULL) {
|
if (pInfo->pTbNameIte != NULL) {
|
||||||
SPartitionDataInfo* pParInfo = (SPartitionDataInfo*)pInfo->pTbNameIte;
|
SPartitionDataInfo* pParInfo = (SPartitionDataInfo*)pInfo->pTbNameIte;
|
||||||
int32_t rowId = *(int32_t*)taosArrayGet(pParInfo->rowIds, 0);
|
int32_t rowId = *(int32_t*)taosArrayGet(pParInfo->rowIds, 0);
|
||||||
appendCreateTableRow(pTask->streamInfo.pState, &pInfo->tbnameCalSup, &pInfo->tagCalSup,
|
code = appendCreateTableRow(pTask->streamInfo.pState, &pInfo->tbnameCalSup, &pInfo->tagCalSup, pParInfo->groupId,
|
||||||
pParInfo->groupId, pSrc, rowId, pInfo->pCreateTbRes, &pTask->storageAPI.stateStore);
|
pSrc, rowId, pInfo->pCreateTbRes, &pTask->storageAPI.stateStore);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
pInfo->pTbNameIte = taosHashIterate(pInfo->pPartitions, pInfo->pTbNameIte);
|
pInfo->pTbNameIte = taosHashIterate(pInfo->pPartitions, pInfo->pTbNameIte);
|
||||||
}
|
}
|
||||||
return pInfo->pCreateTbRes->info.rows > 0 ? pInfo->pCreateTbRes : NULL;
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doStreamHashPartitionImpl(SStreamPartitionOperatorInfo* pInfo, SSDataBlock* pBlock) {
|
static void doStreamHashPartitionImpl(SStreamPartitionOperatorInfo* pInfo, SSDataBlock* pBlock) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
pInfo->pInputDataBlock = pBlock;
|
pInfo->pInputDataBlock = pBlock;
|
||||||
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
||||||
recordNewGroupKeys(pInfo->partitionSup.pGroupCols, pInfo->partitionSup.pGroupColVals, pBlock, i);
|
recordNewGroupKeys(pInfo->partitionSup.pGroupCols, pInfo->partitionSup.pGroupColVals, pBlock, i);
|
||||||
|
|
@ -1255,30 +1386,42 @@ static void doStreamHashPartitionImpl(SStreamPartitionOperatorInfo* pInfo, SSDat
|
||||||
SPartitionDataInfo* pParData =
|
SPartitionDataInfo* pParData =
|
||||||
(SPartitionDataInfo*)taosHashGet(pInfo->pPartitions, pInfo->partitionSup.keyBuf, keyLen);
|
(SPartitionDataInfo*)taosHashGet(pInfo->pPartitions, pInfo->partitionSup.keyBuf, keyLen);
|
||||||
if (pParData) {
|
if (pParData) {
|
||||||
taosArrayPush(pParData->rowIds, &i);
|
void* tmp = taosArrayPush(pParData->rowIds, &i);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
} else {
|
} else {
|
||||||
SPartitionDataInfo newParData = {0};
|
SPartitionDataInfo newParData = {0};
|
||||||
newParData.groupId = calcGroupId(pInfo->partitionSup.keyBuf, keyLen);
|
newParData.groupId = calcGroupId(pInfo->partitionSup.keyBuf, keyLen);
|
||||||
newParData.rowIds = taosArrayInit(64, sizeof(int32_t));
|
newParData.rowIds = taosArrayInit(64, sizeof(int32_t));
|
||||||
taosArrayPush(newParData.rowIds, &i);
|
void* tmp = taosArrayPush(newParData.rowIds, &i);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
code =
|
||||||
taosHashPut(pInfo->pPartitions, pInfo->partitionSup.keyBuf, keyLen, &newParData, sizeof(SPartitionDataInfo));
|
taosHashPut(pInfo->pPartitions, pInfo->partitionSup.keyBuf, keyLen, &newParData, sizeof(SPartitionDataInfo));
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
SStreamPartitionOperatorInfo* pInfo = pOperator->info;
|
||||||
|
|
||||||
if (pOperator->status == OP_EXEC_DONE) {
|
if (pOperator->status == OP_EXEC_DONE) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
||||||
SStreamPartitionOperatorInfo* pInfo = pOperator->info;
|
|
||||||
SSDataBlock* pCtRes = NULL;
|
|
||||||
|
|
||||||
if (hasRemainTbName(pInfo)) {
|
if (hasRemainTbName(pInfo)) {
|
||||||
pCtRes = buildStreamCreateTableResult(pOperator);
|
code = buildStreamCreateTableResult(pOperator);
|
||||||
if (pCtRes != NULL) {
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
return pCtRes;
|
if (pInfo->pCreateTbRes && pInfo->pCreateTbRes->info.rows > 0) {
|
||||||
|
return pInfo->pCreateTbRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1303,7 +1446,9 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
||||||
pInfo->binfo.pRes->info.type = pBlock->info.type;
|
pInfo->binfo.pRes->info.type = pBlock->info.type;
|
||||||
break;
|
break;
|
||||||
case STREAM_DELETE_DATA: {
|
case STREAM_DELETE_DATA: {
|
||||||
copyDataBlock(pInfo->pDelRes, pBlock);
|
code = copyDataBlock(pInfo->pDelRes, pBlock);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;
|
pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;
|
||||||
printDataBlock(pInfo->pDelRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
printDataBlock(pInfo->pDelRes, getStreamOpName(pOperator->operatorType), GET_TASKID(pTaskInfo));
|
||||||
return pInfo->pDelRes;
|
return pInfo->pDelRes;
|
||||||
|
|
@ -1320,8 +1465,9 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||||
if (pInfo->scalarSup.pExprInfo != NULL) {
|
if (pInfo->scalarSup.pExprInfo != NULL) {
|
||||||
projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
|
||||||
pInfo->scalarSup.numOfExprs, NULL);
|
pInfo->scalarSup.numOfExprs, NULL);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
taosHashClear(pInfo->pPartitions);
|
taosHashClear(pInfo->pPartitions);
|
||||||
doStreamHashPartitionImpl(pInfo, pBlock);
|
doStreamHashPartitionImpl(pInfo, pBlock);
|
||||||
|
|
@ -1330,11 +1476,18 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
pInfo->parIte = taosHashIterate(pInfo->pPartitions, NULL);
|
pInfo->parIte = taosHashIterate(pInfo->pPartitions, NULL);
|
||||||
pInfo->pTbNameIte = taosHashIterate(pInfo->pPartitions, NULL);
|
pInfo->pTbNameIte = taosHashIterate(pInfo->pPartitions, NULL);
|
||||||
pCtRes = buildStreamCreateTableResult(pOperator);
|
code = buildStreamCreateTableResult(pOperator);
|
||||||
if (pCtRes != NULL) {
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
return pCtRes;
|
if (pInfo->pCreateTbRes && pInfo->pCreateTbRes->info.rows > 0) {
|
||||||
|
return pInfo->pCreateTbRes;
|
||||||
}
|
}
|
||||||
return buildStreamPartitionResult(pOperator);
|
return buildStreamPartitionResult(pOperator);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyStreamPartitionOperatorInfo(void* param) {
|
static void destroyStreamPartitionOperatorInfo(void* param) {
|
||||||
|
|
@ -1358,7 +1511,8 @@ static void destroyStreamPartitionOperatorInfo(void* param) {
|
||||||
taosMemoryFreeClear(param);
|
taosMemoryFreeClear(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pParSup, SExprSupp* pExpr, SExprSupp* pTbnameExpr) {
|
int32_t initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pParSup, SExprSupp* pExpr,
|
||||||
|
SExprSupp* pTbnameExpr) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
SStorageAPI* pAPI = &downstream->pTaskInfo->storageAPI;
|
SStorageAPI* pAPI = &downstream->pTaskInfo->storageAPI;
|
||||||
|
|
@ -1372,12 +1526,15 @@ int32_t initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pPar
|
||||||
pScanInfo->pPartScalarSup = pExpr;
|
pScanInfo->pPartScalarSup = pExpr;
|
||||||
pScanInfo->pPartTbnameSup = pTbnameExpr;
|
pScanInfo->pPartTbnameSup = pTbnameExpr;
|
||||||
if (!pScanInfo->pUpdateInfo) {
|
if (!pScanInfo->pUpdateInfo) {
|
||||||
code = pAPI->stateStore.updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, 0, pScanInfo->igCheckUpdate, pScanInfo->pkColType, pScanInfo->pkColLen, &pScanInfo->pUpdateInfo);
|
code = pAPI->stateStore.updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, 0, pScanInfo->igCheckUpdate,
|
||||||
|
pScanInfo->pkColType, pScanInfo->pkColLen, &pScanInfo->pUpdateInfo);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag) {
|
SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
pBlock->info.hasVarCol = false;
|
pBlock->info.hasVarCol = false;
|
||||||
pBlock->info.id.groupId = 0;
|
pBlock->info.id.groupId = 0;
|
||||||
|
|
@ -1395,14 +1552,16 @@ SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag) {
|
||||||
}
|
}
|
||||||
pBlock->info.rowSize += infoData.info.bytes;
|
pBlock->info.rowSize += infoData.info.bytes;
|
||||||
// sub table name
|
// sub table name
|
||||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
void* tmp = taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
SColumnInfoData gpIdData = {0};
|
SColumnInfoData gpIdData = {0};
|
||||||
gpIdData.info.type = TSDB_DATA_TYPE_UBIGINT;
|
gpIdData.info.type = TSDB_DATA_TYPE_UBIGINT;
|
||||||
gpIdData.info.bytes = 8;
|
gpIdData.info.bytes = 8;
|
||||||
pBlock->info.rowSize += gpIdData.info.bytes;
|
pBlock->info.rowSize += gpIdData.info.bytes;
|
||||||
// group id
|
// group id
|
||||||
taosArrayPush(pBlock->pDataBlock, &gpIdData);
|
tmp = taosArrayPush(pBlock->pDataBlock, &gpIdData);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
for (int32_t i = 0; i < tag->numOfExprs; i++) {
|
for (int32_t i = 0; i < tag->numOfExprs; i++) {
|
||||||
SColumnInfoData tagCol = {0};
|
SColumnInfoData tagCol = {0};
|
||||||
|
|
@ -1410,10 +1569,17 @@ SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag) {
|
||||||
tagCol.info.bytes = tag->pExprInfo[i].base.resSchema.bytes;
|
tagCol.info.bytes = tag->pExprInfo[i].base.resSchema.bytes;
|
||||||
tagCol.info.precision = tag->pExprInfo[i].base.resSchema.precision;
|
tagCol.info.precision = tag->pExprInfo[i].base.resSchema.precision;
|
||||||
// tag info
|
// tag info
|
||||||
taosArrayPush(pBlock->pDataBlock, &tagCol);
|
tmp = taosArrayPush(pBlock->pDataBlock, &tagCol);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
pBlock->info.rowSize += tagCol.info.bytes;
|
pBlock->info.rowSize += tagCol.info.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1439,42 +1605,33 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
SExprInfo* pCalExprInfo = createExprInfo(pPartNode->part.pExprs, NULL, &num);
|
SExprInfo* pCalExprInfo = createExprInfo(pPartNode->part.pExprs, NULL, &num);
|
||||||
code = initExprSupp(&pInfo->scalarSup, pCalExprInfo, num, &pTaskInfo->storageAPI.functionStore);
|
code = initExprSupp(&pInfo->scalarSup, pCalExprInfo, num, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->tbnameCalSup.numOfExprs = 0;
|
pInfo->tbnameCalSup.numOfExprs = 0;
|
||||||
if (pPartNode->pSubtable != NULL) {
|
if (pPartNode->pSubtable != NULL) {
|
||||||
SExprInfo* pSubTableExpr = taosMemoryCalloc(1, sizeof(SExprInfo));
|
SExprInfo* pSubTableExpr = taosMemoryCalloc(1, sizeof(SExprInfo));
|
||||||
if (pSubTableExpr == NULL) {
|
QUERY_CHECK_NULL(pSubTableExpr, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
pInfo->tbnameCalSup.pExprInfo = pSubTableExpr;
|
pInfo->tbnameCalSup.pExprInfo = pSubTableExpr;
|
||||||
createExprFromOneNode(pSubTableExpr, pPartNode->pSubtable, 0);
|
createExprFromOneNode(pSubTableExpr, pPartNode->pSubtable, 0);
|
||||||
code = initExprSupp(&pInfo->tbnameCalSup, pSubTableExpr, 1, &pTaskInfo->storageAPI.functionStore);
|
code = initExprSupp(&pInfo->tbnameCalSup, pSubTableExpr, 1, &pTaskInfo->storageAPI.functionStore);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->tagCalSup.numOfExprs = 0;
|
pInfo->tagCalSup.numOfExprs = 0;
|
||||||
if (pPartNode->pTags != NULL) {
|
if (pPartNode->pTags != NULL) {
|
||||||
int32_t numOfTags;
|
int32_t numOfTags;
|
||||||
SExprInfo* pTagExpr = createExpr(pPartNode->pTags, &numOfTags);
|
SExprInfo* pTagExpr = createExpr(pPartNode->pTags, &numOfTags);
|
||||||
if (pTagExpr == NULL) {
|
QUERY_CHECK_NULL(pTagExpr, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _error;
|
code = initExprSupp(&pInfo->tagCalSup, pTagExpr, numOfTags, &pTaskInfo->storageAPI.functionStore);
|
||||||
}
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
if (initExprSupp(&pInfo->tagCalSup, pTagExpr, numOfTags, &pTaskInfo->storageAPI.functionStore) != 0) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInfo->tbnameCalSup.numOfExprs != 0 || pInfo->tagCalSup.numOfExprs != 0) {
|
if (pInfo->tbnameCalSup.numOfExprs != 0 || pInfo->tagCalSup.numOfExprs != 0) {
|
||||||
pInfo->pCreateTbRes = buildCreateTableBlock(&pInfo->tbnameCalSup, &pInfo->tagCalSup);
|
pInfo->pCreateTbRes = buildCreateTableBlock(&pInfo->tbnameCalSup, &pInfo->tagCalSup);
|
||||||
|
QUERY_CHECK_NULL(pInfo->pCreateTbRes, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
} else {
|
} else {
|
||||||
pInfo->pCreateTbRes = NULL;
|
pInfo->pCreateTbRes = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1482,18 +1639,15 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr
|
||||||
int32_t keyLen = 0;
|
int32_t keyLen = 0;
|
||||||
code = initGroupOptrInfo(&pInfo->partitionSup.pGroupColVals, &keyLen, &pInfo->partitionSup.keyBuf,
|
code = initGroupOptrInfo(&pInfo->partitionSup.pGroupColVals, &keyLen, &pInfo->partitionSup.keyBuf,
|
||||||
pInfo->partitionSup.pGroupCols);
|
pInfo->partitionSup.pGroupCols);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
pInfo->partitionSup.needCalc = true;
|
pInfo->partitionSup.needCalc = true;
|
||||||
|
|
||||||
pInfo->binfo.pRes = createDataBlockFromDescNode(pPartNode->part.node.pOutputDataBlockDesc);
|
pInfo->binfo.pRes = createDataBlockFromDescNode(pPartNode->part.node.pOutputDataBlockDesc);
|
||||||
if (pInfo->binfo.pRes == NULL) {
|
QUERY_CHECK_NULL(pInfo->binfo.pRes, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
blockDataEnsureCapacity(pInfo->binfo.pRes, 4096);
|
code = blockDataEnsureCapacity(pInfo->binfo.pRes, 4096);
|
||||||
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
pInfo->parIte = NULL;
|
pInfo->parIte = NULL;
|
||||||
pInfo->pTbNameIte = NULL;
|
pInfo->pTbNameIte = NULL;
|
||||||
|
|
@ -1504,6 +1658,7 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr
|
||||||
taosHashSetFreeFp(pInfo->pPartitions, freePartItem);
|
taosHashSetFreeFp(pInfo->pPartitions, freePartItem);
|
||||||
pInfo->tsColIndex = 0;
|
pInfo->tsColIndex = 0;
|
||||||
pInfo->pDelRes = createSpecialDataBlock(STREAM_DELETE_RESULT);
|
pInfo->pDelRes = createSpecialDataBlock(STREAM_DELETE_RESULT);
|
||||||
|
QUERY_CHECK_NULL(pInfo->pDelRes, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pPartNode->part.pTargets, NULL, &numOfCols);
|
SExprInfo* pExprInfo = createExprInfo(pPartNode->part.pTargets, NULL, &numOfCols);
|
||||||
|
|
@ -1512,15 +1667,16 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr
|
||||||
pInfo, pTaskInfo);
|
pInfo, pTaskInfo);
|
||||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||||
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doStreamHashPartition, NULL,
|
pOperator->fpSet =
|
||||||
destroyStreamPartitionOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
createOperatorFpSet(optrDummyOpenFn, doStreamHashPartition, NULL, destroyStreamPartitionOperatorInfo,
|
||||||
|
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
||||||
setOperatorStreamStateFn(pOperator, streamOpReleaseState, streamOpReloadState);
|
setOperatorStreamStateFn(pOperator, streamOpReleaseState, streamOpReloadState);
|
||||||
|
|
||||||
code = initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup, &pInfo->tbnameCalSup);
|
code = initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup, &pInfo->tbnameCalSup);
|
||||||
TSDB_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
code = appendDownstream(pOperator, &downstream, 1);
|
code = appendDownstream(pOperator, &downstream, 1);
|
||||||
TSDB_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
|
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
|
|
@ -1532,12 +1688,15 @@ _error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* extractColumnInfo(SNodeList* pNodeList) {
|
int32_t extractColumnInfo(SNodeList* pNodeList, SArray** pArrayRes) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
int32_t lino = 0;
|
||||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
||||||
if (pList == NULL) {
|
if (pList == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
(*pArrayRes) = NULL;
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
|
|
@ -1547,7 +1706,8 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
|
||||||
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
||||||
|
|
||||||
SColumn c = extractColumnFromColumnNode(pColNode);
|
SColumn c = extractColumnFromColumnNode(pColNode);
|
||||||
taosArrayPush(pList, &c);
|
void* tmp = taosArrayPush(pList, &c);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
} else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) {
|
} else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) {
|
||||||
SValueNode* pValNode = (SValueNode*)pNode->pExpr;
|
SValueNode* pValNode = (SValueNode*)pNode->pExpr;
|
||||||
SColumn c = {0};
|
SColumn c = {0};
|
||||||
|
|
@ -1558,9 +1718,16 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
|
||||||
c.scale = pValNode->node.resType.scale;
|
c.scale = pValNode->node.resType.scale;
|
||||||
c.precision = pValNode->node.resType.precision;
|
c.precision = pValNode->node.resType.precision;
|
||||||
|
|
||||||
taosArrayPush(pList, &c);
|
void* tmp = taosArrayPush(pList, &c);
|
||||||
|
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pList;
|
(*pArrayRes) = pList;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1096,7 +1096,8 @@ static void destroyHashJoinOperator(void* param) {
|
||||||
|
|
||||||
hJoinFreeTableInfo(&pJoinOperator->tbs[0]);
|
hJoinFreeTableInfo(&pJoinOperator->tbs[0]);
|
||||||
hJoinFreeTableInfo(&pJoinOperator->tbs[1]);
|
hJoinFreeTableInfo(&pJoinOperator->tbs[1]);
|
||||||
pJoinOperator->finBlk = blockDataDestroy(pJoinOperator->finBlk);
|
blockDataDestroy(pJoinOperator->finBlk);
|
||||||
|
pJoinOperator->finBlk = NULL;
|
||||||
taosMemoryFreeClear(pJoinOperator->pResColMap);
|
taosMemoryFreeClear(pJoinOperator->pResColMap);
|
||||||
taosArrayDestroyEx(pJoinOperator->pRowBufs, hJoinFreeBufPage);
|
taosArrayDestroyEx(pJoinOperator->pRowBufs, hJoinFreeBufPage);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3555,8 +3555,10 @@ void mJoinDestroyWindowCtx(SMJoinOperatorInfo* pJoin) {
|
||||||
|
|
||||||
mWinJoinResetWindowCache(pCtx, &pCtx->cache);
|
mWinJoinResetWindowCache(pCtx, &pCtx->cache);
|
||||||
|
|
||||||
pCtx->finBlk = blockDataDestroy(pCtx->finBlk);
|
blockDataDestroy(pCtx->finBlk);
|
||||||
pCtx->cache.outBlk = blockDataDestroy(pCtx->cache.outBlk);
|
pCtx->finBlk = NULL;
|
||||||
|
blockDataDestroy(pCtx->cache.outBlk);
|
||||||
|
pCtx->cache.outBlk = NULL;
|
||||||
|
|
||||||
taosArrayDestroy(pCtx->cache.grps);
|
taosArrayDestroy(pCtx->cache.grps);
|
||||||
}
|
}
|
||||||
|
|
@ -3632,9 +3634,11 @@ int32_t mJoinInitWindowCtx(SMJoinOperatorInfo* pJoin, SSortMergeJoinPhysiNode* p
|
||||||
|
|
||||||
void mJoinDestroyMergeCtx(SMJoinOperatorInfo* pJoin) {
|
void mJoinDestroyMergeCtx(SMJoinOperatorInfo* pJoin) {
|
||||||
SMJoinMergeCtx* pCtx = &pJoin->ctx.mergeCtx;
|
SMJoinMergeCtx* pCtx = &pJoin->ctx.mergeCtx;
|
||||||
|
blockDataDestroy(pCtx->finBlk);
|
||||||
|
blockDataDestroy(pCtx->midBlk);
|
||||||
|
|
||||||
pCtx->finBlk = blockDataDestroy(pCtx->finBlk);
|
pCtx->finBlk = NULL;
|
||||||
pCtx->midBlk = blockDataDestroy(pCtx->midBlk);
|
pCtx->midBlk = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,8 +232,11 @@ int32_t getSortMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, u
|
||||||
|
|
||||||
void destroySortMergeOperatorInfo(void* param) {
|
void destroySortMergeOperatorInfo(void* param) {
|
||||||
SSortMergeInfo* pSortMergeInfo = param;
|
SSortMergeInfo* pSortMergeInfo = param;
|
||||||
pSortMergeInfo->pInputBlock = blockDataDestroy(pSortMergeInfo->pInputBlock);
|
blockDataDestroy(pSortMergeInfo->pInputBlock);
|
||||||
pSortMergeInfo->pIntermediateBlock = blockDataDestroy(pSortMergeInfo->pIntermediateBlock);
|
pSortMergeInfo->pInputBlock = NULL;
|
||||||
|
|
||||||
|
blockDataDestroy(pSortMergeInfo->pIntermediateBlock);
|
||||||
|
pSortMergeInfo->pIntermediateBlock = NULL;
|
||||||
|
|
||||||
taosArrayDestroy(pSortMergeInfo->matchInfo.pList);
|
taosArrayDestroy(pSortMergeInfo->matchInfo.pList);
|
||||||
|
|
||||||
|
|
@ -429,7 +432,8 @@ SSDataBlock* doMultiwayMerge(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
void destroyMultiwayMergeOperatorInfo(void* param) {
|
void destroyMultiwayMergeOperatorInfo(void* param) {
|
||||||
SMultiwayMergeOperatorInfo* pInfo = (SMultiwayMergeOperatorInfo*)param;
|
SMultiwayMergeOperatorInfo* pInfo = (SMultiwayMergeOperatorInfo*)param;
|
||||||
pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes);
|
blockDataDestroy(pInfo->binfo.pRes);
|
||||||
|
pInfo->binfo.pRes = NULL;
|
||||||
|
|
||||||
if (NULL != gMultiwayMergeFps[pInfo->type].closeFn) {
|
if (NULL != gMultiwayMergeFps[pInfo->type].closeFn) {
|
||||||
(*gMultiwayMergeFps[pInfo->type].closeFn)(&pInfo->sortMergeInfo);
|
(*gMultiwayMergeFps[pInfo->type].closeFn)(&pInfo->sortMergeInfo);
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue