fix:[TD-31017]process return value in vnode for tmq
This commit is contained in:
commit
e0483d00fe
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -4041,7 +4041,9 @@ static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
|
|||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqSubTopicEp topicEp;
|
||||
buf = tDecodeMqSubTopicEp(buf, &topicEp);
|
||||
taosArrayPush(pRsp->topics, &topicEp);
|
||||
if (taosArrayPush(pRsp->topics, &topicEp) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t pr
|
|||
int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision, char* errMsg,
|
||||
int32_t errMsgLen);
|
||||
|
||||
void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen);
|
||||
int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen);
|
||||
int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr);
|
||||
|
||||
/// @brief get offset seconds from zero timezone to input timezone
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,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
|
||||
|
|
|
@ -41,7 +41,7 @@ static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) {
|
|||
|
||||
pBuf = (uint8_t *)taosMemoryRealloc(pBuf, bsize + sizeof(int64_t));
|
||||
if (pBuf == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arr, int32_t expSize, int32_
|
|||
capacity <<= 1;
|
||||
}
|
||||
void *p = taosMemoryRealloc(a->data, capacity * eleSize);
|
||||
if (p == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (p == NULL) return terrno;
|
||||
a->capacity = capacity;
|
||||
a->data = p;
|
||||
return 0;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ typedef struct {
|
|||
typedef struct SConfig SConfig;
|
||||
typedef struct SConfigIter SConfigIter;
|
||||
|
||||
SConfig *cfgInit();
|
||||
int32_t cfgInit(SConfig **ppCfg);
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
|
||||
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
||||
void cfgCleanup(SConfig *pCfg);
|
||||
|
@ -110,7 +110,7 @@ SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName);
|
|||
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock);
|
||||
int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer);
|
||||
|
||||
SConfigIter *cfgCreateIter(SConfig *pConf);
|
||||
int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter);
|
||||
SConfigItem *cfgNextIter(SConfigIter *pIter);
|
||||
void cfgDestroyIter(SConfigIter *pIter);
|
||||
void cfgLock(SConfig *pCfg);
|
||||
|
@ -131,8 +131,8 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal,
|
|||
const char *cfgStypeStr(ECfgSrcType type);
|
||||
const char *cfgDtypeStr(ECfgDataType type);
|
||||
|
||||
void cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
void cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
int32_t cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
int32_t cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
|
||||
|
||||
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
||||
void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -79,7 +79,7 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
|
|||
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) {
|
||||
|
@ -153,11 +153,11 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
#define TCONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
|
||||
|
||||
#define TAOS_GET_TERRNO(code) \
|
||||
(terrno == 0 ? code : terrno) \
|
||||
(terrno == 0 ? code : terrno)
|
||||
|
||||
#define TAOS_RETURN(code) \
|
||||
#define TAOS_RETURN(CODE) \
|
||||
do { \
|
||||
return (terrno = (code)); \
|
||||
return (terrno = (CODE)); \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_CHECK_RETURN(CMD) \
|
||||
|
@ -179,6 +179,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -332,8 +332,7 @@ static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) {
|
|||
return (SReqResultInfo*)&msg->common.resInfo;
|
||||
}
|
||||
|
||||
SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4);
|
||||
|
||||
int32_t tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4, SReqResultInfo** pResInfo);
|
||||
static FORCE_INLINE SReqResultInfo* tscGetCurResInfo(TAOS_RES* res) {
|
||||
if (TD_RES_QUERY(res)) return &(((SRequestObj*)res)->body.resInfo);
|
||||
return tmqGetCurResInfo(res);
|
||||
|
|
|
@ -426,9 +426,11 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
return doAsyncFetchRows(pRequest, true, true);
|
||||
} else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
||||
SReqResultInfo *pResultInfo;
|
||||
SReqResultInfo *pResultInfo = NULL;
|
||||
if (msg->common.resIter == -1) {
|
||||
pResultInfo = tmqGetNextResInfo(res, true);
|
||||
if(tmqGetNextResInfo(res, true, &pResultInfo) != 0){
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
pResultInfo = tmqGetCurResInfo(res);
|
||||
}
|
||||
|
@ -438,8 +440,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
pResultInfo->current += 1;
|
||||
return pResultInfo->row;
|
||||
} else {
|
||||
pResultInfo = tmqGetNextResInfo(res, true);
|
||||
if (pResultInfo == NULL) {
|
||||
if (tmqGetNextResInfo(res, true, &pResultInfo) != 0){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -754,8 +755,9 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
return pRequest->code;
|
||||
} else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res, true);
|
||||
if (pResultInfo == NULL) return -1;
|
||||
SReqResultInfo *pResultInfo = NULL;
|
||||
int32_t code = tmqGetNextResInfo(res, true, &pResultInfo);
|
||||
if (code != 0) return code;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*rows) = pResultInfo->row;
|
||||
|
@ -776,8 +778,9 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
}
|
||||
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res, false);
|
||||
if (pResultInfo == NULL) {
|
||||
SReqResultInfo *pResultInfo = NULL;
|
||||
int32_t code = tmqGetNextResInfo(res, false, &pResultInfo);
|
||||
if (code != 0) {
|
||||
(*numOfRows) = 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1263,8 +1263,8 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
if (tsCfg == NULL) osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
SConfig *pCfg = NULL;
|
||||
TAOS_CHECK_RETURN(cfgInit(&pCfg));
|
||||
|
||||
if (tsc) {
|
||||
tsLogEmbedded = 0;
|
||||
|
@ -1325,8 +1325,8 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
|
|||
SArray *pArgs) {
|
||||
if (tsCfg == NULL) osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
SConfig *pCfg = NULL;
|
||||
TAOS_CHECK_RETURN(cfgInit(&pCfg));
|
||||
|
||||
if (cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1;
|
||||
|
@ -1371,10 +1371,7 @@ static int32_t taosCheckGlobalCfg() {
|
|||
|
||||
static int32_t cfgInitWrapper(SConfig **pCfg) {
|
||||
if (*pCfg == NULL) {
|
||||
*pCfg = cfgInit();
|
||||
if (*pCfg == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
TAOS_CHECK_RETURN(cfgInit(pCfg));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -270,11 +270,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
|
|||
|
||||
TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf)), NULL, _exit);
|
||||
|
||||
pIter = cfgCreateIter(pConf);
|
||||
if (pIter == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_CHECK_GOTO(code, NULL, _exit);
|
||||
}
|
||||
TAOS_CHECK_GOTO(cfgCreateIter(pConf, &pIter), NULL, _exit);
|
||||
|
||||
cfgLock(pConf);
|
||||
locked = 1;
|
||||
|
@ -296,7 +292,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
|
|||
|
||||
char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
int32_t valueLen = 0;
|
||||
cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen);
|
||||
TAOS_CHECK_GOTO(cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen), NULL, _exit);
|
||||
varDataSetLen(value, valueLen);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
|
||||
|
@ -308,7 +304,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
|
|||
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, value, false), NULL, _exit);
|
||||
|
||||
char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen);
|
||||
TAOS_CHECK_GOTO(cfgDumpItemScope(pItem, &scope[VARSTR_HEADER_SIZE], TSDB_CONFIG_SCOPE_LEN, &valueLen), NULL, _exit);
|
||||
varDataSetLen(scope, valueLen);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, col++);
|
||||
|
|
|
@ -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,55 +130,11 @@ 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:
|
||||
|
@ -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) {
|
||||
|
@ -416,7 +370,6 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
|
||||
if (pIter->colIdx >= pIter->pSchema->numOfCols) {
|
||||
return false;
|
||||
|
@ -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,8 +480,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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,10 +683,9 @@ 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)) {
|
||||
|
@ -784,22 +693,19 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp
|
|||
} else {
|
||||
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;
|
||||
|
@ -821,21 +727,18 @@ int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const vo
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -857,51 +760,13 @@ int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const vo
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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};
|
||||
|
|
|
@ -96,8 +96,6 @@ char* forwardToTimeStringEnd(char* str) {
|
|||
}
|
||||
|
||||
int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFraction) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int32_t i = 0;
|
||||
int64_t fraction = 0;
|
||||
|
||||
|
@ -147,8 +145,6 @@ int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFractio
|
|||
}
|
||||
|
||||
int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int64_t hour = 0;
|
||||
|
||||
int32_t i = 0;
|
||||
|
@ -224,8 +220,6 @@ int32_t offsetOfTimezone(char* tzStr, int64_t* offset) {
|
|||
* 2013-04-12T15:52:01.123+0800
|
||||
*/
|
||||
int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int64_t factor = TSDB_TICK_PER_SECOND(timePrec);
|
||||
int64_t tzOffset = 0;
|
||||
|
||||
|
@ -315,8 +309,6 @@ static FORCE_INLINE bool validateTm(struct tm* pTm) {
|
|||
}
|
||||
|
||||
int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
*utime = 0;
|
||||
struct tm tm = {0};
|
||||
|
||||
|
@ -358,8 +350,6 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP
|
|||
}
|
||||
|
||||
int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
*utime = 0;
|
||||
struct tm tm = {0};
|
||||
tm.tm_isdst = -1;
|
||||
|
@ -484,8 +474,6 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
|
|||
// !!!!notice: double lose precison if time is too large, for example: 1626006833631000000*1.0 = double =
|
||||
// 1626006833631000064
|
||||
int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit, int64_t* pRes) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (fromPrecision != TSDB_TIME_PRECISION_MILLI && fromPrecision != TSDB_TIME_PRECISION_MICRO &&
|
||||
fromPrecision != TSDB_TIME_PRECISION_NANO) {
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
|
@ -559,13 +547,14 @@ int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char
|
|||
}
|
||||
|
||||
int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int32_t charLen = varDataLen(inputData);
|
||||
char* newColData;
|
||||
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_VARBINARY) {
|
||||
newColData = taosMemoryCalloc(1, charLen + 1);
|
||||
memcpy(newColData, varDataVal(inputData), charLen);
|
||||
if (NULL == newColData) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
(void)memcpy(newColData, varDataVal(inputData), charLen);
|
||||
int32_t ret = taosParseTime(newColData, timeVal, charLen, (int32_t)timePrec, tsDaylight);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(newColData);
|
||||
|
@ -574,6 +563,9 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
|
|||
taosMemoryFree(newColData);
|
||||
} else if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
newColData = taosMemoryCalloc(1, charLen + TSDB_NCHAR_SIZE);
|
||||
if (NULL == newColData) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
int len = taosUcs4ToMbs((TdUcs4*)varDataVal(inputData), charLen, newColData);
|
||||
if (len < 0) {
|
||||
taosMemoryFree(newColData);
|
||||
|
@ -593,8 +585,6 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
|
|||
}
|
||||
|
||||
int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
switch (unit) {
|
||||
case 's':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_SECOND) {
|
||||
|
@ -658,8 +648,6 @@ int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecisi
|
|||
*/
|
||||
int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* duration, char* unit,
|
||||
int32_t timePrecision) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
errno = 0;
|
||||
char* endPtr = NULL;
|
||||
|
||||
|
@ -680,8 +668,6 @@ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* dura
|
|||
|
||||
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision,
|
||||
bool negativeAllow) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
errno = 0;
|
||||
|
||||
/* get the basic numeric value */
|
||||
|
@ -718,7 +704,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
|||
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
||||
taosLocalTime(&tt, &tm, NULL);
|
||||
(void)taosLocalTime(&tt, &tm, NULL);
|
||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)numOfMonth;
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
|
@ -779,11 +765,11 @@ int32_t taosTimeCountIntervalForFill(int64_t skey, int64_t ekey, int64_t interva
|
|||
|
||||
struct tm tm;
|
||||
time_t t = (time_t)skey;
|
||||
taosLocalTime(&t, &tm, NULL);
|
||||
(void)taosLocalTime(&t, &tm, NULL);
|
||||
int32_t smon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
t = (time_t)ekey;
|
||||
taosLocalTime(&t, &tm, NULL);
|
||||
(void)taosLocalTime(&t, &tm, NULL);
|
||||
int32_t emon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
if (unit == 'y') {
|
||||
|
@ -808,7 +794,7 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
|
|||
start /= (int64_t)(TSDB_TICK_PER_SECOND(precision));
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)start;
|
||||
taosLocalTime(&tt, &tm, NULL);
|
||||
(void)taosLocalTime(&tt, &tm, NULL);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
|
@ -978,8 +964,6 @@ const char* fmtts(int64_t ts) {
|
|||
}
|
||||
|
||||
int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
char ts[40] = {0};
|
||||
struct tm ptm;
|
||||
|
||||
|
@ -1018,7 +1002,7 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
|||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (taosLocalTime(", &ptm, buf) == NULL) {
|
||||
if (NULL == taosLocalTime(", &ptm, buf)) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm);
|
||||
|
@ -1032,7 +1016,9 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
|||
int32_t taosTs2Tm(int64_t ts, int32_t precision, struct STm* tm) {
|
||||
tm->fsec = ts % TICK_PER_SECOND[precision] * (TICK_PER_SECOND[TSDB_TIME_PRECISION_NANO] / TICK_PER_SECOND[precision]);
|
||||
time_t t = ts / TICK_PER_SECOND[precision];
|
||||
taosLocalTime(&t, &tm->tm, NULL);
|
||||
if (NULL == taosLocalTime(&t, &tm->tm, NULL)) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1344,7 +1330,7 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
TSFormatNode* format = taosArrayGet(formats, i);
|
||||
if (format->type != TS_FORMAT_NODE_TYPE_KEYWORD) {
|
||||
if (s - start + format->len + 1 > outLen) break;
|
||||
strncpy(s, format->c, format->len);
|
||||
(void)strncpy(s, format->c, format->len);
|
||||
s += format->len;
|
||||
continue;
|
||||
}
|
||||
|
@ -1353,37 +1339,37 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
switch (format->key->id) {
|
||||
case TSFKW_AM:
|
||||
case TSFKW_PM:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "PM" : "AM");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "PM" : "AM");
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_A_M:
|
||||
case TSFKW_P_M:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "P.M." : "A.M.");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "P.M." : "A.M.");
|
||||
s += 4;
|
||||
break;
|
||||
case TSFKW_am:
|
||||
case TSFKW_pm:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "pm" : "am");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "pm" : "am");
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_a_m:
|
||||
case TSFKW_p_m:
|
||||
sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "p.m." : "a.m.");
|
||||
(void)sprintf(s, tm->tm.tm_hour % 24 >= 12 ? "p.m." : "a.m.");
|
||||
s += 4;
|
||||
break;
|
||||
case TSFKW_DDD:
|
||||
#ifdef WINDOWS
|
||||
return TSDB_CODE_FUNC_TO_CHAR_NOT_SUPPORTED;
|
||||
#endif
|
||||
sprintf(s, "%03d", tm->tm.tm_yday + 1);
|
||||
(void)sprintf(s, "%03d", tm->tm.tm_yday + 1);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_DD:
|
||||
sprintf(s, "%02d", tm->tm.tm_mday);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_mday);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_D:
|
||||
sprintf(s, "%d", tm->tm.tm_wday + 1);
|
||||
(void)sprintf(s, "%d", tm->tm.tm_wday + 1);
|
||||
s += 1;
|
||||
break;
|
||||
case TSFKW_DAY: {
|
||||
|
@ -1391,20 +1377,20 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* wd = weekDays[tm->tm.tm_wday];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = toupper(wd[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_Day:
|
||||
// Monday, TuesDay...
|
||||
sprintf(s, "%-9s", weekDays[tm->tm.tm_wday]);
|
||||
(void)sprintf(s, "%-9s", weekDays[tm->tm.tm_wday]);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_day: {
|
||||
const char* wd = weekDays[tm->tm.tm_wday];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = tolower(wd[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
|
@ -1413,13 +1399,13 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* wd = shortWeekDays[tm->tm.tm_wday];
|
||||
char buf[8] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = toupper(wd[i]);
|
||||
sprintf(s, "%3s", buf);
|
||||
(void)sprintf(s, "%3s", buf);
|
||||
s += 3;
|
||||
break;
|
||||
}
|
||||
case TSFKW_Dy:
|
||||
// Mon, Tue
|
||||
sprintf(s, "%3s", shortWeekDays[tm->tm.tm_wday]);
|
||||
(void)sprintf(s, "%3s", shortWeekDays[tm->tm.tm_wday]);
|
||||
s += 3;
|
||||
break;
|
||||
case TSFKW_dy: {
|
||||
|
@ -1427,33 +1413,33 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* wd = shortWeekDays[tm->tm.tm_wday];
|
||||
char buf[8] = {0};
|
||||
for (int32_t i = 0; i < strlen(wd); ++i) buf[i] = tolower(wd[i]);
|
||||
sprintf(s, "%3s", buf);
|
||||
(void)sprintf(s, "%3s", buf);
|
||||
s += 3;
|
||||
break;
|
||||
}
|
||||
case TSFKW_HH24:
|
||||
sprintf(s, "%02d", tm->tm.tm_hour);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_hour);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_HH:
|
||||
case TSFKW_HH12:
|
||||
// 0 or 12 o'clock in 24H coresponds to 12 o'clock (AM/PM) in 12H
|
||||
sprintf(s, "%02d", tm->tm.tm_hour % 12 == 0 ? 12 : tm->tm.tm_hour % 12);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_hour % 12 == 0 ? 12 : tm->tm.tm_hour % 12);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MI:
|
||||
sprintf(s, "%02d", tm->tm.tm_min);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_min);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MM:
|
||||
sprintf(s, "%02d", tm->tm.tm_mon + 1);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_mon + 1);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MONTH: {
|
||||
const char* mon = fullMonths[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = toupper(mon[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
|
@ -1461,44 +1447,44 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
const char* mon = months[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = toupper(mon[i]);
|
||||
sprintf(s, "%s", buf);
|
||||
(void)sprintf(s, "%s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_Month:
|
||||
sprintf(s, "%-9s", fullMonths[tm->tm.tm_mon]);
|
||||
(void)sprintf(s, "%-9s", fullMonths[tm->tm.tm_mon]);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_month: {
|
||||
const char* mon = fullMonths[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = tolower(mon[i]);
|
||||
sprintf(s, "%-9s", buf);
|
||||
(void)sprintf(s, "%-9s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_Mon:
|
||||
sprintf(s, "%s", months[tm->tm.tm_mon]);
|
||||
(void)sprintf(s, "%s", months[tm->tm.tm_mon]);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_mon: {
|
||||
const char* mon = months[tm->tm.tm_mon];
|
||||
char buf[10] = {0};
|
||||
for (int32_t i = 0; i < strlen(mon); ++i) buf[i] = tolower(mon[i]);
|
||||
sprintf(s, "%s", buf);
|
||||
(void)sprintf(s, "%s", buf);
|
||||
s += strlen(s);
|
||||
break;
|
||||
}
|
||||
case TSFKW_SS:
|
||||
sprintf(s, "%02d", tm->tm.tm_sec);
|
||||
(void)sprintf(s, "%02d", tm->tm.tm_sec);
|
||||
s += 2;
|
||||
break;
|
||||
case TSFKW_MS:
|
||||
sprintf(s, "%03" PRId64, tm->fsec / 1000000L);
|
||||
(void)sprintf(s, "%03" PRId64, tm->fsec / 1000000L);
|
||||
s += 3;
|
||||
break;
|
||||
case TSFKW_US:
|
||||
sprintf(s, "%06" PRId64, tm->fsec / 1000L);
|
||||
(void)sprintf(s, "%06" PRId64, tm->fsec / 1000L);
|
||||
s += 6;
|
||||
break;
|
||||
case TSFKW_NS:
|
||||
|
@ -1506,23 +1492,23 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
|
|||
s += 9;
|
||||
break;
|
||||
case TSFKW_TZH:
|
||||
sprintf(s, "%s%02d", tsTimezone < 0 ? "-" : "+", tsTimezone);
|
||||
(void)sprintf(s, "%s%02d", tsTimezone < 0 ? "-" : "+", tsTimezone);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_YYYY:
|
||||
sprintf(s, "%04d", tm->tm.tm_year + 1900);
|
||||
(void)sprintf(s, "%04d", tm->tm.tm_year + 1900);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_YYY:
|
||||
sprintf(s, "%03d", (tm->tm.tm_year + 1900) % 1000);
|
||||
(void)sprintf(s, "%03d", (tm->tm.tm_year + 1900) % 1000);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_YY:
|
||||
sprintf(s, "%02d", (tm->tm.tm_year + 1900) % 100);
|
||||
(void)sprintf(s, "%02d", (tm->tm.tm_year + 1900) % 100);
|
||||
s += strlen(s);
|
||||
break;
|
||||
case TSFKW_Y:
|
||||
sprintf(s, "%01d", (tm->tm.tm_year + 1900) % 10);
|
||||
(void)sprintf(s, "%01d", (tm->tm.tm_year + 1900) % 10);
|
||||
s += strlen(s);
|
||||
break;
|
||||
default:
|
||||
|
@ -1557,7 +1543,7 @@ static const char* tsFormatStr2Int32(int32_t* dest, const char* str, int32_t len
|
|||
s = last;
|
||||
} else {
|
||||
char buf[16] = {0};
|
||||
strncpy(buf, s, len);
|
||||
(void)strncpy(buf, s, len);
|
||||
int32_t copiedLen = strlen(buf);
|
||||
if (copiedLen < len) {
|
||||
if (!needMoreDigit) {
|
||||
|
@ -1936,10 +1922,13 @@ static int32_t char2ts(const char* s, SArray* formats, int64_t* ts, int32_t prec
|
|||
int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t precision, char* out, int32_t outLen) {
|
||||
if (!*formats) {
|
||||
*formats = taosArrayInit(8, sizeof(TSFormatNode));
|
||||
if (!*formats){
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
parseTsFormat(format, *formats);
|
||||
}
|
||||
struct STm tm;
|
||||
taosTs2Tm(ts, precision, &tm);
|
||||
TAOS_CHECK_RETURN(taosTs2Tm(ts, precision, &tm));
|
||||
return tm2char(*formats, &tm, out, outLen);
|
||||
}
|
||||
|
||||
|
@ -1949,6 +1938,9 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int
|
|||
int32_t fErrIdx;
|
||||
if (!*formats) {
|
||||
*formats = taosArrayInit(4, sizeof(TSFormatNode));
|
||||
if (!*formats) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
parseTsFormat(format, *formats);
|
||||
}
|
||||
int32_t code = char2ts(tsStr, *formats, ts, precision, &sErrPos, &fErrIdx);
|
||||
|
@ -1964,16 +1956,24 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int
|
|||
snprintf(errMsg, errMsgLen, "timestamp format not supported");
|
||||
code = TSDB_CODE_FUNC_TO_TIMESTAMP_FAILED_NOT_SUPPORTED;
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen) {
|
||||
int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SArray* formats = taosArrayInit(4, sizeof(TSFormatNode));
|
||||
if (!formats) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
parseTsFormat(format, formats);
|
||||
struct STm tm;
|
||||
taosTs2Tm(ts, precision, &tm);
|
||||
tm2char(formats, &tm, out, outLen);
|
||||
TAOS_CHECK_GOTO(taosTs2Tm(ts, precision, &tm), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tm2char(formats, &tm, out, outLen), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(formats);
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr) {
|
||||
|
@ -1997,17 +1997,19 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1,
|
|||
|
||||
#define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97]
|
||||
|
||||
static int64_t UNIT_MATRIX[10][11] = {/* ns, us, ms, s, min, h, d, w, month, y*/
|
||||
/*ns*/ {1, 1000, 0},
|
||||
/*us*/ {1000, 1, 1000, 0},
|
||||
/*ms*/ {0, 1000, 1, 1000, 0},
|
||||
/*s*/ {0, 0, 1000, 1, 60, 0},
|
||||
/*min*/ {0, 0, 0, 60, 1, 60, 0},
|
||||
/*h*/ {0, 0, 0, 0, 60, 1, 1, 0},
|
||||
/*d*/ {0, 0, 0, 0, 0, 24, 1, 7, 1, 0},
|
||||
/*w*/ {0, 0, 0, 0, 0, 0, 7, 1, -1, 0},
|
||||
/*mon*/ {0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 0},
|
||||
/*y*/ {0, 0, 0, 0, 0, 0, 0, 0, 12, 1, 0}};
|
||||
// clang-format off
|
||||
static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h, d, w, month, y*/
|
||||
/*ns*/ { 1, 1000, 0},
|
||||
/*us*/ {1000, 1, 1000, 0},
|
||||
/*ms*/ { 0, 1000, 1, 1000, 0},
|
||||
/*s*/ { 0, 0, 1000, 1, 60, 0},
|
||||
/*min*/ { 0, 0, 0, 60, 1, 60, 0},
|
||||
/*h*/ { 0, 0, 0, 0, 60, 1, 1, 0},
|
||||
/*d*/ { 0, 0, 0, 0, 0, 24, 1, 7, 1, 0},
|
||||
/*w*/ { 0, 0, 0, 0, 0, 0, 7, 1, -1, 0},
|
||||
/*mon*/ { 0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 0},
|
||||
/*y*/ { 0, 0, 0, 0, 0, 0, 0, 0, 12, 1, 0}};
|
||||
// clang-format on
|
||||
|
||||
static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx,
|
||||
bool checkEq) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -465,7 +465,8 @@ TEST(timeTest, timestamp2tm) {
|
|||
|
||||
void test_ts2char(int64_t ts, const char* format, int32_t precison, const char* expected) {
|
||||
char buf[256] = {0};
|
||||
TEST_ts2char(format, ts, precison, buf, 256);
|
||||
int32_t code = TEST_ts2char(format, ts, precison, buf, 256);
|
||||
ASSERT_EQ(code, 0);
|
||||
printf("ts: %ld format: %s res: [%s], expected: [%s]\n", ts, format, buf, expected);
|
||||
ASSERT_STREQ(expected, buf);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -43,18 +43,15 @@ int32_t mndInitView(SMnode *pMnode) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void mndCleanupView(SMnode *pMnode) {
|
||||
mDebug("mnd view cleanup");
|
||||
}
|
||||
void mndCleanupView(SMnode *pMnode) { mDebug("mnd view cleanup"); }
|
||||
|
||||
int32_t mndProcessCreateViewReq(SRpcMsg *pReq) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SCMCreateViewReq createViewReq = {0};
|
||||
SCMCreateViewReq createViewReq = {0};
|
||||
if (tDeserializeSCMCreateViewReq(pReq->pCont, pReq->contLen, &createViewReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_MSG);
|
||||
}
|
||||
|
||||
mInfo("start to create view:%s, sql:%s", createViewReq.fullname, createViewReq.sql);
|
||||
|
@ -65,17 +62,16 @@ int32_t mndProcessCreateViewReq(SRpcMsg *pReq) {
|
|||
|
||||
int32_t mndProcessDropViewReq(SRpcMsg *pReq) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SCMDropViewReq dropViewReq = {0};
|
||||
if (tDeserializeSCMDropViewReq(pReq->pCont, pReq->contLen, &dropViewReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mInfo("start to drop view:%s, sql:%s", dropViewReq.name, dropViewReq.sql);
|
||||
|
||||
return mndProcessDropViewReqImpl(&dropViewReq, pReq);
|
||||
SCMDropViewReq dropViewReq = {0};
|
||||
if (tDeserializeSCMDropViewReq(pReq->pCont, pReq->contLen, &dropViewReq) != 0) {
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_MSG);
|
||||
}
|
||||
|
||||
mInfo("start to drop view:%s, sql:%s", dropViewReq.name, dropViewReq.sql);
|
||||
|
||||
return mndProcessDropViewReqImpl(&dropViewReq, pReq);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -83,18 +79,16 @@ int32_t mndProcessGetViewMetaReq(SRpcMsg *pReq) {
|
|||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SViewMetaReq req = {0};
|
||||
SViewMetaReq req = {0};
|
||||
|
||||
if (tDeserializeSViewMetaReq(pReq->pCont, pReq->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_MSG);
|
||||
}
|
||||
|
||||
return mndProcessViewMetaReqImpl(&req, pReq);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int32_t mndRetrieveView(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return 0;
|
||||
|
@ -107,6 +101,3 @@ void mndCancelGetNextView(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "tqueue.h"
|
||||
|
||||
#include "executor.h"
|
||||
#include "qndInt.h"
|
||||
#include "query.h"
|
||||
|
@ -23,7 +24,7 @@ int32_t qndOpen(const SQnodeOpt *pOption, SQnode **pQnode) {
|
|||
*pQnode = taosMemoryCalloc(1, sizeof(SQnode));
|
||||
if (NULL == *pQnode) {
|
||||
qError("calloc SQnode failed");
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
(*pQnode)->qndId = QNODE_HANDLE;
|
||||
|
||||
|
@ -75,9 +76,9 @@ int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
|||
return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg, false);
|
||||
}
|
||||
|
||||
int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo* pInfo, SRpcMsg *pMsg) {
|
||||
int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||
int32_t code = -1;
|
||||
int64_t ts = pInfo->timestamp;
|
||||
int64_t ts = pInfo->timestamp;
|
||||
SReadHandle handle = {.pMsgCb = &pQnode->msgCb, .pWorkerCb = pInfo->workerCb};
|
||||
qTrace("message in qnode queue is processing");
|
||||
|
||||
|
@ -113,6 +114,9 @@ int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo* pInfo, SRpcMsg *pMsg) {
|
|||
terrno = TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
return code;
|
||||
if (code == 0) {
|
||||
return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,6 @@ SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
|||
int32_t code = 0;
|
||||
SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode));
|
||||
if (pSnode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -244,7 +244,6 @@ void tsdbMemTableDestroy(SMemTable *pMemTable, bool proactive);
|
|||
STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid);
|
||||
int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode);
|
||||
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive);
|
||||
SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable);
|
||||
// STbDataIter
|
||||
int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter);
|
||||
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,45 +336,45 @@ 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
|
||||
|
@ -386,15 +382,15 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) {
|
|||
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) {
|
||||
if ((code = tdInitSmaEnv(pSma, smaType, &pEnv)) < 0) {
|
||||
tdUnLockSma(pSma);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
tdUnLockSma(pSma);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
};
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void *tdRSmaExecutorFunc(void *param) {
|
||||
setThreadName("vnode-rsma");
|
||||
|
@ -404,6 +400,7 @@ void *tdRSmaExecutorFunc(void *param) {
|
|||
}
|
||||
|
||||
static int32_t tdRsmaStartExecutor(const SSma *pSma) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr = {0};
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
@ -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;
|
||||
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;
|
||||
|
@ -453,5 +450,5 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) {
|
|||
|
||||
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,8 +139,7 @@ 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;
|
||||
|
@ -152,18 +161,14 @@ 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) {
|
||||
|
@ -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);
|
||||
|
|
|
@ -38,24 +38,24 @@ SSmaMgmt smaMgmt = {
|
|||
|
||||
typedef struct SRSmaQTaskInfoItem SRSmaQTaskInfoItem;
|
||||
|
||||
static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
||||
static void tdUidStoreDestory(STbUidStore *pStore);
|
||||
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids, bool isAdd);
|
||||
static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo,
|
||||
int8_t idx);
|
||||
static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize, int64_t version, int32_t inputType,
|
||||
SRSmaInfo *pInfo, ERsmaExecType type, int8_t level);
|
||||
static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid);
|
||||
static void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo);
|
||||
static void tdFreeRSmaSubmitItems(SArray *pItems, int32_t type);
|
||||
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo);
|
||||
static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSmaInfoItem *pItem, SRSmaInfo *pInfo,
|
||||
int32_t execType, int8_t *streamFlushed);
|
||||
static void tdRSmaFetchTrigger(void *param, void *tmrId);
|
||||
static void tdRSmaQTaskInfoFree(qTaskInfo_t *taskHandle, int32_t vgId, int32_t level);
|
||||
static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables);
|
||||
static int32_t tdRSmaRestoreQTaskInfoReload(SSma *pSma, int8_t type, int64_t qTaskFileVer);
|
||||
static int32_t tdRSmaRestoreTSDataReload(SSma *pSma);
|
||||
static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
||||
static void tdUidStoreDestory(STbUidStore *pStore);
|
||||
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids, bool isAdd);
|
||||
static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo,
|
||||
int8_t idx);
|
||||
static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize, int64_t version, int32_t inputType,
|
||||
SRSmaInfo *pInfo, ERsmaExecType type, int8_t level);
|
||||
static int32_t tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid, SRSmaInfo **ppRSmaInfo);
|
||||
static void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo);
|
||||
static void tdFreeRSmaSubmitItems(SArray *pItems, int32_t type);
|
||||
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo);
|
||||
static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSmaInfoItem *pItem, SRSmaInfo *pInfo,
|
||||
int32_t execType, int8_t *streamFlushed);
|
||||
static void tdRSmaFetchTrigger(void *param, void *tmrId);
|
||||
static void tdRSmaQTaskInfoFree(qTaskInfo_t *taskHandle, int32_t vgId, int32_t level);
|
||||
static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables);
|
||||
static int32_t tdRSmaRestoreQTaskInfoReload(SSma *pSma, int8_t type, int64_t qTaskFileVer);
|
||||
static int32_t tdRSmaRestoreTSDataReload(SSma *pSma);
|
||||
|
||||
struct SRSmaQTaskInfoItem {
|
||||
int32_t len;
|
||||
|
@ -123,8 +123,7 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) {
|
|||
static FORCE_INLINE int32_t tdUidStoreInit(STbUidStore **pStore) {
|
||||
*pStore = taosMemoryCalloc(1, sizeof(STbUidStore));
|
||||
if (*pStore == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -132,12 +131,13 @@ static FORCE_INLINE int32_t tdUidStoreInit(STbUidStore **pStore) {
|
|||
|
||||
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids, bool isAdd) {
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
if (!suid || !tbUids) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
smaError("vgId:%d, failed to get rsma info for uid:%" PRIi64 " since %s", SMA_VID(pSma), suid ? *suid : -1,
|
||||
terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t nTables = taosArrayGetSize(tbUids);
|
||||
|
@ -147,21 +147,20 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, *suid);
|
||||
code = tdAcquireRSmaInfoBySuid(pSma, *suid, &pRSmaInfo);
|
||||
|
||||
if (!pRSmaInfo) {
|
||||
if (code != 0) {
|
||||
smaError("vgId:%d, failed to get rsma info for uid:%" PRIi64, SMA_VID(pSma), *suid);
|
||||
terrno = TSDB_CODE_RSMA_INVALID_STAT;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pRSmaInfo->taskInfo[i]) {
|
||||
if ((terrno = qUpdateTableListForStreamScanner(pRSmaInfo->taskInfo[i], tbUids, isAdd)) < 0) {
|
||||
if ((code = qUpdateTableListForStreamScanner(pRSmaInfo->taskInfo[i], tbUids, isAdd)) < 0) {
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " level %d since %s", SMA_VID(pSma), *suid, i,
|
||||
terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p. suid:%" PRIi64 " uid:%" PRIi64
|
||||
"nTables:%d level %d",
|
||||
|
@ -170,26 +169,25 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids,
|
|||
}
|
||||
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t tdUpdateTbUidList(SSma *pSma, STbUidStore *pStore, bool isAdd) {
|
||||
int32_t code = 0;
|
||||
if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (tdUpdateTbUidListImpl(pSma, &pStore->suid, pStore->tbUids, isAdd) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdUpdateTbUidListImpl(pSma, &pStore->suid, pStore->tbUids, isAdd));
|
||||
|
||||
void *pIter = NULL;
|
||||
while ((pIter = taosHashIterate(pStore->uidHash, pIter))) {
|
||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||
SArray *pTbUids = *(SArray **)pIter;
|
||||
|
||||
if (tdUpdateTbUidListImpl(pSma, pTbSuid, pTbUids, isAdd) != TSDB_CODE_SUCCESS) {
|
||||
if ((code = tdUpdateTbUidListImpl(pSma, pTbSuid, pTbUids, isAdd)) != TSDB_CODE_SUCCESS) {
|
||||
taosHashCancelIterate(pStore->uidHash, pIter);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -206,6 +204,7 @@ int32_t tdUpdateTbUidList(SSma *pSma, STbUidStore *pStore, bool isAdd) {
|
|||
*/
|
||||
int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_uid_t uid) {
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
int32_t code = 0;
|
||||
|
||||
// only applicable to rollup SMA ctables
|
||||
if (!pEnv) {
|
||||
|
@ -215,8 +214,7 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
|
|||
SRSmaStat *pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||
SHashObj *infoHash = NULL;
|
||||
if (!pStat || !(infoHash = RSMA_INFO_HASH(pStat))) {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_STAT;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_INVALID_STAT);
|
||||
}
|
||||
|
||||
// info cached when create rsma stable and return directly for non-rsma ctables
|
||||
|
@ -225,14 +223,12 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
|
|||
}
|
||||
|
||||
if (!(*ppStore)) {
|
||||
if (tdUidStoreInit(ppStore) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdUidStoreInit(ppStore));
|
||||
}
|
||||
|
||||
if (tdUidStorePut(*ppStore, suid, &uid) < 0) {
|
||||
if ((code = tdUidStorePut(*ppStore, suid, &uid)) < 0) {
|
||||
*ppStore = tdUidStoreFree(*ppStore);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -262,6 +258,7 @@ static void tdRSmaTaskRemove(SStreamMeta *pMeta, int64_t streamId, int32_t taskI
|
|||
|
||||
static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo,
|
||||
int8_t idx) {
|
||||
int32_t code = 0;
|
||||
if ((param->qmsgLen > 0) && param->qmsg[idx]) {
|
||||
SRSmaInfoItem *pItem = &(pRSmaInfo->items[idx]);
|
||||
SRetention *pRetention = SMA_RETENTION(pSma);
|
||||
|
@ -275,18 +272,20 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
|
||||
if (!taosCheckExistFile(taskInfDir)) {
|
||||
char *s = taosStrdup(taskInfDir);
|
||||
if (!s) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
if (taosMulMkDir(s) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosMemoryFree(s);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
taosMemoryFree(s);
|
||||
}
|
||||
|
||||
SStreamTask *pStreamTask = taosMemoryCalloc(1, sizeof(*pStreamTask));
|
||||
if (!pStreamTask) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
pItem->pStreamTask = pStreamTask;
|
||||
pStreamTask->id.taskId = 0;
|
||||
|
@ -294,24 +293,20 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
pStreamTask->chkInfo.startTs = taosGetTimestampMs();
|
||||
pStreamTask->pMeta = pVnode->pTq->pStreamMeta;
|
||||
pStreamTask->exec.qmsg = taosMemoryMalloc(strlen(RSMA_EXEC_TASK_FLAG) + 1);
|
||||
if (!pStreamTask->exec.qmsg) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
sprintf(pStreamTask->exec.qmsg, "%s", RSMA_EXEC_TASK_FLAG);
|
||||
pStreamTask->chkInfo.checkpointId = streamMetaGetLatestCheckpointId(pStreamTask->pMeta);
|
||||
tdRSmaTaskInit(pStreamTask->pMeta, pItem, &pStreamTask->id);
|
||||
|
||||
int32_t code = streamCreateStateMachine(pStreamTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(streamCreateStateMachine(pStreamTask));
|
||||
|
||||
code = streamTaskCreateActiveChkptInfo(&pStreamTask->chkInfo.pActiveInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(streamTaskCreateActiveChkptInfo(&pStreamTask->chkInfo.pActiveInfo));
|
||||
|
||||
pStreamState = streamStateOpen(taskInfDir, pStreamTask, pStreamTask->id.streamId, pStreamTask->id.taskId);
|
||||
if (!pStreamState) {
|
||||
terrno = TSDB_CODE_RSMA_STREAM_STATE_OPEN;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_STREAM_STATE_OPEN);
|
||||
}
|
||||
pItem->pStreamState = pStreamState;
|
||||
|
||||
|
@ -321,12 +316,11 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
initStorageAPI(&handle.api);
|
||||
pRSmaInfo->taskInfo[idx] = qCreateStreamExecTaskInfo(param->qmsg[idx], &handle, TD_VID(pVnode), 0);
|
||||
if (!pRSmaInfo->taskInfo[idx]) {
|
||||
terrno = TSDB_CODE_RSMA_QTASKINFO_CREATE;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_QTASKINFO_CREATE);
|
||||
}
|
||||
|
||||
if (!(pItem->pResList = taosArrayInit(1, POINTER_BYTES))) {
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (pItem->fetchResultVer < pItem->submitReqVer) {
|
||||
|
@ -349,7 +343,9 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
pItem->level = idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2;
|
||||
|
||||
SRSmaRef rsmaRef = {.refId = pStat->refId, .suid = pRSmaInfo->suid};
|
||||
taosHashPut(smaMgmt.refHash, &pItem, POINTER_BYTES, &rsmaRef, sizeof(rsmaRef));
|
||||
if (taosHashPut(smaMgmt.refHash, &pItem, POINTER_BYTES, &rsmaRef, sizeof(rsmaRef)) != 0) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
||||
|
||||
|
@ -359,7 +355,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
TD_VID(pVnode), pItem->pStreamTask, pRSmaInfo->suid, (int8_t)(idx + 1), pStreamTask->chkInfo.checkpointId,
|
||||
pItem->submitReqVer, pItem->fetchResultVer, param->maxdelay[idx], param->watermark[idx], pItem->maxDelay);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,20 +368,14 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
* @return int32_t
|
||||
*/
|
||||
int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName) {
|
||||
int32_t code;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if ((param->qmsgLen[0] == 0) && (param->qmsgLen[1] == 0)) {
|
||||
smaDebug("vgId:%d, no qmsg1/qmsg2 for rollup table %s %" PRIi64, SMA_VID(pSma), tbName, suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_ROLLUP) != TSDB_CODE_SUCCESS) {
|
||||
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
SRSmaStat *pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
@ -399,41 +389,34 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
|
|||
// from write queue: single thead
|
||||
pRSmaInfo = (SRSmaInfo *)taosMemoryCalloc(1, sizeof(SRSmaInfo));
|
||||
if (!pRSmaInfo) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
STSchema *pTSchema = metaGetTbTSchema(SMA_META(pSma), suid, -1, 1);
|
||||
if (!pTSchema) {
|
||||
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
||||
goto _err;
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION);
|
||||
}
|
||||
pRSmaInfo->pSma = pSma;
|
||||
pRSmaInfo->pTSchema = pTSchema;
|
||||
pRSmaInfo->suid = suid;
|
||||
T_REF_INIT_VAL(pRSmaInfo, 1);
|
||||
|
||||
code = taosOpenQueue(&pRSmaInfo->queue);
|
||||
if (code) goto _err;
|
||||
TAOS_CHECK_EXIT(taosOpenQueue(&pRSmaInfo->queue));
|
||||
|
||||
code = taosAllocateQall(&pRSmaInfo->qall);
|
||||
if (code) goto _err;
|
||||
TAOS_CHECK_EXIT(taosAllocateQall(&pRSmaInfo->qall));
|
||||
|
||||
if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0 ||
|
||||
tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 1) < 0) {
|
||||
goto _err;
|
||||
TAOS_CHECK_EXIT(tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0));
|
||||
TAOS_CHECK_EXIT(tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 1));
|
||||
|
||||
TAOS_CHECK_EXIT(taosHashPut(RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)));
|
||||
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
tdFreeRSmaInfo(pSma, pRSmaInfo);
|
||||
} else {
|
||||
smaDebug("vgId:%d, register rsma info succeed for table %" PRIi64, SMA_VID(pSma), suid);
|
||||
}
|
||||
|
||||
if (taosHashPut(RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) != 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
smaDebug("vgId:%d, register rsma info succeed for table %" PRIi64, SMA_VID(pSma), suid);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
tdFreeRSmaInfo(pSma, pRSmaInfo);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -480,11 +463,13 @@ int32_t tdProcessRSmaDrop(SSma *pSma, SVDropStbReq *pReq) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pSmaEnv);
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
SRSmaInfo *pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, pReq->suid);
|
||||
code = tdAcquireRSmaInfoBySuid(pSma, pReq->suid, &pRSmaInfo);
|
||||
|
||||
if (!pRSmaInfo) {
|
||||
if (code != 0) {
|
||||
smaWarn("vgId:%d, drop rsma for stable %s %" PRIi64 " failed no rsma in hash", TD_VID(pVnode), pReq->name,
|
||||
pReq->suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -519,12 +504,11 @@ static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid)
|
|||
if (uid) {
|
||||
if (!pStore->tbUids) {
|
||||
if (!(pStore->tbUids = taosArrayInit(1, sizeof(tb_uid_t)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
if (!taosArrayPush(pStore->tbUids, uid)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -532,32 +516,29 @@ static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid)
|
|||
if (!pStore->uidHash) {
|
||||
pStore->uidHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (!pStore->uidHash) {
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
if (uid) {
|
||||
SArray *uidArray = taosHashGet(pStore->uidHash, &suid, sizeof(tb_uid_t));
|
||||
if (uidArray && ((uidArray = *(SArray **)uidArray))) {
|
||||
taosArrayPush(uidArray, uid);
|
||||
if (!taosArrayPush(uidArray, uid)) {
|
||||
taosArrayDestroy(uidArray);
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
} else {
|
||||
SArray *pUidArray = taosArrayInit(1, sizeof(tb_uid_t));
|
||||
if (!pUidArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
if (!taosArrayPush(pUidArray, uid)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosArrayDestroy(pUidArray);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
TAOS_CHECK_RETURN(taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)));
|
||||
}
|
||||
} else {
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
TAOS_CHECK_RETURN(taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0));
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -600,9 +581,7 @@ static int32_t tdProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
|||
if (pReq) {
|
||||
SSubmitReq2 *pSubmitReq = (SSubmitReq2 *)pReq;
|
||||
// spin lock for race condition during insert data
|
||||
if (tsdbInsertData(pTsdb, version, pSubmitReq, NULL) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tsdbInsertData(pTsdb, version, pSubmitReq, NULL));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -612,13 +591,9 @@ static int32_t tdFetchSubmitReqSuids(SSubmitReq2 *pMsg, STbUidStore *pStore) {
|
|||
SArray *pSubmitTbData = pMsg ? pMsg->aSubmitTbData : NULL;
|
||||
int32_t size = taosArrayGetSize(pSubmitTbData);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSubmitTbData *pData = TARRAY_GET_ELEM(pSubmitTbData, i);
|
||||
if ((terrno = tdUidStorePut(pStore, pData->suid, NULL)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdUidStorePut(pStore, pData->suid, NULL));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -645,7 +620,7 @@ int32_t smaRetention(SSma *pSma, int64_t now) {
|
|||
}
|
||||
|
||||
_end:
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tdRSmaProcessDelReq(SSma *pSma, int64_t suid, int8_t level, SBatchDeleteReq *pDelReq) {
|
||||
|
@ -659,13 +634,17 @@ static int32_t tdRSmaProcessDelReq(SSma *pSma, int64_t suid, int8_t level, SBatc
|
|||
|
||||
void *pBuf = rpcMallocCont(len + sizeof(SMsgHead));
|
||||
if (!pBuf) {
|
||||
code = terrno;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len);
|
||||
tEncodeSBatchDeleteReq(&encoder, pDelReq);
|
||||
if ((code = tEncodeSBatchDeleteReq(&encoder, pDelReq)) < 0) {
|
||||
tEncoderClear(&encoder);
|
||||
rpcFreeCont(pBuf);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode);
|
||||
|
@ -682,7 +661,7 @@ _exit:
|
|||
SMA_VID(pSma), lino, suid, level, tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSmaInfoItem *pItem, SRSmaInfo *pInfo,
|
||||
|
@ -717,7 +696,7 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
|||
SBatchDeleteReq deleteReq = {.suid = suid, .level = pItem->level};
|
||||
deleteReq.deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
if (!deleteReq.deleteReqs) {
|
||||
code = terrno;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
code = tqBuildDeleteReq(pSma->pVnode->pTq, NULL, output, &deleteReq, "", true);
|
||||
|
@ -753,21 +732,15 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
|||
STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]);
|
||||
SSubmitReq2 *pReq = NULL;
|
||||
|
||||
if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, output->info.id.groupId, SMA_VID(pSma), suid) < 0) {
|
||||
code = terrno ? terrno : TSDB_CODE_RSMA_RESULT;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_EXIT(
|
||||
buildSubmitReqFromDataBlock(&pReq, output, pTSchema, output->info.id.groupId, SMA_VID(pSma), suid));
|
||||
|
||||
if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
|
||||
if (terrno == TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE) {
|
||||
if (pReq && (code = tdProcessSubmitReq(sinkTsdb, output->info.version, pReq)) < 0) {
|
||||
if (code == TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE) {
|
||||
// TODO: reconfigure SSubmitReq2
|
||||
} else {
|
||||
if (terrno == 0) terrno = TSDB_CODE_RSMA_RESULT;
|
||||
code = terrno;
|
||||
}
|
||||
tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFree(pReq);
|
||||
pReq = NULL;
|
||||
taosMemoryFreeClear(pReq);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -812,14 +785,12 @@ _exit:
|
|||
*/
|
||||
static int32_t tdExecuteRSmaImplAsync(SSma *pSma, int64_t version, const void *pMsg, int32_t len, int32_t inputType,
|
||||
SRSmaInfo *pInfo, tb_uid_t suid) {
|
||||
int32_t code;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
int32_t size = RSMA_EXEC_MSG_HLEN + len; // header + payload
|
||||
void *qItem;
|
||||
|
||||
code = taosAllocateQitem(size, DEF_QITEM, 0, (void **)&qItem);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(taosAllocateQitem(size, DEF_QITEM, 0, (void **)&qItem));
|
||||
|
||||
void *pItem = qItem;
|
||||
|
||||
|
@ -830,7 +801,7 @@ static int32_t tdExecuteRSmaImplAsync(SSma *pSma, int64_t version, const void *p
|
|||
*(int64_t *)pItem = version;
|
||||
memcpy(POINTER_SHIFT(pItem, sizeof(int64_t)), pMsg, len);
|
||||
|
||||
taosWriteQitem(pInfo->queue, qItem);
|
||||
TAOS_CHECK_RETURN(taosWriteQitem(pInfo->queue, qItem));
|
||||
|
||||
pInfo->lastRecv = taosGetTimestampMs();
|
||||
|
||||
|
@ -863,10 +834,10 @@ static int32_t tdRsmaPrintSubmitReq(SSma *pSma, SSubmitReq *pReq) {
|
|||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
STSRow *row = NULL;
|
||||
if (tInitSubmitMsgIter(pReq, &msgIter) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tInitSubmitMsgIter(pReq, &msgIter));
|
||||
while (true) {
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tGetSubmitMsgNext(&msgIter, &pBlock));
|
||||
if (pBlock == NULL) break;
|
||||
tInitSubmitBlkIter(&msgIter, pBlock, &blkIter);
|
||||
while ((row = tGetSubmitBlkNext(&blkIter)) != NULL) {
|
||||
|
@ -892,6 +863,7 @@ static int32_t tdRsmaPrintSubmitReq(SSma *pSma, SSubmitReq *pReq) {
|
|||
*/
|
||||
static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize, int64_t version, int32_t inputType,
|
||||
SRSmaInfo *pInfo, ERsmaExecType type, int8_t level) {
|
||||
int32_t code = 0;
|
||||
int32_t idx = level - 1;
|
||||
void *qTaskInfo = RSMA_INFO_QTASK(pInfo, idx);
|
||||
SRSmaInfoItem *pItem = RSMA_INFO_ITEM(pInfo, idx);
|
||||
|
@ -902,25 +874,24 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (!pInfo->pTSchema) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
smaWarn("vgId:%d, no schema to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, pInfo->suid);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PTR);
|
||||
}
|
||||
|
||||
smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p, suid:%" PRIu64 ", nMsg:%d, submitReqVer:%" PRIi64
|
||||
", inputType:%d",
|
||||
SMA_VID(pSma), level, RSMA_INFO_QTASK(pInfo, idx), pInfo->suid, msgSize, version, inputType);
|
||||
|
||||
if ((terrno = qSetSMAInput(qTaskInfo, pMsg, msgSize, inputType)) < 0) {
|
||||
smaError("vgId:%d, rsma %" PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(terrno));
|
||||
return TSDB_CODE_FAILED;
|
||||
if ((code = qSetSMAInput(qTaskInfo, pMsg, msgSize, inputType)) < 0) {
|
||||
smaError("vgId:%d, rsma %" PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(code));
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
atomic_store_64(&pItem->submitReqVer, version);
|
||||
|
||||
terrno = tdRSmaExecAndSubmitResult(pSma, qTaskInfo, pItem, pInfo, STREAM_NORMAL, NULL);
|
||||
TAOS_CHECK_RETURN(tdRSmaExecAndSubmitResult(pSma, qTaskInfo, pItem, pInfo, STREAM_NORMAL, NULL));
|
||||
|
||||
return terrno ? TSDB_CODE_FAILED : TDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -928,26 +899,23 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize,
|
|||
*
|
||||
* @param pSma
|
||||
* @param suid
|
||||
* @return SRSmaInfo*
|
||||
*/
|
||||
static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
|
||||
static int32_t tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid, SRSmaInfo **ppRSmaInfo) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
SRSmaStat *pStat = NULL;
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
terrno = 0;
|
||||
*ppRSmaInfo = NULL;
|
||||
|
||||
if (!pEnv) {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_ENV;
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_INVALID_ENV);
|
||||
}
|
||||
|
||||
pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||
if (!pStat || !RSMA_INFO_HASH(pStat)) {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_STAT;
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_INVALID_STAT);
|
||||
}
|
||||
|
||||
taosRLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
|
@ -955,20 +923,20 @@ static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
|
|||
if (pRSmaInfo && (pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||
if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
|
||||
taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_INVALID_STAT);
|
||||
}
|
||||
|
||||
tdRefRSmaInfo(pSma, pRSmaInfo);
|
||||
taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
if (ASSERTS(pRSmaInfo->suid == suid, "suid:%" PRIi64 " != %" PRIi64, pRSmaInfo->suid, suid)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_APP_ERROR);
|
||||
}
|
||||
return pRSmaInfo;
|
||||
*ppRSmaInfo = pRSmaInfo;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
|
||||
return NULL;
|
||||
TAOS_RETURN(TSDB_CODE_RSMA_INVALID_STAT);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) {
|
||||
|
@ -989,16 +957,19 @@ static FORCE_INLINE void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) {
|
|||
*/
|
||||
static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg, int32_t len, int32_t inputType,
|
||||
tb_uid_t suid) {
|
||||
SRSmaInfo *pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, suid);
|
||||
if (!pRSmaInfo) {
|
||||
int32_t code = 0;
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
code = tdAcquireRSmaInfoBySuid(pSma, suid, &pRSmaInfo);
|
||||
if (code != 0) {
|
||||
smaDebug("vgId:%d, execute rsma, no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS); // return success
|
||||
}
|
||||
|
||||
if (inputType == STREAM_INPUT__DATA_SUBMIT || inputType == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||
if (tdExecuteRSmaImplAsync(pSma, version, pMsg, len, inputType, pRSmaInfo, suid) < 0) {
|
||||
if ((code = tdExecuteRSmaImplAsync(pSma, version, pMsg, len, inputType, pRSmaInfo, suid)) < 0) {
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (smaMgmt.tmrHandle) {
|
||||
SRSmaInfoItem *pItem = RSMA_INFO_ITEM(pRSmaInfo, 0);
|
||||
|
@ -1011,11 +982,11 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
smaError("vgId:%d, execute rsma, failed for suid:%" PRIu64 " since %s, type:%d", SMA_VID(pSma), suid,
|
||||
tstrerror(terrno), inputType);
|
||||
return TSDB_CODE_FAILED;
|
||||
tstrerror(code), inputType);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
|
@ -1025,57 +996,56 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg,
|
|||
int32_t tdProcessRSmaSubmit(SSma *pSma, int64_t version, void *pReq, void *pMsg, int32_t len) {
|
||||
if (!SMA_RSMA_ENV(pSma)) return TSDB_CODE_SUCCESS;
|
||||
|
||||
if ((terrno = atomic_load_32(&SMA_RSMA_STAT(pSma)->execStat))) {
|
||||
smaError("vgId:%d, failed to process rsma submit since invalid exec code: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
int32_t code = 0;
|
||||
if ((code = atomic_load_32(&SMA_RSMA_STAT(pSma)->execStat))) {
|
||||
smaError("vgId:%d, failed to process rsma submit since invalid exec code: %s", SMA_VID(pSma), tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
STbUidStore uidStore = {0};
|
||||
|
||||
if (tdFetchSubmitReqSuids(pReq, &uidStore) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit fetch suid since: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
if ((code = tdFetchSubmitReqSuids(pReq, &uidStore)) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit fetch suid since: %s", SMA_VID(pSma), tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (uidStore.suid != 0) {
|
||||
if (tdExecuteRSmaAsync(pSma, version, pMsg, len, STREAM_INPUT__DATA_SUBMIT, uidStore.suid) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 1 since: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
if ((code = tdExecuteRSmaAsync(pSma, version, pMsg, len, STREAM_INPUT__DATA_SUBMIT, uidStore.suid)) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 1 since: %s", SMA_VID(pSma), tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
void *pIter = NULL;
|
||||
while ((pIter = taosHashIterate(uidStore.uidHash, pIter))) {
|
||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||
if (tdExecuteRSmaAsync(pSma, version, pMsg, len, STREAM_INPUT__DATA_SUBMIT, *pTbSuid) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 2 since: %s", SMA_VID(pSma), terrstr());
|
||||
if ((code = tdExecuteRSmaAsync(pSma, version, pMsg, len, STREAM_INPUT__DATA_SUBMIT, *pTbSuid)) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 2 since: %s", SMA_VID(pSma), tstrerror(code));
|
||||
taosHashCancelIterate(uidStore.uidHash, pIter);
|
||||
goto _err;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
_exit:
|
||||
tdUidStoreDestory(&uidStore);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
tdUidStoreDestory(&uidStore);
|
||||
return terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t tdProcessRSmaDelete(SSma *pSma, int64_t version, void *pReq, void *pMsg, int32_t len) {
|
||||
if (!SMA_RSMA_ENV(pSma)) return TSDB_CODE_SUCCESS;
|
||||
|
||||
if ((terrno = atomic_load_32(&SMA_RSMA_STAT(pSma)->execStat))) {
|
||||
smaError("vgId:%d, failed to process rsma delete since invalid exec code: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
int32_t code = 0;
|
||||
if ((code = atomic_load_32(&SMA_RSMA_STAT(pSma)->execStat))) {
|
||||
smaError("vgId:%d, failed to process rsma delete since invalid exec code: %s", SMA_VID(pSma), tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
SDeleteRes *pDelRes = pReq;
|
||||
if (tdExecuteRSmaAsync(pSma, version, pMsg, len, STREAM_INPUT__REF_DATA_BLOCK, pDelRes->suid) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 1 since: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
if ((code = tdExecuteRSmaAsync(pSma, version, pMsg, len, STREAM_INPUT__REF_DATA_BLOCK, pDelRes->suid)) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 1 since: %s", SMA_VID(pSma), tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
return terrno;
|
||||
_exit:
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1099,10 +1069,7 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
|||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (vnodeGetStbIdList(pSma->pVnode, 0, suidList) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_EXIT(vnodeGetStbIdList(pSma->pVnode, 0, suidList));
|
||||
|
||||
int64_t arrSize = taosArrayGetSize(suidList);
|
||||
|
||||
|
@ -1146,10 +1113,7 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
|||
" qmsgLen:%" PRIi32,
|
||||
TD_VID(pVnode), suid, i, param->maxdelay[i], param->watermark[i], param->qmsgLen[i]);
|
||||
}
|
||||
if (tdRSmaProcessCreateImpl(pSma, &mr.me.stbEntry.rsmaParam, suid, mr.me.name) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_EXIT(tdRSmaProcessCreateImpl(pSma, &mr.me.stbEntry.rsmaParam, suid, mr.me.name));
|
||||
#if 0
|
||||
// reload all ctbUids for suid
|
||||
uidStore.suid = suid;
|
||||
|
@ -1180,7 +1144,7 @@ _exit:
|
|||
metaReaderClear(&mr);
|
||||
taosArrayDestroy(suidList);
|
||||
tdUidStoreDestory(&uidStore);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1188,20 +1152,16 @@ _exit:
|
|||
*/
|
||||
int32_t tdRSmaProcessRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer, int8_t rollback) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
int64_t nTables = 0;
|
||||
|
||||
// step 1: init env
|
||||
if (tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_ROLLUP) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TDB_INIT_FAILED;
|
||||
goto _err;
|
||||
}
|
||||
TAOS_CHECK_EXIT(tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_ROLLUP));
|
||||
|
||||
// step 2: iterate all stables to restore the rsma env
|
||||
if ((code = tdRSmaRestoreQTaskInfoInit(pSma, &nTables)) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
TAOS_CHECK_EXIT(tdRSmaRestoreQTaskInfoInit(pSma, &nTables));
|
||||
|
||||
_err:
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, restore rsma task %" PRIi8 "from qtaskf %" PRIi64 " failed since %s", SMA_VID(pSma), type,
|
||||
qtaskFileVer, tstrerror(code));
|
||||
|
@ -1210,7 +1170,7 @@ _err:
|
|||
type, qtaskFileVer, nTables);
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
|
||||
|
@ -1323,9 +1283,8 @@ _checkpoint:
|
|||
}
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
if (streamMetaSaveTask(pMeta, pTask)) {
|
||||
if ((code = streamMetaSaveTask(pMeta, pTask)) != 0) {
|
||||
streamMetaWUnLock(pMeta);
|
||||
code = terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosHashCancelIterate(pInfoHash, infoHash);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
@ -1338,9 +1297,9 @@ _checkpoint:
|
|||
}
|
||||
if (pMeta) {
|
||||
streamMetaWLock(pMeta);
|
||||
if (streamMetaCommit(pMeta)) {
|
||||
if ((code = streamMetaCommit(pMeta)) != 0) {
|
||||
streamMetaWUnLock(pMeta);
|
||||
code = terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (code == -1) code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
@ -1354,8 +1313,7 @@ _exit:
|
|||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1370,6 +1328,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
|||
SRSmaStat *pStat = NULL;
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
SRSmaInfoItem *pItem = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
if (!(pRSmaRef = taosHashGet(smaMgmt.refHash, ¶m, POINTER_BYTES))) {
|
||||
smaDebug("rsma fetch task not start since rsma info item:%p not exist in refHash:%p, rsetId:%d", param,
|
||||
|
@ -1386,7 +1345,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
|||
|
||||
pSma = pStat->pSma;
|
||||
|
||||
if (!(pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, pRSmaRef->suid))) {
|
||||
if ((code = tdAcquireRSmaInfoBySuid(pSma, pRSmaRef->suid, &pRSmaInfo)) != 0) {
|
||||
smaDebug("rsma fetch task not start since rsma info not exist, rsetId:%d refId:%" PRIi64 ")", smaMgmt.rsetId,
|
||||
pRSmaRef->refId); // pRSmaRef freed in taosHashRemove
|
||||
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId);
|
||||
|
@ -1484,6 +1443,8 @@ static void tdFreeRSmaSubmitItems(SArray *pItems, int32_t type) {
|
|||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL};
|
||||
for (int8_t i = 1; i <= TSDB_RETENTION_L2; ++i) {
|
||||
SRSmaInfoItem *pItem = RSMA_INFO_ITEM(pInfo, i - 1);
|
||||
|
@ -1512,12 +1473,10 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) {
|
|||
|
||||
pItem->nScanned = 0;
|
||||
|
||||
if ((terrno = qSetSMAInput(taskInfo, &dataBlock, 1, STREAM_INPUT__DATA_BLOCK)) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
if (tdRSmaExecAndSubmitResult(pSma, taskInfo, pItem, pInfo, STREAM_GET_ALL, NULL) < 0) {
|
||||
atomic_store_32(&SMA_RSMA_STAT(pSma)->execStat, terrno);
|
||||
goto _err;
|
||||
TAOS_CHECK_EXIT(qSetSMAInput(taskInfo, &dataBlock, 1, STREAM_INPUT__DATA_BLOCK));
|
||||
if ((code = tdRSmaExecAndSubmitResult(pSma, taskInfo, pItem, pInfo, STREAM_GET_ALL, NULL)) < 0) {
|
||||
atomic_store_32(&SMA_RSMA_STAT(pSma)->execStat, code);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi32 " maxDelay:%d, fetch finished",
|
||||
|
@ -1529,10 +1488,8 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
_end:
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
return TSDB_CODE_FAILED;
|
||||
_exit:
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SArray *pSubmitArr, ERsmaExecType type) {
|
||||
|
@ -1541,6 +1498,8 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
|
|||
int32_t nSubmit = 0;
|
||||
int32_t nDelete = 0;
|
||||
int64_t version = 0;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
SPackedData packData;
|
||||
|
||||
|
@ -1559,23 +1518,21 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
|
|||
version = packData.ver;
|
||||
if (!taosArrayPush(pSubmitArr, &packData)) {
|
||||
taosFreeQitem(msg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
++nSubmit;
|
||||
} else if (inputType == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||
_resume_delete:
|
||||
version = RSMA_EXEC_MSG_VER(msg);
|
||||
if ((terrno = tqExtractDelDataBlock(RSMA_EXEC_MSG_BODY(msg), RSMA_EXEC_MSG_LEN(msg), version,
|
||||
&packData.pDataBlock, 1))) {
|
||||
if ((code = tqExtractDelDataBlock(RSMA_EXEC_MSG_BODY(msg), RSMA_EXEC_MSG_LEN(msg), version,
|
||||
&packData.pDataBlock, 1))) {
|
||||
taosFreeQitem(msg);
|
||||
goto _err;
|
||||
TAOS_CHECK_EXIT(code);
|
||||
}
|
||||
|
||||
if (packData.pDataBlock && !taosArrayPush(pSubmitArr, &packData)) {
|
||||
taosFreeQitem(msg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
taosFreeQitem(msg);
|
||||
if (packData.pDataBlock) {
|
||||
|
@ -1593,9 +1550,7 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
|
|||
ASSERTS(size > 0, "size is %d", size);
|
||||
int32_t inputType = nSubmit > 0 ? STREAM_INPUT__MERGED_SUBMIT : STREAM_INPUT__REF_DATA_BLOCK;
|
||||
for (int32_t i = 1; i <= TSDB_RETENTION_L2; ++i) {
|
||||
if (tdExecuteRSmaImpl(pSma, pSubmitArr->pData, size, version, inputType, pInfo, type, i) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
TAOS_CHECK_EXIT(tdExecuteRSmaImpl(pSma, pSubmitArr->pData, size, version, inputType, pInfo, type, i));
|
||||
}
|
||||
tdFreeRSmaSubmitItems(pSubmitArr, inputType);
|
||||
nSubmit = 0;
|
||||
|
@ -1612,7 +1567,7 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
|
|||
|
||||
_rtn:
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
_exit:
|
||||
atomic_store_32(&SMA_RSMA_STAT(pSma)->execStat, terrno);
|
||||
smaError("vgId:%d, batch exec for suid:%" PRIi64 " execType:%d size:%d failed since %s", SMA_VID(pSma), pInfo->suid,
|
||||
type, (int32_t)taosArrayGetSize(pSubmitArr), terrstr());
|
||||
|
@ -1626,7 +1581,7 @@ _err:
|
|||
break;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1677,7 +1632,10 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
|||
taosReadAllQitems(pInfo->queue, pInfo->qall); // queue has mutex lock
|
||||
int32_t qallItemSize = taosQallItemSize(pInfo->qall);
|
||||
if (qallItemSize > 0) {
|
||||
tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type);
|
||||
if ((code = tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type)) != 0) {
|
||||
taosHashCancelIterate(infoHash, pIter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
smaDebug("vgId:%d, batchSize:%d, execType:%" PRIi32, SMA_VID(pSma), qallItemSize, type);
|
||||
}
|
||||
|
||||
|
@ -1693,7 +1651,10 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
|||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
tdRSmaFetchAllResult(pSma, pInfo);
|
||||
if ((code = tdRSmaFetchAllResult(pSma, pInfo)) != 0) {
|
||||
taosHashCancelIterate(infoHash, pIter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (0 == atomic_sub_fetch_32(&pRSmaStat->nFetchAll, 1)) {
|
||||
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
||||
|
@ -1742,5 +1703,5 @@ _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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
smaError("vgId:%d, %s failed at line %d since %s", SMA_VID(pReader->pSma), __func__, lino, tstrerror(code));
|
||||
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) {
|
||||
|
@ -114,7 +113,7 @@ int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
|
|||
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;
|
||||
|
@ -221,7 +207,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
|
|||
taosArrayPush(pReq->aSubmitTbData, &tbData);
|
||||
|
||||
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 +223,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 +237,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 +246,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 +260,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 +274,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 +297,7 @@ _exit:
|
|||
indexUid, tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -350,16 +334,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 +361,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 +386,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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
|
||||
int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl) {
|
||||
if (!(lvl[0] = taosMemoryMalloc(sizeof(SSttLvl)))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
lvl[0]->level = level;
|
||||
TARRAY2_INIT(lvl[0]->fobjArr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tsdbSttLvlClearFObj(void *data) { tsdbTFileObjUnref(*(STFileObj **)data); }
|
||||
static void tsdbSttLvlClearFObj(void *data) { TAOS_UNUSED(tsdbTFileObjUnref(*(STFileObj **)data)); }
|
||||
|
||||
int32_t tsdbSttLvlClear(SSttLvl **lvl) {
|
||||
if (lvl[0] != NULL) {
|
||||
|
@ -451,7 +451,9 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f
|
|||
|
||||
int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset) {
|
||||
fset[0] = taosMemoryCalloc(1, sizeof(STFileSet));
|
||||
if (fset[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (fset[0] == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
fset[0]->fid = fid;
|
||||
fset[0]->maxVerValid = VERSION_MAX;
|
||||
|
@ -543,7 +545,9 @@ int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_
|
|||
int32_t tsdbTFileSetRangeInitRef(STsdb *pTsdb, const STFileSet *fset1, int64_t sver, int64_t ever,
|
||||
STFileSetRange **fsr) {
|
||||
fsr[0] = taosMemoryCalloc(1, sizeof(*fsr[0]));
|
||||
if (fsr[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (fsr[0] == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
fsr[0]->fid = fset1->fid;
|
||||
fsr[0]->sver = sver;
|
||||
fsr[0]->ever = ever;
|
||||
|
|
|
@ -227,7 +227,7 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
|
|||
int32_t tsdbTFileObjInit(STsdb *pTsdb, const STFile *f, STFileObj **fobj) {
|
||||
fobj[0] = taosMemoryMalloc(sizeof(*fobj[0]));
|
||||
if (!fobj[0]) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&fobj[0]->mutex, NULL);
|
||||
|
|
|
@ -507,7 +507,7 @@ int32_t tsdbIterOpen(const STsdbIterConfig *config, STsdbIter **iter) {
|
|||
|
||||
iter[0] = taosMemoryCalloc(1, sizeof(*iter[0]));
|
||||
if (iter[0] == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
iter[0]->type = config->type;
|
||||
|
@ -677,7 +677,7 @@ int32_t tsdbIterMergerOpen(const TTsdbIterArray *iterArray, SIterMerger **merger
|
|||
|
||||
merger[0] = taosMemoryCalloc(1, sizeof(*merger[0]));
|
||||
if (merger[0] == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
merger[0]->isTomb = isTomb;
|
||||
|
|
|
@ -54,7 +54,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
|
|||
|
||||
pMemTable = (SMemTable *)taosMemoryCalloc(1, sizeof(*pMemTable));
|
||||
if (pMemTable == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _err;
|
||||
}
|
||||
taosInitRWLatch(&pMemTable->latch);
|
||||
|
@ -71,7 +71,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
|
|||
pMemTable->nBucket = MEM_MIN_HASH;
|
||||
pMemTable->aBucket = (STbData **)taosMemoryCalloc(pMemTable->nBucket, sizeof(STbData *));
|
||||
if (pMemTable->aBucket == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
taosMemoryFree(pMemTable);
|
||||
goto _err;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
|
|||
// do delete
|
||||
SDelData *pDelData = (SDelData *)vnodeBufPoolMalloc(pPool, sizeof(*pDelData));
|
||||
if (pDelData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _err;
|
||||
}
|
||||
pDelData->version = version;
|
||||
|
@ -195,7 +195,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
|
|||
pMemTable->minVer = TMIN(pMemTable->minVer, version);
|
||||
pMemTable->maxVer = TMAX(pMemTable->maxVer, version);
|
||||
|
||||
tsdbCacheDel(pTsdb, suid, uid, sKey, eKey);
|
||||
TAOS_UNUSED(tsdbCacheDel(pTsdb, suid, uid, sKey, eKey));
|
||||
|
||||
tsdbTrace("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64
|
||||
" at version %" PRId64,
|
||||
|
@ -214,7 +214,7 @@ int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backwa
|
|||
|
||||
(*ppIter) = (STbDataIter *)taosMemoryCalloc(1, sizeof(STbDataIter));
|
||||
if ((*ppIter) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ static int32_t tsdbMemTableRehash(SMemTable *pMemTable) {
|
|||
int32_t nBucket = pMemTable->nBucket * 2;
|
||||
STbData **aBucket = (STbData **)taosMemoryCalloc(nBucket, sizeof(STbData *));
|
||||
if (aBucket == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid
|
|||
ASSERT(pPool != NULL);
|
||||
pTbData = vnodeBufPoolMallocAligned(pPool, sizeof(*pTbData) + SL_NODE_SIZE(maxLevel) * 2);
|
||||
if (pTbData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
pTbData->suid = suid;
|
||||
|
@ -520,7 +520,7 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
|
|||
ASSERT(0);
|
||||
}
|
||||
if (pNode == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
|||
// copy and construct block data
|
||||
SBlockData *pBlockData = vnodeBufPoolMalloc(pPool, sizeof(*pBlockData));
|
||||
if (pBlockData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -599,7 +599,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
|||
pBlockData->aUid = NULL;
|
||||
pBlockData->aVersion = vnodeBufPoolMalloc(pPool, aColData[0].nData);
|
||||
if (pBlockData->aVersion == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
for (int32_t i = 0; i < pBlockData->nRow; i++) { // todo: here can be optimized
|
||||
|
@ -608,7 +608,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
|||
|
||||
pBlockData->aTSKEY = vnodeBufPoolMalloc(pPool, aColData[0].nData);
|
||||
if (pBlockData->aTSKEY == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy(pBlockData->aTSKEY, aColData[0].pData, aColData[0].nData);
|
||||
|
@ -616,7 +616,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
|||
pBlockData->nColData = nColData - 1;
|
||||
pBlockData->aColData = vnodeBufPoolMalloc(pPool, sizeof(SColData) * pBlockData->nColData);
|
||||
if (pBlockData->aColData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -661,7 +661,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
|||
}
|
||||
|
||||
if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) {
|
||||
tsdbCacheColFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, pBlockData);
|
||||
TAOS_UNUSED(tsdbCacheColFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, pBlockData));
|
||||
}
|
||||
|
||||
// SMemTable
|
||||
|
@ -720,7 +720,7 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
|||
pTbData->maxKey = key.key.ts;
|
||||
}
|
||||
if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) {
|
||||
tsdbCacheRowFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, version, nRow, aRow);
|
||||
TAOS_UNUSED(tsdbCacheRowFormatUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, version, nRow, aRow));
|
||||
}
|
||||
|
||||
// SMemTable
|
||||
|
@ -780,22 +780,3 @@ static FORCE_INLINE int32_t tbDataPCmprFn(const void *p1, const void *p2) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable) {
|
||||
SArray *aTbDataP = taosArrayInit(pMemTable->nTbData, sizeof(STbData *));
|
||||
if (aTbDataP == NULL) goto _exit;
|
||||
|
||||
for (int32_t iBucket = 0; iBucket < pMemTable->nBucket; iBucket++) {
|
||||
STbData *pTbData = pMemTable->aBucket[iBucket];
|
||||
|
||||
while (pTbData) {
|
||||
taosArrayPush(aTbDataP, &pTbData);
|
||||
pTbData = pTbData->next;
|
||||
}
|
||||
}
|
||||
|
||||
taosArraySort(aTbDataP, tbDataPCmprFn);
|
||||
|
||||
_exit:
|
||||
return aTbDataP;
|
||||
}
|
|
@ -42,7 +42,6 @@ static int32_t tsdbTFileSetRangeCmprFn(STFileSetRange* x, STFileSetRange* y) {
|
|||
STsdbFSetPartition* tsdbFSetPartitionCreate() {
|
||||
STsdbFSetPartition* pSP = taosMemoryCalloc(1, sizeof(STsdbFSetPartition));
|
||||
if (pSP == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
for (int32_t i = 0; i < TSDB_FSET_RANGE_TYP_MAX; i++) {
|
||||
|
@ -140,7 +139,6 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition**
|
|||
STsdbFSetPartList* tsdbFSetPartListCreate() {
|
||||
STsdbFSetPartList* pList = taosMemoryCalloc(1, sizeof(STsdbFSetPartList));
|
||||
if (pList == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
TARRAY2_INIT(pList);
|
||||
|
@ -160,7 +158,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray
|
|||
|
||||
TFileSetRangeArray* pDiff = taosMemoryCalloc(1, sizeof(TFileSetRangeArray));
|
||||
if (pDiff == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _err;
|
||||
}
|
||||
TARRAY2_INIT(pDiff);
|
||||
|
@ -169,7 +167,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray
|
|||
TARRAY2_FOREACH(pList, part) {
|
||||
STFileSetRange* r = taosMemoryCalloc(1, sizeof(STFileSetRange));
|
||||
if (r == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _err;
|
||||
}
|
||||
int64_t maxVerValid = -1;
|
||||
|
|
|
@ -154,14 +154,16 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
|
|||
|
||||
int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize) {
|
||||
int32_t n = 0;
|
||||
int32_t code;
|
||||
int32_t offset;
|
||||
|
||||
tMapDataReset(pMapData);
|
||||
|
||||
n += tGetI32v(p + n, &pMapData->nItem);
|
||||
if (pMapData->nItem) {
|
||||
if (tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t lOffset = 0;
|
||||
|
@ -172,8 +174,9 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData, int32_t *decodedSize) {
|
|||
}
|
||||
|
||||
n += tGetI32v(p + n, &pMapData->nData);
|
||||
if (tRealloc(&pMapData->pData, pMapData->nData)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = tRealloc(&pMapData->pData, pMapData->nData);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
memcpy(pMapData->pData, p + n, pMapData->nData);
|
||||
n += pMapData->nData;
|
||||
|
@ -753,7 +756,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = key.ts}));
|
||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -766,7 +769,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
continue;
|
||||
} else if (pTSchema->columns[jCol].colId > pTColumn->colId) {
|
||||
if (taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -778,7 +781,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
pColVal->value.pData = NULL;
|
||||
code = tRealloc(&pColVal->value.pData, pColVal->value.nData);
|
||||
if (code) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pColVal->value.nData) {
|
||||
|
@ -787,14 +790,14 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
}
|
||||
|
||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
for (; iCol < pMerger->pTSchema->numOfCols; ++iCol) {
|
||||
pTColumn = &pMerger->pTSchema->columns[iCol];
|
||||
if (taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type)) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -866,7 +869,7 @@ int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pSchema) {
|
|||
pMerger->pTSchema = pSchema;
|
||||
pMerger->pArray = taosArrayInit(pSchema->numOfCols, sizeof(SColVal));
|
||||
if (pMerger->pArray == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
} else {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1036,11 +1039,11 @@ int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx,
|
|||
TSDBKEY *pItem1 = taosArrayGet(aSkyline, sidx * 2);
|
||||
TSDBKEY *pItem2 = taosArrayGet(aSkyline, sidx * 2 + 1);
|
||||
if (taosArrayPush(pSkyline, &pItem1) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (taosArrayPush(pSkyline, &pItem2) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
} else {
|
||||
SArray *pSkyline1 = NULL;
|
||||
|
@ -1048,10 +1051,13 @@ int32_t tsdbBuildDeleteSkylineImpl(SArray *aSkyline, int32_t sidx, int32_t eidx,
|
|||
midx = (sidx + eidx) / 2;
|
||||
|
||||
pSkyline1 = taosArrayInit((midx - sidx + 1) * 2, POINTER_BYTES);
|
||||
if (pSkyline1 == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
pSkyline2 = taosArrayInit((eidx - midx) * 2, POINTER_BYTES);
|
||||
if (pSkyline1 == NULL || pSkyline1 == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _clear;
|
||||
if (pSkyline2 == NULL) {
|
||||
taosArrayDestroy(pSkyline1);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = tsdbBuildDeleteSkylineImpl(aSkyline, sidx, midx, pSkyline1);
|
||||
|
@ -1076,25 +1082,25 @@ int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SAr
|
|||
int32_t dataNum = eidx - sidx + 1;
|
||||
SArray *aTmpSkyline = taosArrayInit(dataNum * 2, sizeof(TSDBKEY));
|
||||
if (aTmpSkyline == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SArray *pSkyline = taosArrayInit(dataNum * 2, POINTER_BYTES);
|
||||
if (pSkyline == NULL) {
|
||||
taosArrayDestroy(aTmpSkyline);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
taosArrayClear(aSkyline);
|
||||
for (int32_t i = sidx; i <= eidx; ++i) {
|
||||
pDelData = (SDelData *)taosArrayGet(aDelData, i);
|
||||
if (taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->sKey, .version = pDelData->version}) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _clear;
|
||||
}
|
||||
|
||||
if (taosArrayPush(aTmpSkyline, &(TSDBKEY){.ts = pDelData->eKey, .version = 0}) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _clear;
|
||||
}
|
||||
}
|
||||
|
@ -1106,7 +1112,7 @@ int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SAr
|
|||
for (int32_t i = 0; i < skylineNum; ++i) {
|
||||
TSDBKEY *p = taosArrayGetP(pSkyline, i);
|
||||
if (taosArrayPush(aSkyline, p) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _clear;
|
||||
}
|
||||
}
|
||||
|
@ -1196,7 +1202,7 @@ static int32_t tBlockDataAdjustColData(SBlockData *pBlockData, int32_t nColData)
|
|||
} else if (pBlockData->nColData < nColData) {
|
||||
SColData *aColData = taosMemoryRealloc(pBlockData->aColData, sizeof(SBlockData) * nColData);
|
||||
if (aColData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -1284,7 +1290,7 @@ int32_t tBlockDataAddColData(SBlockData *pBlockData, int16_t cid, int8_t type, i
|
|||
|
||||
SColData *newColData = taosMemoryRealloc(pBlockData->aColData, sizeof(SColData) * (pBlockData->nColData + 1));
|
||||
if (newColData == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pBlockData->aColData = newColData;
|
||||
|
@ -1452,6 +1458,7 @@ int32_t tBlockDataCompress(SBlockData *bData, void *pCompr, SBuffer *buffers, SB
|
|||
|
||||
SColCompressInfo *pInfo = pCompr;
|
||||
code = tsdbGetColCmprAlgFromSet(pInfo->pColCmpr, 1, &pInfo->defaultCmprAlg);
|
||||
TAOS_UNUSED(code);
|
||||
|
||||
SDiskDataHdr hdr = {
|
||||
.delimiter = TSDB_FILE_DLMT,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -140,8 +140,9 @@ void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) {
|
|||
// allocate a new node
|
||||
pNode = taosMemoryMalloc(sizeof(*pNode) + size);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||
if (pPool->lock) {
|
||||
taosThreadSpinUnlock(pPool->lock);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -173,7 +174,6 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
// allocate a new node
|
||||
pNode = taosMemoryMalloc(sizeof(*pNode) + size);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
@ -904,7 +903,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);
|
||||
|
|
|
@ -21,17 +21,16 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "tpagedbuf.h"
|
||||
#include "ttszip.h"
|
||||
|
||||
typedef struct MinMaxEntry {
|
||||
union {
|
||||
double dMinVal;
|
||||
//double i64MinVal;
|
||||
double dMinVal;
|
||||
// double i64MinVal;
|
||||
uint64_t u64MinVal;
|
||||
};
|
||||
union {
|
||||
double dMaxVal;
|
||||
//double i64MaxVal;
|
||||
double dMaxVal;
|
||||
// double i64MaxVal;
|
||||
int64_t u64MaxVal;
|
||||
};
|
||||
} MinMaxEntry;
|
||||
|
|
|
@ -25,5 +25,4 @@
|
|||
#include "tfunctionInt.h"
|
||||
#include "thistogram.h"
|
||||
#include "tpercentile.h"
|
||||
#include "ttszip.h"
|
||||
#include "tudf.h"
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "sclInt.h"
|
||||
#include "sclvector.h"
|
||||
|
||||
typedef int32_t (*_geomDoRelationFunc_t)(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res);
|
||||
typedef int32_t (*_geomDoRelationFunc_t)(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1,
|
||||
const GEOSGeometry *geom2, bool swapped, char *res);
|
||||
|
||||
typedef int32_t (*_geomInitCtxFunc_t)();
|
||||
typedef int32_t (*_geomExecuteOneParamFunc_t)(SColumnInfoData *pInputData, int32_t i, SColumnInfoData *pOutputData);
|
||||
|
@ -35,7 +35,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) {
|
|||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
unsigned char *outputGeom = NULL;
|
||||
size_t size = 0;
|
||||
size_t size = 0;
|
||||
code = doMakePoint(x, y, &outputGeom, &size);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
|
@ -47,7 +47,7 @@ int32_t doMakePointFunc(double x, double y, unsigned char **output) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy(varDataVal(*output), outputGeom, size);
|
||||
(void)memcpy(varDataVal(*output), outputGeom, size);
|
||||
varDataSetLen(*output, size);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -62,14 +62,14 @@ _exit:
|
|||
int32_t doGeomFromTextFunc(const char *input, unsigned char **output) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
if ((varDataLen(input)) == 0) { //empty value
|
||||
if ((varDataLen(input)) == 0) { // empty value
|
||||
*output = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char *inputGeom = NULL;
|
||||
char *inputGeom = NULL;
|
||||
unsigned char *outputGeom = NULL;
|
||||
size_t size = 0;
|
||||
size_t size = 0;
|
||||
|
||||
// make a zero ending string
|
||||
inputGeom = taosMemoryCalloc(1, varDataLen(input) + 1);
|
||||
|
@ -77,12 +77,9 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) {
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy(inputGeom, varDataVal(input), varDataLen(input));
|
||||
(void)memcpy(inputGeom, varDataVal(input), varDataLen(input));
|
||||
|
||||
code = doGeomFromText(inputGeom, &outputGeom, &size);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(doGeomFromText(inputGeom, &outputGeom, &size), NULL, _exit);
|
||||
|
||||
*output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE);
|
||||
if (*output == NULL) {
|
||||
|
@ -90,7 +87,7 @@ int32_t doGeomFromTextFunc(const char *input, unsigned char **output) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy(varDataVal(*output), outputGeom, size);
|
||||
(void)memcpy(varDataVal(*output), outputGeom, size);
|
||||
varDataSetLen(*output, size);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -106,16 +103,13 @@ _exit:
|
|||
int32_t doAsTextFunc(unsigned char *input, char **output) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
if ((varDataLen(input)) == 0) { //empty value
|
||||
if ((varDataLen(input)) == 0) { // empty value
|
||||
*output = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char *outputWKT = NULL;
|
||||
code = doAsText(varDataVal(input), varDataLen(input), &outputWKT);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(doAsText(varDataVal(input), varDataLen(input), &outputWKT), NULL, _exit);
|
||||
|
||||
size_t size = strlen(outputWKT);
|
||||
*output = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE);
|
||||
|
@ -124,7 +118,7 @@ int32_t doAsTextFunc(unsigned char *input, char **output) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy(varDataVal(*output), outputWKT, size);
|
||||
(void)memcpy(varDataVal(*output), outputWKT, size);
|
||||
varDataSetLen(*output, size);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -139,28 +133,17 @@ int32_t executeMakePointFunc(SColumnInfoData *pInputData[], int32_t iLeft, int32
|
|||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
_getDoubleValue_fn_t getDoubleValueFn[2];
|
||||
getDoubleValueFn[0]= getVectorDoubleValueFn(pInputData[0]->info.type);
|
||||
getDoubleValueFn[1]= getVectorDoubleValueFn(pInputData[1]->info.type);
|
||||
getDoubleValueFn[0] = getVectorDoubleValueFn(pInputData[0]->info.type);
|
||||
getDoubleValueFn[1] = getVectorDoubleValueFn(pInputData[1]->info.type);
|
||||
|
||||
unsigned char *output = NULL;
|
||||
double leftRes = 0;
|
||||
double rightRes = 0;
|
||||
code = getDoubleValueFn[0](pInputData[0]->pData, iLeft, &leftRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
code = getDoubleValueFn[1](pInputData[1]->pData, iRight, &rightRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
code = doMakePointFunc(leftRes, rightRes, &output);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
code = colDataSetVal(pOutputData, TMAX(iLeft, iRight), output, (output == NULL));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
double leftRes = 0;
|
||||
double rightRes = 0;
|
||||
|
||||
TAOS_CHECK_GOTO(getDoubleValueFn[0](pInputData[0]->pData, iLeft, &leftRes), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(getDoubleValueFn[1](pInputData[1]->pData, iRight, &rightRes), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(doMakePointFunc(leftRes, rightRes, &output), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pOutputData, TMAX(iLeft, iRight), output, (output == NULL)), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
if (output) {
|
||||
|
@ -173,14 +156,11 @@ _exit:
|
|||
int32_t executeGeomFromTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnInfoData *pOutputData) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
char *input = colDataGetData(pInputData, i);
|
||||
char *input = colDataGetData(pInputData, i);
|
||||
unsigned char *output = NULL;
|
||||
code = doGeomFromTextFunc(input, &output);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = colDataSetVal(pOutputData, i, output, (output == NULL));
|
||||
TAOS_CHECK_GOTO(doGeomFromTextFunc(input, &output), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pOutputData, i, output, (output == NULL)), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
if (output) {
|
||||
|
@ -194,13 +174,10 @@ int32_t executeAsTextFunc(SColumnInfoData *pInputData, int32_t i, SColumnInfoDat
|
|||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
unsigned char *input = colDataGetData(pInputData, i);
|
||||
char *output = NULL;
|
||||
code = doAsTextFunc(input, &output);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
char *output = NULL;
|
||||
|
||||
code = colDataSetVal(pOutputData, i, output, (output == NULL));
|
||||
TAOS_CHECK_GOTO(doAsTextFunc(input, &output), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pOutputData, i, output, (output == NULL)), NULL, _exit);
|
||||
|
||||
_exit:
|
||||
if (output) {
|
||||
|
@ -211,36 +188,22 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t executeRelationFunc(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1,
|
||||
const GEOSGeometry *geom2, int32_t i,
|
||||
bool swapped, SColumnInfoData *pOutputData,
|
||||
const GEOSGeometry *geom2, int32_t i, bool swapped, SColumnInfoData *pOutputData,
|
||||
_geomDoRelationFunc_t doRelationFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
char res = 0;
|
||||
|
||||
if (!geom1 || !geom2) { //if empty input value
|
||||
if (!geom1 || !geom2) { // if empty input value
|
||||
res = -1;
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
else {
|
||||
code = doRelationFn(geom1, preparedGeom1, geom2, swapped, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
TAOS_CHECK_RETURN(doRelationFn(geom1, preparedGeom1, geom2, swapped, &res));
|
||||
}
|
||||
|
||||
code = colDataSetVal(pOutputData, i, &res, (res==-1));
|
||||
|
||||
return code;
|
||||
return colDataSetVal(pOutputData, i, &res, (res == -1));
|
||||
}
|
||||
|
||||
int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
||||
_geomInitCtxFunc_t initCtxFn, _geomExecuteOneParamFunc_t executeOneParamFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
code = initCtxFn();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput, _geomInitCtxFunc_t initCtxFn,
|
||||
_geomExecuteOneParamFunc_t executeOneParamFn) {
|
||||
TAOS_CHECK_RETURN(initCtxFn());
|
||||
|
||||
SColumnInfoData *pInputData = pInput->columnData;
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
|
@ -248,54 +211,40 @@ int32_t geomOneParamFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
|
||||
if (IS_NULL_TYPE(GET_PARAM_TYPE(pInput))) {
|
||||
colDataSetNNULL(pOutputData, 0, pInput->numOfRows);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||
if (colDataIsNull_s(pInputData, i)) {
|
||||
colDataSetNULL(pOutputData, i);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
continue;
|
||||
}
|
||||
|
||||
code = executeOneParamFn(pInputData, i, pOutputData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(executeOneParamFn(pInputData, i, pOutputData));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
||||
_geomInitCtxFunc_t initCtxFn, _geomExecuteTwoParamsFunc_t executeTwoParamsFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
code = initCtxFn();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput, _geomInitCtxFunc_t initCtxFn,
|
||||
_geomExecuteTwoParamsFunc_t executeTwoParamsFn) {
|
||||
TAOS_CHECK_RETURN(initCtxFn());
|
||||
|
||||
SColumnInfoData *pInputData[2];
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
pInputData[0] = pInput[0].columnData;
|
||||
pInputData[1] = pInput[1].columnData;
|
||||
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) ||
|
||||
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool isConstantLeft = (pInput[0].numOfRows == 1);
|
||||
bool isConstantRight = (pInput[1].numOfRows == 1);
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool isConstantLeft = (pInput[0].numOfRows == 1);
|
||||
bool isConstantRight = (pInput[1].numOfRows == 1);
|
||||
int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows);
|
||||
pOutput->numOfRows = numOfRows;
|
||||
|
||||
if (hasNullType || // one of operant is NULL type
|
||||
(isConstantLeft && colDataIsNull_s(pInputData[0], 0)) || // left operand is constant NULL
|
||||
(isConstantRight && colDataIsNull_s(pInputData[1], 0))) { // right operand is constant NULL
|
||||
if (hasNullType || // one of operant is NULL type
|
||||
(isConstantLeft && colDataIsNull_s(pInputData[0], 0)) || // left operand is constant NULL
|
||||
(isConstantRight && colDataIsNull_s(pInputData[1], 0))) { // right operand is constant NULL
|
||||
colDataSetNNULL(pOutputData, 0, numOfRows);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int32_t iLeft = 0;
|
||||
int32_t iRight = 0;
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
|
@ -305,107 +254,80 @@ int32_t geomTwoParamsFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
if ((!isConstantLeft && colDataIsNull_s(pInputData[0], iLeft)) ||
|
||||
(!isConstantRight && colDataIsNull_s(pInputData[1], iRight))) {
|
||||
colDataSetNULL(pOutputData, i);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
continue;
|
||||
}
|
||||
|
||||
code = executeTwoParamsFn(pInputData, iLeft, iRight, pOutputData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(executeTwoParamsFn(pInputData, iLeft, iRight, pOutputData));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
||||
bool swapAllowed, _geomDoRelationFunc_t doRelationFn) {
|
||||
int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput, bool swapAllowed,
|
||||
_geomDoRelationFunc_t doRelationFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
|
||||
code = initCtxRelationFunc();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_RETURN(initCtxRelationFunc());
|
||||
|
||||
// handle with all NULL output
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) ||
|
||||
IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool isConstant1 = (pInput[0].numOfRows == 1);
|
||||
bool isConstant2 = (pInput[1].numOfRows == 1);
|
||||
bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1])));
|
||||
bool isConstant1 = (pInput[0].numOfRows == 1);
|
||||
bool isConstant2 = (pInput[1].numOfRows == 1);
|
||||
int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows);
|
||||
pOutput->numOfRows = numOfRows;
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
|
||||
if (hasNullType || // at least one of operant is NULL type
|
||||
(isConstant1 && colDataIsNull_s(pInput[0].columnData, 0)) || // left operand is constant NULL
|
||||
(isConstant2 && colDataIsNull_s(pInput[1].columnData, 0))) { // right operand is constant NULL
|
||||
if (hasNullType || // at least one of operant is NULL type
|
||||
(isConstant1 && colDataIsNull_s(pInput[0].columnData, 0)) || // left operand is constant NULL
|
||||
(isConstant2 && colDataIsNull_s(pInput[1].columnData, 0))) { // right operand is constant NULL
|
||||
colDataSetNNULL(pOutputData, 0, numOfRows);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
bool swapped = false;
|
||||
bool swapped = false;
|
||||
SColumnInfoData *pInputData[2];
|
||||
|
||||
// swap two input data to make sure input data 0 is constant if swapAllowed and only isConstant2 is true
|
||||
if (swapAllowed &&
|
||||
!isConstant1 && isConstant2) {
|
||||
if (swapAllowed && !isConstant1 && isConstant2) {
|
||||
pInputData[0] = pInput[1].columnData;
|
||||
pInputData[1] = pInput[0].columnData;
|
||||
|
||||
isConstant1 = true;
|
||||
isConstant2 = false;
|
||||
swapped = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pInputData[0] = pInput[0].columnData;
|
||||
pInputData[1] = pInput[1].columnData;
|
||||
}
|
||||
|
||||
GEOSGeometry *geom1 = NULL;
|
||||
GEOSGeometry *geom2 = NULL;
|
||||
GEOSGeometry *geom1 = NULL;
|
||||
GEOSGeometry *geom2 = NULL;
|
||||
const GEOSPreparedGeometry *preparedGeom1 = NULL;
|
||||
|
||||
// if there is constant, make PreparedGeometry from pInputData 0
|
||||
if (isConstant1) {
|
||||
code = readGeometry(colDataGetData(pInputData[0], 0), &geom1, &preparedGeom1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[0], 0), &geom1, &preparedGeom1), NULL, _exit);
|
||||
}
|
||||
if (isConstant2) {
|
||||
code = readGeometry(colDataGetData(pInputData[1], 0), &geom2, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[1], 0), &geom2, NULL), NULL, _exit);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
if ((!isConstant1 && colDataIsNull_s(pInputData[0], i)) ||
|
||||
(!isConstant2 && colDataIsNull_s(pInputData[1], i))) {
|
||||
if ((!isConstant1 && colDataIsNull_s(pInputData[0], i)) || (!isConstant2 && colDataIsNull_s(pInputData[1], i))) {
|
||||
colDataSetNULL(pOutputData, i);
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isConstant1) {
|
||||
code = readGeometry(colDataGetData(pInputData[0], i), &geom1, &preparedGeom1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[0], i), &geom1, &preparedGeom1), NULL, _exit);
|
||||
}
|
||||
if (!isConstant2) {
|
||||
code = readGeometry(colDataGetData(pInputData[1], i), &geom2, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(readGeometry(colDataGetData(pInputData[1], i), &geom2, NULL), NULL, _exit);
|
||||
}
|
||||
|
||||
code = executeRelationFunc(geom1, preparedGeom1, geom2, i, swapped, pOutputData, doRelationFn);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
TAOS_CHECK_GOTO(executeRelationFunc(geom1, preparedGeom1, geom2, i, swapped, pOutputData, doRelationFn), NULL,
|
||||
_exit);
|
||||
|
||||
if (!isConstant1) {
|
||||
destroyGeometry(&geom1, &preparedGeom1);
|
||||
|
@ -415,11 +337,13 @@ int32_t geomRelationFunction(SScalarParam *pInput, SScalarParam *pOutput,
|
|||
}
|
||||
}
|
||||
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
_exit:
|
||||
destroyGeometry(&geom1, &preparedGeom1);
|
||||
destroyGeometry(&geom2, NULL);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t makePointFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
#include "types.h"
|
||||
|
||||
typedef char (*_geosRelationFunc_t)(GEOSContextHandle_t handle, const GEOSGeometry *g1, const GEOSGeometry *g2);
|
||||
typedef char (*_geosPreparedRelationFunc_t)(GEOSContextHandle_t handle, const GEOSPreparedGeometry *pg1, const GEOSGeometry *g2);
|
||||
typedef char (*_geosPreparedRelationFunc_t)(GEOSContextHandle_t handle, const GEOSPreparedGeometry *pg1,
|
||||
const GEOSGeometry *g2);
|
||||
|
||||
void geosFreeBuffer(void *buffer) {
|
||||
if (buffer) {
|
||||
|
@ -27,13 +28,13 @@ void geosFreeBuffer(void *buffer) {
|
|||
}
|
||||
|
||||
void geosErrMsgeHandler(const char *errMsg, void *userData) {
|
||||
char* targetErrMsg = userData;
|
||||
char *targetErrMsg = userData;
|
||||
snprintf(targetErrMsg, 512, "%s", errMsg);
|
||||
}
|
||||
|
||||
int32_t initCtxMakePoint() {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (geosCtx->handle == NULL) {
|
||||
geosCtx->handle = GEOS_init_r();
|
||||
|
@ -41,7 +42,7 @@ int32_t initCtxMakePoint() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKBWriter == NULL) {
|
||||
|
@ -57,10 +58,10 @@ int32_t initCtxMakePoint() {
|
|||
// outputWKT is a zero ending string
|
||||
// need to call geosFreeBuffer(*outputGeom) later
|
||||
int32_t doMakePoint(double x, double y, unsigned char **outputGeom, size_t *size) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
GEOSGeometry *geom = NULL;
|
||||
GEOSGeometry *geom = NULL;
|
||||
unsigned char *wkb = NULL;
|
||||
|
||||
geom = GEOSGeom_createPointFromXY_r(geosCtx->handle, x, y);
|
||||
|
@ -89,6 +90,10 @@ _exit:
|
|||
static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData) {
|
||||
int32_t code = 0;
|
||||
char *wktPatternWithSpace = taosMemoryCalloc(4, 1024);
|
||||
if (NULL == wktPatternWithSpace) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
sprintf(
|
||||
wktPatternWithSpace,
|
||||
"^( *)point( *)z?m?( *)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( "
|
||||
|
@ -148,8 +153,8 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData
|
|||
}
|
||||
|
||||
int32_t initCtxGeomFromText() {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (geosCtx->handle == NULL) {
|
||||
geosCtx->handle = GEOS_init_r();
|
||||
|
@ -157,7 +162,7 @@ int32_t initCtxGeomFromText() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKTReader == NULL) {
|
||||
|
@ -184,15 +189,15 @@ int32_t initCtxGeomFromText() {
|
|||
// inputWKT is a zero ending string
|
||||
// need to call geosFreeBuffer(*outputGeom) later
|
||||
int32_t doGeomFromText(const char *inputWKT, unsigned char **outputGeom, size_t *size) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
GEOSGeometry *geom = NULL;
|
||||
GEOSGeometry *geom = NULL;
|
||||
unsigned char *wkb = NULL;
|
||||
|
||||
if (doRegExec(inputWKT, geosCtx->WKTRegex, geosCtx->WKTMatchData) != 0) {
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
goto _exit;
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
geom = GEOSWKTReader_read_r(geosCtx->handle, geosCtx->WKTReader, inputWKT);
|
||||
|
@ -219,8 +224,8 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t initCtxAsText() {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (geosCtx->handle == NULL) {
|
||||
geosCtx->handle = GEOS_init_r();
|
||||
|
@ -228,7 +233,7 @@ int32_t initCtxAsText() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKBReader == NULL) {
|
||||
|
@ -255,10 +260,10 @@ int32_t initCtxAsText() {
|
|||
// outputWKT is a zero ending string
|
||||
// need to call geosFreeBuffer(*outputWKT) later
|
||||
int32_t doAsText(const unsigned char *inputGeom, size_t size, char **outputWKT) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
GEOSGeometry *geom = NULL;
|
||||
GEOSGeometry *geom = NULL;
|
||||
unsigned char *wkt = NULL;
|
||||
|
||||
geom = GEOSWKBReader_read_r(geosCtx->handle, geosCtx->WKBReader, inputGeom, size);
|
||||
|
@ -286,8 +291,8 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t initCtxRelationFunc() {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (geosCtx->handle == NULL) {
|
||||
geosCtx->handle = GEOS_init_r();
|
||||
|
@ -295,7 +300,7 @@ int32_t initCtxRelationFunc() {
|
|||
return code;
|
||||
}
|
||||
|
||||
GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
(void)GEOSContext_setErrorMessageHandler_r(geosCtx->handle, geosErrMsgeHandler, geosCtx->errMsg);
|
||||
}
|
||||
|
||||
if (geosCtx->WKBReader == NULL) {
|
||||
|
@ -309,88 +314,81 @@ int32_t initCtxRelationFunc() {
|
|||
}
|
||||
|
||||
int32_t doGeosRelation(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res,
|
||||
_geosRelationFunc_t relationFn,
|
||||
_geosRelationFunc_t swappedRelationFn,
|
||||
bool swapped, char *res, _geosRelationFunc_t relationFn, _geosRelationFunc_t swappedRelationFn,
|
||||
_geosPreparedRelationFunc_t preparedRelationFn,
|
||||
_geosPreparedRelationFunc_t swappedPreparedRelationFn) {
|
||||
int32_t code = TSDB_CODE_FAILED;
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (!preparedGeom1) {
|
||||
if (!swapped) {
|
||||
ASSERT(relationFn);
|
||||
*res = relationFn(geosCtx->handle, geom1, geom2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSERT(swappedRelationFn);
|
||||
*res = swappedRelationFn(geosCtx->handle, geom1, geom2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!swapped) {
|
||||
ASSERT(preparedRelationFn);
|
||||
*res = preparedRelationFn(geosCtx->handle, preparedGeom1, geom2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSERT(swappedPreparedRelationFn);
|
||||
*res = swappedPreparedRelationFn(geosCtx->handle, preparedGeom1, geom2);
|
||||
}
|
||||
}
|
||||
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doIntersects(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSIntersects_r, GEOSIntersects_r, GEOSPreparedIntersects_r, GEOSPreparedIntersects_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSIntersects_r, GEOSIntersects_r,
|
||||
GEOSPreparedIntersects_r, GEOSPreparedIntersects_r);
|
||||
}
|
||||
|
||||
int32_t doEquals(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, NULL, geom2, swapped, res,
|
||||
GEOSEquals_r, GEOSEquals_r, NULL, NULL); // no prepared version for eguals()
|
||||
return doGeosRelation(geom1, NULL, geom2, swapped, res, GEOSEquals_r, GEOSEquals_r, NULL,
|
||||
NULL); // no prepared version for eguals()
|
||||
}
|
||||
|
||||
int32_t doTouches(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSTouches_r, GEOSTouches_r, GEOSPreparedTouches_r, GEOSPreparedTouches_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSTouches_r, GEOSTouches_r, GEOSPreparedTouches_r,
|
||||
GEOSPreparedTouches_r);
|
||||
}
|
||||
|
||||
int32_t doCovers(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSCovers_r, GEOSCoveredBy_r, GEOSPreparedCovers_r, GEOSPreparedCoveredBy_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSCovers_r, GEOSCoveredBy_r, GEOSPreparedCovers_r,
|
||||
GEOSPreparedCoveredBy_r);
|
||||
}
|
||||
|
||||
int32_t doContains(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
GEOSContains_r, GEOSWithin_r, GEOSPreparedContains_r, GEOSPreparedWithin_r);
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, GEOSContains_r, GEOSWithin_r, GEOSPreparedContains_r,
|
||||
GEOSPreparedWithin_r);
|
||||
}
|
||||
|
||||
int32_t doContainsProperly(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1, const GEOSGeometry *geom2,
|
||||
bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res,
|
||||
NULL, NULL, GEOSPreparedContainsProperly_r, NULL);
|
||||
int32_t doContainsProperly(const GEOSGeometry *geom1, const GEOSPreparedGeometry *preparedGeom1,
|
||||
const GEOSGeometry *geom2, bool swapped, char *res) {
|
||||
return doGeosRelation(geom1, preparedGeom1, geom2, swapped, res, NULL, NULL, GEOSPreparedContainsProperly_r, NULL);
|
||||
}
|
||||
|
||||
// input is with VARSTR format
|
||||
// need to call destroyGeometry(outputGeom, outputPreparedGeom) later
|
||||
int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, const GEOSPreparedGeometry **outputPreparedGeom) {
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom,
|
||||
const GEOSPreparedGeometry **outputPreparedGeom) {
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
ASSERT(outputGeom); //it is not allowed if outputGeom is NULL
|
||||
ASSERT(outputGeom); // it is not allowed if outputGeom is NULL
|
||||
*outputGeom = NULL;
|
||||
|
||||
if (outputPreparedGeom) { //it means not to generate PreparedGeometry if outputPreparedGeom is NULL
|
||||
if (outputPreparedGeom) { // it means not to generate PreparedGeometry if outputPreparedGeom is NULL
|
||||
*outputPreparedGeom = NULL;
|
||||
}
|
||||
|
||||
if (varDataLen(input) == 0) { //empty value
|
||||
if (varDataLen(input) == 0) { // empty value
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -410,7 +408,7 @@ int32_t readGeometry(const unsigned char *input, GEOSGeometry **outputGeom, cons
|
|||
}
|
||||
|
||||
void destroyGeometry(GEOSGeometry **geom, const GEOSPreparedGeometry **preparedGeom) {
|
||||
SGeosContext* geosCtx = getThreadLocalGeosCtx();
|
||||
SGeosContext *geosCtx = getThreadLocalGeosCtx();
|
||||
|
||||
if (preparedGeom && *preparedGeom) {
|
||||
GEOSPreparedGeom_destroy_r(geosCtx->handle, *preparedGeom);
|
||||
|
|
|
@ -21,29 +21,29 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SERIALIZE_MEM_TO_BUF(buf, key, mem) \
|
||||
do { \
|
||||
memcpy((void *)buf, (void *)(&key->mem), sizeof(key->mem)); \
|
||||
buf += sizeof(key->mem); \
|
||||
#define SERIALIZE_MEM_TO_BUF(buf, key, mem) \
|
||||
do { \
|
||||
(void)memcpy((void *)buf, (void *)(&key->mem), sizeof(key->mem)); \
|
||||
buf += sizeof(key->mem); \
|
||||
} while (0)
|
||||
|
||||
#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \
|
||||
do { \
|
||||
memcpy((void *)buf, (void *)key->mem, len); \
|
||||
buf += len; \
|
||||
#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \
|
||||
do { \
|
||||
(void)memcpy((void *)buf, (void *)key->mem, len); \
|
||||
buf += len; \
|
||||
} while (0)
|
||||
|
||||
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
|
||||
do { \
|
||||
type c = var; \
|
||||
memcpy((void *)buf, (void *)&c, sizeof(c)); \
|
||||
buf += sizeof(c); \
|
||||
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
|
||||
do { \
|
||||
type c = var; \
|
||||
(void)memcpy((void *)buf, (void *)&c, sizeof(c)); \
|
||||
buf += sizeof(c); \
|
||||
} while (0)
|
||||
|
||||
#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
|
||||
do { \
|
||||
memcpy((void *)buf, (void *)var, len); \
|
||||
buf += len; \
|
||||
#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
|
||||
do { \
|
||||
(void)memcpy((void *)buf, (void *)var, len); \
|
||||
buf += len; \
|
||||
} while (0)
|
||||
|
||||
#define INDEX_MERGE_ADD_DEL(src, dst, tgt) \
|
||||
|
|
|
@ -15,17 +15,17 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "monInt.h"
|
||||
#include "taos_monitor.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
#include "thttp.h"
|
||||
#include "ttime.h"
|
||||
#include "taos_monitor.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
SMonitor tsMonitor = {0};
|
||||
char* tsMonUri = "/report";
|
||||
char* tsMonFwUri = "/general-metric";
|
||||
char* tsMonSlowLogUri = "/slow-sql-detail-batch";
|
||||
char* tsMonFwBasicUri = "/taosd-cluster-basic";
|
||||
char *tsMonUri = "/report";
|
||||
char *tsMonFwUri = "/general-metric";
|
||||
char *tsMonSlowLogUri = "/slow-sql-detail-batch";
|
||||
char *tsMonFwBasicUri = "/taosd-cluster-basic";
|
||||
|
||||
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
||||
taosThreadMutexLock(&tsMonitor.lock);
|
||||
|
@ -54,8 +54,7 @@ int32_t monGetLogs(SMonLogs *logs) {
|
|||
taosArrayClear(tsMonitor.logs);
|
||||
taosThreadMutexUnlock(&tsMonitor.lock);
|
||||
if (logs->logs == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -105,8 +104,7 @@ void monSetBmInfo(SMonBmInfo *pInfo) {
|
|||
int32_t monInit(const SMonCfg *pCfg) {
|
||||
tsMonitor.logs = taosArrayInit(16, sizeof(SMonLogItem));
|
||||
if (tsMonitor.logs == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
tsMonitor.cfg = *pCfg;
|
||||
|
@ -146,6 +144,7 @@ static void monCleanupMonitorInfo(SMonInfo *pMonitor) {
|
|||
}
|
||||
|
||||
static SMonInfo *monCreateMonitorInfo() {
|
||||
terrno = 0;
|
||||
SMonInfo *pMonitor = taosMemoryCalloc(1, sizeof(SMonInfo));
|
||||
if (pMonitor == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -274,11 +273,11 @@ static void monGenClusterJsonBasic(SMonInfo *pMonitor) {
|
|||
SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster;
|
||||
if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return;
|
||||
|
||||
//tjsonAddStringToObject(pMonitor->pJson, "first_ep", pInfo->first_ep);
|
||||
// tjsonAddStringToObject(pMonitor->pJson, "first_ep", pInfo->first_ep);
|
||||
tjsonAddStringToObject(pMonitor->pJson, "first_ep", tsFirst);
|
||||
tjsonAddDoubleToObject(pMonitor->pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id);
|
||||
tjsonAddStringToObject(pMonitor->pJson, "cluster_version", pInfo->version);
|
||||
//tjsonAddDoubleToObject(pMonitor->pJson, "monitor_interval", pInfo->monitor_interval);
|
||||
// tjsonAddDoubleToObject(pMonitor->pJson, "monitor_interval", pInfo->monitor_interval);
|
||||
}
|
||||
|
||||
static void monGenVgroupJson(SMonInfo *pMonitor) {
|
||||
|
@ -554,9 +553,9 @@ static void monGenLogJson(SMonInfo *pMonitor) {
|
|||
if (tjsonAddItemToArray(pSummaryJson, pLogTrace) != 0) tjsonDelete(pLogTrace);
|
||||
}
|
||||
|
||||
void monSendReport(SMonInfo *pMonitor){
|
||||
void monSendReport(SMonInfo *pMonitor) {
|
||||
char *pCont = tjsonToString(pMonitor->pJson);
|
||||
if(tsMonitorLogProtocol){
|
||||
if (tsMonitorLogProtocol) {
|
||||
uInfoL("report cont:\n%s", pCont);
|
||||
}
|
||||
if (pCont != NULL) {
|
||||
|
@ -591,7 +590,7 @@ void monGenAndSendReport() {
|
|||
SMonInfo *pMonitor = monCreateMonitorInfo();
|
||||
if (pMonitor == NULL) return;
|
||||
|
||||
if(!tsMonitorForceV2){
|
||||
if (!tsMonitorForceV2) {
|
||||
monGenBasicJson(pMonitor);
|
||||
monGenClusterJson(pMonitor);
|
||||
monGenVgroupJson(pMonitor);
|
||||
|
@ -602,8 +601,7 @@ void monGenAndSendReport() {
|
|||
monGenLogJson(pMonitor);
|
||||
|
||||
monSendReport(pMonitor);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
monGenClusterInfoTable(pMonitor);
|
||||
monGenVgroupInfoTable(pMonitor);
|
||||
monGenDnodeInfoTable(pMonitor);
|
||||
|
@ -624,10 +622,10 @@ void monGenAndSendReport() {
|
|||
monCleanupMonitorInfo(pMonitor);
|
||||
}
|
||||
|
||||
void monSendContent(char *pCont, const char* uri) {
|
||||
void monSendContent(char *pCont, const char *uri) {
|
||||
if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return;
|
||||
if(tsMonitorLogProtocol){
|
||||
if (pCont != NULL){
|
||||
if (tsMonitorLogProtocol) {
|
||||
if (pCont != NULL) {
|
||||
uInfoL("report client cont:\n%s\n", pCont);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char *, void **);
|
|||
|
||||
typedef struct SFilterDataInfo {
|
||||
int32_t idx;
|
||||
void* addr;
|
||||
void *addr;
|
||||
} SFilterDataInfo;
|
||||
|
||||
typedef struct SFilterRangeCompare {
|
||||
|
@ -227,10 +227,9 @@ typedef struct SFltTreeStat {
|
|||
SFilterInfo *info;
|
||||
} SFltTreeStat;
|
||||
|
||||
|
||||
typedef struct SFltScalarCtx {
|
||||
SNode *node;
|
||||
SArray* fltSclRange;
|
||||
SNode *node;
|
||||
SArray *fltSclRange;
|
||||
} SFltScalarCtx;
|
||||
|
||||
typedef struct SFltBuildGroupCtx {
|
||||
|
@ -271,9 +270,9 @@ struct SFilterInfo {
|
|||
SFilterPCtx pctx;
|
||||
};
|
||||
|
||||
#define FILTER_NO_MERGE_DATA_TYPE(t) \
|
||||
((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_VARBINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON || \
|
||||
(t) == TSDB_DATA_TYPE_GEOMETRY)
|
||||
#define FILTER_NO_MERGE_DATA_TYPE(t) \
|
||||
((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_VARBINARY || (t) == TSDB_DATA_TYPE_NCHAR || \
|
||||
(t) == TSDB_DATA_TYPE_JSON || (t) == TSDB_DATA_TYPE_GEOMETRY)
|
||||
#define FILTER_NO_MERGE_OPTR(o) ((o) == OP_TYPE_IS_NULL || (o) == OP_TYPE_IS_NOT_NULL || (o) == FILTER_DUMMY_EMPTY_OPTR)
|
||||
|
||||
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
|
||||
|
@ -361,29 +360,29 @@ struct SFilterInfo {
|
|||
_r = n; \
|
||||
} \
|
||||
} while (0)
|
||||
#define INSERT_RANGE(ctx, r, ra) \
|
||||
do { \
|
||||
SFilterRangeNode *n = NULL; \
|
||||
FLT_ERR_RET(filterNewRange(ctx, ra, &n)); \
|
||||
n->prev = (r)->prev; \
|
||||
if ((r)->prev) { \
|
||||
(r)->prev->next = n; \
|
||||
} else { \
|
||||
(ctx)->rs = n; \
|
||||
} \
|
||||
(r)->prev = n; \
|
||||
n->next = r; \
|
||||
#define INSERT_RANGE(ctx, r, ra) \
|
||||
do { \
|
||||
SFilterRangeNode *n = NULL; \
|
||||
FLT_ERR_RET(filterNewRange(ctx, ra, &n)); \
|
||||
n->prev = (r)->prev; \
|
||||
if ((r)->prev) { \
|
||||
(r)->prev->next = n; \
|
||||
} else { \
|
||||
(ctx)->rs = n; \
|
||||
} \
|
||||
(r)->prev = n; \
|
||||
n->next = r; \
|
||||
} while (0)
|
||||
#define APPEND_RANGE(ctx, r, ra) \
|
||||
do { \
|
||||
SFilterRangeNode *n = NULL; \
|
||||
FLT_ERR_RET(filterNewRange(ctx, ra, &n)); \
|
||||
n->prev = (r); \
|
||||
if (r) { \
|
||||
(r)->next = n; \
|
||||
} else { \
|
||||
(ctx)->rs = n; \
|
||||
} \
|
||||
#define APPEND_RANGE(ctx, r, ra) \
|
||||
do { \
|
||||
SFilterRangeNode *n = NULL; \
|
||||
FLT_ERR_RET(filterNewRange(ctx, ra, &n)); \
|
||||
n->prev = (r); \
|
||||
if (r) { \
|
||||
(r)->next = n; \
|
||||
} else { \
|
||||
(ctx)->rs = n; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FLT_IS_COMPARISON_OPERATOR(_op) ((_op) >= OP_TYPE_GREATER_THAN && (_op) < OP_TYPE_IS_NOT_UNKNOWN)
|
||||
|
@ -454,7 +453,7 @@ struct SFilterInfo {
|
|||
#define FILTER_UNIT_OPTR(u) ((u)->compare.optr)
|
||||
#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func)
|
||||
|
||||
#define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags))
|
||||
#define FILTER_UNIT_CLR_F(i) (void)memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags))
|
||||
#define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1
|
||||
#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx])
|
||||
#define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx])
|
||||
|
@ -482,7 +481,7 @@ struct SFilterInfo {
|
|||
#define FILTER_COPY_IDX(dst, src, n) \
|
||||
do { \
|
||||
*(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); \
|
||||
memcpy(*(dst), src, sizeof(uint32_t) * n); \
|
||||
(void)memcpy(*(dst), src, sizeof(uint32_t) * n); \
|
||||
} while (0)
|
||||
|
||||
#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) \
|
||||
|
|
|
@ -31,7 +31,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i
|
|||
|
||||
pPtr = (uint8_t *)tdbOsCalloc(1, zsize);
|
||||
if (pPtr == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pDb = (TDB *)pPtr;
|
||||
|
@ -64,7 +64,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i
|
|||
tsize = sizeof(SPager *) * pDb->nPgrHash;
|
||||
pDb->pgrHash = tdbOsMalloc(tsize);
|
||||
if (pDb->pgrHash == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
memset(pDb->pgrHash, 0, tsize);
|
||||
|
||||
|
@ -125,7 +125,7 @@ int32_t tdbBegin(TDB *pDb, TXN **ppTxn, void *(*xMalloc)(void *, size_t), void (
|
|||
|
||||
TXN *pTxn = tdbOsCalloc(1, sizeof(*pTxn));
|
||||
if (!pTxn) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
ret = tdbTxnOpen(pTxn, txnId, xMalloc, xFree, xArg, flags);
|
||||
|
|
|
@ -74,16 +74,16 @@ typedef struct STfs {
|
|||
SHashObj *hash; // name to did map
|
||||
} STfs;
|
||||
|
||||
STfsDisk *tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *dir);
|
||||
int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *dir, STfsDisk **ppDisk);
|
||||
STfsDisk *tfsFreeDisk(STfsDisk *pDisk);
|
||||
int32_t tfsUpdateDiskSize(STfsDisk *pDisk);
|
||||
|
||||
int32_t tfsInitTier(STfsTier *pTier, int32_t level);
|
||||
void tfsDestroyTier(STfsTier *pTier);
|
||||
STfsDisk *tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg);
|
||||
void tfsUpdateTierSize(STfsTier *pTier);
|
||||
int32_t tfsAllocDiskOnTier(STfsTier *pTier);
|
||||
void tfsPosNextId(STfsTier *pTier);
|
||||
int32_t tfsInitTier(STfsTier *pTier, int32_t level);
|
||||
void tfsDestroyTier(STfsTier *pTier);
|
||||
int32_t tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg, STfsDisk **ppDisk);
|
||||
void tfsUpdateTierSize(STfsTier *pTier);
|
||||
int32_t tfsAllocDiskOnTier(STfsTier *pTier);
|
||||
void tfsPosNextId(STfsTier *pTier);
|
||||
|
||||
#define tfsLockTier(pTier) taosThreadSpinLock(&(pTier)->lock)
|
||||
#define tfsUnLockTier(pTier) taosThreadSpinUnlock(&(pTier)->lock)
|
||||
|
|
|
@ -21,61 +21,56 @@ static int32_t tfsMount(STfs *pTfs, SDiskCfg *pCfg);
|
|||
static int32_t tfsCheck(STfs *pTfs);
|
||||
static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg);
|
||||
static int32_t tfsFormatDir(char *idir, char *odir);
|
||||
static STfsDisk *tfsGetDiskByName(STfs *pTfs, const char *dir);
|
||||
static int32_t tfsGetDiskByName(STfs *pTfs, const char *dir, STfsDisk **ppDisk);
|
||||
static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pDir);
|
||||
static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter);
|
||||
|
||||
STfs *tfsOpen(SDiskCfg *pCfg, int32_t ndisk) {
|
||||
int32_t tfsOpen(SDiskCfg *pCfg, int32_t ndisk, STfs **ppTfs) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STfs *pTfs = NULL;
|
||||
|
||||
if (ndisk <= 0 || ndisk > TFS_MAX_DISKS) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, &lino, _exit);
|
||||
}
|
||||
|
||||
STfs *pTfs = taosMemoryCalloc(1, sizeof(STfs));
|
||||
pTfs = taosMemoryCalloc(1, sizeof(STfs));
|
||||
if (pTfs == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
if (taosThreadSpinInit(&pTfs->lock, 0) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tfsClose(pTfs);
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
||||
}
|
||||
|
||||
for (int32_t level = 0; level < TFS_MAX_TIERS; level++) {
|
||||
STfsTier *pTier = &pTfs->tiers[level];
|
||||
if (tfsInitTier(pTier, level) < 0) {
|
||||
tfsClose(pTfs);
|
||||
return NULL;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tfsInitTier(pTier, level), &lino, _exit);
|
||||
}
|
||||
|
||||
pTfs->hash = taosHashInit(TFS_MAX_DISKS * 2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (pTfs->hash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tfsClose(pTfs);
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
for (int32_t idisk = 0; idisk < ndisk; idisk++) {
|
||||
if (tfsMount(pTfs, &pCfg[idisk]) < 0) {
|
||||
tfsClose(pTfs);
|
||||
return NULL;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tfsMount(pTfs, &pCfg[idisk]), &lino, _exit);
|
||||
}
|
||||
|
||||
if (tfsCheck(pTfs) < 0) {
|
||||
tfsClose(pTfs);
|
||||
return NULL;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tfsCheck(pTfs) < 0, &lino, _exit);
|
||||
|
||||
tfsUpdateSize(pTfs);
|
||||
for (int32_t level = 0; level < pTfs->nlevel; level++) {
|
||||
tfsPosNextId(&pTfs->tiers[level]);
|
||||
}
|
||||
|
||||
return pTfs;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
tfsClose(pTfs);
|
||||
pTfs = NULL;
|
||||
}
|
||||
*ppTfs = pTfs;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
void tfsClose(STfs *pTfs) {
|
||||
|
@ -149,7 +144,7 @@ bool tfsDiskSpaceSufficient(STfs *pTfs, int32_t level, int32_t disk) {
|
|||
|
||||
int32_t tfsGetDisksAtLevel(STfs *pTfs, int32_t level) {
|
||||
if (level < 0 || level >= pTfs->nlevel) {
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
STfsTier *pTier = TFS_TIER_AT(pTfs, level);
|
||||
|
@ -177,10 +172,10 @@ int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, SDiskID *pDiskId) {
|
|||
continue;
|
||||
}
|
||||
|
||||
return (terrno = 0);
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
return (terrno = TSDB_CODE_FS_NO_VALID_DISK);
|
||||
TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);
|
||||
}
|
||||
|
||||
const char *tfsGetPrimaryPath(STfs *pTfs) { return TFS_PRIMARY_DISK(pTfs)->path; }
|
||||
|
@ -270,22 +265,27 @@ int32_t tfsMkdirAt(STfs *pTfs, const char *rname, SDiskID diskId) {
|
|||
char aname[TMPNAME_LEN];
|
||||
|
||||
if (pDisk == NULL) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
snprintf(aname, TMPNAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, rname);
|
||||
if (taosMkDir(aname) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
int32_t tfsMkdirRecurAt(STfs *pTfs, const char *rname, SDiskID diskId) {
|
||||
if (tfsMkdirAt(pTfs, rname, diskId) < 0) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
char *s = NULL;
|
||||
char *dir = NULL;
|
||||
if ((code = tfsMkdirAt(pTfs, rname, diskId)) < 0) {
|
||||
if (errno == ENOENT) {
|
||||
// Try to create upper
|
||||
char *s = taosStrdup(rname);
|
||||
if ((s = taosStrdup(rname)) == NULL) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
// Make a copy of dirname(s) because the implementation of 'dirname' differs on different platforms.
|
||||
// Some platform may modify the contents of the string passed into dirname(). Others may return a pointer to
|
||||
|
@ -293,25 +293,30 @@ int32_t tfsMkdirRecurAt(STfs *pTfs, const char *rname, SDiskID diskId) {
|
|||
// the pointer directly in this recursion.
|
||||
// See
|
||||
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dirname.3.html
|
||||
char *dir = taosStrdup(taosDirName(s));
|
||||
|
||||
if (strlen(dir) >= strlen(rname) || tfsMkdirRecurAt(pTfs, dir, diskId) < 0) {
|
||||
taosMemoryFree(s);
|
||||
taosMemoryFree(dir);
|
||||
return -1;
|
||||
if ((dir = taosStrdup(taosDirName(s))) == NULL) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
taosMemoryFree(s);
|
||||
taosMemoryFree(dir);
|
||||
|
||||
if (tfsMkdirAt(pTfs, rname, diskId) < 0) {
|
||||
return -1;
|
||||
if (strlen(dir) >= strlen(rname)) { // TODO: check if it is necessary for equal length
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_APP_ERROR, &lino, _exit);
|
||||
}
|
||||
TAOS_CHECK_GOTO(tfsMkdirRecurAt(pTfs, dir, diskId), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tfsMkdirAt(pTfs, rname, diskId), &lino, _exit);
|
||||
} else {
|
||||
return -1;
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
} else {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
fError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
taosMemoryFree(s);
|
||||
taosMemoryFree(dir);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t tfsMkdirRecur(STfs *pTfs, const char *rname) {
|
||||
|
@ -319,13 +324,11 @@ int32_t tfsMkdirRecur(STfs *pTfs, const char *rname) {
|
|||
STfsTier *pTier = TFS_TIER_AT(pTfs, level);
|
||||
for (int32_t id = 0; id < pTier->ndisk; id++) {
|
||||
SDiskID did = {.id = id, .level = level};
|
||||
if (tfsMkdirRecurAt(pTfs, rname, did) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tfsMkdirRecurAt(pTfs, rname, did));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
int32_t tfsMkdir(STfs *pTfs, const char *rname) {
|
||||
|
@ -333,13 +336,11 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname) {
|
|||
STfsTier *pTier = TFS_TIER_AT(pTfs, level);
|
||||
for (int32_t id = 0; id < pTier->ndisk; id++) {
|
||||
SDiskID did = {.id = id, .level = level};
|
||||
if (tfsMkdirAt(pTfs, rname, did) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tfsMkdirAt(pTfs, rname, did));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
bool tfsDirExistAt(STfs *pTfs, const char *rname, SDiskID diskId) {
|
||||
|
@ -352,7 +353,7 @@ bool tfsDirExistAt(STfs *pTfs, const char *rname, SDiskID diskId) {
|
|||
|
||||
int32_t tfsRmdir(STfs *pTfs, const char *rname) {
|
||||
if (rname[0] == 0) {
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
char aname[TMPNAME_LEN] = "\0";
|
||||
|
@ -367,7 +368,7 @@ int32_t tfsRmdir(STfs *pTfs, const char *rname) {
|
|||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t tfsRenameAt(STfs *pTfs, SDiskID diskId, const char *orname, const char *nrname) {
|
||||
|
@ -382,12 +383,12 @@ static int32_t tfsRenameAt(STfs *pTfs, SDiskID diskId, const char *orname, const
|
|||
snprintf(naname, TMPNAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, nrname);
|
||||
|
||||
if (taosRenameFile(oaname, naname) != 0 && errno != ENOENT) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
fError("failed to rename %s to %s since %s", oaname, naname, terrstr());
|
||||
return -1;
|
||||
int32_t code = TAOS_SYSTEM_ERROR(errno); // TODO: use return value of taosRenameFile directly
|
||||
fError("%s failed to rename %s to %s since %s", __func__, oaname, naname, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
int32_t tfsRename(STfs *pTfs, int32_t diskPrimary, const char *orname, const char *nrname) {
|
||||
|
@ -399,14 +400,12 @@ int32_t tfsRename(STfs *pTfs, int32_t diskPrimary, const char *orname, const cha
|
|||
}
|
||||
|
||||
SDiskID diskId = {.level = level, .id = id};
|
||||
if (tfsRenameAt(pTfs, diskId, orname, nrname)) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tfsRenameAt(pTfs, diskId, orname, nrname));
|
||||
}
|
||||
}
|
||||
|
||||
SDiskID diskId = {.level = 0, .id = diskPrimary};
|
||||
return tfsRenameAt(pTfs, diskId, orname, nrname);
|
||||
TAOS_RETURN(tfsRenameAt(pTfs, diskId, orname, nrname));
|
||||
}
|
||||
|
||||
int32_t tfsSearch(STfs *pTfs, int32_t level, const char *fname) {
|
||||
|
@ -426,11 +425,11 @@ int32_t tfsSearch(STfs *pTfs, int32_t level, const char *fname) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
STfsDir *tfsOpendir(STfs *pTfs, const char *rname) {
|
||||
int32_t tfsOpendir(STfs *pTfs, const char *rname, STfsDir **ppDir) {
|
||||
int32_t code = 0;
|
||||
STfsDir *pDir = taosMemoryCalloc(1, sizeof(STfsDir));
|
||||
if (pDir == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exit);
|
||||
}
|
||||
|
||||
SDiskID diskId = {.id = 0, .level = 0};
|
||||
|
@ -438,12 +437,14 @@ STfsDir *tfsOpendir(STfs *pTfs, const char *rname) {
|
|||
pDir->pTfs = pTfs;
|
||||
tstrncpy(pDir->dirName, rname, TSDB_FILENAME_LEN);
|
||||
|
||||
if (tfsOpendirImpl(pTfs, pDir) < 0) {
|
||||
taosMemoryFree(pDir);
|
||||
return NULL;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tfsOpendirImpl(pTfs, pDir), NULL, _exit);
|
||||
|
||||
return pDir;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
taosMemoryFreeClear(pDir);
|
||||
}
|
||||
*ppDir = pDir;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
const STfsFile *tfsReaddir(STfsDir *pTfsDir) {
|
||||
|
@ -490,87 +491,91 @@ void tfsClosedir(STfsDir *pTfsDir) {
|
|||
}
|
||||
|
||||
static int32_t tfsMount(STfs *pTfs, SDiskCfg *pCfg) {
|
||||
if (tfsCheckAndFormatCfg(pTfs, pCfg) < 0) {
|
||||
return -1;
|
||||
}
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
TAOS_CHECK_GOTO(tfsCheckAndFormatCfg(pTfs, pCfg), &lino, _exit);
|
||||
|
||||
SDiskID did = {.level = pCfg->level};
|
||||
STfsDisk *pDisk = tfsMountDiskToTier(TFS_TIER_AT(pTfs, did.level), pCfg);
|
||||
if (pDisk == NULL) {
|
||||
fError("failed to mount disk %s to level %d since %s", pCfg->dir, pCfg->level, terrstr());
|
||||
return -1;
|
||||
}
|
||||
STfsDisk *pDisk = NULL;
|
||||
|
||||
TAOS_CHECK_GOTO(tfsMountDiskToTier(TFS_TIER_AT(pTfs, did.level), pCfg, &pDisk), &lino, _exit);
|
||||
did.id = pDisk->id;
|
||||
|
||||
taosHashPut(pTfs->hash, (void *)(pCfg->dir), strnlen(pCfg->dir, TSDB_FILENAME_LEN), (void *)(&did), sizeof(did));
|
||||
if (taosHashPut(pTfs->hash, (void *)(pCfg->dir), strnlen(pCfg->dir, TSDB_FILENAME_LEN), (void *)(&did),
|
||||
sizeof(did)) != 0) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
if (pTfs->nlevel < pCfg->level + 1) {
|
||||
pTfs->nlevel = pCfg->level + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
fError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t tfsCheckAndFormatCfg(STfs *pTfs, SDiskCfg *pCfg) {
|
||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||
int32_t code = 0;
|
||||
char dirName[TSDB_FILENAME_LEN] = "\0";
|
||||
|
||||
if (pCfg->level < 0 || pCfg->level >= TFS_MAX_TIERS) {
|
||||
fError("failed to mount %s to FS since invalid level %d", pCfg->dir, pCfg->level);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
if (pCfg->primary < 0 || pCfg->primary > 1) {
|
||||
fError("failed to mount %s to FS since invalid primary %d", pCfg->dir, pCfg->primary);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
if (pCfg->disable < 0 || pCfg->disable > 1) {
|
||||
fError("failed to mount %s to FS since invalid disable %" PRIi8, pCfg->dir, pCfg->disable);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
if (pCfg->primary) {
|
||||
if (pCfg->level != 0) {
|
||||
fError("failed to mount %s to FS since disk is primary but level %d not 0", pCfg->dir, pCfg->level);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
if (TFS_PRIMARY_DISK(pTfs) != NULL) {
|
||||
fError("failed to mount %s to FS since duplicate primary mount", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_DUP_PRIMARY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_DUP_PRIMARY);
|
||||
}
|
||||
}
|
||||
|
||||
if (tfsFormatDir(pCfg->dir, dirName) < 0) {
|
||||
fError("failed to mount %s to FS since %s", pCfg->dir, terrstr());
|
||||
return -1;
|
||||
if ((code = tfsFormatDir(pCfg->dir, dirName)) < 0) {
|
||||
fError("failed to mount %s to FS since %s", pCfg->dir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (tfsGetDiskByName(pTfs, dirName) != NULL) {
|
||||
STfsDisk *pDisk = NULL;
|
||||
if ((code = tfsGetDiskByName(pTfs, dirName, NULL)) != 0) {
|
||||
fError("failed to mount %s to FS since %s", pCfg->dir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (pDisk != NULL) {
|
||||
fError("failed to mount %s to FS since duplicate mount", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
if (!taosCheckAccessFile(dirName, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
fError("failed to mount %s to FS since no R/W access rights", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
if (!taosIsDir(dirName)) {
|
||||
fError("failed to mount %s to FS since not a directory", pCfg->dir);
|
||||
terrno = TSDB_CODE_FS_INVLD_CFG;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_INVLD_CFG);
|
||||
}
|
||||
|
||||
strncpy(pCfg->dir, dirName, TSDB_FILENAME_LEN);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t tfsFormatDir(char *idir, char *odir) {
|
||||
|
@ -578,71 +583,73 @@ static int32_t tfsFormatDir(char *idir, char *odir) {
|
|||
|
||||
int32_t code = wordexp(idir, &wep, 0);
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(code));
|
||||
}
|
||||
|
||||
char tmp[PATH_MAX] = {0};
|
||||
if (taosRealPath(wep.we_wordv[0], tmp, PATH_MAX) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
wordfree(&wep);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
strcpy(odir, tmp);
|
||||
|
||||
wordfree(&wep);
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t tfsCheck(STfs *pTfs) {
|
||||
if (TFS_PRIMARY_DISK(pTfs) == NULL) {
|
||||
fError("no primary disk is set");
|
||||
terrno = TSDB_CODE_FS_NO_PRIMARY_DISK;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_NO_PRIMARY_DISK);
|
||||
}
|
||||
|
||||
for (int32_t level = 0; level < pTfs->nlevel; level++) {
|
||||
if (TFS_TIER_AT(pTfs, level)->ndisk == 0) {
|
||||
fError("no disk at level %d", level);
|
||||
terrno = TSDB_CODE_FS_NO_MOUNT_AT_TIER;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_NO_MOUNT_AT_TIER);
|
||||
}
|
||||
|
||||
if (level == 0) {
|
||||
tfsUpdateTierSize(TFS_TIER_AT(pTfs, level));
|
||||
if (TFS_TIER_AT(pTfs, level)->nAvailDisks == 0) {
|
||||
fError("no disk to create new file at level %d", level);
|
||||
terrno = TSDB_CODE_FS_NO_VALID_DISK;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static STfsDisk *tfsGetDiskByName(STfs *pTfs, const char *dir) {
|
||||
static int32_t tfsGetDiskByName(STfs *pTfs, const char *dir, STfsDisk **ppDisk) {
|
||||
void *pr = taosHashGet(pTfs->hash, (void *)dir, strnlen(dir, TSDB_FILENAME_LEN));
|
||||
if (pr == NULL) return NULL;
|
||||
if (pr == NULL) {
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
|
||||
SDiskID did = *(SDiskID *)pr;
|
||||
STfsDisk *pDisk = TFS_DISK_AT(pTfs, did);
|
||||
SDiskID did = *(SDiskID *)pr;
|
||||
*ppDisk = TFS_DISK_AT(pTfs, did);
|
||||
|
||||
return pDisk;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pTfsDir) {
|
||||
STfsDisk *pDisk = NULL;
|
||||
char adir[TMPNAME_LEN * 2] = "\0";
|
||||
int32_t code = 0;
|
||||
|
||||
if (pTfsDir->pDir != NULL) {
|
||||
taosCloseDir(&pTfsDir->pDir);
|
||||
if ((code = taosCloseDir(&pTfsDir->pDir)) != 0) {
|
||||
fError("%s failed to close dir since %s", __func__, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
pTfsDir->pDir = NULL;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
pDisk = tfsNextDisk(pTfs, &pTfsDir->iter);
|
||||
if (pDisk == NULL) return 0;
|
||||
if (pDisk == NULL) TAOS_RETURN(0);
|
||||
|
||||
pTfsDir->did.level = pDisk->level;
|
||||
pTfsDir->did.id = pDisk->id;
|
||||
|
@ -654,9 +661,10 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pTfsDir) {
|
|||
}
|
||||
pTfsDir->pDir = taosOpenDir(adir);
|
||||
if (pTfsDir->pDir != NULL) break;
|
||||
fWarn("%s failed to open dir %s since %s", __func__, adir, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter) {
|
||||
|
@ -684,7 +692,9 @@ static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter) {
|
|||
|
||||
int32_t tfsGetMonitorInfo(STfs *pTfs, SMonDiskInfo *pInfo) {
|
||||
pInfo->datadirs = taosArrayInit(32, sizeof(SMonDiskDesc));
|
||||
if (pInfo->datadirs == NULL) return -1;
|
||||
if (pInfo->datadirs == NULL) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
tfsUpdateSize(pTfs);
|
||||
|
||||
|
@ -697,10 +707,15 @@ int32_t tfsGetMonitorInfo(STfs *pTfs, SMonDiskInfo *pInfo) {
|
|||
dinfo.size = pDisk->size;
|
||||
dinfo.level = pDisk->level;
|
||||
tstrncpy(dinfo.name, pDisk->path, sizeof(dinfo.name));
|
||||
taosArrayPush(pInfo->datadirs, &dinfo);
|
||||
if (taosArrayPush(pInfo->datadirs, &dinfo) == NULL) {
|
||||
tfsUnLock(pTfs);
|
||||
taosArrayDestroy(pInfo->datadirs);
|
||||
pInfo->datadirs = NULL;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
tfsUnLock(pTfs);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
|
|
@ -16,25 +16,34 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tfsInt.h"
|
||||
|
||||
STfsDisk *tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path) {
|
||||
STfsDisk *pDisk = taosMemoryCalloc(1, sizeof(STfsDisk));
|
||||
if (pDisk == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path, STfsDisk **ppDisk) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STfsDisk *pDisk = NULL;
|
||||
|
||||
if ((pDisk = taosMemoryCalloc(1, sizeof(STfsDisk))) == NULL) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
pDisk->path = taosStrdup(path);
|
||||
if (pDisk->path == NULL) {
|
||||
taosMemoryFree(pDisk);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
if ((pDisk->path = taosStrdup(path)) == NULL) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
pDisk->level = level;
|
||||
pDisk->id = id;
|
||||
pDisk->disable = disable;
|
||||
taosGetDiskSize(pDisk->path, &pDisk->size);
|
||||
return pDisk;
|
||||
if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno); // TODO: refactor this line
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
pDisk = tfsFreeDisk(pDisk);
|
||||
fError("%s failed at line %d since %s, disk:%s level:%d id:%d ", __func__, lino, tstrerror(code), path, level, id);
|
||||
}
|
||||
*ppDisk = pDisk;
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
STfsDisk *tfsFreeDisk(STfsDisk *pDisk) {
|
||||
|
@ -48,9 +57,10 @@ STfsDisk *tfsFreeDisk(STfsDisk *pDisk) {
|
|||
|
||||
int32_t tfsUpdateDiskSize(STfsDisk *pDisk) {
|
||||
if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
fError("failed to get disk:%s size, level:%d id:%d since %s", pDisk->path, pDisk->level, pDisk->id, terrstr());
|
||||
return -1;
|
||||
int32_t code = TAOS_SYSTEM_ERROR(errno); // TODO: refactor this line
|
||||
fError("failed to get disk:%s size, level:%d id:%d since %s", pDisk->path, pDisk->level, pDisk->id,
|
||||
tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -22,8 +22,7 @@ int32_t tfsInitTier(STfsTier *pTier, int32_t level) {
|
|||
memset(pTier, 0, sizeof(STfsTier));
|
||||
|
||||
if (taosThreadSpinInit(&pTier->lock, 0) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
pTier->level = level;
|
||||
|
@ -39,10 +38,13 @@ void tfsDestroyTier(STfsTier *pTier) {
|
|||
taosThreadSpinDestroy(&pTier->lock);
|
||||
}
|
||||
|
||||
STfsDisk *tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg) {
|
||||
int32_t tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg, STfsDisk **ppDisk) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STfsDisk *pDisk = NULL;
|
||||
|
||||
if (pTier->ndisk >= TFS_MAX_DISKS_PER_TIER) {
|
||||
terrno = TSDB_CODE_FS_TOO_MANY_MOUNT;
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_FS_TOO_MANY_MOUNT, &lino, _exit);
|
||||
}
|
||||
|
||||
int32_t id = 0;
|
||||
|
@ -61,18 +63,25 @@ STfsDisk *tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg) {
|
|||
}
|
||||
|
||||
if (id >= TFS_MAX_DISKS_PER_TIER) {
|
||||
terrno = TSDB_CODE_FS_TOO_MANY_MOUNT;
|
||||
return NULL;
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_FS_TOO_MANY_MOUNT, &lino, _exit);
|
||||
}
|
||||
|
||||
STfsDisk *pDisk = tfsNewDisk(pCfg->level, id, pCfg->disable, pCfg->dir);
|
||||
if (pDisk == NULL) return NULL;
|
||||
TAOS_CHECK_GOTO(tfsNewDisk(pCfg->level, id, pCfg->disable, pCfg->dir, &pDisk), &lino, _exit);
|
||||
|
||||
pTier->disks[id] = pDisk;
|
||||
pTier->ndisk++;
|
||||
|
||||
fDebug("disk %s is mounted to tier level %d id %d", pCfg->dir, pCfg->level, id);
|
||||
return pTier->disks[id];
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
pDisk = tfsFreeDisk(pDisk);
|
||||
fError("%s failed at line %d since %s, disk:%s level:%d id:%d", __func__, lino, tstrerror(code), pCfg->dir,
|
||||
pCfg->level, id);
|
||||
} else {
|
||||
*ppDisk = pTier->disks[id];
|
||||
fDebug("disk %s is mounted to tier level %d id %d", pCfg->dir, pCfg->level, id);
|
||||
}
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
void tfsUpdateTierSize(STfsTier *pTier) {
|
||||
|
@ -100,13 +109,11 @@ void tfsUpdateTierSize(STfsTier *pTier) {
|
|||
|
||||
// Round-Robin to allocate disk on a tier
|
||||
int32_t tfsAllocDiskOnTier(STfsTier *pTier) {
|
||||
terrno = TSDB_CODE_FS_NO_VALID_DISK;
|
||||
|
||||
tfsLockTier(pTier);
|
||||
|
||||
if (pTier->ndisk <= 0 || pTier->nAvailDisks <= 0) {
|
||||
tfsUnLockTier(pTier);
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);
|
||||
}
|
||||
|
||||
int32_t retId = -1;
|
||||
|
@ -149,6 +156,9 @@ int32_t tfsAllocDiskOnTier(STfsTier *pTier) {
|
|||
}
|
||||
|
||||
tfsUnLockTier(pTier);
|
||||
if (retId < 0) {
|
||||
TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);
|
||||
}
|
||||
return retId;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,12 @@ TEST_F(TfsTest, 01_Open_Close) {
|
|||
dCfg.disable = 0;
|
||||
|
||||
taosRemoveDir(root);
|
||||
STfs *pTfs = tfsOpen(&dCfg, 1);
|
||||
STfs *pTfs = NULL;
|
||||
(void)tfsOpen(&dCfg, 1, &pTfs);
|
||||
ASSERT_EQ(pTfs, nullptr);
|
||||
|
||||
taosMulMkDir(root);
|
||||
pTfs = tfsOpen(&dCfg, 1);
|
||||
(void)tfsOpen(&dCfg, 1, &pTfs);
|
||||
ASSERT_NE(pTfs, nullptr);
|
||||
|
||||
tfsUpdateSize(pTfs);
|
||||
|
@ -68,7 +69,8 @@ TEST_F(TfsTest, 02_AllocDisk) {
|
|||
|
||||
taosRemoveDir(root);
|
||||
taosMkDir(root);
|
||||
STfs *pTfs = tfsOpen(&dCfg, 1);
|
||||
STfs *pTfs = NULL;
|
||||
(void)tfsOpen(&dCfg, 1, &pTfs);
|
||||
ASSERT_NE(pTfs, nullptr);
|
||||
|
||||
SDiskID did;
|
||||
|
@ -120,7 +122,8 @@ TEST_F(TfsTest, 03_Dir) {
|
|||
|
||||
taosRemoveDir(root);
|
||||
taosMkDir(root);
|
||||
STfs *pTfs = tfsOpen(&dCfg, 1);
|
||||
STfs *pTfs = NULL;
|
||||
(void)tfsOpen(&dCfg, 1, &pTfs);
|
||||
ASSERT_NE(pTfs, nullptr);
|
||||
|
||||
char p1[] = "p1";
|
||||
|
@ -175,7 +178,8 @@ TEST_F(TfsTest, 04_File) {
|
|||
|
||||
taosRemoveDir(root);
|
||||
taosMkDir(root);
|
||||
STfs *pTfs = tfsOpen(&dCfg, 1);
|
||||
STfs *pTfs = NULL;
|
||||
(void)tfsOpen(&dCfg, 1, &pTfs);
|
||||
ASSERT_NE(pTfs, nullptr);
|
||||
|
||||
STfsFile file0;
|
||||
|
@ -264,7 +268,8 @@ TEST_F(TfsTest, 04_File) {
|
|||
EXPECT_NE(taosDirExist(af2), 1);
|
||||
|
||||
{
|
||||
STfsDir *pDir = tfsOpendir(pTfs, "t3");
|
||||
STfsDir *pDir = NULL;
|
||||
tfsOpendir(pTfs, "t3", &pDir);
|
||||
|
||||
const STfsFile *pf1 = tfsReaddir(pDir);
|
||||
EXPECT_NE(pf1, nullptr);
|
||||
|
@ -281,7 +286,8 @@ TEST_F(TfsTest, 04_File) {
|
|||
EXPECT_GT(tfsCopyFile(&f1, &f2), 0);
|
||||
|
||||
{
|
||||
STfsDir *pDir = tfsOpendir(pTfs, "t3");
|
||||
STfsDir *pDir = NULL;
|
||||
tfsOpendir(pTfs, "t3", &pDir);
|
||||
|
||||
const STfsFile *pf1 = tfsReaddir(pDir);
|
||||
EXPECT_NE(pf1, nullptr);
|
||||
|
@ -386,17 +392,18 @@ TEST_F(TfsTest, 05_MultiDisk) {
|
|||
taosMkDir(root22);
|
||||
taosMkDir(root23);
|
||||
|
||||
STfs *pTfs = tfsOpen(dCfg, 9);
|
||||
STfs *pTfs = NULL;
|
||||
(void)tfsOpen(dCfg, 9, &pTfs);
|
||||
ASSERT_EQ(pTfs, nullptr);
|
||||
|
||||
dCfg[0].primary = 1;
|
||||
dCfg[1].primary = 1;
|
||||
pTfs = tfsOpen(dCfg, 9);
|
||||
(void)tfsOpen(dCfg, 9, &pTfs);
|
||||
ASSERT_EQ(pTfs, nullptr);
|
||||
|
||||
dCfg[0].primary = 0;
|
||||
dCfg[1].primary = 1;
|
||||
pTfs = tfsOpen(dCfg, 9);
|
||||
(void)tfsOpen(dCfg, 9, &pTfs);
|
||||
ASSERT_NE(pTfs, nullptr);
|
||||
|
||||
tfsUpdateSize(pTfs);
|
||||
|
@ -693,7 +700,8 @@ TEST_F(TfsTest, 05_MultiDisk) {
|
|||
tfsRemoveFile(&f2);
|
||||
|
||||
{
|
||||
STfsDir *pDir = tfsOpendir(pTfs, "t3");
|
||||
STfsDir *pDir = NULL;
|
||||
tfsOpendir(pTfs, "t3", &pDir);
|
||||
|
||||
const STfsFile *pf1 = tfsReaddir(pDir);
|
||||
EXPECT_NE(pf1, nullptr);
|
||||
|
@ -711,7 +719,8 @@ TEST_F(TfsTest, 05_MultiDisk) {
|
|||
EXPECT_GT(tfsCopyFile(&f1, &f2), 0);
|
||||
|
||||
{
|
||||
STfsDir *pDir = tfsOpendir(pTfs, "t3");
|
||||
STfsDir *pDir = NULL;
|
||||
tfsOpendir(pTfs, "t3", &pDir);
|
||||
|
||||
const STfsFile *pf1 = tfsReaddir(pDir);
|
||||
EXPECT_NE(pf1, nullptr);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#define TBASE_BUF_SIZE 256
|
||||
static const char *basis_58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
|
||||
char *base58_encode(const uint8_t *value, int32_t vlen) {
|
||||
int32_t base58_encode(const uint8_t *value, int32_t vlen, char **result) {
|
||||
const uint8_t *pb = value;
|
||||
const uint8_t *pe = pb + vlen;
|
||||
uint8_t buf[TBASE_BUF_SIZE] = {0};
|
||||
|
@ -29,9 +29,10 @@ char *base58_encode(const uint8_t *value, int32_t vlen) {
|
|||
bool bfree = false;
|
||||
int32_t nz = 0, size = 0, len = 0;
|
||||
|
||||
*result = NULL;
|
||||
|
||||
if (vlen > TBASE_MAX_ILEN) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
while (pb != pe && *pb == 0) {
|
||||
|
@ -42,8 +43,7 @@ char *base58_encode(const uint8_t *value, int32_t vlen) {
|
|||
size = (pe - pb) * 69 / 50 + 1;
|
||||
if (size > TBASE_BUF_SIZE) {
|
||||
if (!(pbuf = taosMemoryCalloc(1, size))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
bfree = true;
|
||||
}
|
||||
|
@ -62,17 +62,17 @@ char *base58_encode(const uint8_t *value, int32_t vlen) {
|
|||
|
||||
const uint8_t *pi = pbuf + (size - len);
|
||||
while (pi != pbuf + size && *pi == 0) ++pi;
|
||||
uint8_t *result = taosMemoryCalloc(1, nz + (pbuf + size - pi) + 1);
|
||||
if (!result) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - pi) + 1);
|
||||
if (!pResult) {
|
||||
if (bfree) taosMemoryFree(pbuf);
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
memset(result, '1', nz);
|
||||
while (pi != pbuf + size) result[nz++] = basis_58[*pi++];
|
||||
memset(pResult, '1', nz);
|
||||
while (pi != pbuf + size) pResult[nz++] = basis_58[*pi++];
|
||||
|
||||
if (bfree) taosMemoryFree(pbuf);
|
||||
return result;
|
||||
*result = pResult;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const signed char index_58[256] = {
|
||||
|
@ -86,7 +86,7 @@ static const signed char index_58[256] = {
|
|||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
||||
|
||||
uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
|
||||
int32_t base58_decode(const char *value, size_t inlen, int32_t *outlen, uint8_t **result) {
|
||||
const char *pb = value;
|
||||
const char *pe = value + inlen;
|
||||
uint8_t buf[TBASE_BUF_SIZE] = {0};
|
||||
|
@ -94,15 +94,15 @@ uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
|
|||
bool bfree = false;
|
||||
int32_t nz = 0, size = 0, len = 0;
|
||||
|
||||
*result = NULL;
|
||||
|
||||
if (inlen > TBASE_MAX_OLEN) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
while (pb != pe) {
|
||||
if (*pb == 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
++pb;
|
||||
}
|
||||
|
@ -117,8 +117,7 @@ uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
|
|||
size = (int32_t)(pe - pb) * 733 / 1000 + 1;
|
||||
if (size > TBASE_BUF_SIZE) {
|
||||
if (!(pbuf = taosMemoryCalloc(1, size))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
bfree = true;
|
||||
}
|
||||
|
@ -126,9 +125,8 @@ uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
|
|||
while (pb != pe && *pb && !isspace(*pb)) {
|
||||
int32_t num = index_58[(uint8_t)*pb];
|
||||
if (num == -1) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
if (bfree) taosMemoryFree(pbuf);
|
||||
return NULL;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
int32_t i = 0;
|
||||
for (int32_t j = size - 1; (num != 0 || i < len) && (j >= 0); --j, ++i) {
|
||||
|
@ -143,23 +141,23 @@ uint8_t *base58_decode(const char *value, size_t inlen, int32_t *outlen) {
|
|||
while (pb != pe && isspace(*pb)) ++pb;
|
||||
if (*pb != 0) {
|
||||
if (bfree) taosMemoryFree(pbuf);
|
||||
return NULL;
|
||||
return TSDB_CODE_INVALID_DATA_FMT;
|
||||
}
|
||||
const uint8_t *it = pbuf + (size - len);
|
||||
while (it != pbuf + size && *it == 0) ++it;
|
||||
|
||||
uint8_t *result = taosMemoryCalloc(1, nz + (pbuf + size - it) + 1);
|
||||
if (!result) {
|
||||
uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - it) + 1);
|
||||
if (!pResult) {
|
||||
if (bfree) taosMemoryFree(pbuf);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
memset(result, 0, nz);
|
||||
while (it != pbuf + size) result[nz++] = *it++;
|
||||
memset(pResult, 0, nz);
|
||||
while (it != pbuf + size) pResult[nz++] = *it++;
|
||||
|
||||
if (outlen) *outlen = nz;
|
||||
|
||||
if (bfree) taosMemoryFree(pbuf);
|
||||
return result;
|
||||
*result = pResult;
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue