commit
0689271f4b
|
@ -32,8 +32,8 @@ typedef struct SBlockOrderInfo {
|
|||
SColumnInfoData* pColData;
|
||||
} SBlockOrderInfo;
|
||||
|
||||
#define BLOCK_VERSION_1 1
|
||||
#define BLOCK_VERSION_2 2
|
||||
#define BLOCK_VERSION_1 1
|
||||
#define BLOCK_VERSION_2 2
|
||||
|
||||
#define NBIT (3u)
|
||||
#define BitPos(_n) ((_n) & ((1 << NBIT) - 1))
|
||||
|
@ -46,9 +46,9 @@ typedef struct SBlockOrderInfo {
|
|||
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
|
||||
} while (0)
|
||||
|
||||
#define colDataSetNull_f_s(c_, r_) \
|
||||
do { \
|
||||
colDataSetNull_f((c_)->nullbitmap, r_); \
|
||||
#define colDataSetNull_f_s(c_, r_) \
|
||||
do { \
|
||||
colDataSetNull_f((c_)->nullbitmap, r_); \
|
||||
(void)memset(((char*)(c_)->pData) + (c_)->info.bytes * (r_), 0, (c_)->info.bytes); \
|
||||
} while (0)
|
||||
|
||||
|
@ -143,7 +143,7 @@ static FORCE_INLINE void colDataSetNNULL(SColumnInfoData* pColumnInfoData, uint3
|
|||
for (int32_t i = start; i < start + nRows; ++i) {
|
||||
colDataSetNull_f(pColumnInfoData->nullbitmap, i);
|
||||
}
|
||||
memset(pColumnInfoData->pData + start * pColumnInfoData->info.bytes, 0, pColumnInfoData->info.bytes * nRows);
|
||||
(void)memset(pColumnInfoData->pData + start * pColumnInfoData->info.bytes, 0, pColumnInfoData->info.bytes * nRows);
|
||||
}
|
||||
|
||||
pColumnInfoData->hasNull = true;
|
||||
|
@ -192,15 +192,17 @@ int32_t getJsonValueLen(const char* data);
|
|||
|
||||
int32_t colDataSetVal(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, const char* pData, bool isNull);
|
||||
int32_t colDataReassignVal(SColumnInfoData* pColumnInfoData, uint32_t dstRowIdx, uint32_t srcRowIdx, const char* pData);
|
||||
int32_t colDataSetNItems(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, const char* pData, uint32_t numOfRows, bool trimValue);
|
||||
void colDataSetNItemsNull(SColumnInfoData* pColumnInfoData, uint32_t currentRow, uint32_t numOfRows);
|
||||
int32_t colDataCopyNItems(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData,
|
||||
uint32_t numOfRows, bool isNull);
|
||||
int32_t colDataSetNItems(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, const char* pData, uint32_t numOfRows,
|
||||
bool trimValue);
|
||||
void colDataSetNItemsNull(SColumnInfoData* pColumnInfoData, uint32_t currentRow, uint32_t numOfRows);
|
||||
int32_t colDataCopyNItems(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, uint32_t numOfRows,
|
||||
bool isNull);
|
||||
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int32_t* capacity,
|
||||
const SColumnInfoData* pSource, int32_t numOfRow2);
|
||||
int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows,
|
||||
const SDataBlockInfo* pBlockInfo);
|
||||
int32_t colDataAssignNRows(SColumnInfoData* pDst, int32_t dstIdx, const SColumnInfoData* pSrc, int32_t srcIdx, int32_t numOfRows);
|
||||
int32_t colDataAssignNRows(SColumnInfoData* pDst, int32_t dstIdx, const SColumnInfoData* pSrc, int32_t srcIdx,
|
||||
int32_t numOfRows);
|
||||
int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex);
|
||||
int32_t blockDataUpdatePkRange(SSDataBlock* pDataBlock, int32_t pkColumnIndex, bool asc);
|
||||
|
||||
|
@ -214,7 +216,7 @@ size_t blockDataGetNumOfRows(const SSDataBlock* pBlock);
|
|||
|
||||
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc);
|
||||
int32_t blockDataMergeNRows(SSDataBlock* pDest, const SSDataBlock* pSrc, int32_t srcIdx, int32_t numOfRows);
|
||||
void blockDataShrinkNRows(SSDataBlock* pBlock, int32_t numOfRows);
|
||||
void blockDataShrinkNRows(SSDataBlock* pBlock, int32_t numOfRows);
|
||||
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,
|
||||
int32_t pageSize);
|
||||
int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock);
|
||||
|
@ -237,12 +239,12 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo);
|
|||
int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload);
|
||||
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);
|
||||
|
||||
void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows);
|
||||
void blockDataCleanup(SSDataBlock* pDataBlock);
|
||||
void blockDataReset(SSDataBlock* pDataBlock);
|
||||
void blockDataEmpty(SSDataBlock* pDataBlock);
|
||||
void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows);
|
||||
void blockDataCleanup(SSDataBlock* pDataBlock);
|
||||
void blockDataReset(SSDataBlock* pDataBlock);
|
||||
void blockDataEmpty(SSDataBlock* pDataBlock);
|
||||
int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockInfo, uint32_t numOfRows,
|
||||
bool clearPayload);
|
||||
bool clearPayload);
|
||||
|
||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize, int32_t extraSize);
|
||||
|
||||
|
@ -264,20 +266,20 @@ int32_t blockDataAppendColInfo(SSDataBlock* pBlock, SColumnInfoData* pColIn
|
|||
SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId);
|
||||
SColumnInfoData* bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index);
|
||||
|
||||
int32_t blockGetEncodeSize(const SSDataBlock* pBlock);
|
||||
int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols);
|
||||
int32_t blockGetEncodeSize(const SSDataBlock* pBlock);
|
||||
int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols);
|
||||
const char* blockDecode(SSDataBlock* pBlock, const char* pData);
|
||||
|
||||
// for debug
|
||||
char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** dumpBuf, const char* taskIdStr);
|
||||
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq2** pReq, const SSDataBlock* pDataBlocks, const STSchema* pTSchema, int64_t uid, int32_t vgId,
|
||||
tb_uid_t suid);
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq2** pReq, const SSDataBlock* pDataBlocks, const STSchema* pTSchema,
|
||||
int64_t uid, int32_t vgId, tb_uid_t suid);
|
||||
|
||||
bool alreadyAddGroupId(char* ctbName, int64_t groupId);
|
||||
bool isAutoTableName(char* ctbName);
|
||||
void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId);
|
||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
||||
bool alreadyAddGroupId(char* ctbName, int64_t groupId);
|
||||
bool isAutoTableName(char* ctbName);
|
||||
void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId);
|
||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
||||
int32_t buildCtbNameByGroupIdImpl(const char* stbName, uint64_t groupId, char* pBuf);
|
||||
|
||||
void trimDataBlock(SSDataBlock* pBlock, int32_t totalRows, const bool* pBoolList);
|
||||
|
|
|
@ -315,7 +315,7 @@ struct STag {
|
|||
do { \
|
||||
VarDataLenT __len = (VarDataLenT)strlen(str); \
|
||||
*(VarDataLenT *)(x) = __len; \
|
||||
memcpy(varDataVal(x), (str), __len); \
|
||||
(void)memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \
|
||||
|
@ -324,10 +324,10 @@ struct STag {
|
|||
varDataSetLen(x, (_e - (x)-VARSTR_HEADER_SIZE)); \
|
||||
} while (0)
|
||||
|
||||
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) \
|
||||
do { \
|
||||
*(VarDataLenT *)(x) = (VarDataLenT)(_size); \
|
||||
memcpy(varDataVal(x), (str), (_size)); \
|
||||
#define STR_WITH_SIZE_TO_VARSTR(x, str, _size) \
|
||||
do { \
|
||||
*(VarDataLenT *)(x) = (VarDataLenT)(_size); \
|
||||
(void)memcpy(varDataVal(x), (str), (_size)); \
|
||||
} while (0);
|
||||
|
||||
// STSchema ================================
|
||||
|
|
|
@ -68,7 +68,7 @@ int32_t generateEncryptCode(const char *key, const char *machineId, char **encry
|
|||
int64_t grantRemain(EGrantType grant);
|
||||
int32_t grantCheck(EGrantType grant);
|
||||
int32_t grantCheckExpire(EGrantType grant);
|
||||
char *tGetMachineId();
|
||||
int32_t tGetMachineId(char **result);
|
||||
|
||||
// #ifndef GRANTS_CFG
|
||||
#ifdef TD_ENTERPRISE
|
||||
|
|
|
@ -691,7 +691,7 @@ static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper
|
|||
|
||||
int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
|
||||
pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
|
||||
memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
|
||||
(void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
|
||||
|
||||
return pDstWrapper;
|
||||
}
|
||||
|
@ -732,7 +732,7 @@ static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* p
|
|||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
|
||||
(void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
|
||||
return pSW;
|
||||
}
|
||||
|
||||
|
@ -2837,13 +2837,13 @@ static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeR
|
|||
buf = taosDecodeFixedI32(buf, &topicNum);
|
||||
|
||||
pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
|
||||
if (pReq->topicNames == NULL){
|
||||
if (pReq->topicNames == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t i = 0; i < topicNum; i++) {
|
||||
char* name = NULL;
|
||||
buf = taosDecodeString(buf, &name);
|
||||
if (taosArrayPush(pReq->topicNames, &name) == NULL){
|
||||
if (taosArrayPush(pReq->topicNames, &name) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_TTSZIP_H_
|
||||
#define _TD_COMMON_TTSZIP_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "tdef.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MEM_BUF_SIZE (1 << 20)
|
||||
#define TS_COMP_FILE_MAGIC 0x87F5EC4C
|
||||
#define TS_COMP_FILE_GROUP_MAX 512
|
||||
|
||||
typedef struct STSList {
|
||||
char* rawBuf;
|
||||
int32_t allocSize;
|
||||
int32_t threshold;
|
||||
int32_t len;
|
||||
} STSList;
|
||||
|
||||
typedef struct STSElem {
|
||||
TSKEY ts;
|
||||
SVariant* tag;
|
||||
int32_t id;
|
||||
} STSElem;
|
||||
|
||||
typedef struct STSCursor {
|
||||
int32_t vgroupIndex;
|
||||
int32_t blockIndex;
|
||||
int32_t tsIndex;
|
||||
uint32_t order;
|
||||
} STSCursor;
|
||||
|
||||
typedef struct STSBlock {
|
||||
SVariant tag; // tag value
|
||||
int32_t numOfElem; // number of elements
|
||||
int32_t compLen; // size after compressed
|
||||
int32_t padding; // 0xFFFFFFFF by default, after the payload
|
||||
char* payload; // actual data that is compressed
|
||||
} STSBlock;
|
||||
|
||||
/*
|
||||
* The size of buffer file should not be greater than 2G,
|
||||
* and the offset of int32_t type is enough
|
||||
*/
|
||||
typedef struct STSGroupBlockInfo {
|
||||
int32_t id; // group id
|
||||
int32_t offset; // offset set value in file
|
||||
int32_t numOfBlocks; // number of total blocks
|
||||
int32_t compLen; // compressed size
|
||||
} STSGroupBlockInfo;
|
||||
|
||||
typedef struct STSGroupBlockInfoEx {
|
||||
STSGroupBlockInfo info;
|
||||
int32_t len; // length before compress
|
||||
} STSGroupBlockInfoEx;
|
||||
|
||||
typedef struct STSBuf {
|
||||
TdFilePtr pFile;
|
||||
char path[PATH_MAX];
|
||||
uint32_t fileSize;
|
||||
|
||||
// todo use array
|
||||
STSGroupBlockInfoEx* pData;
|
||||
uint32_t numOfAlloc;
|
||||
uint32_t numOfGroups;
|
||||
|
||||
char* assistBuf;
|
||||
int32_t bufSize;
|
||||
STSBlock block;
|
||||
STSList tsData; // uncompressed raw ts data
|
||||
uint64_t numOfTotal;
|
||||
bool autoDelete;
|
||||
bool remainOpen;
|
||||
int32_t tsOrder; // order of timestamp in ts comp buffer
|
||||
STSCursor cur;
|
||||
} STSBuf;
|
||||
|
||||
typedef struct STSBufFileHeader {
|
||||
uint32_t magic; // file magic number
|
||||
uint32_t numOfGroup; // number of group stored in current file
|
||||
int32_t tsOrder; // timestamp order in current file
|
||||
} STSBufFileHeader;
|
||||
|
||||
STSBuf* tsBufCreate(bool autoDelete, int32_t order);
|
||||
STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete);
|
||||
STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t tsOrder, int32_t id);
|
||||
|
||||
void* tsBufDestroy(STSBuf* pTSBuf);
|
||||
|
||||
void tsBufAppend(STSBuf* pTSBuf, int32_t id, SVariant* tag, const char* pData, int32_t len);
|
||||
int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf);
|
||||
|
||||
STSBuf* tsBufClone(STSBuf* pTSBuf);
|
||||
|
||||
STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id);
|
||||
|
||||
void tsBufFlush(STSBuf* pTSBuf);
|
||||
void tsBufResetPos(STSBuf* pTSBuf);
|
||||
bool tsBufNextPos(STSBuf* pTSBuf);
|
||||
|
||||
STSElem tsBufGetElem(STSBuf* pTSBuf);
|
||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, SVariant* tag);
|
||||
|
||||
STSCursor tsBufGetCursor(STSBuf* pTSBuf);
|
||||
void tsBufSetTraverseOrder(STSBuf* pTSBuf, int32_t order);
|
||||
|
||||
void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur);
|
||||
|
||||
/**
|
||||
* display all data in comp block file, for debug purpose only
|
||||
* @param pTSBuf
|
||||
*/
|
||||
void tsBufDisplay(STSBuf* pTSBuf);
|
||||
|
||||
int32_t tsBufGetNumOfGroup(STSBuf* pTSBuf);
|
||||
|
||||
void tsBufGetGroupIdList(STSBuf* pTSBuf, int32_t* num, int32_t** id);
|
||||
|
||||
int32_t dumpFileBlockByGroupId(STSBuf* pTSBuf, int32_t id, void* buf, int32_t* len, int32_t* numOfBlocks);
|
||||
|
||||
STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, SVariant* pTag);
|
||||
|
||||
bool tsBufIsValidElem(STSElem* pElem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_TTSZIP_H_*/
|
|
@ -46,7 +46,7 @@ typedef struct {
|
|||
#pragma pack(pop)
|
||||
|
||||
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
|
||||
#define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v))
|
||||
#define varDataCopy(dst, v) (void)memcpy((dst), (void *)(v), varDataTLen(v))
|
||||
#define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE))
|
||||
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len))
|
||||
|
||||
|
|
|
@ -105,12 +105,14 @@ typedef uint16_t VarDataLenT; // maxVarDataLen: 65535
|
|||
#define varDataLen(v) ((VarDataLenT *)(v))[0]
|
||||
#define varDataVal(v) ((char *)(v) + VARSTR_HEADER_SIZE)
|
||||
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
|
||||
#define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v))
|
||||
#define varDataCopy(dst, v) (void)memcpy((dst), (void *)(v), varDataTLen(v))
|
||||
#define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE))
|
||||
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len))
|
||||
#define IS_VAR_DATA_TYPE(t) \
|
||||
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR) || ((t) == TSDB_DATA_TYPE_JSON) || ((t) == TSDB_DATA_TYPE_GEOMETRY))
|
||||
#define IS_STR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
|
||||
#define IS_VAR_DATA_TYPE(t) \
|
||||
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR) || \
|
||||
((t) == TSDB_DATA_TYPE_JSON) || ((t) == TSDB_DATA_TYPE_GEOMETRY))
|
||||
#define IS_STR_DATA_TYPE(t) \
|
||||
(((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
|
||||
|
||||
static FORCE_INLINE char *udfColDataGetData(const SUdfColumn *pColumn, int32_t row) {
|
||||
if (IS_VAR_DATA_TYPE(pColumn->colMeta.type)) {
|
||||
|
@ -158,7 +160,7 @@ static FORCE_INLINE int32_t udfColEnsureCapacity(SUdfColumn *pColumn, int32_t ne
|
|||
}
|
||||
data->varLenCol.varOffsets = (int32_t *)tmp;
|
||||
data->varLenCol.varOffsetsLen = sizeof(int32_t) * allocCapacity;
|
||||
memset(&data->varLenCol.varOffsets[existedRows], 0, sizeof(int32_t) * (allocCapacity - existedRows));
|
||||
(void)memset(&data->varLenCol.varOffsets[existedRows], 0, sizeof(int32_t) * (allocCapacity - existedRows));
|
||||
// for payload, add data in udfColDataAppend
|
||||
} else {
|
||||
char *tmp = (char *)realloc(data->fixLenCol.nullBitmap, BitmapLen(allocCapacity));
|
||||
|
@ -166,11 +168,11 @@ static FORCE_INLINE int32_t udfColEnsureCapacity(SUdfColumn *pColumn, int32_t ne
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
uint32_t extend = BitmapLen(allocCapacity) - BitmapLen(data->rowsAlloc);
|
||||
memset(tmp + BitmapLen(data->rowsAlloc), 0, extend);
|
||||
(void)memset(tmp + BitmapLen(data->rowsAlloc), 0, extend);
|
||||
data->fixLenCol.nullBitmap = tmp;
|
||||
data->fixLenCol.nullBitmapLen = BitmapLen(allocCapacity);
|
||||
int32_t oldLen = BitmapLen(existedRows);
|
||||
memset(&data->fixLenCol.nullBitmap[oldLen], 0, BitmapLen(allocCapacity) - oldLen);
|
||||
(void)memset(&data->fixLenCol.nullBitmap[oldLen], 0, BitmapLen(allocCapacity) - oldLen);
|
||||
|
||||
if (meta->type == TSDB_DATA_TYPE_NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -198,7 +200,8 @@ static FORCE_INLINE void udfColDataSetNull(SUdfColumn *pColumn, int32_t row) {
|
|||
udfColDataSetNull_f(pColumn, row);
|
||||
}
|
||||
pColumn->hasNull = true;
|
||||
pColumn->colData.numOfRows = ((int32_t)(row + 1) > pColumn->colData.numOfRows) ? (int32_t)(row + 1) : pColumn->colData.numOfRows;
|
||||
pColumn->colData.numOfRows =
|
||||
((int32_t)(row + 1) > pColumn->colData.numOfRows) ? (int32_t)(row + 1) : pColumn->colData.numOfRows;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t udfColDataSet(SUdfColumn *pColumn, uint32_t currentRow, const char *pData, bool isNull) {
|
||||
|
@ -211,7 +214,7 @@ static FORCE_INLINE int32_t udfColDataSet(SUdfColumn *pColumn, uint32_t currentR
|
|||
} else {
|
||||
if (!isVarCol) {
|
||||
udfColDataSetNotNull_f(pColumn, currentRow);
|
||||
memcpy(data->fixLenCol.data + meta->bytes * currentRow, pData, meta->bytes);
|
||||
(void)memcpy(data->fixLenCol.data + meta->bytes * currentRow, pData, meta->bytes);
|
||||
} else {
|
||||
int32_t dataLen = varDataTLen(pData);
|
||||
if (meta->type == TSDB_DATA_TYPE_JSON) {
|
||||
|
@ -249,7 +252,7 @@ static FORCE_INLINE int32_t udfColDataSet(SUdfColumn *pColumn, uint32_t currentR
|
|||
uint32_t len = data->varLenCol.payloadLen;
|
||||
data->varLenCol.varOffsets[currentRow] = len;
|
||||
|
||||
memcpy(data->varLenCol.payload + len, pData, dataLen);
|
||||
(void)memcpy(data->varLenCol.payload + len, pData, dataLen);
|
||||
data->varLenCol.payloadLen += dataLen;
|
||||
}
|
||||
}
|
||||
|
@ -278,8 +281,8 @@ typedef enum EUdfFuncType { UDF_FUNC_TYPE_SCALAR = 1, UDF_FUNC_TYPE_AGG = 2 } EU
|
|||
|
||||
typedef struct SScriptUdfInfo {
|
||||
const char *name;
|
||||
int32_t version;
|
||||
int64_t createdTime;
|
||||
int32_t version;
|
||||
int64_t createdTime;
|
||||
|
||||
EUdfFuncType funcType;
|
||||
int8_t scriptType;
|
||||
|
|
|
@ -112,11 +112,11 @@ int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId);
|
|||
int64_t nodesReleaseAllocatorWeakRef(int64_t allocatorId);
|
||||
void nodesDestroyAllocator(int64_t allocatorId);
|
||||
|
||||
SNode* nodesMakeNode(ENodeType type);
|
||||
int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut);
|
||||
void nodesDestroyNode(SNode* pNode);
|
||||
void nodesFree(void* p);
|
||||
|
||||
SNodeList* nodesMakeList();
|
||||
int32_t nodesMakeList(SNodeList** ppListOut);
|
||||
int32_t nodesListAppend(SNodeList* pList, SNode* pNode);
|
||||
int32_t nodesListStrictAppend(SNodeList* pList, SNode* pNode);
|
||||
int32_t nodesListMakeAppend(SNodeList** pList, SNode* pNode);
|
||||
|
@ -156,8 +156,8 @@ bool nodeListNodeEqual(const SNodeList* a, const SNode* b);
|
|||
|
||||
bool nodesMatchNode(const SNode* pSub, const SNode* pNode);
|
||||
|
||||
SNode* nodesCloneNode(const SNode* pNode);
|
||||
SNodeList* nodesCloneList(const SNodeList* pList);
|
||||
int32_t nodesCloneNode(const SNode* pNode, SNode** ppNodeOut);
|
||||
int32_t nodesCloneList(const SNodeList* pList, SNodeList** ppList);
|
||||
|
||||
const char* nodesNodeName(ENodeType type);
|
||||
int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* pLen);
|
||||
|
|
|
@ -636,9 +636,9 @@ void* nodesGetValueFromNode(SValueNode* pNode);
|
|||
int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value);
|
||||
char* nodesGetStrValueFromNode(SValueNode* pNode);
|
||||
void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
|
||||
SValueNode* nodesMakeValueNodeFromString(char* literal);
|
||||
SValueNode* nodesMakeValueNodeFromBool(bool b);
|
||||
SNode* nodesMakeValueNodeFromInt32(int32_t value);
|
||||
int32_t nodesMakeValueNodeFromString(char* literal, SValueNode** ppValNode);
|
||||
int32_t nodesMakeValueNodeFromBool(bool b, SValueNode** ppValNode);
|
||||
int32_t nodesMakeValueNodeFromInt32(int32_t value, SNode** ppNode);
|
||||
|
||||
char* nodesGetFillModeString(EFillMode mode);
|
||||
int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc);
|
||||
|
|
|
@ -118,6 +118,7 @@ void qDestroyQuery(SQuery* pQueryNode);
|
|||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
|
||||
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
||||
int32_t qInitKeywordsTable();
|
||||
void qCleanupKeywordsTable();
|
||||
|
||||
int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo);
|
||||
|
|
|
@ -44,9 +44,9 @@ typedef struct {
|
|||
*
|
||||
* @param pCfg Config of the fs.
|
||||
* @param ndisk Length of the config.
|
||||
* @return STfs* The fs object.
|
||||
* @param ppTfs The fs object.
|
||||
*/
|
||||
STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk);
|
||||
int32_t tfsOpen(SDiskCfg *pCfg, int32_t ndisk, STfs **ppTfs);
|
||||
|
||||
/**
|
||||
* @brief Close a fs.
|
||||
|
@ -275,7 +275,7 @@ int32_t tfsCopyFile(const STfsFile *pFile1, const STfsFile *pFile2);
|
|||
* @param rname The rel name of file.
|
||||
* @return STfsDir* The dir object.
|
||||
*/
|
||||
STfsDir *tfsOpendir(STfs *pTfs, const char *rname);
|
||||
int32_t tfsOpendir(STfs *pTfs, const char *rname, STfsDir **ppDir);
|
||||
|
||||
/**
|
||||
* @brief Get a file from dir and move to next pos.
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef int (*__compar_fn_t)(const void *, const void *);
|
|||
#endif
|
||||
#define ssize_t int
|
||||
#define _SSIZE_T_
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define bzero(ptr, size) (void)memset((ptr), 0, (size))
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
|
|
|
@ -114,8 +114,6 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
|||
|
||||
bool taosValidFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosGetErrorFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
int32_t taosSetFileHandlesLimit();
|
||||
|
|
|
@ -30,7 +30,7 @@ extern "C" {
|
|||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
void taosGetSystemLocale(char *outLocale, char *outCharset);
|
||||
void taosSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -65,6 +65,16 @@ void *taosMemoryMallocAlign(uint32_t alignment, int64_t size);
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_MEMORY_REALLOC(ptr, len) \
|
||||
do { \
|
||||
void *tmp = taosMemoryRealloc(ptr, (len)); \
|
||||
if (tmp) { \
|
||||
(ptr) = tmp; \
|
||||
} else { \
|
||||
taosMemoryFreeClear(ptr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -49,11 +49,14 @@ typedef BOOL (*FSignalHandler)(DWORD fdwCtrlType);
|
|||
#else
|
||||
typedef void (*FSignalHandler)(int32_t signum, void *sigInfo, void *context);
|
||||
#endif
|
||||
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||
void taosIgnSignal(int32_t signum);
|
||||
void taosDflSignal(int32_t signum);
|
||||
|
||||
void taosKillChildOnParentStopped();
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
int32_t taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||
int32_t taosIgnSignal(int32_t signum);
|
||||
int32_t taosDflSignal(int32_t signum);
|
||||
|
||||
int32_t taosKillChildOnParentStopped();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -159,13 +159,12 @@ TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, st
|
|||
|
||||
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen);
|
||||
|
||||
void taosBlockSIGPIPE();
|
||||
uint32_t taosGetIpv4FromFqdn(const char *);
|
||||
int32_t taosBlockSIGPIPE();
|
||||
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip);
|
||||
int32_t taosGetFqdn(char *);
|
||||
void tinet_ntoa(char *ipstr, uint32_t ip);
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
void taosIgnSIGPIPE();
|
||||
void taosSetMaskSIGPIPE();
|
||||
int32_t taosIgnSIGPIPE();
|
||||
uint32_t taosInetAddr(const char *ipAddr);
|
||||
const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs);
|
|||
int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv);
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||
TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len);
|
||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
|
||||
|
|
|
@ -44,7 +44,7 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char **__restrict ptrBuf);
|
|||
|
||||
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
||||
|
||||
int64_t taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
void taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
|
||||
void *taosLoadDll(const char *filename);
|
||||
|
||||
|
@ -54,11 +54,11 @@ void taosCloseDll(void *handle);
|
|||
|
||||
int32_t taosSetConsoleEcho(bool on);
|
||||
|
||||
void taosSetTerminalMode();
|
||||
int32_t taosSetTerminalMode();
|
||||
|
||||
int32_t taosGetOldTerminalMode();
|
||||
|
||||
void taosResetTerminalMode();
|
||||
int32_t taosResetTerminalMode();
|
||||
|
||||
#define STACKSIZE 100
|
||||
|
||||
|
|
|
@ -198,7 +198,8 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_TSC_ENCODE_PARAM_ERROR TAOS_DEF_ERROR_CODE(0, 0X0231)
|
||||
#define TSDB_CODE_TSC_ENCODE_PARAM_NULL TAOS_DEF_ERROR_CODE(0, 0X0232)
|
||||
#define TSDB_CODE_TSC_COMPRESS_PARAM_ERROR TAOS_DEF_ERROR_CODE(0, 0X0233)
|
||||
#define TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR TAOS_DEF_ERROR_CODE(0, 0X0234)
|
||||
#define TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR TAOS_DEF_ERROR_CODE(0, 0X0234)
|
||||
#define TSDB_CODE_TSC_FAIL_GENERATE_JSON TAOS_DEF_ERROR_CODE(0, 0X0235)
|
||||
#define TSDB_CODE_TSC_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0X02FF)
|
||||
|
||||
// mnode-common
|
||||
|
|
|
@ -71,9 +71,9 @@ static FORCE_INLINE int32_t tarray2InsertBatch(void *arr, int32_t idx, const voi
|
|||
}
|
||||
if (ret == 0) {
|
||||
if (idx < a->size) {
|
||||
memmove(a->data + (idx + numEle) * eleSize, a->data + idx * eleSize, (a->size - idx) * eleSize);
|
||||
(void)memmove(a->data + (idx + numEle) * eleSize, a->data + idx * eleSize, (a->size - idx) * eleSize);
|
||||
}
|
||||
memcpy(a->data + idx * eleSize, elePtr, numEle * eleSize);
|
||||
(void)memcpy(a->data + idx * eleSize, elePtr, numEle * eleSize);
|
||||
a->size += numEle;
|
||||
}
|
||||
return ret;
|
||||
|
@ -145,18 +145,18 @@ static FORCE_INLINE int32_t tarray2SortInsert(void *arr, const void *elePtr, int
|
|||
#define TARRAY2_SORT_INSERT(a, e, cmp) tarray2SortInsert(a, &(e), sizeof(((a)->data[0])), (__compar_fn_t)cmp)
|
||||
#define TARRAY2_SORT_INSERT_P(a, ep, cmp) tarray2SortInsert(a, ep, sizeof(((a)->data[0])), (__compar_fn_t)cmp)
|
||||
|
||||
#define TARRAY2_REMOVE(a, idx, cb) \
|
||||
do { \
|
||||
if ((idx) < (a)->size) { \
|
||||
if (cb) { \
|
||||
TArray2Cb cb_ = (TArray2Cb)(cb); \
|
||||
cb_((a)->data + (idx)); \
|
||||
} \
|
||||
if ((idx) < (a)->size - 1) { \
|
||||
memmove((a)->data + (idx), (a)->data + (idx) + 1, sizeof((*(a)->data)) * ((a)->size - (idx)-1)); \
|
||||
} \
|
||||
(a)->size--; \
|
||||
} \
|
||||
#define TARRAY2_REMOVE(a, idx, cb) \
|
||||
do { \
|
||||
if ((idx) < (a)->size) { \
|
||||
if (cb) { \
|
||||
TArray2Cb cb_ = (TArray2Cb)(cb); \
|
||||
cb_((a)->data + (idx)); \
|
||||
} \
|
||||
if ((idx) < (a)->size - 1) { \
|
||||
(void)memmove((a)->data + (idx), (a)->data + (idx) + 1, sizeof((*(a)->data)) * ((a)->size - (idx)-1)); \
|
||||
} \
|
||||
(a)->size--; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TARRAY2_FOREACH(a, e) for (int32_t __i = 0; __i < (a)->size && ((e) = (a)->data[__i], 1); __i++)
|
||||
|
|
|
@ -25,8 +25,8 @@ extern "C" {
|
|||
#define TBASE_MAX_ILEN 4096
|
||||
#define TBASE_MAX_OLEN 5653
|
||||
|
||||
uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen);
|
||||
char *base58_encode(const uint8_t *value, int32_t vlen);
|
||||
int32_t base58_decode(const char *value, size_t inlen, int32_t *outlen, uint8_t **result);
|
||||
int32_t base58_encode(const uint8_t *value, int32_t vlen, char **result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen);
|
||||
char *base64_encode(const uint8_t *value, int32_t vlen);
|
||||
int32_t base64_decode(const char *value, int32_t inlen, int32_t *outlen, uint8_t **result);
|
||||
int32_t base64_encode(const uint8_t *value, int32_t vlen, char **result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ static FORCE_INLINE void *taosDecodeFixedBool(const void *buf, bool *value) {
|
|||
static FORCE_INLINE int32_t taosEncodeFixedU16(void **buf, uint16_t value) {
|
||||
if (buf != NULL) {
|
||||
if (IS_LITTLE_ENDIAN()) {
|
||||
memcpy(*buf, &value, sizeof(value));
|
||||
TAOS_MEMCPY(*buf, &value, sizeof(value));
|
||||
} else {
|
||||
((uint8_t *)(*buf))[0] = value & 0xff;
|
||||
((uint8_t *)(*buf))[1] = (value >> 8) & 0xff;
|
||||
|
@ -92,7 +92,7 @@ static FORCE_INLINE int32_t taosEncodeFixedU16(void **buf, uint16_t value) {
|
|||
|
||||
static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
|
||||
if (IS_LITTLE_ENDIAN()) {
|
||||
memcpy(value, buf, sizeof(*value));
|
||||
TAOS_MEMCPY(value, buf, sizeof(*value));
|
||||
} else {
|
||||
((uint8_t *)value)[1] = ((uint8_t *)buf)[0];
|
||||
((uint8_t *)value)[0] = ((uint8_t *)buf)[1];
|
||||
|
@ -117,7 +117,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) {
|
|||
static FORCE_INLINE int32_t taosEncodeFixedU32(void **buf, uint32_t value) {
|
||||
if (buf != NULL) {
|
||||
if (IS_LITTLE_ENDIAN()) {
|
||||
memcpy(*buf, &value, sizeof(value));
|
||||
TAOS_MEMCPY(*buf, &value, sizeof(value));
|
||||
} else {
|
||||
((uint8_t *)(*buf))[0] = value & 0xff;
|
||||
((uint8_t *)(*buf))[1] = (value >> 8) & 0xff;
|
||||
|
@ -132,7 +132,7 @@ static FORCE_INLINE int32_t taosEncodeFixedU32(void **buf, uint32_t value) {
|
|||
|
||||
static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
|
||||
if (IS_LITTLE_ENDIAN()) {
|
||||
memcpy(value, buf, sizeof(*value));
|
||||
TAOS_MEMCPY(value, buf, sizeof(*value));
|
||||
} else {
|
||||
((uint8_t *)value)[3] = ((uint8_t *)buf)[0];
|
||||
((uint8_t *)value)[2] = ((uint8_t *)buf)[1];
|
||||
|
@ -159,7 +159,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) {
|
|||
static FORCE_INLINE int32_t taosEncodeFixedU64(void **buf, uint64_t value) {
|
||||
if (buf != NULL) {
|
||||
if (IS_LITTLE_ENDIAN()) {
|
||||
memcpy(*buf, &value, sizeof(value));
|
||||
TAOS_MEMCPY(*buf, &value, sizeof(value));
|
||||
} else {
|
||||
((uint8_t *)(*buf))[0] = value & 0xff;
|
||||
((uint8_t *)(*buf))[1] = (value >> 8) & 0xff;
|
||||
|
@ -179,7 +179,7 @@ static FORCE_INLINE int32_t taosEncodeFixedU64(void **buf, uint64_t value) {
|
|||
|
||||
static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
|
||||
if (IS_LITTLE_ENDIAN()) {
|
||||
memcpy(value, buf, sizeof(*value));
|
||||
TAOS_MEMCPY(value, buf, sizeof(*value));
|
||||
} else {
|
||||
((uint8_t *)value)[7] = ((uint8_t *)buf)[0];
|
||||
((uint8_t *)value)[6] = ((uint8_t *)buf)[1];
|
||||
|
@ -357,7 +357,7 @@ static FORCE_INLINE int32_t taosEncodeString(void **buf, const char *value) {
|
|||
|
||||
tlen += taosEncodeVariantU64(buf, size);
|
||||
if (buf != NULL) {
|
||||
memcpy(*buf, value, size);
|
||||
TAOS_MEMCPY(*buf, value, size);
|
||||
*buf = POINTER_SHIFT(*buf, size);
|
||||
}
|
||||
tlen += (int32_t)size;
|
||||
|
@ -372,7 +372,7 @@ static FORCE_INLINE void *taosDecodeString(const void *buf, char **value) {
|
|||
*value = (char *)taosMemoryMalloc((size_t)size + 1);
|
||||
|
||||
if (*value == NULL) return NULL;
|
||||
memcpy(*value, buf, (size_t)size);
|
||||
TAOS_MEMCPY(*value, buf, (size_t)size);
|
||||
|
||||
(*value)[size] = '\0';
|
||||
|
||||
|
@ -383,7 +383,7 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) {
|
|||
uint64_t size = 0;
|
||||
|
||||
buf = taosDecodeVariantU64(buf, &size);
|
||||
memcpy(value, buf, (size_t)size);
|
||||
TAOS_MEMCPY(value, buf, (size_t)size);
|
||||
|
||||
value[size] = '\0';
|
||||
|
||||
|
@ -395,7 +395,7 @@ static FORCE_INLINE int32_t taosEncodeBinary(void **buf, const void *value, int3
|
|||
int32_t tlen = 0;
|
||||
|
||||
if (buf != NULL) {
|
||||
memcpy(*buf, value, valueLen);
|
||||
TAOS_MEMCPY(*buf, value, valueLen);
|
||||
*buf = POINTER_SHIFT(*buf, valueLen);
|
||||
}
|
||||
tlen += (int32_t)valueLen;
|
||||
|
@ -406,13 +406,13 @@ static FORCE_INLINE int32_t taosEncodeBinary(void **buf, const void *value, int3
|
|||
static FORCE_INLINE void *taosDecodeBinary(const void *buf, void **value, int32_t valueLen) {
|
||||
*value = taosMemoryMalloc((size_t)valueLen);
|
||||
if (*value == NULL) return NULL;
|
||||
memcpy(*value, buf, (size_t)valueLen);
|
||||
TAOS_MEMCPY(*value, buf, (size_t)valueLen);
|
||||
|
||||
return POINTER_SHIFT(buf, valueLen);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *taosDecodeBinaryTo(const void *buf, void *value, int32_t valueLen) {
|
||||
memcpy(value, buf, (size_t)valueLen);
|
||||
TAOS_MEMCPY(value, buf, (size_t)valueLen);
|
||||
return POINTER_SHIFT(buf, valueLen);
|
||||
}
|
||||
|
||||
|
|
|
@ -131,10 +131,10 @@ static const int64_t TICK_PER_SECOND[] = {
|
|||
: ((precision) == TSDB_TIME_PRECISION_MICRO ? 1000000LL : 1000000000LL)))
|
||||
|
||||
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
|
||||
#define T_APPEND_MEMBER(dst, ptr, type, member) \
|
||||
do { \
|
||||
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member)); \
|
||||
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member)); \
|
||||
#define T_APPEND_MEMBER(dst, ptr, type, member) \
|
||||
do { \
|
||||
(void)memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member)); \
|
||||
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member)); \
|
||||
} while (0)
|
||||
#define T_READ_MEMBER(src, type, target) \
|
||||
do { \
|
||||
|
@ -556,7 +556,7 @@ typedef struct {
|
|||
char name[TSDB_LOG_VAR_LEN];
|
||||
} SLogVar;
|
||||
|
||||
#define TMQ_SEPARATOR ":"
|
||||
#define TMQ_SEPARATOR ":"
|
||||
#define TMQ_SEPARATOR_CHAR ':'
|
||||
|
||||
enum {
|
||||
|
|
|
@ -127,7 +127,7 @@ static FORCE_INLINE int32_t tEncodeFixed(SEncoder* pCoder, const void* val, uint
|
|||
if (pCoder->pos + size > pCoder->size) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
memcpy(pCoder->data + pCoder->pos, val, size);
|
||||
TAOS_MEMCPY(pCoder->data + pCoder->pos, val, size);
|
||||
}
|
||||
|
||||
pCoder->pos += size;
|
||||
|
@ -212,7 +212,7 @@ static FORCE_INLINE int32_t tEncodeBinary(SEncoder* pCoder, const uint8_t* val,
|
|||
if (pCoder->pos + len > pCoder->size) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
memcpy(pCoder->data + pCoder->pos, val, len);
|
||||
TAOS_MEMCPY(pCoder->data + pCoder->pos, val, len);
|
||||
}
|
||||
|
||||
pCoder->pos += len;
|
||||
|
@ -233,7 +233,7 @@ static int32_t tDecodeFixed(SDecoder* pCoder, void* val, uint32_t size) {
|
|||
if (pCoder->pos + size > pCoder->size) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
} else if (val) {
|
||||
memcpy(val, pCoder->data + pCoder->pos, size);
|
||||
TAOS_MEMCPY(val, pCoder->data + pCoder->pos, size);
|
||||
}
|
||||
pCoder->pos += size;
|
||||
return 0;
|
||||
|
@ -427,7 +427,7 @@ static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val) {
|
|||
uint32_t len;
|
||||
TAOS_CHECK_RETURN(tDecodeCStrAndLen(pCoder, &pStr, &len));
|
||||
|
||||
memcpy(val, pStr, len + 1);
|
||||
TAOS_MEMCPY(val, pStr, len + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ static FORCE_INLINE int32_t tDecodeBinaryAlloc(SDecoder* pCoder, void** val, uin
|
|||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(*val, pCoder->data + pCoder->pos, length);
|
||||
TAOS_MEMCPY(*val, pCoder->data + pCoder->pos, length);
|
||||
|
||||
pCoder->pos += length;
|
||||
} else {
|
||||
|
@ -468,7 +468,7 @@ static FORCE_INLINE int32_t tDecodeBinaryAlloc32(SDecoder* pCoder, void** val, u
|
|||
if (*val == NULL) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
memcpy(*val, pCoder->data + pCoder->pos, length);
|
||||
TAOS_MEMCPY(*val, pCoder->data + pCoder->pos, length);
|
||||
|
||||
pCoder->pos += length;
|
||||
} else {
|
||||
|
@ -757,7 +757,7 @@ static FORCE_INLINE int32_t tPutBinary(uint8_t* p, uint8_t* pData, uint32_t nDat
|
|||
int n = 0;
|
||||
|
||||
n += tPutU32v(p ? p + n : p, nData);
|
||||
if (p) memcpy(p + n, pData, nData);
|
||||
if (p) TAOS_MEMCPY(p + n, pData, nData);
|
||||
n += nData;
|
||||
|
||||
return n;
|
||||
|
|
|
@ -156,7 +156,7 @@ void setBufPageCompressOnDisk(SDiskbasedBuf* pBuf, bool comp);
|
|||
* @param pBuf
|
||||
* @param pageId
|
||||
*/
|
||||
void dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage);
|
||||
int32_t dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage);
|
||||
|
||||
/**
|
||||
* Print the statistics when closing this buffer
|
||||
|
|
|
@ -64,7 +64,7 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
|
|||
tMD5Init(&context);
|
||||
tMD5Update(&context, inBuf, (uint32_t)inLen);
|
||||
tMD5Final(&context);
|
||||
memcpy(target, context.digest, tListLen(context.digest));
|
||||
(void)memcpy(target, context.digest, tListLen(context.digest));
|
||||
}
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
|
||||
|
@ -75,11 +75,11 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
|
|||
char buf[TSDB_PASSWORD_LEN + 1];
|
||||
|
||||
buf[TSDB_PASSWORD_LEN] = 0;
|
||||
sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
|
||||
(void)sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
|
||||
context.digest[2], context.digest[3], context.digest[4], context.digest[5], context.digest[6],
|
||||
context.digest[7], context.digest[8], context.digest[9], context.digest[10], context.digest[11],
|
||||
context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
|
||||
memcpy(target, buf, TSDB_PASSWORD_LEN);
|
||||
(void)memcpy(target, buf, TSDB_PASSWORD_LEN);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosCreateMD5Hash(char *pBuf, int32_t len) {
|
||||
|
@ -108,10 +108,10 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
int32_t offset = 0;
|
||||
if (prefix < 0) {
|
||||
offset = -1 * prefix;
|
||||
strncpy(tbName, tbname, offset);
|
||||
(void)strncpy(tbName, tbname, offset);
|
||||
}
|
||||
if (suffix < 0) {
|
||||
strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
|
||||
(void)strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
|
||||
offset += -1 * suffix;
|
||||
}
|
||||
return MurmurHash3_32(tbName, offset);
|
||||
|
@ -176,6 +176,15 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_CHECK_EXIT(CMD) \
|
||||
do { \
|
||||
code = (CMD); \
|
||||
if (code < TSDB_CODE_SUCCESS) { \
|
||||
lino = __LINE__; \
|
||||
goto _exit; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_UNUSED(expr) (void)(expr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -38,7 +38,7 @@ static FORCE_INLINE float taos_align_get_float(const char *pBuf) {
|
|||
assert(sizeof(float) == sizeof(uint32_t));
|
||||
#endif
|
||||
float fv = 0;
|
||||
memcpy(&fv, pBuf, sizeof(fv)); // in ARM, return *((const float*)(pBuf)) may cause problem
|
||||
(void)memcpy(&fv, pBuf, sizeof(fv)); // in ARM, return *((const float*)(pBuf)) may cause problem
|
||||
return fv;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) {
|
|||
assert(sizeof(double) == sizeof(uint64_t));
|
||||
#endif
|
||||
double dv = 0;
|
||||
memcpy(&dv, pBuf, sizeof(dv)); // in ARM, return *((const double*)(pBuf)) may cause problem
|
||||
(void)memcpy(&dv, pBuf, sizeof(dv)); // in ARM, return *((const double*)(pBuf)) may cause problem
|
||||
return dv;
|
||||
}
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ void setResPrecision(SReqResultInfo* pResInfo, int32_t precision);
|
|||
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4);
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows,
|
||||
bool convertUcs4);
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
int32_t setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
void doFreeReqResultInfo(SReqResultInfo* pResInfo);
|
||||
int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, SArray** pReq);
|
||||
void syncCatalogFn(SMetaData* pResult, void* param, int32_t code);
|
||||
|
@ -348,15 +348,16 @@ __async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
|||
|
||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj);
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char* db, int32_t connType, SAppInstInfo* pAppInfo);
|
||||
int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo,
|
||||
STscObj **p);
|
||||
void destroyTscObj(void* pObj);
|
||||
STscObj* acquireTscObj(int64_t rid);
|
||||
int32_t releaseTscObj(int64_t rid);
|
||||
void releaseTscObj(int64_t rid);
|
||||
void destroyAppInst(void* pAppInfo);
|
||||
|
||||
uint64_t generateRequestId();
|
||||
|
||||
void* createRequest(uint64_t connId, int32_t type, int64_t reqid);
|
||||
int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj **pRequest);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
SRequestObj* acquireRequest(int64_t rid);
|
||||
int32_t releaseRequest(int64_t rid);
|
||||
|
@ -370,7 +371,7 @@ void resetConnectDB(STscObj* pTscObj);
|
|||
|
||||
int taos_options_imp(TSDB_OPTION option, const char* str);
|
||||
|
||||
void* openTransporter(const char* user, const char* auth, int32_t numOfThreads);
|
||||
int32_t openTransporter(const char* user, const char* auth, int32_t numOfThreads, void **pDnodeConn);
|
||||
void tscStopCrashReport();
|
||||
|
||||
typedef struct AsyncArg {
|
||||
|
@ -381,8 +382,8 @@ typedef struct AsyncArg {
|
|||
bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType);
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
||||
|
||||
STscObj* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType);
|
||||
int32_t taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType, STscObj** pObj);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb);
|
||||
|
||||
|
@ -395,11 +396,11 @@ void taos_close_internal(void* taos);
|
|||
|
||||
// --- heartbeat
|
||||
// global, called by mgmt
|
||||
int hbMgrInit();
|
||||
void hbMgrCleanUp();
|
||||
int32_t hbMgrInit();
|
||||
void hbMgrCleanUp();
|
||||
|
||||
// cluster level
|
||||
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
||||
int32_t appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key, SAppHbMgr **pAppHbMgr);
|
||||
void appHbMgrCleanup(void);
|
||||
void hbRemoveAppHbMrg(SAppHbMgr** pAppHbMgr);
|
||||
void destroyAllRequests(SHashObj* pRequests);
|
||||
|
@ -408,7 +409,7 @@ void stopAllRequests(SHashObj* pRequests);
|
|||
//SAppInstInfo* getAppInstInfo(const char* clusterKey);
|
||||
|
||||
// conn level
|
||||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
int32_t hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
void hbDeregisterConn(STscObj* pTscObj, SClientHbKey connKey);
|
||||
|
||||
typedef struct SSqlCallbackWrapper {
|
||||
|
@ -427,7 +428,7 @@ void doAsyncQuery(SRequestObj* pRequest, bool forceUpdateMeta);
|
|||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList, bool isView);
|
||||
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog);
|
||||
int32_t handleCreateTbExecRes(void* res, SCatalog* pCatalog);
|
||||
bool qnodeRequired(SRequestObj* pRequest);
|
||||
int32_t qnodeRequired(SRequestObj* pRequest, bool *required);
|
||||
void continueInsertFromCsv(SSqlCallbackWrapper* pWrapper, SRequestObj* pRequest);
|
||||
void destorySqlCallbackWrapper(SSqlCallbackWrapper* pWrapper);
|
||||
void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta, int32_t code);
|
||||
|
@ -443,6 +444,30 @@ void freeQueryParam(SSyncQueryParam* param);
|
|||
int32_t clientParseSqlImpl(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effeciveUser, SParseSqlRes* pRes);
|
||||
#endif
|
||||
|
||||
#define TSC_ERR_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while (0)
|
||||
#define TSC_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
} \
|
||||
return _code; \
|
||||
} while (0)
|
||||
#define TSC_ERR_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void slowQueryLog(int64_t rid, bool killed, int32_t code, int32_t cost);
|
||||
|
||||
|
|
|
@ -44,6 +44,26 @@
|
|||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
#define ENV_JSON_FALSE_CHECK(c) \
|
||||
do { \
|
||||
if (!c) { \
|
||||
tscError("faild to add item to JSON object");\
|
||||
code = TSDB_CODE_TSC_FAIL_GENERATE_JSON; \
|
||||
goto _end; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ENV_ERR_RET(c,info) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
errno = _code; \
|
||||
tscInitRes = _code; \
|
||||
tscError(info); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
STscDbg tscDbg = {0};
|
||||
SAppInfo appInfo;
|
||||
int64_t lastClusterId = 0;
|
||||
|
@ -57,8 +77,14 @@ static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
|||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
// connection has been released already, abort creating request.
|
||||
pRequest->self = taosAddRef(clientReqRefPool, pRequest);
|
||||
if (pRequest->self < 0) {
|
||||
tscError("failed to add ref to request");
|
||||
code = terrno;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t num = atomic_add_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
|
@ -72,19 +98,23 @@ static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) {
|
|||
pRequest->self, pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void concatStrings(SArray *list, char* buf, int size){
|
||||
int len = 0;
|
||||
for(int i = 0; i < taosArrayGetSize(list); i++){
|
||||
char* db = taosArrayGet(list, i);
|
||||
if (NULL == db) {
|
||||
tscError("get dbname failed, buf:%s", buf);
|
||||
break;
|
||||
}
|
||||
char* dot = strchr(db, '.');
|
||||
if (dot != NULL) {
|
||||
db = dot + 1;
|
||||
}
|
||||
if (i != 0){
|
||||
strcat(buf, ",");
|
||||
(void)strcat(buf, ",");
|
||||
len += 1;
|
||||
}
|
||||
int ret = snprintf(buf + len, size - len, "%s", db);
|
||||
|
@ -100,61 +130,70 @@ static void concatStrings(SArray *list, char* buf, int size){
|
|||
}
|
||||
}
|
||||
|
||||
static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_t reqType, int64_t duration){
|
||||
static int32_t generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_t reqType, int64_t duration){
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (json == NULL) {
|
||||
tscError("[monitor] cJSON_CreateObject failed");
|
||||
return;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
char clusterId[32] = {0};
|
||||
if (snprintf(clusterId, sizeof(clusterId), "%" PRId64, pTscObj->pAppInfo->clusterId) < 0){
|
||||
tscError("failed to generate clusterId:%" PRId64, pTscObj->pAppInfo->clusterId);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
char startTs[32] = {0};
|
||||
if (snprintf(startTs, sizeof(startTs), "%" PRId64, pRequest->metric.start/1000) < 0){
|
||||
tscError("failed to generate startTs:%" PRId64, pRequest->metric.start/1000);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
char requestId[32] = {0};
|
||||
if (snprintf(requestId, sizeof(requestId), "%" PRIu64, pRequest->requestId) < 0){
|
||||
tscError("failed to generate requestId:%" PRIu64, pRequest->requestId);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, "cluster_id", cJSON_CreateString(clusterId));
|
||||
cJSON_AddItemToObject(json, "start_ts", cJSON_CreateString(startTs));
|
||||
cJSON_AddItemToObject(json, "request_id", cJSON_CreateString(requestId));
|
||||
cJSON_AddItemToObject(json, "query_time", cJSON_CreateNumber(duration/1000));
|
||||
cJSON_AddItemToObject(json, "code", cJSON_CreateNumber(pRequest->code));
|
||||
cJSON_AddItemToObject(json, "error_info", cJSON_CreateString(tstrerror(pRequest->code)));
|
||||
cJSON_AddItemToObject(json, "type", cJSON_CreateNumber(reqType));
|
||||
cJSON_AddItemToObject(json, "rows_num", cJSON_CreateNumber(pRequest->body.resInfo.numOfRows + pRequest->body.resInfo.totalRows));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "cluster_id", cJSON_CreateString(clusterId)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "start_ts", cJSON_CreateString(startTs)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "request_id", cJSON_CreateString(requestId)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "query_time", cJSON_CreateNumber(duration/1000)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "code", cJSON_CreateNumber(pRequest->code)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "error_info", cJSON_CreateString(tstrerror(pRequest->code))));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "type", cJSON_CreateNumber(reqType)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "rows_num", cJSON_CreateNumber(pRequest->body.resInfo.numOfRows + pRequest->body.resInfo.totalRows)));
|
||||
if(pRequest->sqlstr != NULL && strlen(pRequest->sqlstr) > pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen){
|
||||
char tmp = pRequest->sqlstr[pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen];
|
||||
pRequest->sqlstr[pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen] = '\0';
|
||||
cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr)));
|
||||
pRequest->sqlstr[pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen] = tmp;
|
||||
}else{
|
||||
cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr)));
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json, "user", cJSON_CreateString(pTscObj->user));
|
||||
cJSON_AddItemToObject(json, "process_name", cJSON_CreateString(appInfo.appName));
|
||||
cJSON_AddItemToObject(json, "ip", cJSON_CreateString(tsLocalFqdn));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "user", cJSON_CreateString(pTscObj->user)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "process_name", cJSON_CreateString(appInfo.appName)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "ip", cJSON_CreateString(tsLocalFqdn)));
|
||||
|
||||
char pid[32] = {0};
|
||||
if (snprintf(pid, sizeof(pid), "%d", appInfo.pid) < 0){
|
||||
tscError("failed to generate pid:%d", appInfo.pid);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json, "process_id", cJSON_CreateString(pid));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "process_id", cJSON_CreateString(pid)));
|
||||
if(pRequest->dbList != NULL){
|
||||
char dbList[1024] = {0};
|
||||
concatStrings(pRequest->dbList, dbList, sizeof(dbList) - 1);
|
||||
cJSON_AddItemToObject(json, "db", cJSON_CreateString(dbList));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString(dbList)));
|
||||
}else if(pRequest->pDb != NULL){
|
||||
cJSON_AddItemToObject(json, "db", cJSON_CreateString(pRequest->pDb));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString(pRequest->pDb)));
|
||||
}else{
|
||||
cJSON_AddItemToObject(json, "db", cJSON_CreateString(""));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString("")));
|
||||
}
|
||||
|
||||
char* value = cJSON_PrintUnformatted(json);
|
||||
|
@ -162,11 +201,15 @@ static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_
|
|||
data.clusterId = pTscObj->pAppInfo->clusterId;
|
||||
data.type = SLOW_LOG_WRITE;
|
||||
data.data = value;
|
||||
if(monitorPutData2MonitorQueue(data) < 0){
|
||||
code = monitorPutData2MonitorQueue(data);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFree(value);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
_end:
|
||||
cJSON_Delete(json);
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool checkSlowLogExceptDb(SRequestObj *pRequest, char* exceptDb) {
|
||||
|
@ -176,6 +219,10 @@ static bool checkSlowLogExceptDb(SRequestObj *pRequest, char* exceptDb) {
|
|||
|
||||
for (int i = 0; i < taosArrayGetSize(pRequest->dbList); i++) {
|
||||
char *db = taosArrayGet(pRequest->dbList, i);
|
||||
if (NULL == db) {
|
||||
tscError("get dbname failed, exceptDb:%s", exceptDb);
|
||||
return false;
|
||||
}
|
||||
char *dot = strchr(db, '.');
|
||||
if (dot != NULL) {
|
||||
db = dot + 1;
|
||||
|
@ -215,7 +262,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
"us, planCost:%" PRId64 "us, exec:%" PRId64 "us",
|
||||
duration, pRequest->metric.parseCostUs, pRequest->metric.ctgCostUs, pRequest->metric.analyseCostUs,
|
||||
pRequest->metric.planCostUs, pRequest->metric.execCostUs);
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||
(void)atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||
reqType = SLOW_LOG_TYPE_INSERT;
|
||||
} else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
|
||||
tscDebug("query duration %" PRId64 "us: parseCost:%" PRId64 "us, ctgCost:%" PRId64 "us, analyseCost:%" PRId64
|
||||
|
@ -223,11 +270,13 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
duration, pRequest->metric.parseCostUs, pRequest->metric.ctgCostUs, pRequest->metric.analyseCostUs,
|
||||
pRequest->metric.planCostUs, pRequest->metric.execCostUs);
|
||||
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration);
|
||||
(void)atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration);
|
||||
reqType = SLOW_LOG_TYPE_QUERY;
|
||||
}
|
||||
|
||||
nodesSimReleaseAllocator(pRequest->allocatorRefId);
|
||||
if (TSDB_CODE_SUCCESS != nodesSimReleaseAllocator(pRequest->allocatorRefId)) {
|
||||
tscError("failed to release allocator");
|
||||
}
|
||||
}
|
||||
|
||||
if(pTscObj->pAppInfo->monitorParas.tsEnableMonitor){
|
||||
|
@ -242,14 +291,16 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
|
||||
if ((duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThreshold * 1000000UL || duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThresholdTest * 1000000UL) &&
|
||||
checkSlowLogExceptDb(pRequest, pTscObj->pAppInfo->monitorParas.tsSlowLogExceptDb)) {
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
||||
(void)atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
||||
if (pTscObj->pAppInfo->monitorParas.tsSlowLogScope & reqType) {
|
||||
taosPrintSlowLog("PID:%d, Conn:%u, QID:0x%" PRIx64 ", Start:%" PRId64 " us, Duration:%" PRId64 "us, SQL:%s",
|
||||
taosGetPId(), pTscObj->connId, pRequest->requestId, pRequest->metric.start, duration,
|
||||
pRequest->sqlstr);
|
||||
if(pTscObj->pAppInfo->monitorParas.tsEnableMonitor){
|
||||
slowQueryLog(pTscObj->id, pRequest->killed, pRequest->code, duration);
|
||||
generateWriteSlowLog(pTscObj, pRequest, reqType, duration);
|
||||
if (TSDB_CODE_SUCCESS != generateWriteSlowLog(pTscObj, pRequest, reqType, duration)) {
|
||||
tscError("failed to generate write slow log");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -289,9 +340,9 @@ static bool clientRpcTfp(int32_t code, tmsg_t msgType) {
|
|||
}
|
||||
|
||||
// TODO refactor
|
||||
void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
||||
int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, void **pDnodeConn) {
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
(void)memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "TSC";
|
||||
rpcInit.numOfThreads = tsNumOfRpcThreads;
|
||||
|
@ -315,15 +366,19 @@ void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
|||
rpcInit.connLimitNum = connLimitNum;
|
||||
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
|
||||
|
||||
taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
|
||||
void *pDnodeConn = rpcOpen(&rpcInit);
|
||||
if (pDnodeConn == NULL) {
|
||||
tscError("failed to init connection to server");
|
||||
return NULL;
|
||||
int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("invalid version string.");
|
||||
return code;
|
||||
}
|
||||
|
||||
return pDnodeConn;
|
||||
*pDnodeConn = rpcOpen(&rpcInit);
|
||||
if (*pDnodeConn == NULL) {
|
||||
tscError("failed to init connection to server.");
|
||||
code = TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void destroyAllRequests(SHashObj *pRequests) {
|
||||
|
@ -334,7 +389,7 @@ void destroyAllRequests(SHashObj *pRequests) {
|
|||
SRequestObj *pRequest = acquireRequest(*rid);
|
||||
if (pRequest) {
|
||||
destroyRequest(pRequest);
|
||||
releaseRequest(*rid);
|
||||
(void)releaseRequest(*rid); // ignore error
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pRequests, pIter);
|
||||
|
@ -349,7 +404,7 @@ void stopAllRequests(SHashObj *pRequests) {
|
|||
SRequestObj *pRequest = acquireRequest(*rid);
|
||||
if (pRequest) {
|
||||
taos_stop_query(pRequest);
|
||||
releaseRequest(*rid);
|
||||
(void)releaseRequest(*rid); // ignore error
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pRequests, pIter);
|
||||
|
@ -360,18 +415,31 @@ void destroyAppInst(void *info) {
|
|||
SAppInstInfo* pAppInfo = *(SAppInstInfo**)info;
|
||||
tscDebug("destroy app inst mgr %p", pAppInfo);
|
||||
|
||||
taosThreadMutexLock(&appInfo.mutex);
|
||||
int32_t code = taosThreadMutexLock(&appInfo.mutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to lock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
hbRemoveAppHbMrg(&pAppInfo->pAppHbMgr);
|
||||
|
||||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
code = taosThreadMutexUnlock(&appInfo.mutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to unlock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pAppInfo->instKey);
|
||||
closeTransporter(pAppInfo);
|
||||
|
||||
taosThreadMutexLock(&pAppInfo->qnodeMutex);
|
||||
code = taosThreadMutexLock(&pAppInfo->qnodeMutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to lock qnode mutex, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
taosArrayDestroy(pAppInfo->pQnodeList);
|
||||
taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
|
||||
code = taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to unlock qnode mutex, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
taosMemoryFree(pAppInfo);
|
||||
}
|
||||
|
@ -396,97 +464,111 @@ void destroyTscObj(void *pObj) {
|
|||
pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
// In any cases, we should not free app inst here. Or an race condition rises.
|
||||
/*int64_t connNum = */ atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
/*int64_t connNum = */ (void)atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
taosThreadMutexDestroy(&pTscObj->mutex);
|
||||
(void)taosThreadMutexDestroy(&pTscObj->mutex);
|
||||
taosMemoryFree(pTscObj);
|
||||
|
||||
tscTrace("end to destroy tscObj %" PRIx64 " p:%p", tscId, pTscObj);
|
||||
}
|
||||
|
||||
void *createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo) {
|
||||
STscObj *pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj));
|
||||
if (NULL == pObj) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo,
|
||||
STscObj **pObj) {
|
||||
*pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj));
|
||||
if (NULL == *pObj) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pObj->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pObj->pRequests) {
|
||||
taosMemoryFree(pObj);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
(*pObj)->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == (*pObj)->pRequests) {
|
||||
taosMemoryFree(*pObj);
|
||||
return terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pObj->connType = connType;
|
||||
pObj->pAppInfo = pAppInfo;
|
||||
pObj->appHbMgrIdx = pAppInfo->pAppHbMgr->idx;
|
||||
tstrncpy(pObj->user, user, sizeof(pObj->user));
|
||||
memcpy(pObj->pass, auth, TSDB_PASSWORD_LEN);
|
||||
(*pObj)->connType = connType;
|
||||
(*pObj)->pAppInfo = pAppInfo;
|
||||
(*pObj)->appHbMgrIdx = pAppInfo->pAppHbMgr->idx;
|
||||
tstrncpy((*pObj)->user, user, sizeof((*pObj)->user));
|
||||
(void)memcpy((*pObj)->pass, auth, TSDB_PASSWORD_LEN);
|
||||
|
||||
if (db != NULL) {
|
||||
tstrncpy(pObj->db, db, tListLen(pObj->db));
|
||||
tstrncpy((*pObj)->db, db, tListLen((*pObj)->db));
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
TSC_ERR_RET(taosThreadMutexInit(&(*pObj)->mutex, NULL));
|
||||
|
||||
atomic_add_fetch_64(&pObj->pAppInfo->numOfConns, 1);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64 ",p:%p", pObj->id, pObj);
|
||||
return pObj;
|
||||
(*pObj)->id = taosAddRef(clientConnRefPool, *pObj);
|
||||
if ((*pObj)->id < 0) {
|
||||
tscError("failed to add object to clientConnRefPool");
|
||||
code = terrno;
|
||||
taosMemoryFree(*pObj);
|
||||
return code;
|
||||
}
|
||||
|
||||
(void)atomic_add_fetch_64(&(*pObj)->pAppInfo->numOfConns, 1);
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64 ",p:%p", (*pObj)->id, *pObj);
|
||||
return code;
|
||||
}
|
||||
|
||||
STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientConnRefPool, rid); }
|
||||
|
||||
int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); }
|
||||
void releaseTscObj(int64_t rid) {
|
||||
int32_t code = taosReleaseRef(clientConnRefPool, rid);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscWarn("failed to release TscObj, code:%s", tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
void *createRequest(uint64_t connId, int32_t type, int64_t reqid) {
|
||||
SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
|
||||
if (NULL == pRequest) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj **pRequest) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
*pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
|
||||
if (NULL == *pRequest) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = acquireTscObj(connId);
|
||||
if (pTscObj == NULL) {
|
||||
taosMemoryFree(pRequest);
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return NULL;
|
||||
code = TSDB_CODE_TSC_DISCONNECTED;
|
||||
goto _return;
|
||||
}
|
||||
SSyncQueryParam *interParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
||||
if (interParam == NULL) {
|
||||
releaseTscObj(connId);
|
||||
doDestroyRequest(pRequest);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _return;
|
||||
}
|
||||
tsem_init(&interParam->sem, 0, 0);
|
||||
interParam->pRequest = pRequest;
|
||||
pRequest->body.interParam = interParam;
|
||||
TSC_ERR_JRET(tsem_init(&interParam->sem, 0, 0));
|
||||
interParam->pRequest = *pRequest;
|
||||
(*pRequest)->body.interParam = interParam;
|
||||
|
||||
pRequest->resType = RES_TYPE__QUERY;
|
||||
pRequest->requestId = reqid == 0 ? generateRequestId() : reqid;
|
||||
pRequest->metric.start = taosGetTimestampUs();
|
||||
(*pRequest)->resType = RES_TYPE__QUERY;
|
||||
(*pRequest)->requestId = reqid == 0 ? generateRequestId() : reqid;
|
||||
(*pRequest)->metric.start = taosGetTimestampUs();
|
||||
|
||||
pRequest->body.resInfo.convertUcs4 = true; // convert ucs4 by default
|
||||
pRequest->type = type;
|
||||
pRequest->allocatorRefId = -1;
|
||||
(*pRequest)->body.resInfo.convertUcs4 = true; // convert ucs4 by default
|
||||
(*pRequest)->type = type;
|
||||
(*pRequest)->allocatorRefId = -1;
|
||||
|
||||
pRequest->pDb = getDbOfConnection(pTscObj);
|
||||
pRequest->pTscObj = pTscObj;
|
||||
pRequest->inCallback = false;
|
||||
(*pRequest)->pDb = getDbOfConnection(pTscObj);
|
||||
(*pRequest)->pTscObj = pTscObj;
|
||||
(*pRequest)->inCallback = false;
|
||||
|
||||
pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
|
||||
tsem_init(&pRequest->body.rspSem, 0, 0);
|
||||
|
||||
if (registerRequest(pRequest, pTscObj)) {
|
||||
doDestroyRequest(pRequest);
|
||||
return NULL;
|
||||
(*pRequest)->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
if (NULL == (*pRequest)->msgBuf) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _return;
|
||||
}
|
||||
(*pRequest)->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
|
||||
TSC_ERR_JRET(tsem_init(&(*pRequest)->body.rspSem, 0, 0));
|
||||
TSC_ERR_JRET(registerRequest(*pRequest, pTscObj));
|
||||
|
||||
return pRequest;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_return:
|
||||
doDestroyRequest(*pRequest);
|
||||
return code;
|
||||
}
|
||||
|
||||
void doFreeReqResultInfo(SReqResultInfo *pResInfo) {
|
||||
|
@ -521,12 +603,12 @@ int64_t removeFromMostPrevReq(SRequestObj* pRequest) {
|
|||
pTmp = acquireRequest(pTmp->relation.prevRefId);
|
||||
if (pTmp) {
|
||||
mostPrevReqRefId = pTmp->self;
|
||||
releaseRequest(mostPrevReqRefId);
|
||||
(void)releaseRequest(mostPrevReqRefId); // ignore error
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
removeRequest(mostPrevReqRefId);
|
||||
(void)removeRequest(mostPrevReqRefId); // ignore error
|
||||
return mostPrevReqRefId;
|
||||
}
|
||||
|
||||
|
@ -534,8 +616,8 @@ void destroyNextReq(int64_t nextRefId) {
|
|||
if (nextRefId) {
|
||||
SRequestObj* pObj = acquireRequest(nextRefId);
|
||||
if (pObj) {
|
||||
releaseRequest(nextRefId);
|
||||
releaseRequest(nextRefId);
|
||||
(void)releaseRequest(nextRefId); // ignore error
|
||||
(void)releaseRequest(nextRefId); // ignore error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -555,7 +637,7 @@ void destroySubRequests(SRequestObj *pRequest) {
|
|||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
pReqList[++reqIdx] = pTmp;
|
||||
releaseRequest(tmpRefId);
|
||||
(void)releaseRequest(tmpRefId); // ignore error
|
||||
} else {
|
||||
tscError("prev req ref 0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
|
@ -563,7 +645,7 @@ void destroySubRequests(SRequestObj *pRequest) {
|
|||
}
|
||||
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
removeRequest(pReqList[i]->self);
|
||||
(void)removeRequest(pReqList[i]->self); // ignore error
|
||||
}
|
||||
|
||||
tmpRefId = pRequest->relation.nextRefId;
|
||||
|
@ -571,8 +653,8 @@ void destroySubRequests(SRequestObj *pRequest) {
|
|||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
removeRequest(pTmp->self);
|
||||
releaseRequest(pTmp->self);
|
||||
(void)removeRequest(pTmp->self); // ignore error
|
||||
(void)releaseRequest(pTmp->self); // ignore error
|
||||
} else {
|
||||
tscError("next req ref 0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
|
@ -592,8 +674,10 @@ void doDestroyRequest(void *p) {
|
|||
|
||||
int64_t nextReqRefId = pRequest->relation.nextRefId;
|
||||
|
||||
taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||
|
||||
int32_t code = taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to remove request from hash, code:%s", tstrerror(code));
|
||||
}
|
||||
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||
|
||||
destorySqlCallbackWrapper(pRequest->pWrapper);
|
||||
|
@ -601,7 +685,7 @@ void doDestroyRequest(void *p) {
|
|||
taosMemoryFreeClear(pRequest->msgBuf);
|
||||
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
tsem_destroy(&pRequest->body.rspSem);
|
||||
(void)tsem_destroy(&pRequest->body.rspSem);
|
||||
|
||||
taosArrayDestroy(pRequest->tableList);
|
||||
taosArrayDestroy(pRequest->targetTableList);
|
||||
|
@ -615,13 +699,15 @@ void doDestroyRequest(void *p) {
|
|||
taosMemoryFreeClear(pRequest->pDb);
|
||||
taosArrayDestroy(pRequest->dbList);
|
||||
if (pRequest->body.interParam) {
|
||||
tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem);
|
||||
(void)tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem);
|
||||
}
|
||||
taosMemoryFree(pRequest->body.interParam);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == nodesSimAcquireAllocator(pRequest->allocatorRefId)) {
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
nodesSimReleaseAllocator(pRequest->allocatorRefId);
|
||||
if (TSDB_CODE_SUCCESS != nodesSimReleaseAllocator(pRequest->allocatorRefId)) {
|
||||
tscError("failed to release allocator");
|
||||
}
|
||||
}
|
||||
nodesDestroyAllocator(pRequest->allocatorRefId);
|
||||
|
||||
|
@ -638,7 +724,7 @@ void destroyRequest(SRequestObj *pRequest) {
|
|||
}
|
||||
|
||||
taos_stop_query(pRequest);
|
||||
removeFromMostPrevReq(pRequest);
|
||||
(void)removeFromMostPrevReq(pRequest);
|
||||
}
|
||||
|
||||
void taosStopQueryImpl(SRequestObj *pRequest) {
|
||||
|
@ -677,7 +763,7 @@ void stopAllQueries(SRequestObj *pRequest) {
|
|||
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
taosStopQueryImpl(pReqList[i]);
|
||||
releaseRequest(pReqList[i]->self);
|
||||
(void)releaseRequest(pReqList[i]->self); // ignore error
|
||||
}
|
||||
|
||||
taosStopQueryImpl(pRequest);
|
||||
|
@ -688,7 +774,7 @@ void stopAllQueries(SRequestObj *pRequest) {
|
|||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
taosStopQueryImpl(pTmp);
|
||||
releaseRequest(pTmp->self);
|
||||
(void)releaseRequest(pTmp->self); // ignore error
|
||||
} else {
|
||||
tscError("next req ref 0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
|
@ -701,7 +787,7 @@ void crashReportThreadFuncUnexpectedStopped(void) { atomic_store_32(&clientStop,
|
|||
static void *tscCrashReportThreadFp(void *param) {
|
||||
setThreadName("client-crashReport");
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.taosCrashLog", tsLogDir, TD_DIRSEP);
|
||||
(void)snprintf(filepath, sizeof(filepath), "%s%s.taosCrashLog", tsLogDir, TD_DIRSEP);
|
||||
char *pMsg = NULL;
|
||||
int64_t msgLen = 0;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -770,20 +856,27 @@ static void *tscCrashReportThreadFp(void *param) {
|
|||
|
||||
int32_t tscCrashReportInit() {
|
||||
if (!tsEnableCrashReport) {
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TSC_ERR_JRET(taosThreadAttrInit(&thAttr));
|
||||
TSC_ERR_JRET(taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE));
|
||||
TdThread crashReportThread;
|
||||
if (taosThreadCreate(&crashReportThread, &thAttr, tscCrashReportThreadFp, NULL) != 0) {
|
||||
tscError("failed to create crashReport thread since %s", strerror(errno));
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
TSC_ERR_RET(errno);
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
return 0;
|
||||
(void)taosThreadAttrDestroy(&thAttr);
|
||||
_return:
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
TSC_ERR_RET(terrno);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tscStopCrashReport() {
|
||||
|
@ -842,6 +935,11 @@ void taos_init_imp(void) {
|
|||
appInfo.startTime = taosGetTimestampMs();
|
||||
appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
appInfo.pInstMapByClusterId = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == appInfo.pInstMap || NULL == appInfo.pInstMapByClusterId) {
|
||||
tscError("failed to allocate memory when init appInfo");
|
||||
tscInitRes = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
taosHashSetFreeFp(appInfo.pInstMap, destroyAppInst);
|
||||
deltaToUtcInitOnce();
|
||||
|
||||
|
@ -849,7 +947,7 @@ void taos_init_imp(void) {
|
|||
#ifdef CUS_PROMPT
|
||||
snprintf(logDirName, 64, "%slog", CUS_PROMPT);
|
||||
#else
|
||||
snprintf(logDirName, 64, "taoslog");
|
||||
(void)snprintf(logDirName, 64, "taoslog");
|
||||
#endif
|
||||
if (taosCreateLog(logDirName, 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
printf(" WARING: Create %s failed:%s. configDir=%s\n", logDirName, strerror(errno), configDir);
|
||||
|
@ -857,24 +955,12 @@ void taos_init_imp(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
ENV_ERR_RET(taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1), "failed to init cfg");
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
if (taosConvInit() != 0) {
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init conv");
|
||||
return;
|
||||
}
|
||||
if (monitorInit() != 0){
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init monitor");
|
||||
return;
|
||||
}
|
||||
rpcInit();
|
||||
ENV_ERR_RET(taosConvInit(), "failed to init conv");
|
||||
ENV_ERR_RET(monitorInit(), "failed to init monitor");
|
||||
ENV_ERR_RET(rpcInit(), "failed to init rpc");
|
||||
|
||||
if (InitRegexCache() != 0) {
|
||||
tscInitRes = -1;
|
||||
|
@ -883,34 +969,26 @@ void taos_init_imp(void) {
|
|||
}
|
||||
|
||||
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
||||
catalogInit(&cfg);
|
||||
ENV_ERR_RET(catalogInit(&cfg), "failed to init catalog");
|
||||
ENV_ERR_RET(schedulerInit(), "failed to init scheduler");
|
||||
|
||||
schedulerInit();
|
||||
tscDebug("starting to initialize TAOS driver");
|
||||
|
||||
#ifndef WINDOWS
|
||||
taosSetCoreDump(true);
|
||||
#endif
|
||||
|
||||
if (initTaskQueue() != 0){
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init task queue");
|
||||
return;
|
||||
}
|
||||
if (fmFuncMgtInit() != TSDB_CODE_SUCCESS) {
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init function manager");
|
||||
return;
|
||||
}
|
||||
nodesInitAllocatorSet();
|
||||
ENV_ERR_RET(initTaskQueue(), "failed to init task queue");
|
||||
ENV_ERR_RET(fmFuncMgtInit(), "failed to init funcMgt");
|
||||
ENV_ERR_RET(nodesInitAllocatorSet(), "failed to init allocator set");
|
||||
|
||||
clientConnRefPool = taosOpenRef(200, destroyTscObj);
|
||||
clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
|
||||
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
taosThreadMutexInit(&appInfo.mutex, NULL);
|
||||
|
||||
tscCrashReportInit();
|
||||
ENV_ERR_RET(taosGetAppName(appInfo.appName, NULL), "failed to get app name");
|
||||
ENV_ERR_RET(taosThreadMutexInit(&appInfo.mutex, NULL), "failed to init thread mutex");
|
||||
ENV_ERR_RET(tscCrashReportInit(), "failed to init crash report");
|
||||
ENV_ERR_RET(qInitKeywordsTable(), "failed to init parser keywords table");
|
||||
|
||||
tscDebug("client is initialized successfully");
|
||||
}
|
||||
|
@ -957,7 +1035,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
return -1;
|
||||
}
|
||||
newstr[0] = '"';
|
||||
memcpy(newstr+1, str, len);
|
||||
(void)memcpy(newstr+1, str, len);
|
||||
newstr[len + 1] = '"';
|
||||
newstr[len + 2] = '\0';
|
||||
str = newstr;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -73,7 +73,7 @@ void jniGetGlobalMethod(JNIEnv *env) {
|
|||
}
|
||||
|
||||
if (g_vm == NULL) {
|
||||
(*env)->GetJavaVM(env, &g_vm);
|
||||
(void)(*env)->GetJavaVM(env, &g_vm);
|
||||
}
|
||||
|
||||
jclass arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
|
||||
|
@ -582,20 +582,20 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
|
|||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
case TSDB_DATA_TYPE_GEOMETRY: {
|
||||
memcpy(tmp, row[i], length[i]); // handle the case that terminated does not exist
|
||||
(void)memcpy(tmp, row[i], length[i]); // handle the case that terminated does not exist
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetStringFp, i, (*env)->NewStringUTF(env, tmp));
|
||||
|
||||
memset(tmp, 0, length[i]);
|
||||
(void)memset(tmp, 0, length[i]);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteArrayFp, i,
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_JSON: {
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteArrayFp, i,
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
|
@ -680,6 +680,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab
|
|||
jsize len = (*env)->GetArrayLength(env, jsql);
|
||||
|
||||
char *str = (char *)taosMemoryCalloc(1, sizeof(char) * (len + 1));
|
||||
if (str == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, jsql, 0, len, (jbyte *)str);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// todo handle error
|
||||
|
@ -843,6 +847,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
|
||||
jsize len = (*env)->GetArrayLength(env, tags);
|
||||
char *tagsData = (char *)taosMemoryCalloc(1, len);
|
||||
if (tagsData == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, tags, 0, len, (jbyte *)tagsData);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// todo handle error
|
||||
|
@ -850,18 +858,30 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
|
||||
len = (*env)->GetArrayLength(env, lengthList);
|
||||
int32_t *lengthArray = (int32_t *)taosMemoryCalloc(1, len);
|
||||
if (lengthArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, lengthList, 0, len, (jbyte *)lengthArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
len = (*env)->GetArrayLength(env, typeList);
|
||||
char *typeArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (typeArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, typeList, 0, len, (jbyte *)typeArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
len = (*env)->GetArrayLength(env, nullList);
|
||||
char *nullArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (nullArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, nullList, 0, len, (jbyte *)nullArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
@ -870,6 +890,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
char *curTags = tagsData;
|
||||
|
||||
TAOS_MULTI_BIND *tagsBind = taosMemoryCalloc(numOfTags, sizeof(TAOS_MULTI_BIND));
|
||||
if (tagsBind == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
tagsBind[i].buffer_type = typeArray[i];
|
||||
tagsBind[i].buffer = curTags;
|
||||
|
@ -916,6 +940,10 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp(
|
|||
// todo refactor
|
||||
jsize len = (*env)->GetArrayLength(env, colDataList);
|
||||
char *colBuf = (char *)taosMemoryCalloc(1, len);
|
||||
if (colBuf == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, colDataList, 0, len, (jbyte *)colBuf);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// todo handle error
|
||||
|
@ -923,18 +951,30 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp(
|
|||
|
||||
len = (*env)->GetArrayLength(env, lengthList);
|
||||
char *lengthArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (lengthArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, lengthList, 0, len, (jbyte *)lengthArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
len = (*env)->GetArrayLength(env, nullList);
|
||||
char *nullArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (nullArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, nullList, 0, len, (jbyte *)nullArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
// bind multi-rows with only one invoke.
|
||||
TAOS_MULTI_BIND *b = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND));
|
||||
if (b == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
b->num = numOfRows;
|
||||
b->buffer_type = dataType; // todo check data type
|
||||
|
@ -1043,14 +1083,14 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_stmtErrorMsgIm
|
|||
TAOS *tscon = (TAOS *)con;
|
||||
if (tscon == NULL) {
|
||||
jniError("jobj:%p, connection already closed", jobj);
|
||||
sprintf(errMsg, "jobj:%p, connection already closed", jobj);
|
||||
(void)sprintf(errMsg, "jobj:%p, connection already closed", jobj);
|
||||
return (*env)->NewStringUTF(env, errMsg);
|
||||
}
|
||||
|
||||
TAOS_STMT *pStmt = (TAOS_STMT *)stmt;
|
||||
if (pStmt == NULL) {
|
||||
jniError("jobj:%p, conn:%p, invalid stmt", jobj, tscon);
|
||||
sprintf(errMsg, "jobj:%p, conn:%p, invalid stmt", jobj, tscon);
|
||||
(void)sprintf(errMsg, "jobj:%p, conn:%p, invalid stmt", jobj, tscon);
|
||||
return (*env)->NewStringUTF(env, errMsg);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,15 +69,21 @@ void taos_cleanup(void) {
|
|||
qCleanupKeywordsTable();
|
||||
nodesDestroyAllocatorSet();
|
||||
|
||||
cleanupTaskQueue();
|
||||
if (TSDB_CODE_SUCCESS != cleanupTaskQueue()) {
|
||||
tscWarn("failed to cleanup task queue");
|
||||
}
|
||||
|
||||
int32_t id = clientReqRefPool;
|
||||
clientReqRefPool = -1;
|
||||
taosCloseRef(id);
|
||||
if (TSDB_CODE_SUCCESS != taosCloseRef(id)) {
|
||||
tscWarn("failed to close clientReqRefPool");
|
||||
}
|
||||
|
||||
id = clientConnRefPool;
|
||||
clientConnRefPool = -1;
|
||||
taosCloseRef(id);
|
||||
if (TSDB_CODE_SUCCESS != taosCloseRef(id)) {
|
||||
tscWarn("failed to close clientReqRefPool");
|
||||
}
|
||||
|
||||
DestroyRegexCache();
|
||||
rpcCleanup();
|
||||
|
@ -115,11 +121,19 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
|||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
STscObj *pObj = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY);
|
||||
if (pObj) {
|
||||
STscObj *pObj = NULL;
|
||||
int32_t code = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY, &pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t));
|
||||
if (NULL == rid) {
|
||||
tscError("out of memory when taos connect to %s:%u, user:%s db:%s", ip, port, user, db);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
*rid = pObj->id;
|
||||
return (TAOS *)rid;
|
||||
} else {
|
||||
terrno = code;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -140,24 +154,24 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)
|
|||
|
||||
switch (type) {
|
||||
case TAOS_NOTIFY_PASSVER: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexLock(&pObj->mutex));
|
||||
pObj->passInfo.fp = fp;
|
||||
pObj->passInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexUnlock(&pObj->mutex));
|
||||
break;
|
||||
}
|
||||
case TAOS_NOTIFY_WHITELIST_VER: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexLock(&pObj->mutex));
|
||||
pObj->whiteListInfo.fp = fp;
|
||||
pObj->whiteListInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexUnlock(&pObj->mutex));
|
||||
break;
|
||||
}
|
||||
case TAOS_NOTIFY_USER_DROPPED: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexLock(&pObj->mutex));
|
||||
pObj->userDroppedInfo.fp = fp;
|
||||
pObj->userDroppedInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexUnlock(&pObj->mutex));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -189,7 +203,13 @@ int32_t fetchWhiteListCallbackFn(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
SGetUserWhiteListRsp wlRsp;
|
||||
tDeserializeSGetUserWhiteListRsp(pMsg->pData, pMsg->len, &wlRsp);
|
||||
if (TSDB_CODE_SUCCESS != tDeserializeSGetUserWhiteListRsp(pMsg->pData, pMsg->len, &wlRsp)) {
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
taosMemoryFree(pInfo);
|
||||
tFreeSGetUserWhiteListRsp(&wlRsp);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
uint64_t* pWhiteLists = taosMemoryMalloc(wlRsp.numWhiteLists * sizeof(uint64_t));
|
||||
if (pWhiteLists == NULL) {
|
||||
|
@ -229,8 +249,14 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa
|
|||
}
|
||||
|
||||
SGetUserWhiteListReq req;
|
||||
memcpy(req.user, pTsc->user, TSDB_USER_LEN);
|
||||
(void)memcpy(req.user, pTsc->user, TSDB_USER_LEN);
|
||||
int32_t msgLen = tSerializeSGetUserWhiteListReq(NULL, 0, &req);
|
||||
if (msgLen < 0) {
|
||||
fp(param, TSDB_CODE_INVALID_PARA, taos, 0, NULL);
|
||||
releaseTscObj(connId);
|
||||
return;
|
||||
}
|
||||
|
||||
void* pReq = taosMemoryMalloc(msgLen);
|
||||
if (pReq == NULL) {
|
||||
fp(param, TSDB_CODE_OUT_OF_MEMORY, taos, 0, NULL);
|
||||
|
@ -274,7 +300,9 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa
|
|||
|
||||
int64_t transportId = 0;
|
||||
SEpSet epSet = getEpSet_s(&pTsc->pAppInfo->mgmtEp);
|
||||
asyncSendMsgToServer(pTsc->pAppInfo->pTransporter, &epSet, &transportId, pSendInfo);
|
||||
if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pTsc->pAppInfo->pTransporter, &epSet, &transportId, pSendInfo)) {
|
||||
tscWarn("failed to async send msg to server");
|
||||
}
|
||||
releaseTscObj(connId);
|
||||
return;
|
||||
}
|
||||
|
@ -287,7 +315,7 @@ void taos_close_internal(void *taos) {
|
|||
STscObj *pTscObj = (STscObj *)taos;
|
||||
tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
|
||||
|
||||
taosRemoveRef(clientConnRefPool, pTscObj->id);
|
||||
(void)taosRemoveRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
void taos_close(TAOS *taos) {
|
||||
|
@ -453,6 +481,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
} else {
|
||||
// assert to avoid un-initialization error
|
||||
tscError("invalid result passed to taos_fetch_row");
|
||||
terrno = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -521,7 +550,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
if(taosAscii2Hex(row[i], charLen, &data, &size) < 0){
|
||||
break;
|
||||
}
|
||||
memcpy(str + len, data, size);
|
||||
(void)memcpy(str + len, data, size);
|
||||
len += size;
|
||||
taosMemoryFree(data);
|
||||
}break;
|
||||
|
@ -539,7 +568,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
}
|
||||
}
|
||||
|
||||
memcpy(str + len, row[i], charLen);
|
||||
(void)memcpy(str + len, row[i], charLen);
|
||||
len += charLen;
|
||||
} break;
|
||||
|
||||
|
@ -686,7 +715,7 @@ int taos_select_db(TAOS *taos, const char *db) {
|
|||
}
|
||||
|
||||
char sql[256] = {0};
|
||||
snprintf(sql, tListLen(sql), "use %s", db);
|
||||
(void)snprintf(sql, tListLen(sql), "use %s", db);
|
||||
|
||||
TAOS_RES *pRequest = taos_query(taos, sql);
|
||||
int32_t code = taos_errno(pRequest);
|
||||
|
@ -742,10 +771,10 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
doAsyncFetchRows(pRequest, false, true);
|
||||
(void)doAsyncFetchRows(pRequest, false, true);
|
||||
|
||||
// TODO refactor
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -795,10 +824,10 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
doAsyncFetchRows(pRequest, false, false);
|
||||
(void)doAsyncFetchRows(pRequest, false, false);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
|
@ -806,7 +835,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||
|
@ -864,26 +893,24 @@ const char *taos_get_server_info(TAOS *taos) {
|
|||
int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
|
||||
STscObj *pTscObj = acquireTscObj(*(int64_t *)taos);
|
||||
if (pTscObj == NULL) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_DISCONNECTED;
|
||||
}
|
||||
|
||||
int code = TSDB_CODE_SUCCESS;
|
||||
taosThreadMutexLock(&pTscObj->mutex);
|
||||
(void)taosThreadMutexLock(&pTscObj->mutex);
|
||||
if (database == NULL || len <= 0) {
|
||||
if (required != NULL) *required = strlen(pTscObj->db) + 1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = -1;
|
||||
TSC_ERR_JRET(TSDB_CODE_INVALID_PARA);
|
||||
} else if (len < strlen(pTscObj->db) + 1) {
|
||||
tstrncpy(database, pTscObj->db, len);
|
||||
if (required) *required = strlen(pTscObj->db) + 1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = -1;
|
||||
TSC_ERR_JRET(TSDB_CODE_INVALID_PARA);
|
||||
} else {
|
||||
strcpy(database, pTscObj->db);
|
||||
(void)strcpy(database, pTscObj->db);
|
||||
code = 0;
|
||||
}
|
||||
taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
_return:
|
||||
(void)taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
return code;
|
||||
}
|
||||
|
@ -924,8 +951,8 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t
|
|||
pRequest->metric.analyseCostUs += taosGetTimestampUs() - analyseStart;
|
||||
|
||||
if (pRequest->parseOnly) {
|
||||
memcpy(&pRequest->parseMeta, pResultMeta, sizeof(*pResultMeta));
|
||||
memset(pResultMeta, 0, sizeof(*pResultMeta));
|
||||
(void)memcpy(&pRequest->parseMeta, pResultMeta, sizeof(*pResultMeta));
|
||||
(void)memset(pResultMeta, 0, sizeof(*pResultMeta));
|
||||
}
|
||||
|
||||
handleQueryAnslyseRes(pWrapper, pResultMeta, code);
|
||||
|
@ -972,10 +999,9 @@ void handleSubQueryFromAnalyse(SSqlCallbackWrapper *pWrapper, SMetaData *pResult
|
|||
return;
|
||||
}
|
||||
|
||||
pNewRequest->pQuery = (SQuery *)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pNewRequest->pQuery) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pNewRequest->pQuery = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pNewRequest->pQuery);
|
||||
if (pNewRequest->pQuery) {
|
||||
pNewRequest->pQuery->pRoot = pRoot;
|
||||
pRoot = NULL;
|
||||
pNewRequest->pQuery->execStage = QUERY_EXEC_STAGE_ANALYSE;
|
||||
|
@ -1013,10 +1039,12 @@ void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta
|
|||
}
|
||||
|
||||
if (pQuery->haveResultSet) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols);
|
||||
code = setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, pQuery->precision);
|
||||
}
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
TSWAP(pRequest->dbList, (pQuery)->pDbList);
|
||||
TSWAP(pRequest->tableList, (pQuery)->pTableList);
|
||||
TSWAP(pRequest->targetTableList, (pQuery)->pTargetTableList);
|
||||
|
@ -1201,7 +1229,7 @@ int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *p
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pWrapper->pCatalogReq->forceUpdate = updateMetaForce;
|
||||
pWrapper->pCatalogReq->qNodeRequired = qnodeRequired(pRequest);
|
||||
TSC_ERR_RET(qnodeRequired(pRequest, &pWrapper->pCatalogReq->qNodeRequired));
|
||||
code = qParseSqlSyntax(pWrapper->pParseCtx, &pRequest->pQuery, pWrapper->pCatalogReq);
|
||||
}
|
||||
|
||||
|
@ -1244,7 +1272,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
if (NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId);
|
||||
refreshMeta(pRequest->pTscObj, pRequest);
|
||||
(void)refreshMeta(pRequest->pTscObj, pRequest); //ignore return code,try again
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
|
@ -1259,13 +1287,13 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
void restartAsyncQuery(SRequestObj *pRequest, int32_t code) {
|
||||
tscInfo("restart request: %s p: %p", pRequest->sqlstr, pRequest);
|
||||
SRequestObj* pUserReq = pRequest;
|
||||
acquireRequest(pRequest->self);
|
||||
(void)acquireRequest(pRequest->self);
|
||||
while (pUserReq) {
|
||||
if (pUserReq->self == pUserReq->relation.userRefId || pUserReq->relation.userRefId == 0) {
|
||||
break;
|
||||
} else {
|
||||
int64_t nextRefId = pUserReq->relation.nextRefId;
|
||||
releaseRequest(pUserReq->self);
|
||||
(void)releaseRequest(pUserReq->self);
|
||||
if (nextRefId) {
|
||||
pUserReq = acquireRequest(nextRefId);
|
||||
}
|
||||
|
@ -1275,16 +1303,16 @@ void restartAsyncQuery(SRequestObj *pRequest, int32_t code) {
|
|||
if (pUserReq) {
|
||||
destroyCtxInRequest(pUserReq);
|
||||
pUserReq->prevCode = code;
|
||||
memset(&pUserReq->relation, 0, sizeof(pUserReq->relation));
|
||||
(void)memset(&pUserReq->relation, 0, sizeof(pUserReq->relation));
|
||||
} else {
|
||||
tscError("User req is missing");
|
||||
removeFromMostPrevReq(pRequest);
|
||||
(void)removeFromMostPrevReq(pRequest);
|
||||
return;
|
||||
}
|
||||
if (hasSubRequest)
|
||||
removeFromMostPrevReq(pRequest);
|
||||
(void)removeFromMostPrevReq(pRequest);
|
||||
else
|
||||
releaseRequest(pUserReq->self);
|
||||
(void)releaseRequest(pUserReq->self);
|
||||
doAsyncQuery(pUserReq, true);
|
||||
}
|
||||
|
||||
|
@ -1374,7 +1402,7 @@ int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInf
|
|||
conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
snprintf(dbFName, sizeof(dbFName), "%d.%s", pTscObj->acctId, db);
|
||||
(void)snprintf(dbFName, sizeof(dbFName), "%d.%s", pTscObj->acctId, db);
|
||||
|
||||
code = catalogGetDBVgInfo(pCtg, &conn, dbFName, dbInfo);
|
||||
if (code) {
|
||||
|
@ -1424,7 +1452,7 @@ int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId
|
|||
conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
SName tableName;
|
||||
toName(pTscObj->acctId, db, table, &tableName);
|
||||
(void)toName(pTscObj->acctId, db, table, &tableName);
|
||||
|
||||
SVgroupInfo vgInfo;
|
||||
code = catalogGetTableHashVgroup(pCtg, &conn, &tableName, &vgInfo);
|
||||
|
@ -1545,7 +1573,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
}
|
||||
|
||||
SSyncQueryParam *pParam = pRequest->body.interParam;
|
||||
tsem_wait(&pParam->sem);
|
||||
(void)tsem_wait(&pParam->sem);
|
||||
|
||||
_return:
|
||||
destoryCatalogReq(&catalogReq);
|
||||
|
@ -1562,7 +1590,9 @@ TAOS_STMT *taos_stmt_init(TAOS *taos) {
|
|||
}
|
||||
|
||||
TAOS_STMT *pStmt = stmtInit(pObj, 0, NULL);
|
||||
|
||||
if (NULL == pStmt) {
|
||||
tscError("stmt init failed, errcode:%s", terrstr());
|
||||
}
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
||||
return pStmt;
|
||||
|
@ -1577,7 +1607,9 @@ TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid) {
|
|||
}
|
||||
|
||||
TAOS_STMT *pStmt = stmtInit(pObj, reqid, NULL);
|
||||
|
||||
if (NULL == pStmt) {
|
||||
tscError("stmt init failed, errcode:%s", terrstr());
|
||||
}
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
||||
return pStmt;
|
||||
|
@ -1592,7 +1624,9 @@ TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS *options) {
|
|||
}
|
||||
|
||||
TAOS_STMT *pStmt = stmtInit(pObj, options->reqId, options);
|
||||
|
||||
if (NULL == pStmt) {
|
||||
tscError("stmt init failed, errcode:%s", terrstr());
|
||||
}
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
||||
return pStmt;
|
||||
|
@ -1707,7 +1741,11 @@ int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
|||
}
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
int32_t code = stmtIsInsert(stmt, &insert);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("stmt insert failed, errcode:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
if (0 == insert && bind->num > 1) {
|
||||
tscError("only one row data allowed for query");
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -1731,7 +1769,11 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, in
|
|||
}
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
int32_t code = stmtIsInsert(stmt, &insert);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("stmt insert failed, errcode:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
if (0 == insert && bind->num > 1) {
|
||||
tscError("only one row data allowed for query");
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -1858,4 +1900,4 @@ int taos_set_conn_mode(TAOS* taos, int mode, int value) {
|
|||
|
||||
char* getBuildInfo(){
|
||||
return buildinfo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1214,12 +1214,14 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
}
|
||||
SArray* pBufArray = NULL;
|
||||
RAW_RETURN_CHECK(serializeVgroupsCreateTableBatch(pVgroupHashmap, &pBufArray));
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
RAW_NULL_CHECK(pQuery);
|
||||
pQuery = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
|
||||
if (TSDB_CODE_SUCCESS != code) goto end;
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->msgType = TDMT_VND_CREATE_TABLE;
|
||||
pQuery->stableQuery = false;
|
||||
pQuery->pRoot = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT);
|
||||
code = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT, &pQuery->pRoot);
|
||||
if (TSDB_CODE_SUCCESS != code) goto end;
|
||||
RAW_NULL_CHECK(pQuery->pRoot);
|
||||
|
||||
RAW_RETURN_CHECK(rewriteToVnodeModifyOpStmt(pQuery, pBufArray));
|
||||
|
@ -1343,13 +1345,14 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
}
|
||||
SArray* pBufArray = NULL;
|
||||
RAW_RETURN_CHECK(serializeVgroupsDropTableBatch(pVgroupHashmap, &pBufArray));
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
RAW_NULL_CHECK(pQuery);
|
||||
code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
|
||||
if (TSDB_CODE_SUCCESS != code) goto end;
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->msgType = TDMT_VND_DROP_TABLE;
|
||||
pQuery->stableQuery = false;
|
||||
pQuery->pRoot = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT);
|
||||
RAW_NULL_CHECK(pQuery->pRoot);
|
||||
pQuery->pRoot = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, &pQuery->pRoot);
|
||||
if (TSDB_CODE_SUCCESS != code) goto end;
|
||||
RAW_RETURN_CHECK(rewriteToVnodeModifyOpStmt(pQuery, pBufArray));
|
||||
|
||||
(void)launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
|
@ -1486,13 +1489,15 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
pVgData->numOfTables = 1;
|
||||
RAW_NULL_CHECK(taosArrayPush(pArray, &pVgData));
|
||||
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
RAW_NULL_CHECK(pQuery);
|
||||
pQuery = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
|
||||
if (NULL == pQuery) goto end;
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->msgType = TDMT_VND_ALTER_TABLE;
|
||||
pQuery->stableQuery = false;
|
||||
pQuery->pRoot = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
RAW_NULL_CHECK(pQuery->pRoot);
|
||||
pQuery->pRoot = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, &pQuery->pRoot);
|
||||
if (TSDB_CODE_SUCCESS != code) goto end;
|
||||
RAW_RETURN_CHECK(rewriteToVnodeModifyOpStmt(pQuery, pArray));
|
||||
|
||||
|
||||
|
@ -1537,8 +1542,8 @@ int taos_write_raw_block_with_fields_with_reqid(TAOS* taos, int rows, char* pDat
|
|||
SQuery* pQuery = NULL;
|
||||
SHashObj* pVgHash = NULL;
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, reqid);
|
||||
RAW_NULL_CHECK(pRequest);
|
||||
SRequestObj* pRequest = NULL;
|
||||
RAW_RETURN_CHECK(createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, reqid, &pRequest));
|
||||
|
||||
uDebug(LOG_ID_TAG " write raw block with field, rows:%d, pData:%p, tbname:%s, fields:%p, numFields:%d", LOG_ID_VALUE,
|
||||
rows, pData, tbname, fields, numFields);
|
||||
|
@ -1597,8 +1602,8 @@ int taos_write_raw_block_with_reqid(TAOS* taos, int rows, char* pData, const cha
|
|||
SQuery* pQuery = NULL;
|
||||
SHashObj* pVgHash = NULL;
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, reqid);
|
||||
RAW_NULL_CHECK(pRequest);
|
||||
SRequestObj* pRequest = NULL;
|
||||
RAW_RETURN_CHECK(createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, reqid, &pRequest));
|
||||
|
||||
uDebug(LOG_ID_TAG " write raw block, rows:%d, pData:%p, tbname:%s", LOG_ID_VALUE, rows, pData, tbname);
|
||||
|
||||
|
@ -1667,8 +1672,8 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
SDecoder decoder = {0};
|
||||
STableMeta* pTableMeta = NULL;
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
||||
RAW_NULL_CHECK(pRequest);
|
||||
SRequestObj* pRequest = NULL;
|
||||
RAW_RETURN_CHECK(createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0, &pRequest));
|
||||
|
||||
uDebug(LOG_ID_TAG " write raw data, data:%p, dataLen:%d", LOG_ID_VALUE, data, dataLen);
|
||||
pRequest->syncQuery = true;
|
||||
|
@ -1778,8 +1783,8 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
STableMeta* pTableMeta = NULL;
|
||||
SVCreateTbReq* pCreateReqDst = NULL;
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
||||
RAW_NULL_CHECK(pRequest);
|
||||
SRequestObj* pRequest = NULL;
|
||||
RAW_RETURN_CHECK(createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0, &pRequest));
|
||||
|
||||
uDebug(LOG_ID_TAG " write raw metadata, data:%p, dataLen:%d", LOG_ID_VALUE, data, dataLen);
|
||||
pRequest->syncQuery = true;
|
||||
|
|
|
@ -2137,8 +2137,8 @@ TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine,
|
|||
SSmlHandle *info = NULL;
|
||||
int cnt = 0;
|
||||
while (1) {
|
||||
request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, reqid);
|
||||
if (request == NULL) {
|
||||
code = createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, reqid, &request);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
uError("SML:taos_schemaless_insert error request is null");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1237,8 +1237,9 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
}
|
||||
|
||||
// init connection
|
||||
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ);
|
||||
if (pTmq->pTscObj == NULL) {
|
||||
code = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ, &pTmq->pTscObj);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
(void)tsem2_destroy(&pTmq->rspSem);
|
||||
SET_ERROR_MSG_TMQ("init tscObj failed")
|
||||
|
|
|
@ -1354,8 +1354,9 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
|
|||
}
|
||||
|
||||
static int32_t taosCheckGlobalCfg() {
|
||||
uint32_t ipv4 = taosGetIpv4FromFqdn(tsLocalFqdn);
|
||||
if (ipv4 == 0xffffffff) {
|
||||
uint32_t ipv4 = 0;
|
||||
int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4);
|
||||
if (code) {
|
||||
terrno = TSDB_CODE_RPC_FQDN_ERROR;
|
||||
uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -10590,7 +10590,7 @@ int32_t tCloneTbTSMAInfo(STableTSMAInfo *pInfo, STableTSMAInfo **pRes) {
|
|||
if (!pRet->ast) code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (code) {
|
||||
tFreeTableTSMAInfo(pRet);
|
||||
tFreeAndClearTableTSMAInfo(pRet);
|
||||
pRet = NULL;
|
||||
}
|
||||
*pRes = pRet;
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#include "trow.h"
|
||||
#include "tlog.h"
|
||||
|
||||
static bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
|
||||
static bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal);
|
||||
static bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
|
||||
static bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal);
|
||||
|
||||
void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) {
|
||||
pIter->pSchema = pSchema;
|
||||
|
@ -110,8 +110,7 @@ bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset,
|
|||
|
||||
int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||
|
@ -131,59 +130,15 @@ int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pVa
|
|||
*pValType = ((*pDestByte) & 0x03);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS_I;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR_I;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pValType = (((*pDestByte) & 0x80) >> 7);
|
||||
break;
|
||||
case 1:
|
||||
*pValType = (((*pDestByte) & 0x40) >> 6);
|
||||
break;
|
||||
case 2:
|
||||
*pValType = (((*pDestByte) & 0x20) >> 5);
|
||||
break;
|
||||
case 3:
|
||||
*pValType = (((*pDestByte) & 0x10) >> 4);
|
||||
break;
|
||||
case 4:
|
||||
*pValType = (((*pDestByte) & 0x08) >> 3);
|
||||
break;
|
||||
case 5:
|
||||
*pValType = (((*pDestByte) & 0x04) >> 2);
|
||||
break;
|
||||
case 6:
|
||||
*pValType = (((*pDestByte) & 0x02) >> 1);
|
||||
break;
|
||||
case 7:
|
||||
*pValType = ((*pDestByte) & 0x01);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
switch (bitmapMode) {
|
||||
case 0:
|
||||
tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
(void)tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
break;
|
||||
#if 0
|
||||
case -1:
|
||||
|
@ -192,10 +147,9 @@ int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValT
|
|||
break;
|
||||
#endif
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal) {
|
||||
|
@ -400,8 +354,8 @@ bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVa
|
|||
}
|
||||
|
||||
void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow));
|
||||
tdGetKvRowValOfCol(pVal, pRow, pBitmap, pColIdx->offset,
|
||||
POINTER_DISTANCE(pColIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx));
|
||||
(void)tdGetKvRowValOfCol(pVal, pRow, pBitmap, pColIdx->offset,
|
||||
POINTER_DISTANCE(pColIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -412,11 +366,10 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl
|
|||
return true;
|
||||
}
|
||||
void *pBitmap = tdGetBitmapAddrTp(pRow, flen);
|
||||
tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset, colIdx);
|
||||
(void)tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset, colIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
|
||||
if (pIter->colIdx >= pIter->pSchema->numOfCols) {
|
||||
return false;
|
||||
|
@ -432,9 +385,9 @@ bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
|
|||
}
|
||||
|
||||
if (TD_IS_TP_ROW(pIter->pRow)) {
|
||||
tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal);
|
||||
(void)tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal);
|
||||
} else if (TD_IS_KV_ROW(pIter->pRow)) {
|
||||
tdSTSRowIterGetKvVal(pIter, pCol->colId, &pIter->kvIdx, pVal);
|
||||
(void)tdSTSRowIterGetKvVal(pIter, pCol->colId, &pIter->kvIdx, pVal);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -452,6 +405,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
int32_t maxVarDataLen = 0;
|
||||
int32_t iColVal = 0;
|
||||
int32_t nBound = 0;
|
||||
int32_t code = 0;
|
||||
void *varBuf = NULL;
|
||||
bool isAlloc = false;
|
||||
|
||||
|
@ -481,7 +435,8 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
} else {
|
||||
varDataLen += sizeof(VarDataLenT);
|
||||
if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR || pTColumn->type == TSDB_DATA_TYPE_VARBINARY || pTColumn->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR || pTColumn->type == TSDB_DATA_TYPE_VARBINARY ||
|
||||
pTColumn->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
varDataLen += CHAR_BYTES;
|
||||
if (maxVarDataLen < CHAR_BYTES + sizeof(VarDataLenT)) {
|
||||
maxVarDataLen = CHAR_BYTES + sizeof(VarDataLenT);
|
||||
|
@ -494,7 +449,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if(pColVal && COL_VAL_IS_VALUE(pColVal)) {
|
||||
if (pColVal && COL_VAL_IS_VALUE(pColVal)) {
|
||||
nonVarDataLen += TYPE_BYTES[pTColumn->type];
|
||||
}
|
||||
}
|
||||
|
@ -516,8 +471,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
|
||||
if (!(*ppRow)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (maxVarDataLen > 0) {
|
||||
|
@ -526,15 +480,14 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
if (isAlloc) {
|
||||
taosMemoryFreeClear(*ppRow);
|
||||
}
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
SRowBuilder rb = {.rowType = rowType};
|
||||
tdSRowInit(&rb, pTSchema->version);
|
||||
tdSRowSetInfo(&rb, pTSchema->numOfCols, nBound, pTSchema->flen);
|
||||
tdSRowResetBuf(&rb, *ppRow);
|
||||
(void)tdSRowSetInfo(&rb, pTSchema->numOfCols, nBound, pTSchema->flen);
|
||||
(void)tdSRowResetBuf(&rb, *ppRow);
|
||||
int32_t iBound = 0;
|
||||
|
||||
iColVal = 0;
|
||||
|
@ -553,7 +506,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
} else if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
varDataSetLen(varBuf, pColVal->value.nData);
|
||||
if (pColVal->value.nData != 0) {
|
||||
memcpy(varDataVal(varBuf), pColVal->value.pData, pColVal->value.nData);
|
||||
(void)memcpy(varDataVal(varBuf), pColVal->value.pData, pColVal->value.nData);
|
||||
}
|
||||
val = varBuf;
|
||||
++iBound;
|
||||
|
@ -567,18 +520,28 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
|
||||
if (TD_IS_TP_ROW(rb.pBuf)) {
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, pTColumn->offset, iColVal);
|
||||
TAOS_CHECK_GOTO(
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, pTColumn->offset, iColVal),
|
||||
NULL, _exit);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, rb.offset, iBound - 1);
|
||||
TAOS_CHECK_GOTO(
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, rb.offset, iBound - 1), NULL,
|
||||
_exit);
|
||||
}
|
||||
|
||||
++iColVal;
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
|
||||
_exit:
|
||||
taosMemoryFreeClear(varBuf);
|
||||
if (code < 0) {
|
||||
if (isAlloc) {
|
||||
taosMemoryFreeClear(*ppRow);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdCompareColId(const void *arg1, const void *arg2) {
|
||||
|
@ -615,7 +578,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell
|
|||
#ifdef TD_SUPPORT_BITMAP
|
||||
colIdx = POINTER_DISTANCE(pCol, pSchema->columns) / sizeof(STColumn);
|
||||
#endif
|
||||
tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset, colIdx - 1);
|
||||
(void)tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset, colIdx - 1);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
SKvRowIdx *pIdx = (SKvRowIdx *)taosbsearch(&colId, TD_ROW_COL_IDX(pRow), tdRowGetNCols(pRow), sizeof(SKvRowIdx),
|
||||
compareKvRowColId, TD_EQ);
|
||||
|
@ -624,7 +587,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell
|
|||
colIdx = POINTER_DISTANCE(pIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx);
|
||||
}
|
||||
#endif
|
||||
tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx);
|
||||
(void)tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx);
|
||||
} else {
|
||||
if (COL_REACH_END(colId, pIter->maxColId)) return false;
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
|
@ -632,83 +595,31 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell
|
|||
|
||||
return true;
|
||||
}
|
||||
#if 0
|
||||
int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS_I;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR_I;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pDestByte = ((*pDestByte) & 0x7F) | (valType << 7);
|
||||
// set the value and clear other partitions for offset 0
|
||||
// *pDestByte |= (valType << 7);
|
||||
break;
|
||||
case 1:
|
||||
*pDestByte = ((*pDestByte) & 0xBF) | (valType << 6);
|
||||
// *pDestByte |= (valType << 6);
|
||||
break;
|
||||
case 2:
|
||||
*pDestByte = ((*pDestByte) & 0xDF) | (valType << 5);
|
||||
// *pDestByte |= (valType << 5);
|
||||
break;
|
||||
case 3:
|
||||
*pDestByte = ((*pDestByte) & 0xEF) | (valType << 4);
|
||||
// *pDestByte |= (valType << 4);
|
||||
break;
|
||||
case 4:
|
||||
*pDestByte = ((*pDestByte) & 0xF7) | (valType << 3);
|
||||
// *pDestByte |= (valType << 3);
|
||||
break;
|
||||
case 5:
|
||||
*pDestByte = ((*pDestByte) & 0xFB) | (valType << 2);
|
||||
// *pDestByte |= (valType << 2);
|
||||
break;
|
||||
case 6:
|
||||
*pDestByte = ((*pDestByte) & 0xFD) | (valType << 1);
|
||||
// *pDestByte |= (valType << 1);
|
||||
break;
|
||||
case 7:
|
||||
*pDestByte = ((*pDestByte) & 0xFE) | valType;
|
||||
// *pDestByte |= (valType);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_t offset, int16_t colIdx) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
ASSERT(colIdx < tdRowGetNCols(pRow) - 1);
|
||||
if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
int32_t code = 0;
|
||||
if ((code = tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0)) != TSDB_CODE_SUCCESS) {
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (tdValTypeIsNorm(output->valType)) {
|
||||
if (offset < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
output->val = POINTER_SHIFT(pRow, offset);
|
||||
}
|
||||
#else
|
||||
if (offset < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
output->val = POINTER_SHIFT(pRow, offset);
|
||||
output->valType = isNull(output->val, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t colType, int32_t offset,
|
||||
|
@ -720,12 +631,13 @@ int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t
|
|||
} else {
|
||||
output->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
int32_t code = 0;
|
||||
if ((code = tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0)) != TSDB_CODE_SUCCESS) {
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (output->valType == TD_VTYPE_NORM) {
|
||||
|
@ -736,7 +648,7 @@ int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t
|
|||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colType, TDRowValT valType, const void *val,
|
||||
|
@ -745,23 +657,21 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp
|
|||
if (!val) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (valType == TD_VTYPE_NORM) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
#else
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
d
|
||||
#endif
|
||||
}
|
||||
// TS KEY is stored in STSRow.ts and not included in STSRow.data field.
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
if (!val) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
TD_ROW_KEY(pRow) = *(TSKEY *)val;
|
||||
// The primary TS key is Norm all the time, thus its valType is not stored in bitmap.
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
// TODO: We can avoid the type judegement by FP, but would prevent the inline scheme.
|
||||
|
||||
|
@ -773,33 +683,29 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp
|
|||
break;
|
||||
case TD_VTYPE_NONE:
|
||||
if (!pBuilder->hasNone) pBuilder->hasNone = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset);
|
||||
(void)tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset);
|
||||
} else {
|
||||
tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId);
|
||||
(void)tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData,
|
||||
int8_t colType, int16_t colIdx, int32_t offset, col_id_t colId) {
|
||||
if (colIdx < 1) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
ASSERTS(0, "colIdx is %" PRIi64, colIdx);
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
--colIdx;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0));
|
||||
#endif
|
||||
|
||||
STSRow *row = pBuilder->pBuf;
|
||||
|
@ -812,30 +718,27 @@ int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const vo
|
|||
char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
if (isCopyVarData) {
|
||||
memcpy(ptr, val, varDataTLen(val));
|
||||
(void)memcpy(ptr, val, varDataTLen(val));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(val);
|
||||
} else {
|
||||
memcpy(ptr, val, TYPE_BYTES[colType]);
|
||||
(void)memcpy(ptr, val, TYPE_BYTES[colType]);
|
||||
TD_ROW_LEN(row) += TYPE_BYTES[colType];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData,
|
||||
int8_t colType, int16_t colIdx, int32_t offset) {
|
||||
if (colIdx < 1) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
--colIdx;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0));
|
||||
#endif
|
||||
|
||||
STSRow *row = pBuilder->pBuf;
|
||||
|
@ -849,59 +752,21 @@ int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const vo
|
|||
// ts key stored in STSRow.ts
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(row), offset) = TD_ROW_LEN(row);
|
||||
if (isCopyVarData) {
|
||||
memcpy(POINTER_SHIFT(row, TD_ROW_LEN(row)), val, varDataTLen(val));
|
||||
(void)memcpy(POINTER_SHIFT(row, TD_ROW_LEN(row)), val, varDataTLen(val));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(val);
|
||||
} else {
|
||||
memcpy(POINTER_SHIFT(TD_ROW_DATA(row), offset), val, TYPE_BYTES[colType]);
|
||||
(void)memcpy(POINTER_SHIFT(TD_ROW_DATA(row), offset), val, TYPE_BYTES[colType]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
#if 0
|
||||
int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen,
|
||||
int32_t allNullLen, int32_t boundNullLen) {
|
||||
if ((boundNullLen > 0) && (allNullLen > 0) && (nBoundCols > 0)) {
|
||||
uint32_t tpLen = allNullLen;
|
||||
uint32_t kvLen = sizeof(col_id_t) + sizeof(SKvRowIdx) * nBoundCols + boundNullLen;
|
||||
if (isSelectKVRow(kvLen, tpLen)) {
|
||||
pBuilder->rowType = TD_ROW_KV;
|
||||
} else {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
}
|
||||
|
||||
} else {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
}
|
||||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
pBuilder->nBoundCols = nBoundCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
pBuilder->nBitmaps = (col_id_t)TD_BITMAP_BYTES(pBuilder->nCols - 1);
|
||||
if (nBoundCols > 0) {
|
||||
pBuilder->nBoundBitmaps = (col_id_t)TD_BITMAP_BYTES(pBuilder->nBoundCols - 1);
|
||||
} else {
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
}
|
||||
#else
|
||||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
||||
pBuilder->pBuf = (STSRow *)pBuf;
|
||||
if (!pBuilder->pBuf) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (pBuilder->hasNone) pBuilder->hasNone = false;
|
||||
|
@ -917,7 +782,7 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
case TD_ROW_TP:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrTp(pBuilder->pBuf, pBuilder->flen);
|
||||
memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps);
|
||||
(void)memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps);
|
||||
#endif
|
||||
// the primary TS key is stored separatedly
|
||||
len = TD_ROW_HEAD_LEN + pBuilder->flen + pBuilder->nBitmaps;
|
||||
|
@ -927,7 +792,7 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
case TD_ROW_KV:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols);
|
||||
memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBoundBitmaps);
|
||||
(void)memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBoundBitmaps);
|
||||
#endif
|
||||
len = TD_ROW_HEAD_LEN + TD_ROW_NCOLS_LEN + (pBuilder->nBoundCols - 1) * sizeof(SKvRowIdx) +
|
||||
pBuilder->nBoundBitmaps; // add
|
||||
|
@ -937,18 +802,16 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
pBuilder->offset = 0;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
||||
pBuilder->pBuf = (STSRow *)pBuf;
|
||||
if (!pBuilder->pBuf) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
ASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0);
|
||||
|
@ -966,10 +829,9 @@ int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
#endif
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void tdSRowReset(SRowBuilder *pBuilder) {
|
||||
|
@ -985,8 +847,7 @@ int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) {
|
|||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
|
@ -995,7 +856,7 @@ int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) {
|
|||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen) {
|
||||
|
@ -1003,8 +864,7 @@ int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols,
|
|||
pBuilder->nCols = nCols;
|
||||
pBuilder->nBoundCols = nBoundCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
|
@ -1018,24 +878,12 @@ int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols,
|
|||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode) {
|
||||
TDRowValT valType = 0;
|
||||
tdGetBitmapValType(pBitmap, idx, &valType, bitmapMode);
|
||||
if (tdValTypeIsNorm(valType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||
|
@ -1060,10 +908,9 @@ int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
|||
// *pDestByte |= (valType);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int8_t bitmapMode) {
|
||||
|
@ -1078,14 +925,11 @@ int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int
|
|||
break;
|
||||
#endif
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColVal) {
|
||||
STColumn *pTColumn = &pTSchema->columns[iCol];
|
||||
SCellVal cv = {0};
|
||||
|
@ -1093,9 +937,9 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
|
|||
ASSERT((pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) || (iCol > 0));
|
||||
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv);
|
||||
(void)tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv);
|
||||
(void)tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -1113,7 +957,7 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
|
|||
pColVal->value.nData = varDataLen(cv.val);
|
||||
pColVal->value.pData = varDataVal(cv.val);
|
||||
} else {
|
||||
memcpy(&pColVal->value.val, cv.val, tDataTypes[pTColumn->type].bytes);
|
||||
(void)memcpy(&pColVal->value.val, cv.val, tDataTypes[pTColumn->type].bytes);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -109,13 +109,6 @@ static int32_t dmCheckDiskSpace() {
|
|||
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() {
|
||||
SDnode *pDnode = dmInstance();
|
||||
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
||||
|
@ -127,10 +120,10 @@ int32_t dmDiskInit() {
|
|||
numOfDisks = 1;
|
||||
}
|
||||
|
||||
int32_t code = tfsOpenWrapper(pDisks, numOfDisks, &pDnode->pTfs);
|
||||
int32_t code = tfsOpen(pDisks, numOfDisks, &pDnode->pTfs);
|
||||
if (code != 0) {
|
||||
dError("failed to init tfs since %s", tstrerror(code));
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,8 @@ int32_t dmInitVars(SDnode *pDnode) {
|
|||
pData->rebootTime = taosGetTimestampMs();
|
||||
pData->dropped = 0;
|
||||
pData->stopped = 0;
|
||||
char *machineId = tGetMachineId();
|
||||
char *machineId = NULL;
|
||||
code = tGetMachineId(&machineId);
|
||||
if (machineId) {
|
||||
tstrncpy(pData->machineId, machineId, TSDB_MACHINE_ID_LEN + 1);
|
||||
taosMemoryFreeClear(machineId);
|
||||
|
@ -181,7 +182,7 @@ int32_t dmInitVars(SDnode *pDnode) {
|
|||
code = 0;
|
||||
strncpy(tsEncryptKey, tsAuthCode, 16);
|
||||
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
if(code == -1){
|
||||
terrno = TSDB_CODE_DNODE_NO_ENCRYPT_KEY;
|
||||
dError("machine code changed, can't get crypt key");
|
||||
|
|
|
@ -380,6 +380,7 @@ _OVER:
|
|||
int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
|
||||
#ifdef TD_ENTERPRISE
|
||||
int32_t code = -1;
|
||||
int32_t lino = 0;
|
||||
char *machineId = NULL;
|
||||
char *encryptCode = NULL;
|
||||
|
||||
|
@ -428,14 +429,9 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!(machineId = tGetMachineId())) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tGetMachineId(&machineId), &lino, _OVER);
|
||||
|
||||
if ((code = generateEncryptCode(key, machineId, &encryptCode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(generateEncryptCode(key, machineId, &encryptCode), &lino, _OVER);
|
||||
|
||||
if ((code = dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile)) != 0) {
|
||||
goto _OVER;
|
||||
|
@ -452,9 +448,9 @@ _OVER:
|
|||
taosMemoryFree(encryptCode);
|
||||
taosMemoryFree(machineId);
|
||||
if (code != 0) {
|
||||
encryptError("failed to update encrypt key since %s", tstrerror(code));
|
||||
encryptError("failed to update encrypt key at line %d since %s", lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -539,8 +535,7 @@ int32_t dmGetEncryptKey() {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!(machineId = tGetMachineId())) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if ((code = tGetMachineId(&machineId)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -574,7 +569,7 @@ _OVER:
|
|||
if (code != 0) {
|
||||
dError("failed to get encrypt key since %s", tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
|
|
@ -30,7 +30,7 @@ SEpSet mndGetDnodeEpset(SDnodeObj *pDnode);
|
|||
SEpSet mndGetDnodeEpsetById(SMnode *pMnode, int32_t dnodeId);
|
||||
int32_t mndGetDnodeSize(SMnode *pMnode);
|
||||
bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs);
|
||||
void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo);
|
||||
int32_t mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define COL_DATA_SET_VAL_RET(pData, isNull, pObj) \
|
||||
#define COL_DATA_SET_VAL_GOTO(pData, isNull, pObj, LABEL) \
|
||||
do { \
|
||||
if ((code = colDataSetVal(pColInfo, numOfRows, (pData), (isNull))) != 0) { \
|
||||
if (pObj) sdbRelease(pSdb, (pObj)); \
|
||||
return code; \
|
||||
lino = __LINE__; \
|
||||
goto LABEL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
|
|
@ -27,29 +27,29 @@ enum {
|
|||
IP_WHITE_ADD,
|
||||
IP_WHITE_DROP,
|
||||
};
|
||||
int32_t mndInitUser(SMnode *pMnode);
|
||||
void mndCleanupUser(SMnode *pMnode);
|
||||
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName);
|
||||
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
||||
int32_t mndInitUser(SMnode *pMnode);
|
||||
void mndCleanupUser(SMnode *pMnode);
|
||||
int32_t mndAcquireUser(SMnode *pMnode, const char *userName, SUserObj **ppUser);
|
||||
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
||||
|
||||
// for trans test
|
||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
SHashObj *mndDupDbHash(SHashObj *pOld);
|
||||
SHashObj *mndDupTableHash(SHashObj *pOld);
|
||||
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||
int32_t *pRspLen, int64_t ipWhiteListVer);
|
||||
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||
int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb);
|
||||
int32_t mndUserRemoveView(SMnode *pMnode, STrans *pTrans, char *view);
|
||||
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic);
|
||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
int32_t mndDupDbHash(SHashObj *pOld, SHashObj **ppNew);
|
||||
int32_t mndDupTableHash(SHashObj *pOld, SHashObj **ppNew);
|
||||
int32_t mndDupTopicHash(SHashObj *pOld, SHashObj **ppNew);
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||
int32_t *pRspLen, int64_t ipWhiteListVer);
|
||||
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||
int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb);
|
||||
int32_t mndUserRemoveView(SMnode *pMnode, STrans *pTrans, char *view);
|
||||
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic);
|
||||
|
||||
int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew);
|
||||
void mndUserFreeObj(SUserObj *pUser);
|
||||
|
||||
int64_t mndGetIpWhiteVer(SMnode *pMnode);
|
||||
|
||||
void mndUpdateIpWhiteForAllUser(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock);
|
||||
int32_t mndUpdateIpWhiteForAllUser(SMnode *pMnode, char *user, char *fqdn, int8_t type, int8_t lock);
|
||||
|
||||
int32_t mndRefreshUserIpWhiteList(SMnode *pMnode);
|
||||
|
||||
|
|
|
@ -113,6 +113,8 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE);
|
||||
|
@ -153,6 +155,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SAcctObj *pAcct = NULL;
|
||||
SSdbRow *pRow = NULL;
|
||||
|
|
|
@ -114,6 +114,8 @@ void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) {
|
|||
}
|
||||
|
||||
SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SArbGroup) + ARBGROUP_RESERVE_SIZE;
|
||||
|
@ -152,6 +154,8 @@ _OVER:
|
|||
}
|
||||
|
||||
SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SArbGroup *pGroup = NULL;
|
||||
|
|
|
@ -144,6 +144,8 @@ int64_t mndGetClusterUpTime(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
|
||||
|
@ -172,6 +174,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SClusterObj *pCluster = NULL;
|
||||
SSdbRow *pRow = NULL;
|
||||
|
@ -287,6 +291,7 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *
|
|||
SMnode *pMnode = pMsg->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
SClusterObj *pCluster = NULL;
|
||||
|
@ -297,31 +302,32 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *
|
|||
|
||||
cols = 0;
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
COL_DATA_SET_VAL_RET((const char *)&pCluster->id, false, pCluster);
|
||||
COL_DATA_SET_VAL_GOTO((const char *)&pCluster->id, false, pCluster, _OVER);
|
||||
|
||||
char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->pMeta->pSchemas[cols].bytes);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
COL_DATA_SET_VAL_RET(buf, false, pCluster);
|
||||
COL_DATA_SET_VAL_GOTO(buf, false, pCluster, _OVER);
|
||||
|
||||
int32_t upTime = mndGetClusterUpTimeImp(pCluster);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
COL_DATA_SET_VAL_RET((const char *)&upTime, false, pCluster);
|
||||
COL_DATA_SET_VAL_GOTO((const char *)&upTime, false, pCluster, _OVER);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
COL_DATA_SET_VAL_RET((const char *)&pCluster->createdTime, false, pCluster);
|
||||
COL_DATA_SET_VAL_GOTO((const char *)&pCluster->createdTime, false, pCluster, _OVER);
|
||||
|
||||
|
||||
char ver[12] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
COL_DATA_SET_VAL_RET((const char *)ver, false, pCluster);
|
||||
COL_DATA_SET_VAL_GOTO((const char *)ver, false, pCluster, _OVER);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
if (tsExpireTime <= 0) {
|
||||
colDataSetNULL(pColInfo, numOfRows);
|
||||
} else {
|
||||
COL_DATA_SET_VAL_RET((const char *)&tsExpireTime, false, pCluster);
|
||||
COL_DATA_SET_VAL_GOTO((const char *)&tsExpireTime, false, pCluster, _OVER);
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pCluster);
|
||||
|
@ -329,6 +335,12 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *
|
|||
}
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
mError("failed to retrieve cluster info at line %d since %s", lino, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) {
|
|||
}
|
||||
|
||||
SSdbRaw *mndCompactActionEncode(SCompactObj *pCompact) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
void *buf = NULL;
|
||||
|
@ -136,6 +138,8 @@ OVER:
|
|||
}
|
||||
|
||||
SSdbRow *mndCompactActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSdbRow *pRow = NULL;
|
||||
SCompactObj *pCompact = NULL;
|
||||
void *buf = NULL;
|
||||
|
|
|
@ -144,6 +144,8 @@ int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailO
|
|||
}
|
||||
|
||||
SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
void *buf = NULL;
|
||||
|
@ -193,9 +195,11 @@ OVER:
|
|||
}
|
||||
|
||||
SSdbRow *mndCompactDetailActionDecode(SSdbRaw *pRaw) {
|
||||
SSdbRow *pRow = NULL;
|
||||
SCompactDetailObj *pCompact = NULL;
|
||||
void *buf = NULL;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSdbRow *pRow = NULL;
|
||||
SCompactDetailObj *pCompact = NULL;
|
||||
void *buf = NULL;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
int8_t sver = 0;
|
||||
|
|
|
@ -590,6 +590,8 @@ END:
|
|||
}
|
||||
|
||||
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
void *buf = NULL;
|
||||
|
@ -628,6 +630,8 @@ CM_ENCODE_OVER:
|
|||
}
|
||||
|
||||
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSdbRow *pRow = NULL;
|
||||
SMqConsumerObj *pConsumer = NULL;
|
||||
void *buf = NULL;
|
||||
|
|
|
@ -88,6 +88,8 @@ int32_t mndInitDb(SMnode *pMnode) {
|
|||
void mndCleanupDb(SMnode *pMnode) {}
|
||||
|
||||
SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SDbObj) + pDb->cfg.numOfRetensions * sizeof(SRetention) + DB_RESERVE_SIZE;
|
||||
|
@ -166,6 +168,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SDbObj *pDb = NULL;
|
||||
|
@ -731,8 +735,9 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
}
|
||||
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, SUserObj *pUser) {
|
||||
int32_t code = -1;
|
||||
SDbObj dbObj = {0};
|
||||
int32_t code = 0;
|
||||
SUserObj newUserObj = {0};
|
||||
SDbObj dbObj = {0};
|
||||
memcpy(dbObj.name, pCreate->db, TSDB_DB_FNAME_LEN);
|
||||
memcpy(dbObj.acct, pUser->acct, TSDB_USER_LEN);
|
||||
dbObj.createdTime = taosGetTimestampMs();
|
||||
|
@ -812,7 +817,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
}
|
||||
|
||||
// add database privileges for user
|
||||
SUserObj newUserObj = {0}, *pNewUserDuped = NULL;
|
||||
SUserObj *pNewUserDuped = NULL;
|
||||
if (!pUser->superUser) {
|
||||
TAOS_CHECK_GOTO(mndUserDupObj(pUser, &newUserObj), NULL, _OVER);
|
||||
taosHashPut(newUserObj.readDbs, dbObj.name, strlen(dbObj.name) + 1, dbObj.name, TSDB_FILENAME_LEN);
|
||||
|
@ -841,8 +846,6 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
TAOS_CHECK_GOTO(mndSetCreateDbUndoActions(pMnode, pTrans, &dbObj, pVgroups), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
taosMemoryFree(pVgroups);
|
||||
mndUserFreeObj(&newUserObj);
|
||||
|
@ -958,12 +961,7 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
|||
|
||||
TAOS_CHECK_GOTO(mndCheckDbEncryptKey(pMnode, &createReq), &lino, _OVER);
|
||||
|
||||
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
||||
if (pUser == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndAcquireUser(pMnode, pReq->info.conn.user, &pUser), &lino, _OVER);
|
||||
|
||||
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
@ -2441,9 +2439,10 @@ static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SDbObj *pDb = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
ESdbStatus objStatus = 0;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
||||
(void)mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
|
||||
if (pUser == NULL) return 0;
|
||||
bool sysinfo = pUser->sysInfo;
|
||||
|
||||
|
|
|
@ -153,7 +153,8 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
|
|||
tstrncpy(dnodeObj.fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
dnodeObj.fqdn[TSDB_FQDN_LEN - 1] = 0;
|
||||
snprintf(dnodeObj.ep, TSDB_EP_LEN - 1, "%s:%u", tsLocalFqdn, tsServerPort);
|
||||
char *machineId = tGetMachineId();
|
||||
char *machineId = NULL;
|
||||
code = tGetMachineId(&machineId);
|
||||
if (machineId) {
|
||||
memcpy(dnodeObj.machineId, machineId, TSDB_MACHINE_ID_LEN);
|
||||
taosMemoryFreeClear(machineId);
|
||||
|
@ -184,7 +185,8 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
|
|||
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
code = 0;
|
||||
mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1);
|
||||
mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD,
|
||||
1); // TODO: check the return value
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -193,6 +195,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
|
||||
|
@ -224,6 +228,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SDnodeObj *pDnode = NULL;
|
||||
|
@ -426,8 +432,9 @@ static void mndGetDnodeEps(SMnode *pMnode, SArray *pDnodeEps) {
|
|||
}
|
||||
}
|
||||
|
||||
void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t numOfEps = 0;
|
||||
void *pIter = NULL;
|
||||
|
@ -449,8 +456,13 @@ void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) {
|
|||
dInfo.isMnode = 0;
|
||||
}
|
||||
|
||||
taosArrayPush(pDnodeInfo, &dInfo);
|
||||
if(taosArrayPush(pDnodeInfo, &dInfo) == NULL){
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
#define CHECK_MONITOR_PARA(para,err) \
|
||||
|
@ -902,7 +914,7 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC
|
|||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
code = 0;
|
||||
|
||||
mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1);
|
||||
mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1); // TODO: check the return value
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
sdbFreeRaw(pRaw);
|
||||
|
@ -1190,7 +1202,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM
|
|||
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP, 1);
|
||||
mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP, 1); // TODO: check the return value
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
|
|
@ -61,6 +61,8 @@ int32_t mndInitFunc(SMnode *pMnode) {
|
|||
void mndCleanupFunc(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj) + SDB_FUNC_RESERVE_SIZE;
|
||||
|
@ -101,6 +103,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SFuncObj *pFunc = NULL;
|
||||
|
|
|
@ -25,12 +25,16 @@
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols); \
|
||||
src = (display); \
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tmp, src, 32); \
|
||||
colDataSetVal(pColInfo, numOfRows, tmp, false); \
|
||||
COL_DATA_SET_VAL_GOTO(tmp, false, NULL, _exit); \
|
||||
} while (0)
|
||||
|
||||
static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
char tmp[32];
|
||||
|
||||
if (pShow->numOfRows < 1) {
|
||||
|
@ -38,7 +42,7 @@ static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
|||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
const char *src = TD_PRODUCT_NAME;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tmp, src, 32);
|
||||
colDataSetVal(pColInfo, numOfRows, tmp, false);
|
||||
COL_DATA_SET_VAL_GOTO(tmp, false, NULL, _exit);
|
||||
|
||||
GRANT_ITEM_SHOW("unlimited");
|
||||
GRANT_ITEM_SHOW("limited");
|
||||
|
@ -52,6 +56,11 @@ static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
|||
}
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
mError("failed to retrieve grant at line %d since %s", lino, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
|
@ -78,7 +87,10 @@ void grantReset(SMnode *pMnode, EGrantType grant, uint64_t value) {}
|
|||
void grantAdd(EGrantType grant, uint64_t value) {}
|
||||
void grantRestore(EGrantType grant, uint64_t value) {}
|
||||
int64_t grantRemain(EGrantType grant) { return 0; }
|
||||
char *tGetMachineId() { return NULL; };
|
||||
int32_t tGetMachineId(char **result) {
|
||||
*result = NULL;
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
int32_t dmProcessGrantReq(void *pInfo, SRpcMsg *pMsg) { return TSDB_CODE_SUCCESS; }
|
||||
int32_t dmProcessGrantNotify(void *pInfo, SRpcMsg *pMsg) { return TSDB_CODE_SUCCESS; }
|
||||
int32_t mndProcessConfigGrantReq(SMnode *pMnode, SRpcMsg *pReq, SMCfgClusterReq *pCfg) { return 0; }
|
||||
|
|
|
@ -213,6 +213,8 @@ void mndCleanupIdx(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndIdxActionEncode(SIdxObj *pIdx) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
// int32_t size =
|
||||
|
@ -250,6 +252,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndIdxActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SIdxObj *pIdx = NULL;
|
||||
|
|
|
@ -127,6 +127,8 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, MNODE_VER_NUMBER, sizeof(SMnodeObj) + MNODE_RESERVE_SIZE);
|
||||
|
@ -154,6 +156,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SMnodeObj *pObj = NULL;
|
||||
|
|
|
@ -229,32 +229,29 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
SUserObj *pUser = NULL;
|
||||
SDbObj *pDb = NULL;
|
||||
SConnObj *pConn = NULL;
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
SConnectReq connReq = {0};
|
||||
char ip[24] = {0};
|
||||
const STraceId *trace = &pReq->info.traceId;
|
||||
|
||||
if ((code = tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq)) != 0) {
|
||||
terrno = (-1 == code ? TSDB_CODE_INVALID_MSG : code);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, version, 3)) != 0) {
|
||||
mGError("version not compatible. client version: %s, server version: %s", connReq.sVer, version);
|
||||
terrno = code;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = -1;
|
||||
taosIp2String(pReq->info.conn.clientIp, ip);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT) != 0) {
|
||||
mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, terrstr());
|
||||
if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT)) != 0) {
|
||||
mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
||||
code = mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
|
||||
if (pUser == NULL) {
|
||||
mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, terrstr());
|
||||
mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -271,22 +268,22 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
if (pDb == NULL) {
|
||||
if (0 != strcmp(connReq.db, TSDB_INFORMATION_SCHEMA_DB) &&
|
||||
(0 != strcmp(connReq.db, TSDB_PERFORMANCE_SCHEMA_DB))) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
code = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db,
|
||||
terrstr());
|
||||
tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb), NULL, _OVER);
|
||||
}
|
||||
|
||||
pConn = mndCreateConn(pMnode, pReq->info.conn.user, connReq.connType, pReq->info.conn.clientIp,
|
||||
pReq->info.conn.clientPort, connReq.pid, connReq.app, connReq.startTime);
|
||||
if (pConn == NULL) {
|
||||
mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip, terrstr());
|
||||
code = terrno;
|
||||
mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip,
|
||||
tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -316,10 +313,19 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
mndGetMnodeEpSet(pMnode, &connectRsp.epSet);
|
||||
|
||||
int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp);
|
||||
if (contLen < 0) goto _OVER;
|
||||
if (contLen < 0) {
|
||||
TAOS_CHECK_GOTO(contLen, NULL, _OVER);
|
||||
}
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
if (pRsp == NULL) goto _OVER;
|
||||
tSerializeSConnectRsp(pRsp, contLen, &connectRsp);
|
||||
if (pRsp == NULL) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||
}
|
||||
|
||||
contLen = tSerializeSConnectRsp(pRsp, contLen, &connectRsp);
|
||||
if (contLen < 0) {
|
||||
rpcFreeCont(pRsp);
|
||||
TAOS_CHECK_GOTO(contLen, NULL, _OVER);
|
||||
}
|
||||
|
||||
pReq->info.rspLen = contLen;
|
||||
pReq->info.rsp = pRsp;
|
||||
|
@ -339,7 +345,7 @@ _OVER:
|
|||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseConn(pMnode, pConn, true);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSaveQueryList(SConnObj *pConn, SQueryHbReqBasic *pBasic) {
|
||||
|
@ -656,6 +662,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
|
||||
static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
||||
SClientHbBatchReq batchReq = {0};
|
||||
|
@ -675,6 +682,9 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
|||
SClientHbBatchRsp batchRsp = {0};
|
||||
batchRsp.svrTimestamp = taosGetTimestampSec();
|
||||
batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp));
|
||||
if (batchRsp.rsps == NULL) {
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
batchRsp.monitorParas.tsEnableMonitor = tsEnableMonitor;
|
||||
batchRsp.monitorParas.tsMonitorInterval = tsMonitorInterval;
|
||||
batchRsp.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold;
|
||||
|
@ -687,7 +697,7 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
|||
for (int i = 0; i < sz; i++) {
|
||||
SClientHbReq *pHbReq = taosArrayGet(batchReq.reqs, i);
|
||||
if (pHbReq->connKey.connType == CONN_TYPE__QUERY) {
|
||||
mndProcessQueryHeartBeat(pMnode, pReq, pHbReq, &batchRsp, &obj);
|
||||
TAOS_CHECK_EXIT(mndProcessQueryHeartBeat(pMnode, pReq, pHbReq, &batchRsp, &obj));
|
||||
} else if (pHbReq->connKey.connType == CONN_TYPE__TMQ) {
|
||||
SClientHbRsp *pRsp = mndMqHbBuildRsp(pMnode, pHbReq);
|
||||
if (pRsp != NULL) {
|
||||
|
@ -699,12 +709,22 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
|||
taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq);
|
||||
|
||||
int32_t tlen = tSerializeSClientHbBatchRsp(NULL, 0, &batchRsp);
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp);
|
||||
|
||||
tFreeClientHbBatchRsp(&batchRsp);
|
||||
if (tlen < 0) {
|
||||
TAOS_CHECK_EXIT(tlen);
|
||||
}
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
if (!buf) {
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
tlen = tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp);
|
||||
if (tlen < 0) {
|
||||
rpcFreeCont(buf);
|
||||
TAOS_CHECK_EXIT(tlen);
|
||||
}
|
||||
pReq->info.rspLen = tlen;
|
||||
pReq->info.rsp = buf;
|
||||
_exit:
|
||||
tFreeClientHbBatchRsp(&batchRsp);
|
||||
|
||||
taosArrayDestroy(obj.pQnodeList);
|
||||
|
||||
|
@ -771,24 +791,31 @@ static int32_t mndProcessKillConnReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessSvrVerReq(SRpcMsg *pReq) {
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SServerVerRsp rsp = {0};
|
||||
tstrncpy(rsp.ver, version, sizeof(rsp.ver));
|
||||
|
||||
int32_t contLen = tSerializeSServerVerRsp(NULL, 0, &rsp);
|
||||
if (contLen < 0) goto _over;
|
||||
if (contLen < 0) {
|
||||
TAOS_CHECK_EXIT(contLen);
|
||||
}
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
if (pRsp == NULL) goto _over;
|
||||
tSerializeSServerVerRsp(pRsp, contLen, &rsp);
|
||||
if (pRsp == NULL) {
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
contLen = tSerializeSServerVerRsp(pRsp, contLen, &rsp);
|
||||
if (contLen < 0) {
|
||||
rpcFreeCont(pRsp);
|
||||
TAOS_CHECK_EXIT(contLen);
|
||||
}
|
||||
|
||||
pReq->info.rspLen = contLen;
|
||||
pReq->info.rsp = pRsp;
|
||||
|
||||
code = 0;
|
||||
_exit:
|
||||
|
||||
_over:
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
|
|
@ -75,6 +75,8 @@ void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, QNODE_VER_NUMBER, sizeof(SQnodeObj) + QNODE_RESERVE_SIZE);
|
||||
|
@ -100,6 +102,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SQnodeObj *pObj = NULL;
|
||||
|
|
|
@ -112,6 +112,8 @@ int32_t mndInitSma(SMnode *pMnode) {
|
|||
void mndCleanupSma(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size =
|
||||
|
@ -173,6 +175,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SSmaObj *pSma = NULL;
|
||||
|
@ -294,12 +298,7 @@ void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma) {
|
|||
sdbRelease(pSdb, pSma);
|
||||
}
|
||||
|
||||
SDbObj *mndAcquireDbBySma(SMnode *pMnode, const char *smaName) {
|
||||
SName name = {0};
|
||||
tNameFromString(&name, smaName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
char db[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, db);
|
||||
SDbObj *mndAcquireDbBySma(SMnode *pMnode, const char *db) {
|
||||
|
||||
return mndAcquireDb(pMnode, db);
|
||||
}
|
||||
|
@ -308,7 +307,10 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
|
|||
SEncoder encoder = {0};
|
||||
int32_t contLen = 0;
|
||||
SName name = {0};
|
||||
tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
int32_t code = tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SVCreateTSmaReq req = {0};
|
||||
req.version = 0;
|
||||
|
@ -366,7 +368,7 @@ static void *mndBuildVDropSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma,
|
|||
SEncoder encoder = {0};
|
||||
int32_t contLen;
|
||||
SName name = {0};
|
||||
tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
(void)tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
SVDropTSmaReq req = {0};
|
||||
req.indexUid = pSma->uid;
|
||||
|
@ -778,10 +780,14 @@ static int32_t mndCheckCreateSmaReq(SMCreateSmaReq *pCreate) {
|
|||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void mndGetStreamNameFromSmaName(char *streamName, char *smaName) {
|
||||
static int32_t mndGetStreamNameFromSmaName(char *streamName, char *smaName) {
|
||||
SName n;
|
||||
tNameFromString(&n, smaName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
int32_t code = tNameFromString(&n, smaName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
sprintf(streamName, "%d.%s", n.acctId, n.tname);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) {
|
||||
|
@ -813,7 +819,10 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
char streamName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
mndGetStreamNameFromSmaName(streamName, createReq.name);
|
||||
code = mndGetStreamNameFromSmaName(streamName, createReq.name);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndAcquireStream(pMnode, streamName, &pStream);
|
||||
if (pStream != NULL || code == 0) {
|
||||
|
@ -839,7 +848,15 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) {
|
|||
}
|
||||
}
|
||||
|
||||
pDb = mndAcquireDbBySma(pMnode, createReq.name);
|
||||
SName name = {0};
|
||||
code = tNameFromString(&name, createReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
char db[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
(void)tNameGetFullDbName(&name, db);
|
||||
|
||||
pDb = mndAcquireDb(pMnode, db);
|
||||
if (pDb == NULL) {
|
||||
code = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
goto _OVER;
|
||||
|
@ -960,6 +977,7 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
|
|||
SVgObj *pVgroup = NULL;
|
||||
SStbObj *pStb = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
SStreamObj *pStream = NULL;
|
||||
|
||||
pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
||||
if (pVgroup == NULL) {
|
||||
|
@ -989,9 +1007,11 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
|
|||
mndTransSetSerial(pTrans);
|
||||
|
||||
char streamName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
mndGetStreamNameFromSmaName(streamName, pSma->name);
|
||||
code = mndGetStreamNameFromSmaName(streamName, pSma->name);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SStreamObj *pStream = NULL;
|
||||
|
||||
code = mndAcquireStream(pMnode, streamName, &pStream);
|
||||
if (pStream == NULL || pStream->smaId != pSma->uid || code != 0) {
|
||||
|
@ -1050,7 +1070,10 @@ int32_t mndDropSmasByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p
|
|||
}
|
||||
|
||||
char streamName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
mndGetStreamNameFromSmaName(streamName, pSma->name);
|
||||
code = mndGetStreamNameFromSmaName(streamName, pSma->name);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SStreamObj *pStream = NULL;
|
||||
code = mndAcquireStream(pMnode, streamName, &pStream);
|
||||
|
@ -1140,7 +1163,15 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) {
|
|||
}
|
||||
}
|
||||
|
||||
pDb = mndAcquireDbBySma(pMnode, dropReq.name);
|
||||
SName name = {0};
|
||||
code = tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
char db[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
(void)tNameGetFullDbName(&name, db);
|
||||
|
||||
pDb = mndAcquireDb(pMnode, db);
|
||||
if (pDb == NULL) {
|
||||
code = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
goto _OVER;
|
||||
|
@ -1299,7 +1330,11 @@ static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
tSerializeSUserIndexRsp(pRsp, contLen, &rsp);
|
||||
contLen = tSerializeSUserIndexRsp(pRsp, contLen, &rsp);
|
||||
if (contLen < 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pReq->info.rsp = pRsp;
|
||||
pReq->info.rspLen = contLen;
|
||||
|
@ -1345,7 +1380,11 @@ static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
tSerializeSTableIndexRsp(pRsp, contLen, &rsp);
|
||||
contLen = tSerializeSTableIndexRsp(pRsp, contLen, &rsp);
|
||||
if (contLen < 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pReq->info.rsp = pRsp;
|
||||
pReq->info.rspLen = contLen;
|
||||
|
@ -1368,6 +1407,7 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
|
|||
int32_t numOfRows = 0;
|
||||
SSmaObj *pSma = NULL;
|
||||
int32_t cols = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
SDbObj *pDb = NULL;
|
||||
if (strlen(pShow->db) > 0) {
|
||||
|
@ -1387,47 +1427,63 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
|
|||
cols = 0;
|
||||
|
||||
SName smaName = {0};
|
||||
tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
char n1[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(n1, (char *)tNameGetTableName(&smaName));
|
||||
|
||||
char n2[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(n2, (char *)mndGetDbStr(pSma->db));
|
||||
|
||||
SName stbName = {0};
|
||||
tNameFromString(&stbName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
char n2[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char n3[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(n3, (char *)tNameGetTableName(&stbName));
|
||||
code = tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
char n1[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
STR_TO_VARSTR(n1, (char *)tNameGetTableName(&smaName));
|
||||
STR_TO_VARSTR(n2, (char *)mndGetDbStr(pSma->db));
|
||||
code = tNameFromString(&stbName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
}
|
||||
SColumnInfoData* pColInfo = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
STR_TO_VARSTR(n3, (char *)tNameGetTableName(&stbName));
|
||||
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)n1, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)n2, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)n3, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pSma->dstVgId, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pSma->createdTime, false);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)n1, false);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)n2, false);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)n3, false);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pSma->dstVgId, false);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pSma->createdTime, false);
|
||||
}
|
||||
|
||||
char col[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(col, (char *)"");
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)col, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)col, false);
|
||||
}
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
|
||||
char tag[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(tag, (char *)"sma_index");
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)tag, false);
|
||||
char tag[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(tag, (char *)"sma_index");
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)tag, false);
|
||||
}
|
||||
|
||||
numOfRows++;
|
||||
sdbRelease(pSdb, pSma);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
sdbCancelFetch(pMnode->pSdb, pIter->pSmaIter);
|
||||
numOfRows = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
@ -1516,7 +1572,7 @@ static void initStreamObj(SStreamObj *pStream, const char *streamName, const SMC
|
|||
pStream->ast = taosStrdup(pSma->ast);
|
||||
}
|
||||
|
||||
static void mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
|
||||
static int32_t mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
|
||||
tstrncpy(pCxt->pCreateStreamReq->name, pCxt->streamName, TSDB_STREAM_FNAME_LEN);
|
||||
tstrncpy(pCxt->pCreateStreamReq->sourceDB, pCxt->pDb->name, TSDB_DB_FNAME_LEN);
|
||||
tstrncpy(pCxt->pCreateStreamReq->targetStbFullName, pCxt->targetStbFullName, TSDB_TABLE_FNAME_LEN);
|
||||
|
@ -1536,11 +1592,21 @@ static void mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
|
|||
pCxt->pCreateStreamReq->lastTs = pCxt->pCreateSmaReq->lastTs;
|
||||
pCxt->pCreateStreamReq->smaId = pCxt->pSma->uid;
|
||||
pCxt->pCreateStreamReq->ast = taosStrdup(pCxt->pCreateSmaReq->ast);
|
||||
if (!pCxt->pCreateStreamReq->ast) {
|
||||
return terrno;
|
||||
}
|
||||
pCxt->pCreateStreamReq->sql = taosStrdup(pCxt->pCreateSmaReq->sql);
|
||||
if (!pCxt->pCreateStreamReq->sql) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
// construct tags
|
||||
pCxt->pCreateStreamReq->pTags = taosArrayInit(pCxt->pCreateStreamReq->numOfTags, sizeof(SField));
|
||||
if (!pCxt->pCreateStreamReq->pTags) {
|
||||
return terrno;
|
||||
}
|
||||
SField f = {0};
|
||||
int32_t code = 0;
|
||||
if (pCxt->pSrcStb) {
|
||||
for (int32_t idx = 0; idx < pCxt->pCreateStreamReq->numOfTags - 1; ++idx) {
|
||||
SSchema *pSchema = &pCxt->pSrcStb->pTags[idx];
|
||||
|
@ -1548,25 +1614,39 @@ static void mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
|
|||
f.type = pSchema->type;
|
||||
f.flags = pSchema->flags;
|
||||
tstrncpy(f.name, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
taosArrayPush(pCxt->pCreateStreamReq->pTags, &f);
|
||||
if (NULL == taosArrayPush(pCxt->pCreateStreamReq->pTags, &f)) {
|
||||
code = terrno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
f.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE;
|
||||
f.flags = COL_SMA_ON;
|
||||
f.type = TSDB_DATA_TYPE_BINARY;
|
||||
tstrncpy(f.name, "tbname", strlen("tbname") + 1);
|
||||
taosArrayPush(pCxt->pCreateStreamReq->pTags, &f);
|
||||
|
||||
// construct output cols
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pCxt->pProjects) {
|
||||
SExprNode* pExprNode = (SExprNode*)pNode;
|
||||
f.bytes = pExprNode->resType.bytes;
|
||||
f.type = pExprNode->resType.type;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
f.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE;
|
||||
f.flags = COL_SMA_ON;
|
||||
strcpy(f.name, pExprNode->userAlias);
|
||||
taosArrayPush(pCxt->pCreateStreamReq->pCols, &f);
|
||||
f.type = TSDB_DATA_TYPE_BINARY;
|
||||
tstrncpy(f.name, "tbname", strlen("tbname") + 1);
|
||||
if (NULL == taosArrayPush(pCxt->pCreateStreamReq->pTags, &f)) {
|
||||
code = terrno;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// construct output cols
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pCxt->pProjects) {
|
||||
SExprNode* pExprNode = (SExprNode*)pNode;
|
||||
f.bytes = pExprNode->resType.bytes;
|
||||
f.type = pExprNode->resType.type;
|
||||
f.flags = COL_SMA_ON;
|
||||
strcpy(f.name, pExprNode->userAlias);
|
||||
if (NULL == taosArrayPush(pCxt->pCreateStreamReq->pCols, &f)) {
|
||||
code = terrno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mndCreateTSMABuildDropStreamReq(SCreateTSMACxt* pCxt) {
|
||||
|
@ -1729,7 +1809,10 @@ static int32_t mndCreateTSMA(SCreateTSMACxt *pCxt) {
|
|||
}
|
||||
}
|
||||
pCxt->pDropStreamReq = &dropStreamReq;
|
||||
mndCreateTSMABuildCreateStreamReq(pCxt);
|
||||
code = mndCreateTSMABuildCreateStreamReq(pCxt);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
mndCreateTSMABuildDropStreamReq(pCxt);
|
||||
|
||||
if (TSDB_CODE_SUCCESS != (code = mndCreateTSMATxnPrepare(pCxt))) {
|
||||
|
@ -1749,11 +1832,15 @@ _OVER:
|
|||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void mndTSMAGenerateOutputName(const char* tsmaName, char* streamName, char* targetStbName) {
|
||||
static int32_t mndTSMAGenerateOutputName(const char* tsmaName, char* streamName, char* targetStbName) {
|
||||
SName smaName;
|
||||
tNameFromString(&smaName, tsmaName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
int32_t code = tNameFromString(&smaName, tsmaName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname);
|
||||
snprintf(targetStbName, TSDB_TABLE_FNAME_LEN, "%s"TSMA_RES_STB_POSTFIX, tsmaName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) {
|
||||
|
@ -1795,7 +1882,11 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) {
|
|||
|
||||
char streamName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
char streamTargetStbFullName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
mndTSMAGenerateOutputName(createReq.name, streamName, streamTargetStbFullName);
|
||||
code = mndTSMAGenerateOutputName(createReq.name, streamName, streamTargetStbFullName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
mInfo("tsma:%s, faield to generate name", createReq.name);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pSma = sdbAcquire(pMnode->pSdb, SDB_SMA, createReq.name);
|
||||
if (pSma && createReq.igExists) {
|
||||
|
@ -1824,7 +1915,15 @@ static int32_t mndProcessCreateTSMAReq(SRpcMsg* pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
pDb = mndAcquireDbBySma(pMnode, createReq.name);
|
||||
SName name = {0};
|
||||
code = tNameFromString(&name, createReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
char db[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
(void)tNameGetFullDbName(&name, db);
|
||||
|
||||
pDb = mndAcquireDb(pMnode, db);
|
||||
if (pDb == NULL) {
|
||||
code = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
goto _OVER;
|
||||
|
@ -1974,7 +2073,10 @@ static int32_t mndProcessDropTSMAReq(SRpcMsg* pReq) {
|
|||
|
||||
char streamName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
char streamTargetStbFullName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
mndTSMAGenerateOutputName(dropReq.name, streamName, streamTargetStbFullName);
|
||||
code = mndTSMAGenerateOutputName(dropReq.name, streamName, streamTargetStbFullName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SStbObj* pStb = mndAcquireStb(pMnode, streamTargetStbFullName);
|
||||
|
||||
|
@ -1987,7 +2089,15 @@ static int32_t mndProcessDropTSMAReq(SRpcMsg* pReq) {
|
|||
code = TSDB_CODE_MND_SMA_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
pDb = mndAcquireDbBySma(pMnode, dropReq.name);
|
||||
SName name = {0};
|
||||
code = tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _OVER;
|
||||
}
|
||||
char db[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
(void)tNameGetFullDbName(&name, db);
|
||||
|
||||
pDb = mndAcquireDb(pMnode, db);
|
||||
if (!pDb) {
|
||||
code = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto _OVER;
|
||||
|
@ -2028,6 +2138,7 @@ static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
|
|||
int32_t numOfRows = 0;
|
||||
SSmaObj * pSma = NULL;
|
||||
SMnode * pMnode = pReq->info.node;
|
||||
int32_t code = 0;
|
||||
SColumnInfoData *pColInfo;
|
||||
if (pShow->db[0]) {
|
||||
pDb = mndAcquireDb(pMnode, pShow->db);
|
||||
|
@ -2050,65 +2161,90 @@ static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
|
|||
int32_t cols = 0;
|
||||
SName n = {0};
|
||||
|
||||
tNameFromString(&n, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
code = tNameFromString(&n, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
char smaName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(smaName, (char *)tNameGetTableName(&n));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)smaName, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
STR_TO_VARSTR(smaName, (char *)tNameGetTableName(&n));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char *)smaName, false);
|
||||
}
|
||||
|
||||
char db[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(db, (char *)mndGetDbStr(pSma->db));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char*)db, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
STR_TO_VARSTR(db, (char *)mndGetDbStr(pSma->db));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char*)db, false);
|
||||
}
|
||||
|
||||
tNameFromString(&n, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tNameFromString(&n, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
}
|
||||
char srcTb[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(srcTb, (char *)tNameGetTableName(&n));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char*)srcTb, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
STR_TO_VARSTR(srcTb, (char *)tNameGetTableName(&n));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char*)srcTb, false);
|
||||
}
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char*)db, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char*)db, false);
|
||||
}
|
||||
|
||||
tNameFromString(&n, pSma->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
char targetTb[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(targetTb, (char*)tNameGetTableName(&n));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char*)targetTb, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tNameFromString(&n, pSma->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
}
|
||||
|
||||
// stream name
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char*)smaName, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
char targetTb[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(targetTb, (char*)tNameGetTableName(&n));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char*)targetTb, false);
|
||||
}
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char*)(&pSma->createdTime), false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// stream name
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char*)smaName, false);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, (const char*)(&pSma->createdTime), false);
|
||||
}
|
||||
|
||||
// interval
|
||||
char interval[64 + VARSTR_HEADER_SIZE] = {0};
|
||||
int32_t len = 0;
|
||||
if (!IS_CALENDAR_TIME_DURATION(pSma->intervalUnit)) {
|
||||
len = snprintf(interval + VARSTR_HEADER_SIZE, 64, "%" PRId64 "%c", pSma->interval,
|
||||
getPrecisionUnit(pSrcDb->cfg.precision));
|
||||
} else {
|
||||
len = snprintf(interval + VARSTR_HEADER_SIZE, 64, "%" PRId64 "%c", pSma->interval, pSma->intervalUnit);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (!IS_CALENDAR_TIME_DURATION(pSma->intervalUnit)) {
|
||||
len = snprintf(interval + VARSTR_HEADER_SIZE, 64, "%" PRId64 "%c", pSma->interval,
|
||||
getPrecisionUnit(pSrcDb->cfg.precision));
|
||||
} else {
|
||||
len = snprintf(interval + VARSTR_HEADER_SIZE, 64, "%" PRId64 "%c", pSma->interval, pSma->intervalUnit);
|
||||
}
|
||||
varDataSetLen(interval, len);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, interval, false);
|
||||
}
|
||||
varDataSetLen(interval, len);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, interval, false);
|
||||
|
||||
// create sql
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
char buf[TSDB_MAX_SAVED_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
len = snprintf(buf + VARSTR_HEADER_SIZE, TSDB_MAX_SAVED_SQL_LEN, "%s", pSma->sql);
|
||||
varDataSetLen(buf, TMIN(len, TSDB_MAX_SAVED_SQL_LEN));
|
||||
colDataSetVal(pColInfo, numOfRows, buf, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// create sql
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
len = snprintf(buf + VARSTR_HEADER_SIZE, TSDB_MAX_SAVED_SQL_LEN, "%s", pSma->sql);
|
||||
varDataSetLen(buf, TMIN(len, TSDB_MAX_SAVED_SQL_LEN));
|
||||
code = colDataSetVal(pColInfo, numOfRows, buf, false);
|
||||
}
|
||||
|
||||
// func list
|
||||
len = 0;
|
||||
char * start = buf + VARSTR_HEADER_SIZE;
|
||||
SNode *pNode = NULL, *pFunc = NULL;
|
||||
nodesStringToNode(pSma->ast, &pNode);
|
||||
if (pNode) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesStringToNode(pSma->ast, &pNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
char * start = buf + VARSTR_HEADER_SIZE;
|
||||
FOREACH(pFunc, ((SSelectStmt *)pNode)->pProjectionList) {
|
||||
if (nodeType(pFunc) == QUERY_NODE_FUNCTION) {
|
||||
SFunctionNode *pFuncNode = (SFunctionNode *)pFunc;
|
||||
|
@ -2124,13 +2260,21 @@ static int32_t mndRetrieveTSMA(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
|
|||
}
|
||||
nodesDestroyNode(pNode);
|
||||
}
|
||||
varDataSetLen(buf, len);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, buf, false);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
varDataSetLen(buf, len);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
code = colDataSetVal(pColInfo, numOfRows, buf, false);
|
||||
}
|
||||
|
||||
numOfRows++;
|
||||
mndReleaseSma(pMnode, pSma);
|
||||
mndReleaseDb(pMnode, pSrcDb);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
sdbCancelFetch(pMnode->pSdb, pIter->pSmaIter);
|
||||
numOfRows = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
pShow->numOfRows += numOfRows;
|
||||
|
@ -2159,13 +2303,22 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa
|
|||
pInfo->tsmaId = pSma->uid;
|
||||
pInfo->destTbUid = pDestStb->uid;
|
||||
SName sName = {0};
|
||||
tNameFromString(&sName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
code = tNameFromString(&sName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
tstrncpy(pInfo->name, sName.tname, TSDB_TABLE_NAME_LEN);
|
||||
tstrncpy(pInfo->targetDbFName, pSma->db, TSDB_DB_FNAME_LEN);
|
||||
tNameFromString(&sName, pSma->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
code = tNameFromString(&sName, pSma->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
tstrncpy(pInfo->targetTb, sName.tname, TSDB_TABLE_NAME_LEN);
|
||||
tstrncpy(pInfo->dbFName, pSma->db, TSDB_DB_FNAME_LEN);
|
||||
tNameFromString(&sName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
code = tNameFromString(&sName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
tstrncpy(pInfo->tb, sName.tname, TSDB_TABLE_NAME_LEN);
|
||||
pInfo->pFuncs = taosArrayInit(8, sizeof(STableTSMAFuncInfo));
|
||||
if (!pInfo->pFuncs) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -2202,7 +2355,10 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
for (int32_t i = 0; i < pDestStb->numOfTags; ++i) {
|
||||
taosArrayPush(pInfo->pTags, &pDestStb->pTags[i]);
|
||||
if (NULL == taosArrayPush(pInfo->pTags, &pDestStb->pTags[i])) {
|
||||
code = terrno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2213,7 +2369,10 @@ int32_t dumpTSMAInfoFromSmaObj(const SSmaObj* pSma, const SStbObj* pDestStb, STa
|
|||
else {
|
||||
// skip _wstart, _wend, _duration
|
||||
for (int32_t i = 1; i < pDestStb->numOfColumns - 2; ++i) {
|
||||
taosArrayPush(pInfo->pUsedCols, &pDestStb->pColumns[i]);
|
||||
if (NULL == taosArrayPush(pInfo->pUsedCols, &pDestStb->pColumns[i])) {
|
||||
code = terrno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2276,12 +2435,12 @@ static int32_t mndGetTSMA(SMnode *pMnode, char *tsmaFName, STableTSMAInfoRsp *rs
|
|||
sdbRelease(pMnode->pSdb, pSma);
|
||||
if (pBaseTsma) mndReleaseSma(pMnode, pBaseTsma);
|
||||
if (terrno) {
|
||||
tFreeTableTSMAInfo(pTsma);
|
||||
tFreeAndClearTableTSMAInfo(pTsma);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (NULL == taosArrayPush(rsp->pTsmas, &pTsma)) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tFreeTableTSMAInfo(pTsma);
|
||||
tFreeAndClearTableTSMAInfo(pTsma);
|
||||
}
|
||||
*exist = true;
|
||||
}
|
||||
|
@ -2316,7 +2475,11 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt
|
|||
|
||||
SName smaName;
|
||||
char streamName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
code = tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
sdbRelease(pSdb, pSma);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname);
|
||||
pStream = NULL;
|
||||
|
||||
|
@ -2347,13 +2510,13 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt
|
|||
sdbRelease(pSdb, pSma);
|
||||
if (pBaseTsma) mndReleaseSma(pMnode, pBaseTsma);
|
||||
if (terrno) {
|
||||
tFreeTableTSMAInfo(pTsma);
|
||||
tFreeAndClearTableTSMAInfo(pTsma);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (NULL == taosArrayPush(pRsp->pTsmas, &pTsma)) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tFreeTableTSMAInfo(pTsma);
|
||||
tFreeAndClearTableTSMAInfo(pTsma);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
@ -2414,7 +2577,11 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
tSerializeTableTSMAInfoRsp(pRsp, contLen, &rsp);
|
||||
int32_t len = tSerializeTableTSMAInfoRsp(pRsp, contLen, &rsp);
|
||||
if (len < 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pReq->info.rsp = pRsp;
|
||||
pReq->info.rspLen = contLen;
|
||||
|
@ -2430,7 +2597,7 @@ _OVER:
|
|||
static int32_t mkNonExistTSMAInfo(const STSMAVersion *pTsmaVer, STableTSMAInfo **ppTsma) {
|
||||
STableTSMAInfo *pInfo = taosMemoryCalloc(1, sizeof(STableTSMAInfo));
|
||||
if (!pInfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
pInfo->pFuncs = NULL;
|
||||
pInfo->tsmaId = pTsmaVer->tsmaId;
|
||||
|
@ -2439,6 +2606,10 @@ static int32_t mkNonExistTSMAInfo(const STSMAVersion *pTsmaVer, STableTSMAInfo *
|
|||
tstrncpy(pInfo->name, pTsmaVer->name, TSDB_TABLE_NAME_LEN);
|
||||
pInfo->dbId = pTsmaVer->dbId;
|
||||
pInfo->ast = taosMemoryCalloc(1, 1);
|
||||
if (!pInfo->ast) {
|
||||
taosMemoryFree(pInfo);
|
||||
return terrno;
|
||||
}
|
||||
*ppTsma = pInfo;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -2454,7 +2625,7 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t
|
|||
|
||||
hbRsp.pTsmas = taosArrayInit(numOfTsmas, POINTER_BYTES);
|
||||
if (!hbRsp.pTsmas) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
|
@ -2469,7 +2640,11 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t
|
|||
if (!pSma) {
|
||||
code = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo);
|
||||
if (code) goto _OVER;
|
||||
taosArrayPush(hbRsp.pTsmas, &pTsmaInfo);
|
||||
if (NULL == taosArrayPush(hbRsp.pTsmas, &pTsmaInfo)) {
|
||||
code = terrno;
|
||||
tFreeAndClearTableTSMAInfo(pTsmaInfo);
|
||||
goto _OVER;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2478,7 +2653,11 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t
|
|||
code = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo);
|
||||
mndReleaseSma(pMnode, pSma);
|
||||
if (code) goto _OVER;
|
||||
taosArrayPush(hbRsp.pTsmas, &pTsmaInfo);
|
||||
if (NULL == taosArrayPush(hbRsp.pTsmas, &pTsmaInfo)) {
|
||||
code = terrno;
|
||||
tFreeAndClearTableTSMAInfo(pTsmaInfo);
|
||||
goto _OVER;
|
||||
}
|
||||
continue;
|
||||
} else if (pSma->version == pTsmaVer->version) {
|
||||
mndReleaseSma(pMnode, pSma);
|
||||
|
@ -2491,7 +2670,11 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t
|
|||
code = mkNonExistTSMAInfo(pTsmaVer, &pTsmaInfo);
|
||||
mndReleaseSma(pMnode, pSma);
|
||||
if (code) goto _OVER;
|
||||
taosArrayPush(hbRsp.pTsmas, &pTsmaInfo);
|
||||
if (NULL == taosArrayPush(hbRsp.pTsmas, &pTsmaInfo)) {
|
||||
code = terrno;
|
||||
tFreeAndClearTableTSMAInfo(pTsmaInfo);
|
||||
goto _OVER;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2499,7 +2682,7 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t
|
|||
STableTSMAInfo * pInfo = NULL;
|
||||
pInfo = taosMemoryCalloc(1, sizeof(STableTSMAInfo));
|
||||
if (!pInfo) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
mndReleaseSma(pMnode, pSma);
|
||||
mndReleaseStb(pMnode, pDestStb);
|
||||
goto _OVER;
|
||||
|
@ -2513,27 +2696,35 @@ int32_t mndValidateTSMAInfo(SMnode *pMnode, STSMAVersion *pTsmaVersions, int32_t
|
|||
mndReleaseSma(pMnode, pSma);
|
||||
if (pBaseSma) mndReleaseSma(pMnode, pBaseSma);
|
||||
if (terrno) {
|
||||
tFreeTableTSMAInfo(pInfo);
|
||||
tFreeAndClearTableTSMAInfo(pInfo);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosArrayPush(hbRsp.pTsmas, pInfo);
|
||||
if (NULL == taosArrayPush(hbRsp.pTsmas, pInfo)) {
|
||||
code = terrno;
|
||||
tFreeAndClearTableTSMAInfo(pInfo);
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
rspLen = tSerializeTSMAHbRsp(NULL, 0, &hbRsp);
|
||||
if (rspLen < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pRsp = taosMemoryMalloc(rspLen);
|
||||
if (!pRsp) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
rspLen = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tSerializeTSMAHbRsp(pRsp, rspLen, &hbRsp);
|
||||
rspLen = tSerializeTSMAHbRsp(pRsp, rspLen, &hbRsp);
|
||||
if (rspLen < 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
code = 0;
|
||||
_OVER:
|
||||
tFreeTSMAHbRsp(&hbRsp);
|
||||
|
|
|
@ -79,6 +79,8 @@ void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, SNODE_VER_NUMBER, sizeof(SSnodeObj) + SNODE_RESERVE_SIZE);
|
||||
|
@ -104,6 +106,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SSnodeObj *pObj = NULL;
|
||||
|
|
|
@ -115,6 +115,8 @@ int32_t mndInitStb(SMnode *pMnode) {
|
|||
void mndCleanupStb(SMnode *pMnode) {}
|
||||
|
||||
SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + pStb->commentLen +
|
||||
|
@ -205,6 +207,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SStbObj *pStb = NULL;
|
||||
|
@ -2898,9 +2902,9 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) {
|
|||
int32_t code = -1;
|
||||
STableInfoReq infoReq = {0};
|
||||
STableMetaRsp metaRsp = {0};
|
||||
SUserObj *pUser = NULL;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
||||
//TODO why return 0 here
|
||||
code = mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
|
||||
if (pUser == NULL) return 0;
|
||||
bool sysinfo = pUser->sysInfo;
|
||||
|
||||
|
|
|
@ -164,6 +164,8 @@ void mndCleanupStream(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRow *pRow = NULL;
|
||||
|
|
|
@ -193,6 +193,8 @@ int32_t doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnCo
|
|||
}
|
||||
|
||||
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
void *buf = NULL;
|
||||
|
||||
|
|
|
@ -1099,6 +1099,8 @@ END:
|
|||
void mndCleanupSubscribe(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
void *buf = NULL;
|
||||
int32_t tlen = tEncodeSubscribeObj(NULL, pSub);
|
||||
|
@ -1137,6 +1139,8 @@ SUB_ENCODE_OVER:
|
|||
}
|
||||
|
||||
static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SMqSubscribeObj *pSub = NULL;
|
||||
|
|
|
@ -81,6 +81,8 @@ void mndTopicGetShowName(const char* fullTopic, char* topic) {
|
|||
}
|
||||
|
||||
SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
void *swBuf = NULL;
|
||||
|
@ -170,6 +172,8 @@ TOPIC_ENCODE_OVER:
|
|||
}
|
||||
|
||||
SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SMqTopicObj *pTopic = NULL;
|
||||
|
|
|
@ -105,6 +105,8 @@ static int32_t mndTransGetActionsSize(SArray *pArray) {
|
|||
}
|
||||
|
||||
static int32_t mndTransEncodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionsNum) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
int32_t dataPos = *offset;
|
||||
int8_t unused = 0;
|
||||
int32_t ret = -1;
|
||||
|
@ -142,6 +144,8 @@ _OVER:
|
|||
}
|
||||
|
||||
SSdbRaw *mndTransEncode(STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
|
||||
|
||||
|
@ -225,6 +229,8 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndTransDecodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionNum) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STransAction action = {0};
|
||||
int32_t dataPos = *offset;
|
||||
int8_t unused = 0;
|
||||
|
@ -279,7 +285,8 @@ _OVER:
|
|||
|
||||
SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSdbRow *pRow = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
char *pData = NULL;
|
||||
|
@ -541,8 +548,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
pOld->id, pOld, mndTransStr(pOld->stage), pOld->createdTime, pNew, mndTransStr(pNew->stage),
|
||||
pNew->createdTime);
|
||||
// only occured while sync timeout
|
||||
terrno = TSDB_CODE_MND_TRANS_SYNC_TIMEOUT;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT);
|
||||
}
|
||||
|
||||
mndTransUpdateActions(pOld->prepareActions, pNew->prepareActions);
|
||||
|
@ -660,8 +666,7 @@ static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) {
|
|||
|
||||
void *ptr = taosArrayPush(pArray, pAction);
|
||||
if (ptr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -772,26 +777,29 @@ void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
|
|||
void mndTransSetOper(STrans *pTrans, EOperType oper) { pTrans->oper = oper; }
|
||||
|
||||
static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRaw = mndTransEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("trans:%d, sync to other mnodes, stage:%s createTime:%" PRId64, pTrans->id, mndTransStr(pTrans->stage),
|
||||
pTrans->createdTime);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw, pTrans->id);
|
||||
code = mndSyncPropose(pMnode, pRaw, pTrans->id);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync, errno:%s code:0x%x createTime:%" PRId64 " saved trans:%d", pTrans->id, terrstr(),
|
||||
code, pTrans->createdTime, pMnode->syncMgmt.transId);
|
||||
mError("trans:%d, failed to sync, errno:%s code:0x%x createTime:%" PRId64 " saved trans:%d", pTrans->id,
|
||||
tstrerror(code), code, pTrans->createdTime, pMnode->syncMgmt.transId);
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
sdbFreeRaw(pRaw);
|
||||
mInfo("trans:%d, sync finished, createTime:%" PRId64, pTrans->id, pTrans->createdTime);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static bool mndCheckDbConflict(const char *conflict, STrans *pTrans) {
|
||||
|
@ -883,24 +891,26 @@ static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) {
|
|||
}
|
||||
|
||||
int32_t mndTransCheckConflict(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
|
||||
if (strlen(pTrans->dbname) == 0 && strlen(pTrans->stbname) == 0) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
code = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
mError("trans:%d, failed to prepare conflict db not set", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
if (mndCheckTransConflict(pMnode, pTrans)) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndTransCheckConflictWithCompact(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
void *pIter = NULL;
|
||||
bool conflict = false;
|
||||
SCompactObj *pCompact = NULL;
|
||||
|
@ -927,12 +937,12 @@ int32_t mndTransCheckConflictWithCompact(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
if (conflict) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT_COMPACT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_TRANS_CONFLICT_COMPACT;
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static bool mndTransActionsOfSameType(SArray *pActions) {
|
||||
|
@ -953,66 +963,65 @@ static bool mndTransActionsOfSameType(SArray *pActions) {
|
|||
}
|
||||
|
||||
static int32_t mndTransCheckParallelActions(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (pTrans->exec == TRN_EXEC_PARALLEL) {
|
||||
if (mndTransActionsOfSameType(pTrans->redoActions) == false) {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
mError("trans:%d, types of parallel redo actions are not the same", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
if (mndTransActionsOfSameType(pTrans->undoActions) == false) {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
mError("trans:%d, types of parallel undo actions are not the same", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransCheckCommitActions(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (!pTrans->changeless && taosArrayGetSize(pTrans->commitActions) <= 0) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CLOG_IS_NULL;
|
||||
code = TSDB_CODE_MND_TRANS_CLOG_IS_NULL;
|
||||
mError("trans:%d, commit actions of non-changeless trans are empty", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (mndTransActionsOfSameType(pTrans->commitActions) == false) {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
mError("trans:%d, types of commit actions are not the same", pTrans->id);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (pTrans == NULL) return -1;
|
||||
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
|
||||
|
||||
if (mndTransCheckParallelActions(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
|
||||
|
||||
if (mndTransCheckCommitActions(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransCheckCommitActions(pMnode, pTrans));
|
||||
|
||||
mInfo("trans:%d, prepare transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, prepare finished", pTrans->id);
|
||||
|
||||
STrans *pNew = mndAcquireTrans(pMnode, pTrans->id);
|
||||
if (pNew == NULL) {
|
||||
mError("trans:%d, failed to read from sdb since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mError("trans:%d, failed to read from sdb since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pNew->pRpcArray = pTrans->pRpcArray;
|
||||
|
@ -1025,37 +1034,41 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
|||
|
||||
mndTransExecute(pMnode, pNew);
|
||||
mndReleaseTrans(pMnode, pNew);
|
||||
// TDOD change to TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
mInfo("trans:%d, commit transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to commit since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to commit since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, commit finished", pTrans->id);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
mInfo("trans:%d, rollback transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to rollback since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to rollback since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, rollback finished", pTrans->id);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransPreFinish(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
mInfo("trans:%d, pre-finish transaction", pTrans->id);
|
||||
if (mndTransSync(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to pre-finish since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to pre-finish since %s", pTrans->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, pre-finish finished", pTrans->id);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
||||
|
@ -1161,6 +1174,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
int64_t signature = (int64_t)(pRsp->info.ahandle);
|
||||
int32_t transId = (int32_t)(signature >> 32);
|
||||
|
@ -1168,7 +1182,9 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
|||
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans == NULL) {
|
||||
mError("trans:%d, failed to get transId from vnode rsp since %s", transId, terrstr());
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mError("trans:%d, failed to get transId from vnode rsp since %s", transId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1209,7 +1225,7 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
|||
|
||||
_OVER:
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void mndTransResetAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
|
||||
|
@ -1245,8 +1261,7 @@ static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray)
|
|||
static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
|
||||
if (pAction->rawWritten) return 0;
|
||||
if (topHalf) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
return TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
|
||||
}
|
||||
|
||||
int32_t code = sdbWriteWithoutFree(pMnode->pSdb, pAction->pRaw);
|
||||
|
@ -1265,15 +1280,14 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
|
|||
mndSetTransLastAction(pTrans, pAction);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// execute at top half
|
||||
static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
|
||||
if (pAction->msgSent) return 0;
|
||||
if (mndCannotExecuteTransAction(pMnode, topHalf)) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
return TSDB_CODE_MND_TRANS_CTX_SWITCH;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
|
||||
}
|
||||
|
||||
int64_t signature = pTrans->id;
|
||||
|
@ -1317,7 +1331,7 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
|
|||
mndSetTransLastAction(pTrans, pAction);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndTransExecNullMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
|
||||
|
@ -1815,8 +1829,7 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
|||
} else if (pTrans->stage == TRN_STAGE_UNDO_ACTION) {
|
||||
pArray = pTrans->undoActions;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_TRANS_INVALID_STAGE;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
|
@ -1839,17 +1852,19 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq) {
|
|||
STrans *pTrans = NULL;
|
||||
|
||||
if (tDeserializeSKillTransReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, start to kill", killReq.transId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS) != 0) {
|
||||
if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pTrans = mndAcquireTrans(pMnode, killReq.transId);
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1861,7 +1876,7 @@ _OVER:
|
|||
}
|
||||
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndCompareTransId(int32_t *pTransId1, int32_t *pTransId2) { return *pTransId1 >= *pTransId2 ? 1 : 0; }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -89,6 +89,8 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
void mndCleanupVgroup(SMnode *pMnode) {}
|
||||
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, VGROUP_VER_NUMBER, sizeof(SVgObj) + VGROUP_RESERVE_SIZE);
|
||||
|
@ -127,6 +129,8 @@ _OVER:
|
|||
}
|
||||
|
||||
SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SSdbRow *pRow = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
|
|
|
@ -39,18 +39,20 @@ extern "C" {
|
|||
|
||||
#define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \
|
||||
{ \
|
||||
if (func(pRaw, dataPos, val) != 0) { \
|
||||
if ((code = func(pRaw, dataPos, val)) != 0) { \
|
||||
lino = __LINE__; \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += sizeof(type); \
|
||||
}
|
||||
|
||||
#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
{ \
|
||||
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
{ \
|
||||
if ((code = sdbGetRawBinary(pRaw, dataPos, val, valLen)) != 0) { \
|
||||
lino = __LINE__; \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t)
|
||||
|
@ -67,7 +69,8 @@ extern "C" {
|
|||
|
||||
#define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \
|
||||
{ \
|
||||
if (func(pRaw, dataPos, val) != 0) { \
|
||||
if ((code = func(pRaw, dataPos, val)) != 0) { \
|
||||
lino = __LINE__; \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += sizeof(type); \
|
||||
|
@ -79,12 +82,13 @@ extern "C" {
|
|||
#define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t)
|
||||
#define SDB_SET_UINT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawUInt8, uint8_t)
|
||||
|
||||
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
{ \
|
||||
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
{ \
|
||||
if ((code = sdbSetRawBinary(pRaw, dataPos, val, valLen)) != 0) { \
|
||||
lino = __LINE__; \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \
|
||||
|
@ -93,11 +97,12 @@ extern "C" {
|
|||
SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
}
|
||||
|
||||
#define SDB_SET_DATALEN(pRaw, dataLen, pos) \
|
||||
{ \
|
||||
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
|
||||
goto pos; \
|
||||
} \
|
||||
#define SDB_SET_DATALEN(pRaw, dataLen, pos) \
|
||||
{ \
|
||||
if ((code = sdbSetRawDataLen(pRaw, dataLen)) != 0) { \
|
||||
lino = __LINE__; \
|
||||
goto pos; \
|
||||
} \
|
||||
}
|
||||
|
||||
typedef struct SMnode SMnode;
|
||||
|
|
|
@ -136,15 +136,14 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
|
||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
||||
if (hash == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pSdb->maxId[sdbType] = 0;
|
||||
pSdb->hashObjs[sdbType] = hash;
|
||||
mInfo("sdb table:%s is initialized", sdbTableName(sdbType));
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t sdbCreateDir(SSdb *pSdb) {
|
||||
|
|
|
@ -48,27 +48,23 @@ void metaReaderClear(SMetaReader *pReader) {
|
|||
}
|
||||
|
||||
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
|
||||
int32_t code = 0;
|
||||
SMeta *pMeta = pReader->pMeta;
|
||||
STbDbKey tbDbKey = {.version = version, .uid = uid};
|
||||
|
||||
// query table.db
|
||||
if (tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
goto _err;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
// decode the entry
|
||||
tDecoderInit(&pReader->coder, pReader->pBuf, pReader->szBuf);
|
||||
|
||||
if (metaDecodeEntry(&pReader->coder, &pReader->me) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
code = metaDecodeEntry(&pReader->coder, &pReader->me);
|
||||
if (code) return code;
|
||||
// taosMemoryFreeClear(pReader->me.colCmpr.pColCmpr);
|
||||
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool metaIsTableExist(void *pVnode, tb_uid_t uid) {
|
||||
|
@ -90,8 +86,7 @@ int metaReaderGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
|
|||
|
||||
// query uid.idx
|
||||
if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
version1 = ((SUidIdxVal *)pReader->pBuf)[0].version;
|
||||
|
@ -103,8 +98,7 @@ int metaReaderGetTableEntryByUidCache(SMetaReader *pReader, tb_uid_t uid) {
|
|||
|
||||
SMetaInfo info;
|
||||
if (metaGetInfo(pMeta, uid, &info, pReader) == TSDB_CODE_NOT_FOUND) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
return metaGetTableEntryByVersion(pReader, info.version, uid);
|
||||
|
@ -116,8 +110,7 @@ int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
|
|||
|
||||
// query name.idx
|
||||
if (tdbTbGet(pMeta->pNameIdx, name, strlen(name) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pReader->pBuf;
|
||||
|
@ -148,7 +141,7 @@ int metaGetTableNameByUid(void *pVnode, uint64_t uid, char *tbName) {
|
|||
code = metaReaderGetTableEntryByUid(&mr, uid);
|
||||
if (code < 0) {
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
STR_TO_VARSTR(tbName, mr.me.name);
|
||||
|
@ -164,7 +157,7 @@ int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName) {
|
|||
code = metaReaderGetTableEntryByUid(&mr, uid);
|
||||
if (code < 0) {
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
strncpy(tbName, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
metaReaderClear(&mr);
|
||||
|
@ -181,9 +174,8 @@ int metaGetTableUidByName(void *pVnode, char *tbName, uint64_t *uid) {
|
|||
|
||||
// query name.idx
|
||||
if (tdbTbGet(((SMeta *)pReader->pMeta)->pNameIdx, tbName, strlen(tbName) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
*uid = *(tb_uid_t *)pReader->pBuf;
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "meta.h"
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
static int metaHandleSmaEntry(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaSaveSmaToDB(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
@ -34,15 +33,15 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
|
|||
int32_t szBuf = 0;
|
||||
void *p = NULL;
|
||||
SMetaReader mr = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
// validate req
|
||||
// save smaIndex
|
||||
metaReaderDoInit(&mr, pMeta, META_READER_LOCK);
|
||||
if (metaReaderGetTableEntryByUidCache(&mr, pCfg->indexUid) == 0) {
|
||||
#if 1
|
||||
terrno = TSDB_CODE_TSMA_ALREADY_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1; // don't goto _err;
|
||||
return terrno = TSDB_CODE_TSMA_ALREADY_EXIST;
|
||||
#else
|
||||
metaReaderClear(&mr);
|
||||
return 0;
|
||||
|
@ -57,7 +56,8 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
|
|||
me.name = pCfg->indexName;
|
||||
me.smaEntry.tsma = pCfg;
|
||||
|
||||
if (metaHandleSmaEntry(pMeta, &me) < 0) goto _err;
|
||||
code = metaHandleSmaEntry(pMeta, &me);
|
||||
if (code) goto _err;
|
||||
|
||||
metaDebug("vgId:%d, tsma is created, name:%s uid:%" PRId64, TD_VID(pMeta->pVnode), pCfg->indexName, pCfg->indexUid);
|
||||
|
||||
|
@ -66,7 +66,7 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
|
|||
_err:
|
||||
metaError("vgId:%d, failed to create tsma:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pCfg->indexName,
|
||||
pCfg->indexUid, tstrerror(terrno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
|
||||
|
@ -147,24 +147,25 @@ static int metaUpdateSmaIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
}
|
||||
|
||||
static int metaHandleSmaEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
int32_t code = 0;
|
||||
metaWLock(pMeta);
|
||||
|
||||
// save to table.db
|
||||
if (metaSaveSmaToDB(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaSaveSmaToDB(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
// update uid.idx
|
||||
if (metaUpdateUidIdx(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaUpdateUidIdx(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
// update name.idx
|
||||
if (metaUpdateNameIdx(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaUpdateNameIdx(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
// update sma.idx
|
||||
if (metaUpdateSmaIdx(pMeta, pME) < 0) goto _err;
|
||||
if ((code = metaUpdateSmaIdx(pMeta, pME)) < 0) goto _err;
|
||||
|
||||
metaULock(pMeta);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaULock(pMeta);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ int32_t metaSnapReaderOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapRe
|
|||
// alloc
|
||||
pReader = (SMetaSnapReader*)taosMemoryCalloc(1, sizeof(*pReader));
|
||||
if (pReader == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||
}
|
||||
pReader->pMeta = pMeta;
|
||||
pReader->sver = sver;
|
||||
|
@ -261,7 +261,9 @@ static void saveSuperTableInfoForChildTable(SMetaEntry* me, SHashObj* suidInfo)
|
|||
int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8_t subType, int8_t withMeta,
|
||||
SSnapContext** ctxRet) {
|
||||
SSnapContext* ctx = taosMemoryCalloc(1, sizeof(SSnapContext));
|
||||
if (ctx == NULL) return -1;
|
||||
if (ctx == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
*ctxRet = ctx;
|
||||
ctx->pMeta = pVnode->pMeta;
|
||||
ctx->snapVersion = snapVersion;
|
||||
|
@ -271,12 +273,12 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
|
|||
ctx->withMeta = withMeta;
|
||||
ctx->idVersion = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
if (ctx->idVersion == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ctx->suidInfo = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
if (ctx->suidInfo == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
taosHashSetFreeFp(ctx->suidInfo, destroySTableInfoForChildTable);
|
||||
|
||||
|
@ -426,21 +428,21 @@ static int32_t buildSuperTableInfo(SVCreateStbReq* req, void** pBuf, int32_t* co
|
|||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSVCreateStbReq, req, *contLen, ret);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
*contLen += sizeof(SMsgHead);
|
||||
*pBuf = taosMemoryMalloc(*contLen);
|
||||
if (NULL == *pBuf) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(*pBuf, sizeof(SMsgHead)), *contLen);
|
||||
if (tEncodeSVCreateStbReq(&encoder, req) < 0) {
|
||||
if ((ret = tEncodeSVCreateStbReq(&encoder, req)) < 0) {
|
||||
taosMemoryFreeClear(*pBuf);
|
||||
tEncoderClear(&encoder);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
return 0;
|
||||
|
|
|
@ -36,11 +36,15 @@ static int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
|||
static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
||||
int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress) {
|
||||
static int32_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress) {
|
||||
int32_t nCols = pWp->nCols;
|
||||
int32_t ver = pWp->version;
|
||||
if (add) {
|
||||
SColCmpr *p = taosMemoryCalloc(1, sizeof(SColCmpr) * (nCols + 1));
|
||||
if (p == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
memcpy(p, pWp->pColCmpr, sizeof(SColCmpr) * nCols);
|
||||
|
||||
SColCmpr *pCol = p + nCols;
|
||||
|
@ -64,7 +68,7 @@ int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, ui
|
|||
pWp->nCols = nCols;
|
||||
pWp->version = ver;
|
||||
}
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
||||
pInfo->uid = pEntry->uid;
|
||||
|
@ -87,8 +91,7 @@ static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema
|
|||
pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
|
||||
|
||||
if (NULL == pMetaRsp->pSchemas) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMetaRsp->pSchemaExt = taosMemoryMalloc(pSchema->nCols * sizeof(SSchemaExt));
|
||||
|
@ -105,9 +108,11 @@ static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema
|
|||
}
|
||||
|
||||
static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
void *data = pCtbEntry->ctbEntry.pTags;
|
||||
const char *tagName = pSchema->name;
|
||||
|
@ -118,8 +123,9 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
|
|||
int32_t nTagData = 0;
|
||||
|
||||
SArray *pTagVals = NULL;
|
||||
if (tTagToValArray((const STag *)data, &pTagVals) != 0) {
|
||||
return -1;
|
||||
code = tTagToValArray((const STag *)data, &pTagVals);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
|
@ -168,7 +174,7 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
|
|||
int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
void *data = pCtbEntry->ctbEntry.pTags;
|
||||
const char *tagName = pSchema->name;
|
||||
|
@ -179,8 +185,9 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche
|
|||
int32_t nTagData = 0;
|
||||
|
||||
SArray *pTagVals = NULL;
|
||||
if (tTagToValArray((const STag *)data, &pTagVals) != 0) {
|
||||
return -1;
|
||||
int32_t code = tTagToValArray((const STag *)data, &pTagVals);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
|
@ -247,6 +254,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
void *pBuf = NULL;
|
||||
int32_t szBuf = 0;
|
||||
void *p = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
// validate req
|
||||
void *pData = NULL;
|
||||
|
@ -256,14 +264,12 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
tdbFree(pData);
|
||||
SMetaInfo info;
|
||||
if (metaGetInfo(pMeta, uid, &info, NULL) == TSDB_CODE_NOT_FOUND) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
if (info.uid == info.suid) {
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +289,8 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
me.colCmpr = pReq->colCmpr;
|
||||
}
|
||||
|
||||
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
|
||||
code = metaHandleEntry(pMeta, &me);
|
||||
if (code) goto _err;
|
||||
|
||||
++pMeta->pVnode->config.vndStats.numOfSTables;
|
||||
|
||||
|
@ -295,7 +302,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
_err:
|
||||
metaError("vgId:%d, failed to create stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid,
|
||||
tstrerror(terrno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tbUidList) {
|
||||
|
@ -310,8 +317,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb
|
|||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||
if (rc < 0 || *(tb_uid_t *)pData != pReq->suid) {
|
||||
tdbFree(pData);
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
// drop all child tables
|
||||
|
@ -424,16 +430,14 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
if (ret < 0 || c) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
@ -444,9 +448,8 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
metaError("meta/table: invalide ret: %" PRId32 " or c: %" PRId32 "alter stb failed.", ret, c);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -454,8 +457,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
}
|
||||
|
||||
oStbEntry.pBuf = taosMemoryMalloc(nData);
|
||||
|
@ -870,8 +872,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
tb_uid_t suid = metaGetTableEntryUidByName(pMeta, pReq->ctb.stbName);
|
||||
if (suid != pReq->ctb.suid) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -879,17 +880,15 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
metaReaderDoInit(&mr, pMeta, META_READER_LOCK);
|
||||
if (metaGetTableEntryByName(&mr, pReq->name) == 0) {
|
||||
if (pReq->type == TSDB_CHILD_TABLE && pReq->ctb.suid != mr.me.ctbEntry.suid) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
|
||||
}
|
||||
pReq->uid = mr.me.uid;
|
||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
pReq->ctb.suid = mr.me.ctbEntry.suid;
|
||||
}
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
} else if (terrno == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1001,7 +1000,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
_err:
|
||||
metaError("vgId:%d, failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->type == TSDB_CHILD_TABLE ? "child table" : "normal table", tstrerror(terrno));
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids, tb_uid_t *tbUid) {
|
||||
|
@ -1015,8 +1014,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
|||
|
||||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||
if (rc < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
uid = *(tb_uid_t *)pData;
|
||||
|
||||
|
@ -1154,7 +1152,7 @@ int32_t metaTrimTables(SMeta *pMeta) {
|
|||
|
||||
SArray *tbUids = taosArrayInit(8, sizeof(int64_t));
|
||||
if (tbUids == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = metaFilterTableByHash(pMeta, tbUids);
|
||||
|
@ -1195,7 +1193,7 @@ static int metaBuildBtimeIdxKey(SBtimeIdxKey *btimeKey, const SMetaEntry *pME) {
|
|||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
btime = pME->ntbEntry.btime;
|
||||
} else {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
btimeKey->btime = btime;
|
||||
|
@ -1208,7 +1206,7 @@ static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
|
|||
ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
|
||||
ncolKey->uid = pME->uid;
|
||||
} else {
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1235,7 +1233,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p
|
|||
|
||||
rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
|
||||
if (rc < 0) {
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
int64_t version = ((SUidIdxVal *)pData)[0].version;
|
||||
|
||||
|
@ -1245,7 +1243,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p
|
|||
rc = metaDecodeEntry(&dc, &e);
|
||||
if (rc < 0) {
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (type) *type = e.type;
|
||||
|
@ -1408,16 +1406,14 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
int c;
|
||||
bool freeColCmpr = false;
|
||||
if (pAlterTbReq->colName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
metaError("meta/table: null pAlterTbReq->colName");
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
|
@ -1432,7 +1428,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1447,7 +1443,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1463,7 +1459,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
tdbTbcClose(pTbDbc);
|
||||
tDecoderClear(&dc);
|
||||
metaError("meta/table: invalide ret: %" PRId32 " alt tb column failed.", ret);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (entry.type != TSDB_NORMAL_TABLE) {
|
||||
|
@ -1660,7 +1656,7 @@ _err:
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||
|
@ -1676,15 +1672,13 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
int nData = 0;
|
||||
|
||||
if (pAlterTbReq->tagName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
|
@ -1698,9 +1692,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1717,9 +1710,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1866,8 +1858,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
|
@ -1882,7 +1873,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1897,7 +1888,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
@ -1913,7 +1904,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide ret: %" PRId32 " alt tb options failed.", ret);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
entry.version = version;
|
||||
|
@ -1968,15 +1959,13 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
|
|||
SDecoder dc = {0};
|
||||
|
||||
if (pAlterTbReq->tagName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
} else {
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
|
@ -2085,7 +2074,7 @@ _err:
|
|||
// if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
|
||||
// tdbTbcClose(pTbDbc);
|
||||
// tdbTbcClose(pUidIdxc);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
typedef struct SMetaPair {
|
||||
|
@ -2106,15 +2095,13 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
|
|||
SDecoder dc = {0};
|
||||
|
||||
if (pAlterTbReq->tagName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
suid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
|
@ -2200,7 +2187,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
|
|||
// set pCol->flags; INDEX_ON
|
||||
return 0;
|
||||
_err:
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
|
||||
// impl later
|
||||
|
@ -2216,8 +2203,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
SDecoder dc = {0};
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pReq->tbName, strlen(pReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
suid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
|
@ -2290,7 +2276,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
|
||||
return 0;
|
||||
_err:
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pMetaRsp) {
|
||||
|
@ -2313,8 +2299,7 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta
|
|||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS:
|
||||
return metaUpdateTableColCompress(pMeta, version, pReq);
|
||||
default:
|
||||
terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2370,7 +2355,7 @@ _err:
|
|||
pME->uid, tstrerror(terrno));
|
||||
|
||||
taosMemoryFree(pVal);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -2446,8 +2431,7 @@ int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void *pTagData, int32_
|
|||
|
||||
*ppTagIdxKey = (STagIdxKey *)taosMemoryMalloc(*nTagIdxKey);
|
||||
if (*ppTagIdxKey == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*ppTagIdxKey)->suid = suid;
|
||||
|
@ -2667,7 +2651,7 @@ _err:
|
|||
metaULock(pMeta);
|
||||
metaError("vgId:%d, failed to handle meta entry since %s at line:%d, ver:%" PRId64 ", uid:%" PRId64 ", name:%s",
|
||||
TD_VID(pMeta->pVnode), terrstr(), line, pME->version, pME->uid, pME->name);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int32_t colCompressDebug(SHashObj *pColCmprObj) {
|
||||
|
@ -2703,7 +2687,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) {
|
|||
if (rc < 0) {
|
||||
taosHashClear(pColCmprObj);
|
||||
metaULock(pMeta);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int64_t version = ((SUidIdxVal *)pData)[0].version;
|
||||
rc = tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
|
||||
|
@ -2721,7 +2705,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) {
|
|||
tdbFree(pData);
|
||||
metaULock(pMeta);
|
||||
taosHashClear(pColCmprObj);
|
||||
return -1;
|
||||
return rc;
|
||||
}
|
||||
if (useCompress(e.type)) {
|
||||
SColCmprWrapper *p = &e.colCmpr;
|
||||
|
|
|
@ -99,8 +99,7 @@ int32_t smaBegin(SSma *pSma) {
|
|||
}
|
||||
}
|
||||
_exit:
|
||||
terrno = code;
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
extern int32_t tsdbCommitCommit(STsdb *tsdb);
|
||||
|
@ -119,7 +118,7 @@ _exit:
|
|||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +201,7 @@ _exit:
|
|||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s(%d)", SMA_VID(pSma), __func__, lino, tstrerror(code), isCommit);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +228,7 @@ _exit:
|
|||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,7 +240,7 @@ _exit:
|
|||
static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
if (!pEnv) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||
|
@ -276,5 +275,5 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
|
|||
|
||||
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ static void tdDestroyRSmaStat(void *pRSmaStat);
|
|||
*/
|
||||
// implementation
|
||||
int32_t smaInit() {
|
||||
int32_t code = 0;
|
||||
int8_t old;
|
||||
int32_t nLoops = 0;
|
||||
while (1) {
|
||||
|
@ -56,8 +57,9 @@ int32_t smaInit() {
|
|||
|
||||
if (smaMgmt.rsetId < 0) {
|
||||
atomic_store_8(&smaMgmt.inited, 0);
|
||||
smaError("failed to init sma rset since %s", terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
code = terrno;
|
||||
smaError("failed to init sma rset since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t type = (8 == POINTER_BYTES) ? TSDB_DATA_TYPE_UBIGINT : TSDB_DATA_TYPE_UINT;
|
||||
|
@ -66,21 +68,22 @@ int32_t smaInit() {
|
|||
smaMgmt.tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA");
|
||||
|
||||
if (!smaMgmt.refHash || !smaMgmt.tmrHandle) {
|
||||
code = terrno;
|
||||
taosCloseRef(smaMgmt.rsetId);
|
||||
if (smaMgmt.refHash) {
|
||||
taosHashCleanup(smaMgmt.refHash);
|
||||
smaMgmt.refHash = NULL;
|
||||
}
|
||||
atomic_store_8(&smaMgmt.inited, 0);
|
||||
smaError("failed to init sma tmr handle since %s", terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
smaError("failed to init sma tmr handle since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
atomic_store_8(&smaMgmt.inited, 1);
|
||||
smaInfo("sma mgmt env is initialized, rsetId:%d, tmrHandle:%p", smaMgmt.rsetId, smaMgmt.tmrHandle);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +103,7 @@ void smaCleanUp() {
|
|||
}
|
||||
|
||||
if (old == 1) {
|
||||
taosCloseRef(smaMgmt.rsetId);
|
||||
(void)taosCloseRef(smaMgmt.rsetId);
|
||||
taosHashCleanup(smaMgmt.refHash);
|
||||
smaMgmt.refHash = NULL;
|
||||
taosTmrCleanUp(smaMgmt.tmrHandle);
|
||||
|
@ -110,13 +113,13 @@ void smaCleanUp() {
|
|||
}
|
||||
|
||||
static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
|
||||
int32_t code = 0;
|
||||
SSmaEnv *pEnv = NULL;
|
||||
|
||||
pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv));
|
||||
*ppEnv = pEnv;
|
||||
if (!pEnv) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SMA_ENV_TYPE(pEnv) = smaType;
|
||||
|
@ -126,26 +129,23 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
|
|||
(smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), *ppEnv)
|
||||
: atomic_store_ptr(&SMA_RSMA_ENV(pSma), *ppEnv);
|
||||
|
||||
if ((terrno = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) {
|
||||
if ((code = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) {
|
||||
tdFreeSmaEnv(pEnv);
|
||||
*ppEnv = NULL;
|
||||
(smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), NULL)
|
||||
: atomic_store_ptr(&SMA_RSMA_ENV(pSma), NULL);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tdInitSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
|
||||
|
||||
if (!(*ppEnv)) {
|
||||
if (tdNewSmaEnv(pSma, smaType, ppEnv) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdNewSmaEnv(pSma, smaType, ppEnv));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,10 +174,10 @@ static void tRSmaInfoHashFreeNode(void *data) {
|
|||
|
||||
if ((pRSmaInfo = *(SRSmaInfo **)data)) {
|
||||
if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 0)) && pItem->level) {
|
||||
taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
|
||||
(void)taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
|
||||
}
|
||||
if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 1)) && pItem->level) {
|
||||
taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
|
||||
(void)taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
|
||||
}
|
||||
tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo);
|
||||
}
|
||||
|
@ -187,9 +187,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
|
||||
if (*pSmaStat) { // no lock
|
||||
return code; // success, return directly
|
||||
if (*pSmaStat) { // no lock
|
||||
TAOS_RETURN(code); // success, return directly
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,7 +200,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat) + sizeof(TdThread) * tsNumOfVnodeRsmaThreads);
|
||||
if (!(*pSmaStat)) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
|
||||
if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||
|
@ -211,20 +210,20 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
tsem_init(&pRSmaStat->notEmpty, 0, 0);
|
||||
if (!(pRSmaStat->blocks = taosArrayInit(1, sizeof(SSDataBlock)))) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
SSDataBlock datablock = {.info.type = STREAM_CHECKPOINT};
|
||||
taosArrayPush(pRSmaStat->blocks, &datablock);
|
||||
(void)taosArrayPush(pRSmaStat->blocks, &datablock);
|
||||
|
||||
// init smaMgmt
|
||||
smaInit();
|
||||
|
||||
int64_t refId = taosAddRef(smaMgmt.rsetId, pRSmaStat);
|
||||
if (refId < 0) {
|
||||
smaError("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d failed since:%s", SMA_VID(pSma),
|
||||
refId, smaMgmt.rsetId, SMA_MGMT_REF_NUM, tstrerror(terrno));
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
smaError("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d failed since:%s", SMA_VID(pSma),
|
||||
refId, smaMgmt.rsetId, SMA_MGMT_REF_NUM, tstrerror(code));
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
} else {
|
||||
smaDebug("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d succeed", SMA_VID(pSma), refId,
|
||||
smaMgmt.rsetId, SMA_MGMT_REF_NUM);
|
||||
|
@ -236,14 +235,11 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||
if (!RSMA_INFO_HASH(pRSmaStat)) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
taosHashSetFreeFp(RSMA_INFO_HASH(pRSmaStat), tRSmaInfoHashFreeNode);
|
||||
|
||||
if (tdRsmaStartExecutor(pSma) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_GOTO(tdRsmaStartExecutor(pSma), &lino, _exit);
|
||||
|
||||
taosInitRWLatch(RSMA_FS_LOCK(pRSmaStat));
|
||||
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||
|
@ -256,7 +252,7 @@ _exit:
|
|||
} else {
|
||||
smaDebug("vgId:%d, %s succeed, type:%" PRIi8, SMA_VID(pSma), __func__, smaType);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void tdDestroyTSmaStat(STSmaStat *pStat) {
|
||||
|
@ -340,73 +336,74 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
|||
}
|
||||
|
||||
int32_t tdLockSma(SSma *pSma) {
|
||||
int code = taosThreadMutexLock(&pSma->mutex);
|
||||
if (code != 0) {
|
||||
smaError("vgId:%d, failed to lock since %s", SMA_VID(pSma), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
int errCode = taosThreadMutexLock(&pSma->mutex);
|
||||
if (errCode != 0) {
|
||||
int32_t code = TAOS_SYSTEM_ERROR(errCode);
|
||||
smaError("vgId:%d, failed to lock since %s", SMA_VID(pSma), tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
pSma->locked = true;
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
int32_t tdUnLockSma(SSma *pSma) {
|
||||
|
||||
pSma->locked = false;
|
||||
int code = taosThreadMutexUnlock(&pSma->mutex);
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
smaError("vgId:%d, failed to unlock since %s", SMA_VID(pSma), strerror(errno));
|
||||
return -1;
|
||||
int errCode = taosThreadMutexUnlock(&pSma->mutex);
|
||||
if (errCode != 0) {
|
||||
int32_t code = TAOS_SYSTEM_ERROR(errCode);
|
||||
smaError("vgId:%d, failed to unlock since %s", SMA_VID(pSma), tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) {
|
||||
int32_t code = 0;
|
||||
SSmaEnv *pEnv = NULL;
|
||||
|
||||
switch (smaType) {
|
||||
case TSDB_SMA_TYPE_TIME_RANGE:
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&SMA_TSMA_ENV(pSma)))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case TSDB_SMA_TYPE_ROLLUP:
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&SMA_RSMA_ENV(pSma)))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
smaError("vgId:%d, undefined smaType:%" PRIi8, SMA_VID(pSma), smaType);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
// init sma env
|
||||
tdLockSma(pSma);
|
||||
(void)tdLockSma(pSma);
|
||||
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&SMA_TSMA_ENV(pSma))
|
||||
: atomic_load_ptr(&SMA_RSMA_ENV(pSma));
|
||||
if (!pEnv) {
|
||||
if (tdInitSmaEnv(pSma, smaType, &pEnv) < 0) {
|
||||
tdUnLockSma(pSma);
|
||||
return TSDB_CODE_FAILED;
|
||||
if ((code = tdInitSmaEnv(pSma, smaType, &pEnv)) < 0) {
|
||||
(void)tdUnLockSma(pSma);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
tdUnLockSma(pSma);
|
||||
(void)tdUnLockSma(pSma);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
};
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void *tdRSmaExecutorFunc(void *param) {
|
||||
setThreadName("vnode-rsma");
|
||||
|
||||
tdRSmaProcessExecImpl((SSma *)param, RSMA_EXEC_OVERFLOW);
|
||||
(void)tdRSmaProcessExecImpl((SSma *)param, RSMA_EXEC_OVERFLOW);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t tdRsmaStartExecutor(const SSma *pSma) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr = {0};
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
(void)taosThreadAttrInit(&thAttr);
|
||||
(void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
|
@ -414,15 +411,15 @@ static int32_t tdRsmaStartExecutor(const SSma *pSma) {
|
|||
|
||||
for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) {
|
||||
if (taosThreadCreate(&pthread[i], &thAttr, tdRSmaExecutorFunc, (void *)pSma) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
smaError("vgId:%d, failed to create pthread for rsma since %s", SMA_VID(pSma), terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
smaError("vgId:%d, failed to create pthread for rsma since %s", SMA_VID(pSma), tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
smaDebug("vgId:%d, success to create pthread for rsma", SMA_VID(pSma));
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
return 0;
|
||||
(void)taosThreadAttrDestroy(&thAttr);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tdRsmaStopExecutor(const SSma *pSma) {
|
||||
|
@ -433,7 +430,7 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) {
|
|||
TdThread *pthread = NULL;
|
||||
|
||||
if (!(pEnv = SMA_RSMA_ENV(pSma)) || !(pStat = SMA_ENV_STAT(pEnv))) {
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
pEnv->flag |= SMA_ENV_FLG_CLOSE;
|
||||
|
@ -447,11 +444,11 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) {
|
|||
for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) {
|
||||
if (taosCheckPthreadValid(pthread[i])) {
|
||||
smaDebug("vgId:%d, start to join pthread for rsma:%" PRId64 "", SMA_VID(pSma), taosGetPthreadId(pthread[i]));
|
||||
taosThreadJoin(pthread[i], NULL);
|
||||
(void)taosThreadJoin(pthread[i], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
smaInfo("vgId:%d, rsma executor stopped, number:%d", SMA_VID(pSma), tsNumOfVnodeRsmaThreads);
|
||||
}
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
|
|
@ -16,38 +16,34 @@
|
|||
#include "sma.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t precision, int32_t duration);
|
||||
static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t precision, int32_t duration,
|
||||
int32_t *days);
|
||||
static int32_t smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int type);
|
||||
static int32_t rsmaRestore(SSma *pSma);
|
||||
|
||||
#define SMA_SET_KEEP_CFG(v, l) \
|
||||
do { \
|
||||
SRetention *r = &pCfg->retentions[l]; \
|
||||
int64_t keep = -1; \
|
||||
convertTimeFromPrecisionToUnit(r->keep, pCfg->precision, TIME_UNIT_MINUTE, &keep); \
|
||||
pKeepCfg->keep2 = (int32_t)keep; \
|
||||
pKeepCfg->keep0 = pKeepCfg->keep2; \
|
||||
pKeepCfg->keep1 = pKeepCfg->keep2; \
|
||||
pKeepCfg->days = smaEvalDays(v, pCfg->retentions, l, pCfg->precision, pCfg->days); \
|
||||
pKeepCfg->keepTimeOffset = 0; \
|
||||
#define SMA_SET_KEEP_CFG(v, l) \
|
||||
do { \
|
||||
SRetention *r = &pCfg->retentions[l]; \
|
||||
int64_t keep = -1; \
|
||||
TAOS_CHECK_EXIT(convertTimeFromPrecisionToUnit(r->keep, pCfg->precision, TIME_UNIT_MINUTE, &keep)); \
|
||||
pKeepCfg->keep2 = (int32_t)keep; \
|
||||
pKeepCfg->keep0 = pKeepCfg->keep2; \
|
||||
pKeepCfg->keep1 = pKeepCfg->keep2; \
|
||||
TAOS_CHECK_EXIT(smaEvalDays(v, pCfg->retentions, l, pCfg->precision, pCfg->days, &pKeepCfg->days)); \
|
||||
pKeepCfg->keepTimeOffset = 0; \
|
||||
} while (0)
|
||||
|
||||
#define SMA_OPEN_RSMA_IMPL(v, l, force) \
|
||||
do { \
|
||||
SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
|
||||
if (!RETENTION_VALID(l, r)) { \
|
||||
if (l == 0) { \
|
||||
code = TSDB_CODE_INVALID_PARA; \
|
||||
TSDB_CHECK_CODE(code, lino, _exit); \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
code = smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
|
||||
TSDB_CHECK_CODE(code, lino, _exit); \
|
||||
if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback, force) < 0) { \
|
||||
code = terrno; \
|
||||
TSDB_CHECK_CODE(code, lino, _exit); \
|
||||
} \
|
||||
#define SMA_OPEN_RSMA_IMPL(v, l, force) \
|
||||
do { \
|
||||
SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
|
||||
if (!RETENTION_VALID(l, r)) { \
|
||||
if (l == 0) { \
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_INVALID_PARA); \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
TAOS_CHECK_EXIT(smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l)); \
|
||||
TAOS_CHECK_EXIT(tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback, force)); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
|
@ -59,51 +55,61 @@ static int32_t rsmaRestore(SSma *pSma);
|
|||
* @param level
|
||||
* @param precision
|
||||
* @param duration
|
||||
* @param days
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t precision, int32_t duration) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t precision, int32_t duration,
|
||||
int32_t *days) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
int64_t freqDuration = -1;
|
||||
int64_t keepDuration = -1;
|
||||
code = convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->freq, precision, TIME_UNIT_MINUTE, &freqDuration);
|
||||
code = convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->keep, precision, TIME_UNIT_MINUTE, &keepDuration);
|
||||
int32_t days = duration; // min
|
||||
TAOS_CHECK_EXIT(
|
||||
convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->freq, precision, TIME_UNIT_MINUTE, &freqDuration));
|
||||
TAOS_CHECK_EXIT(
|
||||
convertTimeFromPrecisionToUnit((r + TSDB_RETENTION_L0)->keep, precision, TIME_UNIT_MINUTE, &keepDuration));
|
||||
*days = duration; // min
|
||||
|
||||
if (days < freqDuration) {
|
||||
days = freqDuration;
|
||||
if (*days < freqDuration) {
|
||||
*days = freqDuration;
|
||||
}
|
||||
|
||||
if (days > keepDuration) {
|
||||
days = keepDuration;
|
||||
if (*days > keepDuration) {
|
||||
*days = keepDuration;
|
||||
}
|
||||
|
||||
if (level < TSDB_RETENTION_L1 || level > TSDB_RETENTION_L2) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = convertTimeFromPrecisionToUnit((r + level)->freq, precision, TIME_UNIT_MINUTE, &freqDuration);
|
||||
code = convertTimeFromPrecisionToUnit((r + level)->keep, precision, TIME_UNIT_MINUTE, &keepDuration);
|
||||
TAOS_CHECK_EXIT(convertTimeFromPrecisionToUnit((r + level)->freq, precision, TIME_UNIT_MINUTE, &freqDuration));
|
||||
TAOS_CHECK_EXIT(convertTimeFromPrecisionToUnit((r + level)->keep, precision, TIME_UNIT_MINUTE, &keepDuration));
|
||||
|
||||
int32_t nFreqTimes = (r + level)->freq / (60 * 1000); // use 60s for freq of 1st level
|
||||
days *= (nFreqTimes > 1 ? nFreqTimes : 1);
|
||||
*days *= (nFreqTimes > 1 ? nFreqTimes : 1);
|
||||
|
||||
if (days < freqDuration) {
|
||||
days = freqDuration;
|
||||
if (*days < freqDuration) {
|
||||
*days = freqDuration;
|
||||
}
|
||||
|
||||
int32_t maxKeepDuration = TMIN(keepDuration, TSDB_MAX_DURATION_PER_FILE);
|
||||
if (days > maxKeepDuration) {
|
||||
days = maxKeepDuration;
|
||||
if (*days > maxKeepDuration) {
|
||||
*days = maxKeepDuration;
|
||||
}
|
||||
|
||||
_exit:
|
||||
smaInfo("vgId:%d, evaluated duration for level %d is %d, raw val:%d", TD_VID(pVnode), level + 1, days, duration);
|
||||
return days;
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
} else {
|
||||
smaInfo("vgId:%d, evaluated duration for level %d is %d, raw val:%d", TD_VID(pVnode), level + 1, *days, duration);
|
||||
}
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int type) {
|
||||
terrno = 0;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
pKeepCfg->precision = pCfg->precision;
|
||||
switch (type) {
|
||||
case TSDB_TYPE_RSMA_L0:
|
||||
|
@ -116,10 +122,14 @@ int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int ty
|
|||
SMA_SET_KEEP_CFG(pVnode, 2);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
break;
|
||||
}
|
||||
return terrno;
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t smaOpen(SVnode *pVnode, int8_t rollback, bool force) {
|
||||
|
@ -129,14 +139,13 @@ int32_t smaOpen(SVnode *pVnode, int8_t rollback, bool force) {
|
|||
|
||||
SSma *pSma = taosMemoryCalloc(1, sizeof(SSma));
|
||||
if (!pSma) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pVnode->pSma = pSma;
|
||||
|
||||
pSma->pVnode = pVnode;
|
||||
taosThreadMutexInit(&pSma->mutex, NULL);
|
||||
(void)taosThreadMutexInit(&pSma->mutex, NULL);
|
||||
pSma->locked = false;
|
||||
|
||||
if (VND_IS_RSMA(pVnode)) {
|
||||
|
@ -152,24 +161,20 @@ int32_t smaOpen(SVnode *pVnode, int8_t rollback, bool force) {
|
|||
}
|
||||
|
||||
// restore the rsma
|
||||
if (tdRSmaRestore(pSma, RSMA_RESTORE_REBOOT, pVnode->state.committed, rollback) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_EXIT(tdRSmaRestore(pSma, RSMA_RESTORE_REBOOT, pVnode->state.committed, rollback));
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
terrno = code;
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t smaClose(SSma *pSma) {
|
||||
if (pSma) {
|
||||
smaPreClose(pSma);
|
||||
taosThreadMutexDestroy(&pSma->mutex);
|
||||
(void)smaPreClose(pSma);
|
||||
(void)taosThreadMutexDestroy(&pSma->mutex);
|
||||
SMA_TSMA_ENV(pSma) = tdFreeSmaEnv(SMA_TSMA_ENV(pSma));
|
||||
SMA_RSMA_ENV(pSma) = tdFreeSmaEnv(SMA_RSMA_ENV(pSma));
|
||||
if SMA_RSMA_TSDB0 (pSma) tsdbClose(&SMA_RSMA_TSDB0(pSma));
|
||||
|
@ -190,7 +195,7 @@ int32_t smaClose(SSma *pSma) {
|
|||
*/
|
||||
int32_t tdRSmaRestore(SSma *pSma, int8_t type, int64_t committedVer, int8_t rollback) {
|
||||
if (!VND_IS_RSMA(pSma->pVnode)) {
|
||||
return TSDB_CODE_RSMA_INVALID_ENV;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_INVALID_ENV);
|
||||
}
|
||||
|
||||
return tdRSmaProcessRestoreImpl(pSma, type, committedVer, rollback);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -38,8 +38,7 @@ int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapRead
|
|||
// alloc
|
||||
pReader = (SRSmaSnapReader*)taosMemoryCalloc(1, sizeof(*pReader));
|
||||
if (pReader == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
pReader->pSma = pSma;
|
||||
pReader->sver = sver;
|
||||
|
@ -50,7 +49,7 @@ int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapRead
|
|||
if (pSma->pRSmaTsdb[i]) {
|
||||
code = tsdbSnapReaderOpen(pSma->pRSmaTsdb[i], sver, ever, (i == 0 ? SNAP_DATA_RSMA1 : SNAP_DATA_RSMA2), NULL,
|
||||
&pReader->pDataReader[i]);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +60,7 @@ _exit:
|
|||
*ppReader = NULL;
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData) {
|
||||
|
@ -80,7 +79,7 @@ int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData) {
|
|||
if (!pReader->rsmaDataDone[i]) {
|
||||
smaInfo("vgId:%d, vnode snapshot rsma read level %d not done", SMA_VID(pReader->pSma), i);
|
||||
code = tsdbSnapRead(pTsdbSnapReader, ppData);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
if (*ppData) {
|
||||
goto _exit;
|
||||
} else {
|
||||
|
@ -93,12 +92,12 @@ int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, vnode snapshot rsma read failed since %s", SMA_VID(pReader->pSma), tstrerror(code));
|
||||
rsmaSnapReaderClose(&pReader);
|
||||
smaError("vgId:%d, %s failed at line %d since %s", SMA_VID(pReader->pSma), __func__, lino, tstrerror(code));
|
||||
(void)rsmaSnapReaderClose(&pReader);
|
||||
} else {
|
||||
smaInfo("vgId:%d, vnode snapshot rsma read succeed", SMA_VID(pReader->pSma));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
|
||||
|
@ -107,14 +106,14 @@ int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
|
|||
|
||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pReader->pDataReader[i]) {
|
||||
tsdbSnapReaderClose(&pReader->pDataReader[i]);
|
||||
(void)tsdbSnapReaderClose(&pReader->pDataReader[i]);
|
||||
}
|
||||
}
|
||||
|
||||
smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma));
|
||||
|
||||
taosMemoryFreeClear(*ppReader);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// SRSmaSnapWriter ========================================
|
||||
|
@ -137,8 +136,7 @@ int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, void** ppRang
|
|||
// alloc
|
||||
pWriter = (SRSmaSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
|
||||
if (!pWriter) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
pWriter->pSma = pSma;
|
||||
pWriter->sver = sver;
|
||||
|
@ -148,7 +146,7 @@ int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, void** ppRang
|
|||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pSma->pRSmaTsdb[i]) {
|
||||
code = tsdbSnapWriterOpen(pSma->pRSmaTsdb[i], sver, ever, ((void**)ppRanges)[i], &pWriter->pDataWriter[i]);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +160,7 @@ _exit:
|
|||
} else {
|
||||
smaInfo("vgId:%d, rsma snapshot writer open succeed", TD_VID(pSma->pVnode));
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t rsmaSnapWriterPrepareClose(SRSmaSnapWriter* pWriter) {
|
||||
|
@ -171,13 +169,13 @@ int32_t rsmaSnapWriterPrepareClose(SRSmaSnapWriter* pWriter) {
|
|||
if (pWriter->pDataWriter[i]) {
|
||||
code = tsdbSnapWriterPrepareClose(pWriter->pDataWriter[i]);
|
||||
if (code) {
|
||||
smaError("vgId:%d, failed to prepare close tsdbSnapWriter since %s. i: %d", SMA_VID(pWriter->pSma), terrstr(),
|
||||
i);
|
||||
return -1;
|
||||
smaError("vgId:%d, failed to prepare close tsdbSnapWriter since %s. i: %d", SMA_VID(pWriter->pSma),
|
||||
tstrerror(code), i);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) {
|
||||
|
@ -206,13 +204,13 @@ int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) {
|
|||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pWriter->pDataWriter[i]) {
|
||||
code = tsdbSnapWriterClose(&pWriter->pDataWriter[i], rollback);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
// rsma restore
|
||||
code = tdRSmaRestore(pWriter->pSma, RSMA_RESTORE_SYNC, pWriter->ever, rollback);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
smaInfo("vgId:%d, vnode snapshot rsma writer restore from sync succeed", SMA_VID(pSma));
|
||||
|
||||
_exit:
|
||||
|
@ -221,12 +219,13 @@ _exit:
|
|||
if (code) {
|
||||
if (pOutFD) taosCloseFile(&pOutFD);
|
||||
if (pInFD) taosCloseFile(&pInFD);
|
||||
smaError("vgId:%d, vnode snapshot rsma writer close failed since %s", SMA_VID(pSma), tstrerror(code));
|
||||
smaError("vgId:%d, vnode snapshot rsma writer close failed at line %d since %s", SMA_VID(pSma), lino,
|
||||
tstrerror(code));
|
||||
} else {
|
||||
smaInfo("vgId:%d, vnode snapshot rsma writer close succeed", pSma ? SMA_VID(pSma) : 0);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t rsmaSnapWrite(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
|
@ -244,7 +243,7 @@ int32_t rsmaSnapWrite(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData)
|
|||
} else {
|
||||
code = TSDB_CODE_RSMA_FS_SYNC;
|
||||
}
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
|
@ -253,5 +252,5 @@ _exit:
|
|||
} else {
|
||||
smaInfo("vgId:%d, rsma snapshot write for data type %" PRIi8 " succeed", SMA_VID(pWriter->pSma), pHdr->type);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
|
|
@ -32,19 +32,19 @@ int32_t tdProcessTSmaInsert(SSma *pSma, int64_t indexUid, const char *msg) {
|
|||
smaError("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t tdProcessTSmaCreate(SSma *pSma, int64_t ver, const char *msg) {
|
||||
int32_t code = tdProcessTSmaCreateImpl(pSma, ver, msg);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) {
|
||||
int32_t code = tdProcessTSmaGetDaysImpl(pCfg, pCont, contLen, days);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,8 +70,8 @@ static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t c
|
|||
|
||||
STsdbCfg *pTsdbCfg = &pCfg->tsdbCfg;
|
||||
int64_t sInterval = -1;
|
||||
code = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_SECOND, &sInterval);
|
||||
if (TSDB_CODE_SUCCESS != code || 0 == sInterval) {
|
||||
TAOS_CHECK_EXIT(convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_SECOND, &sInterval));
|
||||
if (0 == sInterval) {
|
||||
*days = pTsdbCfg->days;
|
||||
goto _exit;
|
||||
}
|
||||
|
@ -80,10 +80,7 @@ static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t c
|
|||
*days = pTsdbCfg->days;
|
||||
} else {
|
||||
int64_t mInterval = -1;
|
||||
code = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE, &mInterval);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_EXIT(convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE, &mInterval));
|
||||
int64_t daysPerFile = mInterval * SMA_STORAGE_MINUTES_DAY * 2;
|
||||
|
||||
if (daysPerFile > SMA_STORAGE_MINUTES_MAX) {
|
||||
|
@ -103,7 +100,7 @@ _exit:
|
|||
smaDebug("vgId:%d, succeed to get tsma days %d", pCfg->vgId, *days);
|
||||
}
|
||||
tDecoderClear(&coder);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,10 +120,7 @@ static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t ver, const char *pMsg
|
|||
|
||||
if (TD_VID(pSma->pVnode) == pCfg->dstVgId) {
|
||||
// create tsma meta in dstVgId
|
||||
if (metaCreateTSma(SMA_META(pSma), ver, pCfg) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_EXIT(metaCreateTSma(SMA_META(pSma), ver, pCfg));
|
||||
|
||||
// create stable to save tsma result in dstVgId
|
||||
tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
@ -135,28 +129,24 @@ static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t ver, const char *pMsg
|
|||
pReq.schemaRow = pCfg->schemaRow;
|
||||
pReq.schemaTag = pCfg->schemaTag;
|
||||
|
||||
if (metaCreateSTable(SMA_META(pSma), ver, &pReq) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_EXIT(metaCreateSTable(SMA_META(pSma), ver, &pReq));
|
||||
} else {
|
||||
code = terrno = TSDB_CODE_TSMA_INVALID_STAT;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_TSMA_INVALID_STAT);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, failed at line %d to create sma index %s %" PRIi64 " on stb:%" PRIi64 ", dstSuid:%" PRIi64
|
||||
" dstTb:%s dstVg:%d",
|
||||
" dstTb:%s dstVg:%d since %s",
|
||||
SMA_VID(pSma), lino, pCfg->indexName, pCfg->indexUid, pCfg->tableUid, pCfg->dstTbUid, pReq.name,
|
||||
pCfg->dstVgId);
|
||||
pCfg->dstVgId, tstrerror(code));
|
||||
} else {
|
||||
smaDebug("vgId:%d, success to create sma index %s %" PRIi64 " on stb:%" PRIi64 ", dstSuid:%" PRIi64
|
||||
" dstTb:%s dstVg:%d",
|
||||
SMA_VID(pSma), pCfg->indexName, pCfg->indexUid, pCfg->tableUid, pCfg->dstTbUid, pReq.name, pCfg->dstVgId);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *pTSchema, int64_t suid,
|
||||
|
@ -167,6 +157,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
int32_t len = 0;
|
||||
SSubmitReq2 *pReq = NULL;
|
||||
SArray *tagArray = NULL;
|
||||
SHashObj *pTableIndexMap = NULL;
|
||||
|
||||
int32_t numOfBlocks = taosArrayGetSize(pBlocks);
|
||||
|
||||
|
@ -174,18 +165,18 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
pReq = taosMemoryCalloc(1, sizeof(SSubmitReq2));
|
||||
|
||||
if (!tagArray || !pReq) {
|
||||
code = terrno == TSDB_CODE_SUCCESS ? TSDB_CODE_OUT_OF_MEMORY : terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pReq->aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData));
|
||||
if (pReq->aSubmitTbData == NULL) {
|
||||
code = terrno == TSDB_CODE_SUCCESS ? TSDB_CODE_OUT_OF_MEMORY : terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SHashObj *pTableIndexMap =
|
||||
taosHashInit(numOfBlocks, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
pTableIndexMap = taosHashInit(numOfBlocks, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
if (pTableIndexMap == NULL) {
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// SSubmitTbData req
|
||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||
|
@ -193,8 +184,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
pDeleteReq->suid = suid;
|
||||
pDeleteReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
code = tqBuildDeleteReq(pVnode->pTq, stbFullName, pDataBlock, pDeleteReq, "", true);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_EXIT(tqBuildDeleteReq(pVnode->pTq, stbFullName, pDataBlock, pDeleteReq, "", true));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -202,11 +192,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
|
||||
int32_t cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1;
|
||||
|
||||
code = buildAutoCreateTableReq(stbFullName, suid, cid, pDataBlock, tagArray, true, &tbData.pCreateTbReq);
|
||||
if (code) {
|
||||
smaError("failed to build create-table req, code:%d", code);
|
||||
continue;
|
||||
}
|
||||
TAOS_CHECK_EXIT(buildAutoCreateTableReq(stbFullName, suid, cid, pDataBlock, tagArray, true, &tbData.pCreateTbReq));
|
||||
|
||||
{
|
||||
uint64_t groupId = pDataBlock->info.id.groupId;
|
||||
|
@ -218,10 +204,13 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
continue;
|
||||
}
|
||||
|
||||
taosArrayPush(pReq->aSubmitTbData, &tbData);
|
||||
if( taosArrayPush(pReq->aSubmitTbData, &tbData) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t size = (int32_t)taosArrayGetSize(pReq->aSubmitTbData) - 1;
|
||||
taosHashPut(pTableIndexMap, &groupId, sizeof(groupId), &size, sizeof(size));
|
||||
TAOS_CHECK_EXIT(taosHashPut(pTableIndexMap, &groupId, sizeof(groupId), &size, sizeof(size)));
|
||||
} else {
|
||||
code = tqSetDstTableDataPayload(suid, pTSchema, i, pDataBlock, &tbData, INT64_MIN, "");
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -237,15 +226,13 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
}
|
||||
}
|
||||
|
||||
taosHashCleanup(pTableIndexMap);
|
||||
|
||||
// encode
|
||||
tEncodeSize(tEncodeSubmitReq, pReq, len, code);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SEncoder encoder;
|
||||
len += sizeof(SSubmitReq2Msg);
|
||||
if (!(pBuf = rpcMallocCont(len))) {
|
||||
code = terrno;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -253,9 +240,8 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
((SSubmitReq2Msg *)pBuf)->header.contLen = htonl(len);
|
||||
((SSubmitReq2Msg *)pBuf)->version = htobe64(1);
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
|
||||
if (tEncodeSubmitReq(&encoder, pReq) < 0) {
|
||||
if ((code = tEncodeSubmitReq(&encoder, pReq)) < 0) {
|
||||
tEncoderClear(&encoder);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
|
@ -263,6 +249,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
|
||||
_exit:
|
||||
taosArrayDestroy(tagArray);
|
||||
taosHashCleanup(pTableIndexMap);
|
||||
if (pReq != NULL) {
|
||||
tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFree(pReq);
|
||||
|
@ -276,7 +263,7 @@ _exit:
|
|||
if (ppData) *ppData = pBuf;
|
||||
if (pLen) *pLen = len;
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq *pDelReq) {
|
||||
|
@ -290,7 +277,7 @@ static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq *
|
|||
|
||||
void *pBuf = rpcMallocCont(len + sizeof(SMsgHead));
|
||||
if (!pBuf) {
|
||||
code = terrno;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -313,7 +300,7 @@ _exit:
|
|||
indexUid, tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -350,16 +337,15 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
pTsmaStat = SMA_STAT_TSMA(pStat);
|
||||
|
||||
if (!pTsmaStat->pTSma) {
|
||||
terrno = 0;
|
||||
STSma *pTSma = metaGetSmaInfoByIndex(SMA_META(pSma), indexUid);
|
||||
if (!pTSma) {
|
||||
code = terrno ? terrno : TSDB_CODE_TSMA_INVALID_PTR;
|
||||
code = TSDB_CODE_TSMA_INVALID_PTR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
pTsmaStat->pTSma = pTSma;
|
||||
pTsmaStat->pTSchema = metaGetTbTSchema(SMA_META(pSma), pTSma->dstTbUid, -1, 1);
|
||||
if (!pTsmaStat->pTSchema) {
|
||||
code = terrno ? terrno : TSDB_CODE_TSMA_INVALID_PTR;
|
||||
code = TSDB_CODE_TSMA_INVALID_PTR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
|
@ -378,15 +364,13 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
pTsmaStat->pTSma->dstTbName, &deleteReq, &pSubmitReq, &contLen);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
if ((terrno = tsmaProcessDelReq(pSma, indexUid, &deleteReq)) != 0) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_EXIT(tsmaProcessDelReq(pSma, indexUid, &deleteReq));
|
||||
|
||||
#if 0
|
||||
if (!strncasecmp("td.tsma.rst.tb", pTsmaStat->pTSma->dstTbName, 14)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
smaError("vgId:%d, tsma insert for smaIndex %" PRIi64 " failed since %s, %s", SMA_VID(pSma), indexUid,
|
||||
pTsmaStat->pTSma->indexUid, tstrerror(terrno), pTsmaStat->pTSma->dstTbName);
|
||||
pTsmaStat->pTSma->indexUid, tstrerror(code), pTsmaStat->pTSma->dstTbName);
|
||||
goto _err;
|
||||
}
|
||||
#endif
|
||||
|
@ -405,5 +389,5 @@ _exit:
|
|||
smaError("vgId:%d, %s failed at line %d since %s, smaIndex:%" PRIi64, SMA_VID(pSma), __func__, lino,
|
||||
tstrerror(code), indexUid);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
|
|
@ -19,19 +19,19 @@
|
|||
void tdRSmaQTaskInfoGetFullPath(SVnode *pVnode, tb_uid_t suid, int8_t level, STfs *pTfs, char *outputName) {
|
||||
tdRSmaGetDirName(pVnode, pTfs, true, outputName);
|
||||
int32_t rsmaLen = strlen(outputName);
|
||||
snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8 "%s%" PRIi64, level, TD_DIRSEP, suid);
|
||||
(void)snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8 "%s%" PRIi64, level, TD_DIRSEP, suid);
|
||||
}
|
||||
|
||||
void tdRSmaGetDirName(SVnode *pVnode, STfs *pTfs, bool endWithSep, char *outputName) {
|
||||
int32_t offset = 0;
|
||||
|
||||
// vnode
|
||||
vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pTfs, outputName, TSDB_FILENAME_LEN);
|
||||
(void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pTfs, outputName, TSDB_FILENAME_LEN);
|
||||
offset = strlen(outputName);
|
||||
|
||||
// rsma
|
||||
snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s%s", TD_DIRSEP, VNODE_RSMA_DIR,
|
||||
(endWithSep ? TD_DIRSEP : ""));
|
||||
(void)snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s%s", TD_DIRSEP, VNODE_RSMA_DIR,
|
||||
(endWithSep ? TD_DIRSEP : ""));
|
||||
}
|
||||
|
||||
// smaXXXUtil ================
|
||||
|
@ -39,9 +39,10 @@ void *tdAcquireSmaRef(int32_t rsetId, int64_t refId) { return taosAcquireRef(rse
|
|||
|
||||
int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId) {
|
||||
if (taosReleaseRef(rsetId, refId) < 0) {
|
||||
smaWarn("rsma release ref for rsetId:%d refId:%" PRIi64 " failed since %s", rsetId, refId, terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
int32_t code = terrno;
|
||||
smaWarn("rsma release ref for rsetId:%d refId:%" PRIi64 " failed since %s", rsetId, refId, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -523,12 +523,8 @@ static int32_t tsdbFSDoSanAndFix(STFileSystem *fs) {
|
|||
}
|
||||
|
||||
{ // clear unreferenced files
|
||||
STfsDir *dir = tfsOpendir(fs->tsdb->pVnode->pTfs, fs->tsdb->path);
|
||||
if (dir == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(terrno);
|
||||
lino = __LINE__;
|
||||
goto _exit;
|
||||
}
|
||||
STfsDir *dir = NULL;
|
||||
TAOS_CHECK_GOTO(tfsOpendir(fs->tsdb->pVnode->pTfs, fs->tsdb->path, &dir), &lino, _exit);
|
||||
|
||||
STFileHash fobjHash = {0};
|
||||
code = tsdbFSCreateFileObjHash(fs, &fobjHash);
|
||||
|
|
|
@ -34,7 +34,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq2 *pMsg, SSubmitRsp2
|
|||
int32_t numOfRows = 0;
|
||||
|
||||
if (ASSERTS(pTsdb->mem != NULL, "vgId:%d, mem is NULL", TD_VID(pTsdb->pVnode))) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PTR);
|
||||
}
|
||||
|
||||
arrSize = taosArrayGetSize(pMsg->aSubmitTbData);
|
||||
|
@ -42,7 +42,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq2 *pMsg, SSubmitRsp2
|
|||
// scan and convert
|
||||
if ((code = tsdbScanAndConvertSubmitMsg(pTsdb, pMsg)) < 0) {
|
||||
if (code != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||
tsdbError("vgId:%d, failed to insert data since %s", TD_VID(pTsdb->pVnode), tstrerror(terrno));
|
||||
tsdbError("vgId:%d, failed to insert data since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -175,7 +175,8 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr
|
|||
snprintf(tsdbFilePrefix, TSDB_FILENAME_LEN, "tsdb%sv", TD_DIRSEP);
|
||||
int32_t prefixLen = strlen(tsdbFilePrefix);
|
||||
|
||||
STfsDir *tsdbDir = tfsOpendir(pTfs, tsdbPath);
|
||||
STfsDir *tsdbDir = NULL;
|
||||
(void)tfsOpendir(pTfs, tsdbPath, &tsdbDir);
|
||||
if (tsdbDir == NULL) return 0;
|
||||
|
||||
while (1) {
|
||||
|
@ -280,12 +281,13 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s
|
|||
int32_t diskPrimary, STfs *pTfs) {
|
||||
SVnodeInfo info = {0};
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
vnodeGetPrimaryDir(dstPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
||||
if (vnodeLoadInfo(dir, &info) == 0) {
|
||||
if (info.config.vgId != dstVgId) {
|
||||
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return dstVgId;
|
||||
}
|
||||
|
@ -301,13 +303,13 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s
|
|||
return srcVgId;
|
||||
} else if (info.config.vgId != dstVgId) {
|
||||
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
vInfo("vgId:%d, rename %s to %s", dstVgId, srcPath, dstPath);
|
||||
if (vnodeRenameVgroupId(srcPath, dstPath, srcVgId, dstVgId, diskPrimary, pTfs) < 0) {
|
||||
vError("vgId:%d, failed to rename vnode from %s to %s since %s", dstVgId, srcPath, dstPath, tstrerror(terrno));
|
||||
return -1;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return dstVgId;
|
||||
|
@ -332,8 +334,7 @@ static int32_t vnodeCheckDisk(int32_t diskPrimary, STfs *pTfs) {
|
|||
}
|
||||
if (diskPrimary < 0 || diskPrimary >= ndisk) {
|
||||
vError("disk:%d is unavailable from the %d disks mounted at level 0", diskPrimary, ndisk);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -601,7 +601,7 @@ int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
|
||||
if (!pCur) {
|
||||
return TSDB_CODE_FAILED;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
|
|
@ -513,6 +513,7 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
void *ptr = NULL;
|
||||
void *pReq;
|
||||
int32_t len;
|
||||
|
@ -520,8 +521,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
if (ver <= pVnode->state.applied) {
|
||||
vError("vgId:%d, duplicate write request. ver: %" PRId64 ", applied: %" PRId64 "", TD_VID(pVnode), ver,
|
||||
pVnode->state.applied);
|
||||
terrno = TSDB_CODE_VND_DUP_REQUEST;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_VND_DUP_REQUEST;
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, start to process write request %s, index:%" PRId64 ", applied:%" PRId64 ", state.applyTerm:%" PRId64
|
||||
|
@ -693,7 +693,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
break;
|
||||
default:
|
||||
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
|
||||
|
@ -701,21 +701,24 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
|
||||
walApplyVer(pVnode->pWal, ver);
|
||||
|
||||
if (tqPushMsg(pVnode->pTq, pMsg->msgType) < 0) {
|
||||
code = tqPushMsg(pVnode->pTq, pMsg->msgType);
|
||||
if (code) {
|
||||
vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
// commit if need
|
||||
if (needCommit) {
|
||||
vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), ver);
|
||||
if (vnodeAsyncCommit(pVnode) < 0) {
|
||||
code = vnodeAsyncCommit(pVnode);
|
||||
if (code) {
|
||||
vError("vgId:%d, failed to vnode async commit since %s.", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// start a new one
|
||||
if (vnodeBegin(pVnode) < 0) {
|
||||
code = vnodeBegin(pVnode);
|
||||
if (code) {
|
||||
vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
@ -727,7 +730,7 @@ _exit:
|
|||
_err:
|
||||
vError("vgId:%d, process %s request failed since %s, ver:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
|
||||
tstrerror(terrno), ver);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
|
@ -987,11 +990,18 @@ static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void
|
|||
if (terrno < 0) goto _end;
|
||||
strncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
void *p = taosArrayPush(pNames, buf);
|
||||
if (p == NULL) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
expiredTb.name = p;
|
||||
if (mr.me.type == TSDB_CHILD_TABLE) {
|
||||
expiredTb.suid = mr.me.ctbEntry.suid;
|
||||
}
|
||||
taosArrayPush(rsp.pExpiredTbs, &expiredTb);
|
||||
|
||||
if (taosArrayPush(rsp.pExpiredTbs, &expiredTb) == NULL) {
|
||||
goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
|
@ -1017,6 +1027,7 @@ _end:
|
|||
}
|
||||
|
||||
static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder coder;
|
||||
|
||||
|
@ -1028,18 +1039,20 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
// decode and process req
|
||||
tDecoderInit(&coder, pReq, len);
|
||||
|
||||
if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
code = tDecodeSVCreateStbReq(&coder, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (metaCreateSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
code = metaCreateSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (tdProcessRSmaCreate(pVnode->pSma, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
if ((code = tdProcessRSmaCreate(pVnode->pSma, &req)) < 0) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
@ -1048,7 +1061,7 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
|
||||
_err:
|
||||
tDecoderClear(&coder);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp,
|
||||
|
@ -1100,7 +1113,11 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
goto _exit;
|
||||
}
|
||||
strcpy(str, pCreateReq->name);
|
||||
taosArrayPush(tbNames, &str);
|
||||
if (taosArrayPush(tbNames, &str) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
// validate hash
|
||||
|
@ -1185,6 +1202,7 @@ _exit:
|
|||
}
|
||||
|
||||
static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder dc = {0};
|
||||
|
||||
|
@ -1196,16 +1214,17 @@ static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
tDecoderInit(&dc, pReq, len);
|
||||
|
||||
// decode req
|
||||
if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = tDecodeSVCreateStbReq(&dc, &req);
|
||||
if (code) {
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (metaAlterSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
code = metaAlterSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tDecoderClear(&dc);
|
||||
|
@ -2224,6 +2243,7 @@ _err:
|
|||
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder dc = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
pRsp->msgType = TDMT_VND_CREATE_INDEX_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
|
@ -2233,35 +2253,38 @@ static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
tDecoderInit(&dc, pReq, len);
|
||||
// decode req
|
||||
if (tDecodeSVCreateStbReq(&dc, &req) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
if (metaAddIndexToSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
|
||||
code = metaAddIndexToSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
goto _err;
|
||||
}
|
||||
tDecoderClear(&dc);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tDecoderClear(&dc);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SDropIndexReq req = {0};
|
||||
int32_t code = 0;
|
||||
pRsp->msgType = TDMT_VND_DROP_INDEX_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
|
||||
if (tDeserializeSDropIdxReq(pReq, len, &req)) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
if ((code = tDeserializeSDropIdxReq(pReq, len, &req))) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (metaDropIndexFromSTable(pVnode->pMeta, ver, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
return -1;
|
||||
code = metaDropIndexFromSTable(pVnode->pMeta, ver, &req);
|
||||
if (code) {
|
||||
pRsp->code = code;
|
||||
return code;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -2290,20 +2313,17 @@ static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pR
|
|||
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
|
||||
SSyncState syncState = syncGetState(pVnode->sync);
|
||||
if (syncState.state != TAOS_SYNC_STATE_LEADER) {
|
||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
}
|
||||
|
||||
char token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
if (vnodeGetArbToken(pVnode, token) != 0) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
|
||||
strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
return -1;
|
||||
return terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
@ -2324,9 +2344,9 @@ static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t l
|
|||
|
||||
SVArbCheckSyncReq syncReq = {0};
|
||||
|
||||
if (tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq);
|
||||
if (code) {
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
|
||||
|
|
|
@ -371,7 +371,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
pDisks.disable = 0;
|
||||
strncpy(pDisks.dir, TD_DATA_DIR_PATH, TSDB_FILENAME_LEN);
|
||||
int32_t numOfDisks = 1;
|
||||
pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks);
|
||||
(void)tfsOpen(&pDisks, numOfDisks, &pTsdb->pTfs);
|
||||
EXPECT_NE(pTsdb->pTfs, nullptr);
|
||||
|
||||
// generate SSubmitReq msg and update expire window
|
||||
|
|
|
@ -2672,7 +2672,7 @@ _return:
|
|||
ctgReleaseVgInfoToCache(pCtg, pDbCache);
|
||||
}
|
||||
if (pTsma) {
|
||||
tFreeTableTSMAInfo(pTsma);
|
||||
tFreeAndClearTableTSMAInfo(pTsma);
|
||||
pTsma = NULL;
|
||||
}
|
||||
if (pVgHash) {
|
||||
|
|
|
@ -3546,15 +3546,23 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
|
|||
continue;
|
||||
}
|
||||
|
||||
int32_t schemaExtSize = 0;
|
||||
if (stbMeta->schemaExt != NULL) {
|
||||
schemaExtSize = stbMeta->tableInfo.numOfColumns * sizeof(SSchemaExt);
|
||||
}
|
||||
metaSize = CTG_META_SIZE(stbMeta);
|
||||
pTableMeta = taosMemoryRealloc(pTableMeta, metaSize);
|
||||
pTableMeta = taosMemoryRealloc(pTableMeta, metaSize + schemaExtSize);
|
||||
if (NULL == pTableMeta) {
|
||||
ctgReleaseTbMetaToCache(pCtg, dbCache, pCache);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
TAOS_MEMCPY(&pTableMeta->sversion, &stbMeta->sversion, metaSize - sizeof(SCTableMeta));
|
||||
pTableMeta->schemaExt = NULL;
|
||||
TAOS_MEMCPY(&pTableMeta->sversion, &stbMeta->sversion, metaSize + schemaExtSize - sizeof(SCTableMeta));
|
||||
if (stbMeta->schemaExt != NULL) {
|
||||
pTableMeta->schemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
|
||||
} else {
|
||||
pTableMeta->schemaExt = NULL;
|
||||
}
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &pCache->metaLock);
|
||||
taosHashRelease(dbCache->tbCache, pCache);
|
||||
|
|
|
@ -163,10 +163,10 @@ int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNo
|
|||
SNodeList *pPhysiChildren = pNode->pChildren;
|
||||
|
||||
if (pPhysiChildren) {
|
||||
*pChildren = nodesMakeList();
|
||||
int32_t code = nodesMakeList(pChildren);
|
||||
if (NULL == *pChildren) {
|
||||
qError("nodesMakeList failed");
|
||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
QRY_ERR_RET(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
longjmp((_obj), (_c)); \
|
||||
} while (0)
|
||||
|
||||
#define SET_RES_WINDOW_KEY(_k, _ori, _len, _uid) \
|
||||
do { \
|
||||
assert(sizeof(_uid) == sizeof(uint64_t)); \
|
||||
*(uint64_t*)(_k) = (_uid); \
|
||||
memcpy((_k) + sizeof(uint64_t), (_ori), (_len)); \
|
||||
#define SET_RES_WINDOW_KEY(_k, _ori, _len, _uid) \
|
||||
do { \
|
||||
assert(sizeof(_uid) == sizeof(uint64_t)); \
|
||||
*(uint64_t*)(_k) = (_uid); \
|
||||
(void)memcpy((_k) + sizeof(uint64_t), (_ori), (_len)); \
|
||||
} while (0)
|
||||
|
||||
#define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t))
|
||||
|
@ -175,7 +175,7 @@ int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
int32_t type, SColMatchInfo* pMatchInfo);
|
||||
|
||||
int32_t createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId);
|
||||
int32_t createExprFromTargetNode(SExprInfo* pExp, STargetNode* pTargetNode);
|
||||
int32_t createExprFromTargetNode(SExprInfo* pExp, STargetNode* pTargetNode);
|
||||
SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* numOfExprs);
|
||||
|
||||
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowEntryInfoOffset,
|
||||
|
|
|
@ -24,7 +24,6 @@ extern "C" {
|
|||
#include "theap.h"
|
||||
#include "tlosertree.h"
|
||||
#include "tsort.h"
|
||||
#include "ttszip.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
#include "dataSinkMgt.h"
|
||||
|
@ -365,6 +364,7 @@ typedef struct STagScanFilterContext {
|
|||
SHashObj* colHash;
|
||||
int32_t index;
|
||||
SArray* cInfoList;
|
||||
int32_t code;
|
||||
} STagScanFilterContext;
|
||||
|
||||
typedef struct STagScanInfo {
|
||||
|
@ -904,7 +904,7 @@ int32_t appendDataToSpecialBlock(SSDataBlock* pBlock, TSKEY* pStartTs, TSKEY* pE
|
|||
uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t rowId);
|
||||
|
||||
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
|
||||
SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
bool groupbyTbname(SNodeList* pGroupList);
|
||||
void getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
|
||||
|
|
|
@ -128,9 +128,9 @@ SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfFillExpr, SExprIn
|
|||
int32_t numOfNotFillCols, const struct SNodeListNode* val);
|
||||
bool taosFillHasMoreResults(struct SFillInfo* pFillInfo);
|
||||
|
||||
SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
|
||||
SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t slotId,
|
||||
int32_t order, const char* id, SExecTaskInfo* pTaskInfo);
|
||||
void taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t numOfNotFillCols, int32_t capacity,
|
||||
SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t slotId,
|
||||
int32_t order, const char* id, SExecTaskInfo* pTaskInfo, SFillInfo** ppFillInfo);
|
||||
|
||||
void* taosDestroyFillInfo(struct SFillInfo* pFillInfo);
|
||||
int32_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity);
|
||||
|
|
|
@ -252,14 +252,15 @@ _end:
|
|||
return pBlock != NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
||||
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
SAggOperatorInfo* pAggInfo = pOperator->info;
|
||||
SOptrBasicInfo* pInfo = &pAggInfo->binfo;
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -291,10 +292,18 @@ SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
|||
_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 (rows == 0) ? NULL : pInfo->pRes;
|
||||
(*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = getAggregateResultNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
|
||||
|
@ -371,7 +380,7 @@ static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBloc
|
|||
|
||||
for (int32_t k = numOfCols; k < slotId + 1; ++k) {
|
||||
void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
|
||||
}
|
||||
}
|
||||
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
||||
|
|
|
@ -132,20 +132,20 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
}
|
||||
|
||||
SArray* pCidList = taosArrayInit(numOfCols, sizeof(int16_t));
|
||||
QUERY_CHECK_NULL(pCidList, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(pCidList, code, lino, _error, terrno);
|
||||
|
||||
pInfo->pFuncTypeList = taosArrayInit(taosArrayGetSize(pScanNode->pFuncTypes), sizeof(int32_t));
|
||||
QUERY_CHECK_NULL(pInfo->pFuncTypeList, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(pInfo->pFuncTypeList, code, lino, _error, terrno);
|
||||
|
||||
void* tmp = taosArrayAddAll(pInfo->pFuncTypeList, pScanNode->pFuncTypes);
|
||||
if (!tmp && taosArrayGetSize(pScanNode->pFuncTypes) > 0) {
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _error, terrno);
|
||||
}
|
||||
|
||||
for (int i = 0; i < TARRAY_SIZE(pInfo->matchInfo.pList); ++i) {
|
||||
SColMatchItem* pColInfo = taosArrayGet(pInfo->matchInfo.pList, i);
|
||||
void* tmp = taosArrayPush(pCidList, &pColInfo->colId);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _error, TSDB_CODE_OUT_OF_MEMORY);
|
||||
void* tmp = taosArrayPush(pCidList, &pColInfo->colId);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _error, terrno);
|
||||
if (pInfo->pFuncTypeList != NULL && taosArrayGetSize(pInfo->pFuncTypeList) > i) {
|
||||
pColInfo->funcType = *(int32_t*)taosArrayGet(pInfo->pFuncTypeList, i);
|
||||
}
|
||||
|
@ -219,9 +219,12 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
||||
int32_t doScanCacheNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
SCacheRowsScanInfo* pInfo = pOperator->info;
|
||||
|
@ -234,7 +237,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
int32_t size = tableListGetSize(pTableList);
|
||||
if (size == 0) {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
|
@ -249,11 +253,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
blockDataCleanup(pBufRes);
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
|
||||
int32_t code =
|
||||
code =
|
||||
pReaderFn->retrieveRows(pInfo->pLastrowReader, pBufRes, pInfo->pSlotIds, pInfo->pDstSlotIds, pInfo->pUidList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
// check for tag values
|
||||
int32_t resultRows = pBufRes->info.rows;
|
||||
|
@ -277,12 +279,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
colDataSetNULL(pDst, 0);
|
||||
} else {
|
||||
if (pSrc->pData) {
|
||||
char* p = colDataGetData(pSrc, pInfo->indexOfBufferedRes);
|
||||
int32_t code = colDataSetVal(pDst, 0, p, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
char* p = colDataGetData(pSrc, pInfo->indexOfBufferedRes);
|
||||
code = colDataSetVal(pDst, 0, p, false);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -292,19 +291,22 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
pRes->info.scanFlag = MAIN_SCAN;
|
||||
|
||||
SExprSupp* pSup = &pInfo->pseudoExprSup;
|
||||
int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pRes,
|
||||
pRes->info.rows, pTaskInfo, NULL);
|
||||
code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pRes, pRes->info.rows,
|
||||
pTaskInfo, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
pRes->info.id.groupId = tableListGetTableGroupId(pTableList, pRes->info.id.uid);
|
||||
pInfo->indexOfBufferedRes += 1;
|
||||
return pRes;
|
||||
(*ppRes) = pRes;
|
||||
return code;
|
||||
} else {
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
size_t totalGroups = tableListGetOutputGroups(pTableList);
|
||||
|
@ -317,37 +319,30 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
STableKeyInfo* pList = NULL;
|
||||
int32_t num = 0;
|
||||
|
||||
int32_t code = tableListGetGroupList(pTableList, pInfo->currentGroupIndex, &pList, &num);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
code = tableListGetGroupList(pTableList, pInfo->currentGroupIndex, &pList, &num);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
if (NULL == pInfo->pLastrowReader) {
|
||||
code = pReaderFn->openReader(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), pInfo->pCidList, pInfo->pSlotIds, suid,
|
||||
&pInfo->pLastrowReader, pTaskInfo->id.str, pInfo->pFuncTypeList, &pInfo->pkCol,
|
||||
pInfo->numOfPks);
|
||||
int32_t tmpRes = pReaderFn->openReader(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), pInfo->pCidList,
|
||||
pInfo->pSlotIds, suid, &pInfo->pLastrowReader, pTaskInfo->id.str,
|
||||
pInfo->pFuncTypeList, &pInfo->pkCol, pInfo->numOfPks);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (tmpRes != TSDB_CODE_SUCCESS) {
|
||||
pInfo->currentGroupIndex += 1;
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
code = pReaderFn->reuseReader(pInfo->pLastrowReader, pList, num);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
}
|
||||
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
|
||||
code = pReaderFn->retrieveRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pDstSlotIds,
|
||||
pInfo->pUidList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
pInfo->currentGroupIndex += 1;
|
||||
|
||||
|
@ -365,13 +360,15 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
pInfo->pRes->info.rows, pTaskInfo, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader);
|
||||
return pInfo->pRes;
|
||||
(*ppRes) = pInfo->pRes;
|
||||
return code;
|
||||
} else {
|
||||
// pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader);
|
||||
}
|
||||
|
@ -380,8 +377,23 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
pReaderFn->closeReader(pInfo->pLastrowReader);
|
||||
pInfo->pLastrowReader = NULL;
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
(*ppRes) = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
_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 code;
|
||||
}
|
||||
|
||||
static SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = doScanCacheNext(pOperator, &pRes);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void destroyCacheScanOperator(void* param) {
|
||||
|
@ -457,7 +469,7 @@ int32_t removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SColMatchInfo* pC
|
|||
|
||||
size_t size = taosArrayGetSize(pColMatchInfo->pList);
|
||||
SArray* pMatchInfo = taosArrayInit(size, sizeof(SColMatchItem));
|
||||
QUERY_CHECK_NULL(pMatchInfo, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(pMatchInfo, code, lino, _end, terrno);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SColMatchItem* pColInfo = taosArrayGet(pColMatchInfo->pList, i);
|
||||
|
@ -468,10 +480,10 @@ int32_t removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SColMatchInfo* pC
|
|||
SSlotDescNode* pDesc = (SSlotDescNode*)nodesListGetNode(pList, slotId);
|
||||
if (pDesc->dataType.type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
void* tmp = taosArrayPush(pMatchInfo, pColInfo);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
|
||||
} else if (FUNCTION_TYPE_CACHE_LAST_ROW == pColInfo->funcType) {
|
||||
void* tmp = taosArrayPush(pMatchInfo, pColInfo);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _end, TSDB_CODE_OUT_OF_MEMORY);
|
||||
QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue