Merge remote-tracking branch 'origin/3.0' into fix/refactorTransport
This commit is contained in:
commit
baed4a67da
|
@ -12,7 +12,7 @@ extern "C" {
|
|||
#include "tarray.h"
|
||||
|
||||
void stopRsync();
|
||||
void startRsync();
|
||||
int32_t startRsync();
|
||||
int32_t uploadByRsync(const char* id, const char* path);
|
||||
int32_t downloadRsync(const char* id, const char* path);
|
||||
int32_t deleteRsync(const char* id);
|
||||
|
|
|
@ -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,10 +46,10 @@ typedef struct SBlockOrderInfo {
|
|||
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
|
||||
} while (0)
|
||||
|
||||
#define colDataSetNull_f_s(c_, r_) \
|
||||
do { \
|
||||
colDataSetNull_f((c_)->nullbitmap, r_); \
|
||||
memset(((char*)(c_)->pData) + (c_)->info.bytes * (r_), 0, (c_)->info.bytes); \
|
||||
#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)
|
||||
|
||||
#define colDataClearNull_f(bm_, r_) \
|
||||
|
@ -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,17 +239,17 @@ 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);
|
||||
|
||||
int32_t blockDataTrimFirstRows(SSDataBlock* pBlock, size_t n);
|
||||
int32_t blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n);
|
||||
void blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n);
|
||||
|
||||
int32_t assignOneDataBlock(SSDataBlock* dst, const SSDataBlock* src);
|
||||
int32_t copyDataBlock(SSDataBlock* pDst, const SSDataBlock* pSrc);
|
||||
|
@ -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 ================================
|
||||
|
|
|
@ -272,11 +272,11 @@ int32_t taosCfgDynamicOptions(SConfig *pCfg, const char *name, bool forServer);
|
|||
|
||||
struct SConfig *taosGetCfg();
|
||||
|
||||
void taosSetGlobalDebugFlag(int32_t flag);
|
||||
void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
|
||||
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
|
||||
int8_t taosGranted(int8_t type);
|
||||
int32_t taosSetSlowLogScope(char *pScope);
|
||||
int32_t taosSetGlobalDebugFlag(int32_t flag);
|
||||
int32_t taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
|
||||
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
|
||||
int8_t taosGranted(int8_t type);
|
||||
int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -683,36 +683,55 @@ typedef struct {
|
|||
} SColCmprWrapper;
|
||||
|
||||
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
|
||||
if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) return NULL;
|
||||
if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
|
||||
if (pDstWrapper == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pDstWrapper->nCols = pSrcWrapper->nCols;
|
||||
pDstWrapper->version = pSrcWrapper->version;
|
||||
|
||||
int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
|
||||
pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
|
||||
memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
|
||||
if (pDstWrapper->pColCmpr == NULL) {
|
||||
taosMemoryFree(pDstWrapper);
|
||||
return NULL;
|
||||
}
|
||||
(void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
|
||||
|
||||
return pDstWrapper;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
|
||||
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
|
||||
assert(!pCmpr->pColCmpr);
|
||||
pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
|
||||
if (pCmpr->pColCmpr == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
pCmpr->nCols = nCols;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
|
||||
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
|
||||
pCmpr->nCols = pSchema->nCols;
|
||||
assert(!pCmpr->pColCmpr);
|
||||
pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
|
||||
if (pCmpr->pColCmpr == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
for (int32_t i = 0; i < pCmpr->nCols; i++) {
|
||||
SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
|
||||
SSchema* pColSchema = &pSchema->pSchema[i];
|
||||
pColCmpr->id = pColSchema->colId;
|
||||
pColCmpr->alg = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
|
||||
if (pWrapper == NULL) return;
|
||||
|
||||
|
@ -723,7 +742,9 @@ static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* p
|
|||
if (pSchemaWrapper->pSchema == NULL) return NULL;
|
||||
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||
if (pSW == NULL) return pSW;
|
||||
if (pSW == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pSW->nCols = pSchemaWrapper->nCols;
|
||||
pSW->version = pSchemaWrapper->version;
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
|
@ -732,7 +753,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;
|
||||
}
|
||||
|
||||
|
@ -770,32 +791,32 @@ static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
|
||||
if (tEncodeI8(pEncoder, pSchema->type) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pSchema->flags) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pSchema->bytes) < 0) return -1;
|
||||
if (tEncodeI16v(pEncoder, pSchema->colId) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pSchema->name) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
|
||||
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
|
||||
TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
|
||||
TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
|
||||
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
|
||||
if (tDecodeI8(pDecoder, &pSchema->type) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pSchema->flags) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSchema->bytes) < 0) return -1;
|
||||
if (tDecodeI16v(pDecoder, &pSchema->colId) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pSchema->name) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
|
||||
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
|
||||
TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
|
||||
TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
|
||||
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
|
||||
if (tEncodeI16v(pEncoder, pSchemaExt->colId) < 0) return -1;
|
||||
if (tEncodeU32(pEncoder, pSchemaExt->compress) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
|
||||
TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
|
||||
if (tDecodeI16v(pDecoder, &pSchemaExt->colId) < 0) return -1;
|
||||
if (tDecodeU32(pDecoder, &pSchemaExt->compress) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
|
||||
TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -828,36 +849,39 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapp
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
if (tEncodeI32v(pEncoder, pSW->nCols) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pSW->version) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
|
||||
TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tEncodeSSchema(pEncoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
if (tDecodeI32v(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSW->version) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
|
||||
TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
|
||||
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) return -1;
|
||||
if (pSW->pSchema == NULL) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
if (tDecodeI32v(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSW->version) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
|
||||
TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
|
||||
|
||||
pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) return -1;
|
||||
if (pSW->pSchema == NULL) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -2828,19 +2852,24 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) {
|
||||
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) {
|
||||
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
||||
buf = taosDecodeStringTo(buf, pReq->cgroup);
|
||||
buf = taosDecodeStringTo(buf, pReq->clientId);
|
||||
|
||||
int32_t topicNum;
|
||||
int32_t topicNum = 0;
|
||||
buf = taosDecodeFixedI32(buf, &topicNum);
|
||||
|
||||
pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
|
||||
if (pReq->topicNames == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
for (int32_t i = 0; i < topicNum; i++) {
|
||||
char* name;
|
||||
char* name = NULL;
|
||||
buf = taosDecodeString(buf, &name);
|
||||
taosArrayPush(pReq->topicNames, &name);
|
||||
if (taosArrayPush(pReq->topicNames, &name) == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
buf = taosDecodeFixedI8(buf, &pReq->withTbName);
|
||||
|
@ -2849,7 +2878,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
|
|||
buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
|
||||
return buf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -2870,6 +2899,7 @@ static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
|
|||
}
|
||||
pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
|
||||
if (pRebInfo->newConsumers == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
return pRebInfo;
|
||||
|
@ -3353,30 +3383,32 @@ int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchR
|
|||
void tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
|
||||
if (tEncodeI32(pEncoder, pKv->key) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pKv->valueLen) < 0) return -1;
|
||||
if (tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
|
||||
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
|
||||
TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
|
||||
if (tDecodeI32(pDecoder, &pKv->key) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pKv->valueLen) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
|
||||
pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
|
||||
if (pKv->value == NULL) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, (char*)pKv->value) < 0) return -1;
|
||||
if (pKv->value == NULL) {
|
||||
TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
|
||||
if (tEncodeI64(pEncoder, pKey->tscRid) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pKey->connType) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
|
||||
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
|
||||
if (tDecodeI64(pDecoder, &pKey->tscRid) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pKey->connType) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
|
||||
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3427,7 +3459,9 @@ static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTo
|
|||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqReportVgInfo vgInfo;
|
||||
buf = taosDecodeSMqVgInfo(buf, &vgInfo);
|
||||
taosArrayPush(pTopicInfo->pVgInfo, &vgInfo);
|
||||
if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
@ -3463,7 +3497,9 @@ static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg)
|
|||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqTopicInfo topicInfo;
|
||||
buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
|
||||
taosArrayPush(pMsg->pTopics, &topicInfo);
|
||||
if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
@ -3602,7 +3638,7 @@ int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
|
|||
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
|
||||
int32_t tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
|
||||
bool tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
|
||||
void tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pOffsetVal);
|
||||
int32_t tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
|
||||
void tOffsetDestroy(void* pVal);
|
||||
|
||||
typedef struct {
|
||||
|
@ -3803,17 +3839,17 @@ int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
|
|||
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
|
||||
|
||||
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
|
||||
if (tEncodeI32(pEncoder, pReq->number) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
|
||||
for (int32_t i = 0; i < pReq->number; ++i) {
|
||||
tEncodeTSma(pEncoder, pReq->tSma + i);
|
||||
TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
|
||||
if (tDecodeI32(pDecoder, &pReq->number) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
|
||||
for (int32_t i = 0; i < pReq->number; ++i) {
|
||||
tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy);
|
||||
TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -4036,7 +4072,12 @@ 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 (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -86,11 +86,11 @@ void deltaToUtcInitOnce();
|
|||
char getPrecisionUnit(int32_t precision);
|
||||
|
||||
int64_t convertTimePrecision(int64_t ts, int32_t fromPrecision, int32_t toPrecision);
|
||||
int64_t convertTimeFromPrecisionToUnit(int64_t ts, int32_t fromPrecision, char toUnit);
|
||||
int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit, int64_t* pRes);
|
||||
int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal);
|
||||
int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision);
|
||||
|
||||
void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t ts, int32_t precision);
|
||||
int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t ts, int32_t precision);
|
||||
|
||||
struct STm {
|
||||
struct tm tm;
|
||||
|
@ -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))
|
||||
|
||||
|
|
|
@ -34,9 +34,10 @@ typedef struct {
|
|||
* @brief Start one Qnode in Dnode.
|
||||
*
|
||||
* @param pOption Option of the qnode.
|
||||
* @return SQnode* The qnode object.
|
||||
* @param pQnode The qnode object.
|
||||
* @return int32_t The error code.
|
||||
*/
|
||||
SQnode *qndOpen(const SQnodeOpt *pOption);
|
||||
int32_t qndOpen(const SQnodeOpt *pOption, SQnode **pQnode);
|
||||
|
||||
/**
|
||||
* @brief Stop Qnode in Dnode.
|
||||
|
|
|
@ -211,7 +211,7 @@ const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
|
|||
|
||||
void* qExtractReaderFromStreamScanner(void* scanner);
|
||||
|
||||
int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
|
||||
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
|
||||
|
||||
int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo);
|
||||
int32_t qStreamSourceScanParamForHistoryScanStep1(qTaskInfo_t tinfo, SVersionRange *pVerRange, STimeWindow* pWindow);
|
||||
|
|
|
@ -195,7 +195,7 @@ typedef struct SStoreCacheReader {
|
|||
int32_t (*openReader)(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols,
|
||||
SArray *pCidList, int32_t *pSlotIds, uint64_t suid, void **pReader, const char *idstr,
|
||||
SArray *pFuncTypeList, SColumnInfo* pPkCol, int32_t numOfPks);
|
||||
void *(*closeReader)(void *pReader);
|
||||
void (*closeReader)(void *pReader);
|
||||
int32_t (*retrieveRows)(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, const int32_t *dstSlotIds,
|
||||
SArray *pTableUidList);
|
||||
int32_t (*reuseReader)(void *pReader, void *pTableIdList, int32_t numOfTables);
|
||||
|
@ -218,10 +218,10 @@ typedef struct SStoreTqReader {
|
|||
int32_t (*tqGetStreamExecProgress)();
|
||||
|
||||
void (*tqReaderSetColIdList)();
|
||||
int32_t (*tqReaderSetQueryTableList)();
|
||||
void (*tqReaderSetQueryTableList)();
|
||||
|
||||
int32_t (*tqReaderAddTables)();
|
||||
int32_t (*tqReaderRemoveTables)();
|
||||
void (*tqReaderAddTables)();
|
||||
void (*tqReaderRemoveTables)();
|
||||
|
||||
void (*tqSetTablePrimaryKey)();
|
||||
bool (*tqGetTablePrimaryKey)();
|
||||
|
@ -239,8 +239,8 @@ typedef struct SStoreSnapshotFn {
|
|||
bool (*taosXGetTablePrimaryKey)(SSnapContext* ctx);
|
||||
void (*taosXSetTablePrimaryKey)(SSnapContext* ctx, int64_t uid);
|
||||
int32_t (*setForSnapShot)(SSnapContext* ctx, int64_t uid);
|
||||
int32_t (*destroySnapshot)(SSnapContext* ctx);
|
||||
SMetaTableInfo (*getMetaTableInfoFromSnapshot)(SSnapContext* ctx);
|
||||
void (*destroySnapshot)(SSnapContext* ctx);
|
||||
int32_t (*getMetaTableInfoFromSnapshot)(SSnapContext* ctx, SMetaTableInfo* info);
|
||||
int32_t (*getTableInfoFromSnapshot)(SSnapContext* ctx, void** pBuf, int32_t* contLen, int16_t* type, int64_t* uid);
|
||||
} SStoreSnapshotFn;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ typedef struct SFuncExecEnv {
|
|||
} SFuncExecEnv;
|
||||
|
||||
typedef bool (*FExecGetEnv)(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv);
|
||||
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo);
|
||||
typedef int32_t (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo);
|
||||
typedef int32_t (*FExecProcess)(struct SqlFunctionCtx *pCtx);
|
||||
typedef int32_t (*FExecFinalize)(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock);
|
||||
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
|
|
@ -138,6 +138,7 @@ typedef enum EFunctionType {
|
|||
FUNCTION_TYPE_CACHE_LAST_ROW,
|
||||
FUNCTION_TYPE_CACHE_LAST,
|
||||
FUNCTION_TYPE_TABLE_COUNT,
|
||||
FUNCTION_TYPE_GROUP_CONST_VALUE,
|
||||
|
||||
// distributed splitting functions
|
||||
FUNCTION_TYPE_APERCENTILE_PARTIAL = 4000,
|
||||
|
@ -256,9 +257,10 @@ bool fmIsConstantResFunc(SFunctionNode* pFunc);
|
|||
bool fmIsSkipScanCheckFunc(int32_t funcId);
|
||||
bool fmIsPrimaryKeyFunc(int32_t funcId);
|
||||
bool fmIsProcessByRowFunc(int32_t funcId);
|
||||
bool fmisSelectGroupConstValueFunc(int32_t funcId);
|
||||
|
||||
void getLastCacheDataType(SDataType* pType, int32_t pkBytes);
|
||||
SFunctionNode* createFunction(const char* pName, SNodeList* pParameterList);
|
||||
int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNode** pFunc);
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc, SFunctionNode** pMergeFunc);
|
||||
|
||||
|
@ -271,7 +273,7 @@ typedef enum EFuncDataRequired {
|
|||
} EFuncDataRequired;
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, SDataBlockInfo* pBlockInfo);
|
||||
int32_t fmFuncDynDataRequired(int32_t funcId, void* pRes, SDataBlockInfo* pBlockInfo, int32_t *reqStatus);
|
||||
|
||||
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -77,7 +77,7 @@ void freeUdfInterBuf(SUdfInterBuf *buf);
|
|||
|
||||
// high level APIs
|
||||
bool udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv);
|
||||
bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo);
|
||||
int32_t udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo);
|
||||
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
|
||||
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery);
|
|||
* @param type (input, single query type)
|
||||
* @return error code
|
||||
*/
|
||||
int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType type);
|
||||
int32_t indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType type);
|
||||
/*
|
||||
* open index
|
||||
* @param opt (input, index opt)
|
||||
|
@ -91,7 +91,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde
|
|||
* @param index (output, index object)
|
||||
* @return error code
|
||||
*/
|
||||
int indexOpen(SIndexOpts* opt, const char* path, SIndex** index);
|
||||
int32_t indexOpen(SIndexOpts* opt, const char* path, SIndex** index);
|
||||
/*
|
||||
* close index
|
||||
* @param index (input, index to be closed)
|
||||
|
@ -106,7 +106,7 @@ void indexClose(SIndex* index);
|
|||
* @param uid (input, uid of terms)
|
||||
* @return error code
|
||||
*/
|
||||
int indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
|
||||
int32_t indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
|
||||
/*
|
||||
* delete terms that meet query condition
|
||||
* @param index (input, index object)
|
||||
|
@ -114,7 +114,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
|
|||
* @return error code
|
||||
*/
|
||||
|
||||
int indexDelete(SIndex* index, SIndexMultiTermQuery* query);
|
||||
int32_t indexDelete(SIndex* index, SIndexMultiTermQuery* query);
|
||||
/*
|
||||
* search index
|
||||
* @param index (input, index object)
|
||||
|
@ -122,7 +122,7 @@ int indexDelete(SIndex* index, SIndexMultiTermQuery* query);
|
|||
* @param result(output, query result)
|
||||
* @return error code
|
||||
*/
|
||||
int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
|
||||
int32_t indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
|
||||
/*
|
||||
* rebuild index
|
||||
* @param index (input, index object)
|
||||
|
@ -138,7 +138,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
|
|||
* @param index (output, index json object)
|
||||
* @return error code
|
||||
*/
|
||||
int indexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index);
|
||||
int32_t indexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index);
|
||||
/*
|
||||
* close index
|
||||
* @param index (input, index to be closed)
|
||||
|
@ -154,7 +154,7 @@ void indexJsonClose(SIndexJson* index);
|
|||
* @param uid (input, uid of terms)
|
||||
* @return error code
|
||||
*/
|
||||
int indexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
||||
int32_t indexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
||||
/*
|
||||
* search index
|
||||
* @param index (input, index object)
|
||||
|
@ -163,7 +163,7 @@ int indexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
|||
* @return error code
|
||||
*/
|
||||
|
||||
int indexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result);
|
||||
int32_t indexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result);
|
||||
/*
|
||||
* @param
|
||||
* @param
|
||||
|
|
|
@ -112,11 +112,11 @@ int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId);
|
|||
int64_t nodesReleaseAllocatorWeakRef(int64_t allocatorId);
|
||||
void nodesDestroyAllocator(int64_t allocatorId);
|
||||
|
||||
SNode* nodesMakeNode(ENodeType type);
|
||||
int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut);
|
||||
void nodesDestroyNode(SNode* pNode);
|
||||
void nodesFree(void* p);
|
||||
|
||||
SNodeList* nodesMakeList();
|
||||
int32_t nodesMakeList(SNodeList** ppListOut);
|
||||
int32_t nodesListAppend(SNodeList* pList, SNode* pNode);
|
||||
int32_t nodesListStrictAppend(SNodeList* pList, SNode* pNode);
|
||||
int32_t nodesListMakeAppend(SNodeList** pList, SNode* pNode);
|
||||
|
@ -156,8 +156,8 @@ bool nodeListNodeEqual(const SNodeList* a, const SNode* b);
|
|||
|
||||
bool nodesMatchNode(const SNode* pSub, const SNode* pNode);
|
||||
|
||||
SNode* nodesCloneNode(const SNode* pNode);
|
||||
SNodeList* nodesCloneList(const SNodeList* pList);
|
||||
int32_t nodesCloneNode(const SNode* pNode, SNode** ppNodeOut);
|
||||
int32_t nodesCloneList(const SNodeList* pList, SNodeList** ppList);
|
||||
|
||||
const char* nodesNodeName(ENodeType type);
|
||||
int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* pLen);
|
||||
|
|
|
@ -636,9 +636,9 @@ void* nodesGetValueFromNode(SValueNode* pNode);
|
|||
int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value);
|
||||
char* nodesGetStrValueFromNode(SValueNode* pNode);
|
||||
void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
|
||||
SValueNode* nodesMakeValueNodeFromString(char* literal);
|
||||
SValueNode* nodesMakeValueNodeFromBool(bool b);
|
||||
SNode* nodesMakeValueNodeFromInt32(int32_t value);
|
||||
int32_t nodesMakeValueNodeFromString(char* literal, SValueNode** ppValNode);
|
||||
int32_t nodesMakeValueNodeFromBool(bool b, SValueNode** ppValNode);
|
||||
int32_t nodesMakeValueNodeFromInt32(int32_t value, SNode** ppNode);
|
||||
|
||||
char* nodesGetFillModeString(EFillMode mode);
|
||||
int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc);
|
||||
|
|
|
@ -118,6 +118,7 @@ void qDestroyQuery(SQuery* pQueryNode);
|
|||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
|
||||
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
||||
int32_t qInitKeywordsTable();
|
||||
void qCleanupKeywordsTable();
|
||||
|
||||
int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo);
|
||||
|
|
|
@ -335,7 +335,7 @@ SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* nam
|
|||
|
||||
void destroyQueryExecRes(SExecResult* pRes);
|
||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
||||
char* parseTagDatatoJson(void* p);
|
||||
void parseTagDatatoJson(void* p, char** jsonStr);
|
||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||
void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType);
|
||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
||||
|
|
|
@ -686,7 +686,7 @@ int32_t streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration);
|
|||
bool streamHistoryTaskSetVerRangeStep2(SStreamTask* pTask, int64_t latestVer);
|
||||
|
||||
// checkpoint related
|
||||
int32_t streamTaskGetActiveCheckpointInfo(const SStreamTask* pTask, int32_t* pTransId, int64_t* pCheckpointId);
|
||||
void streamTaskGetActiveCheckpointInfo(const SStreamTask* pTask, int32_t* pTransId, int64_t* pCheckpointId);
|
||||
int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeCheckpointId);
|
||||
int32_t streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId);
|
||||
bool streamTaskAlreadySendTrigger(SStreamTask* pTask, int32_t downstreamNodeId);
|
||||
|
@ -770,9 +770,9 @@ bool streamMetaAllTasksReady(const SStreamMeta* pMeta);
|
|||
int32_t streamTaskSendRestoreChkptMsg(SStreamTask* pTask);
|
||||
|
||||
// timer
|
||||
tmr_h streamTimerGetInstance();
|
||||
void streamTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* handle, tmr_h* pTmrId, int32_t vgId,
|
||||
const char* pMsg);
|
||||
int32_t streamTimerGetInstance(tmr_h* pTmr);
|
||||
void streamTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* handle, tmr_h* pTmrId, int32_t vgId,
|
||||
const char* pMsg);
|
||||
|
||||
// checkpoint
|
||||
int32_t streamProcessCheckpointSourceReq(SStreamTask* pTask, SStreamCheckpointSourceReq* pReq);
|
||||
|
@ -809,6 +809,9 @@ void streamTaskSendRetrieveRsp(SStreamRetrieveReq* pReq, SRpcMsg* pRsp);
|
|||
int32_t streamProcessHeartbeatRsp(SStreamMeta* pMeta, SMStreamHbRspMsg* pRsp);
|
||||
int32_t streamTaskSendCheckpointsourceRsp(SStreamTask* pTask);
|
||||
|
||||
void streamMutexLock(TdThreadMutex *pMutex);
|
||||
void streamMutexUnlock(TdThreadMutex *pMutex);
|
||||
void streamMutexDestroy(TdThreadMutex *pMutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* 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_WAL_H_
|
||||
#define _TD_WAL_H_
|
||||
|
||||
|
@ -20,19 +21,11 @@
|
|||
#include "tdef.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
#define wFatal(...) { if (wDebugFlag & DEBUG_FATAL) { taosPrintLog("WAL FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||
#define wError(...) { if (wDebugFlag & DEBUG_ERROR) { taosPrintLog("WAL ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||
#define wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||
#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||
#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", DEBUG_DEBUG, wDebugFlag, __VA_ARGS__); }}
|
||||
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); }}
|
||||
// clang-format on
|
||||
|
||||
#define WAL_PROTO_VER 0
|
||||
#define WAL_NOSUFFIX_LEN 20
|
||||
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
|
||||
|
@ -131,8 +124,7 @@ typedef struct SWal {
|
|||
typedef struct {
|
||||
int64_t refId;
|
||||
int64_t refVer;
|
||||
// int64_t refFile;
|
||||
SWal *pWal;
|
||||
SWal *pWal;
|
||||
} SWalRef;
|
||||
|
||||
typedef struct {
|
||||
|
@ -143,10 +135,8 @@ typedef struct {
|
|||
int8_t enableRef;
|
||||
} SWalFilterCond;
|
||||
|
||||
typedef struct SWalReader SWalReader;
|
||||
|
||||
// todo hide this struct
|
||||
struct SWalReader {
|
||||
typedef struct SWalReader {
|
||||
SWal *pWal;
|
||||
int64_t readerId;
|
||||
TdFilePtr pLogFile;
|
||||
|
@ -159,7 +149,7 @@ struct SWalReader {
|
|||
TdThreadMutex mutex;
|
||||
SWalFilterCond cond;
|
||||
SWalCkHead *pHead;
|
||||
};
|
||||
} SWalReader;
|
||||
|
||||
// module initialization
|
||||
int32_t walInit();
|
||||
|
@ -172,17 +162,9 @@ int32_t walPersist(SWal *);
|
|||
void walClose(SWal *);
|
||||
|
||||
// write interfaces
|
||||
|
||||
// By assigning index by the caller, wal gurantees linearizability
|
||||
int32_t walWrite(SWal *, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen);
|
||||
int32_t walWriteWithSyncInfo(SWal *, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body,
|
||||
int32_t bodyLen);
|
||||
|
||||
// Assign version automatically and return to caller,
|
||||
// -1 will be returned for failed writes
|
||||
int64_t walAppendLog(SWal *, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen);
|
||||
|
||||
void walFsync(SWal *, bool force);
|
||||
int32_t walAppendLog(SWal *, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen);
|
||||
int32_t walFsync(SWal *, bool force);
|
||||
|
||||
// apis for lifecycle management
|
||||
int32_t walCommit(SWal *, int64_t ver);
|
||||
|
@ -191,17 +173,13 @@ int32_t walRollback(SWal *, int64_t ver);
|
|||
int32_t walBeginSnapshot(SWal *, int64_t ver, int64_t logRetention);
|
||||
int32_t walEndSnapshot(SWal *);
|
||||
int32_t walRestoreFromSnapshot(SWal *, int64_t ver);
|
||||
// for tq
|
||||
int32_t walApplyVer(SWal *, int64_t ver);
|
||||
|
||||
// int32_t walDataCorrupted(SWal*);
|
||||
|
||||
// wal reader
|
||||
SWalReader *walOpenReader(SWal *, SWalFilterCond *pCond, int64_t id);
|
||||
void walCloseReader(SWalReader *pRead);
|
||||
void walReadReset(SWalReader *pReader);
|
||||
int32_t walReadVer(SWalReader *pRead, int64_t ver);
|
||||
void decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const char *func);
|
||||
int32_t walReaderSeekVer(SWalReader *pRead, int64_t ver);
|
||||
int32_t walNextValidMsg(SWalReader *pRead);
|
||||
int64_t walReaderGetCurrentVer(const SWalReader *pReader);
|
||||
|
@ -216,12 +194,11 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver);
|
|||
int32_t walFetchBody(SWalReader *pRead);
|
||||
int32_t walSkipFetchBody(SWalReader *pRead);
|
||||
|
||||
void walRefFirstVer(SWal *, SWalRef *);
|
||||
void walRefLastVer(SWal *, SWalRef *);
|
||||
|
||||
SWalRef *walOpenRef(SWal *);
|
||||
void walCloseRef(SWal *pWal, int64_t refId);
|
||||
int32_t walSetRefVer(SWalRef *, int64_t ver);
|
||||
void walRefFirstVer(SWal *, SWalRef *);
|
||||
void walRefLastVer(SWal *, SWalRef *);
|
||||
|
||||
// helper function for raft
|
||||
bool walLogExist(SWal *, int64_t ver);
|
||||
|
|
|
@ -97,6 +97,7 @@ extern "C" {
|
|||
#include <nmmintrin.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "osThread.h"
|
||||
|
||||
#include "osAtomic.h"
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef int (*__compar_fn_t)(const void *, const void *);
|
|||
#endif
|
||||
#define ssize_t int
|
||||
#define _SSIZE_T_
|
||||
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||
#define bzero(ptr, size) (void)memset((ptr), 0, (size))
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define wcsncasecmp _wcsnicmp
|
||||
|
|
|
@ -54,7 +54,7 @@ extern SDiskSpace tsDataSpace;
|
|||
extern SDiskSpace tsLogSpace;
|
||||
extern SDiskSpace tsTempSpace;
|
||||
|
||||
void osDefaultInit();
|
||||
int32_t osDefaultInit();
|
||||
void osUpdate();
|
||||
void osCleanup();
|
||||
|
||||
|
@ -66,7 +66,7 @@ bool osLogSpaceSufficient();
|
|||
bool osDataSpaceSufficient();
|
||||
bool osTempSpaceSufficient();
|
||||
|
||||
void osSetTimezone(const char *timezone);
|
||||
int32_t osSetTimezone(const char *timezone);
|
||||
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
void osSetProcPath(int32_t argc, char **argv);
|
||||
|
||||
|
|
|
@ -114,8 +114,6 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
|||
|
||||
bool taosValidFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosGetErrorFile(TdFilePtr pFile);
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
||||
|
||||
int32_t taosSetFileHandlesLimit();
|
||||
|
|
|
@ -30,7 +30,7 @@ extern "C" {
|
|||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
void taosGetSystemLocale(char *outLocale, char *outCharset);
|
||||
void taosSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -65,6 +65,16 @@ void *taosMemoryMallocAlign(uint32_t alignment, int64_t size);
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_MEMORY_REALLOC(ptr, len) \
|
||||
do { \
|
||||
void *tmp = taosMemoryRealloc(ptr, (len)); \
|
||||
if (tmp) { \
|
||||
(ptr) = tmp; \
|
||||
} else { \
|
||||
taosMemoryFreeClear(ptr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -49,11 +49,14 @@ typedef BOOL (*FSignalHandler)(DWORD fdwCtrlType);
|
|||
#else
|
||||
typedef void (*FSignalHandler)(int32_t signum, void *sigInfo, void *context);
|
||||
#endif
|
||||
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||
void taosIgnSignal(int32_t signum);
|
||||
void taosDflSignal(int32_t signum);
|
||||
|
||||
void taosKillChildOnParentStopped();
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
int32_t taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||
int32_t taosIgnSignal(int32_t signum);
|
||||
int32_t taosDflSignal(int32_t signum);
|
||||
|
||||
int32_t taosKillChildOnParentStopped();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -159,13 +159,12 @@ TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, st
|
|||
|
||||
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen);
|
||||
|
||||
void taosBlockSIGPIPE();
|
||||
uint32_t taosGetIpv4FromFqdn(const char *);
|
||||
int32_t taosBlockSIGPIPE();
|
||||
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip);
|
||||
int32_t taosGetFqdn(char *);
|
||||
void tinet_ntoa(char *ipstr, uint32_t ip);
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
void taosIgnSIGPIPE();
|
||||
void taosSetMaskSIGPIPE();
|
||||
int32_t taosIgnSIGPIPE();
|
||||
uint32_t taosInetAddr(const char *ipAddr);
|
||||
const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len);
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef enum { M2C = 0, C2M } ConvType;
|
|||
|
||||
#define TAOS_STRCPY(_dst, _src) ((void)strcpy(_dst, _src))
|
||||
#define TAOS_STRNCPY(_dst, _src, _size) ((void)strncpy(_dst, _src, _size))
|
||||
#define TAOS_STRCAT(_dst, _src) ((void)strcat(_dst, _src))
|
||||
|
||||
char *tstrdup(const char *src);
|
||||
int32_t taosUcs4len(TdUcs4 *ucs4);
|
||||
|
@ -74,7 +75,7 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs);
|
|||
int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv);
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||
TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len);
|
||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
|
||||
|
|
|
@ -44,7 +44,7 @@ int64_t taosGetLineCmd(TdCmdPtr pCmd, char **__restrict ptrBuf);
|
|||
|
||||
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
||||
|
||||
int64_t taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
void taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
|
||||
void *taosLoadDll(const char *filename);
|
||||
|
||||
|
@ -54,11 +54,11 @@ void taosCloseDll(void *handle);
|
|||
|
||||
int32_t taosSetConsoleEcho(bool on);
|
||||
|
||||
void taosSetTerminalMode();
|
||||
int32_t taosSetTerminalMode();
|
||||
|
||||
int32_t taosGetOldTerminalMode();
|
||||
|
||||
void taosResetTerminalMode();
|
||||
int32_t taosResetTerminalMode();
|
||||
|
||||
#define STACKSIZE 100
|
||||
|
||||
|
|
|
@ -65,28 +65,28 @@ int32_t taosGetTimestampSec();
|
|||
//@return timestamp in millisecond
|
||||
static FORCE_INLINE int64_t taosGetTimestampMs() {
|
||||
struct timeval systemTime;
|
||||
taosGetTimeOfDay(&systemTime);
|
||||
(void)taosGetTimeOfDay(&systemTime);
|
||||
return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_usec / 1000;
|
||||
}
|
||||
|
||||
//@return timestamp in microsecond
|
||||
static FORCE_INLINE int64_t taosGetTimestampUs() {
|
||||
struct timeval systemTime;
|
||||
taosGetTimeOfDay(&systemTime);
|
||||
(void)taosGetTimeOfDay(&systemTime);
|
||||
return (int64_t)systemTime.tv_sec * 1000000LL + (int64_t)systemTime.tv_usec;
|
||||
}
|
||||
|
||||
//@return timestamp in nanosecond
|
||||
static FORCE_INLINE int64_t taosGetTimestampNs() {
|
||||
struct timespec systemTime = {0};
|
||||
taosClockGetTime(CLOCK_REALTIME, &systemTime);
|
||||
(void)taosClockGetTime(CLOCK_REALTIME, &systemTime);
|
||||
return (int64_t)systemTime.tv_sec * 1000000000LL + (int64_t)systemTime.tv_nsec;
|
||||
}
|
||||
|
||||
//@return timestamp of monotonic clock in millisecond
|
||||
static FORCE_INLINE int64_t taosGetMonoTimestampMs() {
|
||||
struct timespec systemTime = {0};
|
||||
taosClockGetTime(CLOCK_MONOTONIC, &systemTime);
|
||||
(void)taosClockGetTime(CLOCK_MONOTONIC, &systemTime);
|
||||
return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ enum TdTimezone {
|
|||
};
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
|
||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||
int32_t taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ int32_t taosGetErrSize();
|
|||
#define terrln (*taosGetErrln())
|
||||
|
||||
#define SET_ERROR_MSG(MSG, ...) \
|
||||
snprintf(terrMsg, ERR_MSG_LEN, MSG, ##__VA_ARGS__)
|
||||
(void)snprintf(terrMsg, ERR_MSG_LEN, MSG, ##__VA_ARGS__)
|
||||
|
||||
#define TSDB_CODE_SUCCESS 0
|
||||
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error
|
||||
|
@ -200,7 +200,8 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_TSC_ENCODE_PARAM_ERROR TAOS_DEF_ERROR_CODE(0, 0X0231)
|
||||
#define TSDB_CODE_TSC_ENCODE_PARAM_NULL TAOS_DEF_ERROR_CODE(0, 0X0232)
|
||||
#define TSDB_CODE_TSC_COMPRESS_PARAM_ERROR TAOS_DEF_ERROR_CODE(0, 0X0233)
|
||||
#define TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR TAOS_DEF_ERROR_CODE(0, 0X0234)
|
||||
#define TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR TAOS_DEF_ERROR_CODE(0, 0X0234)
|
||||
#define TSDB_CODE_TSC_FAIL_GENERATE_JSON TAOS_DEF_ERROR_CODE(0, 0X0235)
|
||||
#define TSDB_CODE_TSC_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0X02FF)
|
||||
|
||||
// mnode-common
|
||||
|
@ -670,8 +671,16 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_SYN_BUFFER_FULL TAOS_DEF_ERROR_CODE(0, 0x0916)
|
||||
#define TSDB_CODE_SYN_WRITE_STALL TAOS_DEF_ERROR_CODE(0, 0x0917)
|
||||
#define TSDB_CODE_SYN_NEGOTIATION_WIN_FULL TAOS_DEF_ERROR_CODE(0, 0x0918)
|
||||
#define TSDB_CODE_SYN_WRONG_TERM TAOS_DEF_ERROR_CODE(0, 0x0919)
|
||||
#define TSDB_CODE_SYN_WRONG_FSM_STATE TAOS_DEF_ERROR_CODE(0, 0x091A)
|
||||
#define TSDB_CODE_SYN_WRONG_SYNC_STATE TAOS_DEF_ERROR_CODE(0, 0x091B)
|
||||
#define TSDB_CODE_SYN_WRONG_REF TAOS_DEF_ERROR_CODE(0, 0x091C)
|
||||
#define TSDB_CODE_SYN_INVALID_ID TAOS_DEF_ERROR_CODE(0, 0x091D)
|
||||
#define TSDB_CODE_SYN_RETURN_VALUE_NULL TAOS_DEF_ERROR_CODE(0, 0x091E)
|
||||
#define TSDB_CODE_SYN_WRONG_ROLE TAOS_DEF_ERROR_CODE(0, 0x091F)
|
||||
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
|
||||
|
||||
|
||||
// tq
|
||||
#define TSDB_CODE_TQ_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0A00)
|
||||
#define TSDB_CODE_TQ_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0A01)
|
||||
|
@ -862,6 +871,11 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_FUNC_TO_TIMESTAMP_FAILED_TS_ERR TAOS_DEF_ERROR_CODE(0, 0x2807)
|
||||
#define TSDB_CODE_FUNC_TO_TIMESTAMP_FAILED_NOT_SUPPORTED TAOS_DEF_ERROR_CODE(0, 0x2808)
|
||||
#define TSDB_CODE_FUNC_TO_CHAR_NOT_SUPPORTED TAOS_DEF_ERROR_CODE(0, 0x2809)
|
||||
#define TSDB_CODE_FUNC_TIME_UNIT_INVALID TAOS_DEF_ERROR_CODE(0, 0x280A)
|
||||
#define TSDB_CODE_FUNC_TIME_UNIT_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x280B)
|
||||
#define TSDB_CODE_FUNC_INVALID_VALUE_RANGE TAOS_DEF_ERROR_CODE(0, 0x280C)
|
||||
#define TSDB_CODE_FUNC_SETUP_ERROR TAOS_DEF_ERROR_CODE(0, 0x280D)
|
||||
|
||||
|
||||
//udf
|
||||
#define TSDB_CODE_UDF_STOPPING TAOS_DEF_ERROR_CODE(0, 0x2901)
|
||||
|
|
|
@ -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,8 @@ typedef struct {
|
|||
char name[TSDB_LOG_VAR_LEN];
|
||||
} SLogVar;
|
||||
|
||||
#define TMQ_SEPARATOR ':'
|
||||
#define TMQ_SEPARATOR ":"
|
||||
#define TMQ_SEPARATOR_CHAR ':'
|
||||
|
||||
enum {
|
||||
SND_WORKER_TYPE__SHARED = 1,
|
||||
|
|
|
@ -64,10 +64,10 @@ typedef struct TDigest {
|
|||
} TDigest;
|
||||
|
||||
TDigest *tdigestNewFrom(void *pBuf, int32_t compression);
|
||||
void tdigestAdd(TDigest *t, double x, int64_t w);
|
||||
void tdigestMerge(TDigest *t1, TDigest *t2);
|
||||
int32_t tdigestAdd(TDigest *t, double x, int64_t w);
|
||||
int32_t tdigestMerge(TDigest *t1, TDigest *t2);
|
||||
double tdigestQuantile(TDigest *t, double q);
|
||||
void tdigestCompress(TDigest *t);
|
||||
int32_t tdigestCompress(TDigest *t);
|
||||
void tdigestFreeFrom(TDigest *t);
|
||||
void tdigestAutoFill(TDigest *t, int32_t compression);
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ static FORCE_INLINE int32_t tEncodeFixed(SEncoder* pCoder, const void* val, uint
|
|||
if (pCoder->pos + size > pCoder->size) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
memcpy(pCoder->data + pCoder->pos, val, size);
|
||||
TAOS_MEMCPY(pCoder->data + pCoder->pos, val, size);
|
||||
}
|
||||
|
||||
pCoder->pos += size;
|
||||
|
@ -212,7 +212,7 @@ static FORCE_INLINE int32_t tEncodeBinary(SEncoder* pCoder, const uint8_t* val,
|
|||
if (pCoder->pos + len > pCoder->size) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
memcpy(pCoder->data + pCoder->pos, val, len);
|
||||
TAOS_MEMCPY(pCoder->data + pCoder->pos, val, len);
|
||||
}
|
||||
|
||||
pCoder->pos += len;
|
||||
|
@ -233,7 +233,7 @@ static int32_t tDecodeFixed(SDecoder* pCoder, void* val, uint32_t size) {
|
|||
if (pCoder->pos + size > pCoder->size) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
} else if (val) {
|
||||
memcpy(val, pCoder->data + pCoder->pos, size);
|
||||
TAOS_MEMCPY(val, pCoder->data + pCoder->pos, size);
|
||||
}
|
||||
pCoder->pos += size;
|
||||
return 0;
|
||||
|
@ -427,7 +427,7 @@ static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val) {
|
|||
uint32_t len;
|
||||
TAOS_CHECK_RETURN(tDecodeCStrAndLen(pCoder, &pStr, &len));
|
||||
|
||||
memcpy(val, pStr, len + 1);
|
||||
TAOS_MEMCPY(val, pStr, len + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ static FORCE_INLINE int32_t tDecodeBinaryAlloc(SDecoder* pCoder, void** val, uin
|
|||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(*val, pCoder->data + pCoder->pos, length);
|
||||
TAOS_MEMCPY(*val, pCoder->data + pCoder->pos, length);
|
||||
|
||||
pCoder->pos += length;
|
||||
} else {
|
||||
|
@ -468,7 +468,7 @@ static FORCE_INLINE int32_t tDecodeBinaryAlloc32(SDecoder* pCoder, void** val, u
|
|||
if (*val == NULL) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
memcpy(*val, pCoder->data + pCoder->pos, length);
|
||||
TAOS_MEMCPY(*val, pCoder->data + pCoder->pos, length);
|
||||
|
||||
pCoder->pos += length;
|
||||
} else {
|
||||
|
@ -757,7 +757,7 @@ static FORCE_INLINE int32_t tPutBinary(uint8_t* p, uint8_t* pData, uint32_t nDat
|
|||
int n = 0;
|
||||
|
||||
n += tPutU32v(p ? p + n : p, nData);
|
||||
if (p) memcpy(p + n, pData, nData);
|
||||
if (p) TAOS_MEMCPY(p + n, pData, nData);
|
||||
n += nData;
|
||||
|
||||
return n;
|
||||
|
|
|
@ -156,7 +156,7 @@ void setBufPageCompressOnDisk(SDiskbasedBuf* pBuf, bool comp);
|
|||
* @param pBuf
|
||||
* @param pageId
|
||||
*/
|
||||
void dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage);
|
||||
int32_t dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage);
|
||||
|
||||
/**
|
||||
* Print the statistics when closing this buffer
|
||||
|
|
|
@ -64,7 +64,7 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
|
|||
tMD5Init(&context);
|
||||
tMD5Update(&context, inBuf, (uint32_t)inLen);
|
||||
tMD5Final(&context);
|
||||
memcpy(target, context.digest, tListLen(context.digest));
|
||||
(void)memcpy(target, context.digest, tListLen(context.digest));
|
||||
}
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
|
||||
|
@ -75,11 +75,11 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
|
|||
char buf[TSDB_PASSWORD_LEN + 1];
|
||||
|
||||
buf[TSDB_PASSWORD_LEN] = 0;
|
||||
sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
|
||||
(void)sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1],
|
||||
context.digest[2], context.digest[3], context.digest[4], context.digest[5], context.digest[6],
|
||||
context.digest[7], context.digest[8], context.digest[9], context.digest[10], context.digest[11],
|
||||
context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
|
||||
memcpy(target, buf, TSDB_PASSWORD_LEN);
|
||||
(void)memcpy(target, buf, TSDB_PASSWORD_LEN);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosCreateMD5Hash(char *pBuf, int32_t len) {
|
||||
|
@ -108,10 +108,10 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
int32_t offset = 0;
|
||||
if (prefix < 0) {
|
||||
offset = -1 * prefix;
|
||||
strncpy(tbName, tbname, offset);
|
||||
(void)strncpy(tbName, tbname, offset);
|
||||
}
|
||||
if (suffix < 0) {
|
||||
strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
|
||||
(void)strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
|
||||
offset += -1 * suffix;
|
||||
}
|
||||
return MurmurHash3_32(tbName, offset);
|
||||
|
@ -135,6 +135,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define QUERY_CHECK_CODE TSDB_CHECK_CODE
|
||||
|
||||
#define TSDB_CHECK_NULL(ptr, CODE, LINO, LABEL, ERRNO) \
|
||||
if ((ptr) == NULL) { \
|
||||
(CODE) = (ERRNO); \
|
||||
|
@ -142,15 +144,20 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
goto LABEL; \
|
||||
}
|
||||
|
||||
#define QUERY_CHECK_NULL TSDB_CHECK_NULL
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
#define VND_CHECK_CODE(CODE, LINO, LABEL) TSDB_CHECK_CODE(CODE, LINO, LABEL)
|
||||
|
||||
#define TCONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
|
||||
|
||||
#define TAOS_RETURN(code) \
|
||||
#define TAOS_GET_TERRNO(code) \
|
||||
(terrno == 0 ? code : terrno)
|
||||
|
||||
#define TAOS_RETURN(CODE) \
|
||||
do { \
|
||||
return (terrno = (code)); \
|
||||
return (terrno = (CODE)); \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_CHECK_RETURN(CMD) \
|
||||
|
@ -172,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ if [ -f ${insmetaPath}/preun.sh ]; then
|
|||
else
|
||||
bin_link_dir="/usr/bin"
|
||||
lib_link_dir="/usr/lib"
|
||||
lib64_link_dir="/usr/lib64"
|
||||
inc_link_dir="/usr/include"
|
||||
|
||||
data_link_dir="/usr/local/taos/data"
|
||||
|
@ -40,9 +41,11 @@ else
|
|||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
[ -f ${lib_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.so || :
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
${csudo}rm -f ${lib_link_dir}/libtaosws.so || :
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaosws.so || :
|
||||
|
||||
${csudo}rm -f ${log_link_dir} || :
|
||||
${csudo}rm -f ${data_link_dir} || :
|
||||
|
|
|
@ -223,6 +223,7 @@ if [ $1 -eq 0 ];then
|
|||
else
|
||||
bin_link_dir="/usr/bin"
|
||||
lib_link_dir="/usr/lib"
|
||||
lib64_link_dir="/usr/lib64"
|
||||
inc_link_dir="/usr/include"
|
||||
|
||||
data_link_dir="/usr/local/taos/data"
|
||||
|
@ -235,13 +236,18 @@ if [ $1 -eq 0 ];then
|
|||
${csudo}rm -f ${bin_link_dir}/udfd || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
||||
${csudo}rm -f ${bin_link_dir}/taoskeeper || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdump || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosBenchmark || :
|
||||
${csudo}rm -f ${cfg_link_dir}/* || :
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
${csudo}rm -f ${inc_link_dir}/taows.h || :
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.so || :
|
||||
${csudo}rm -f ${lib_link_dir}/libtaosws.so || :
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaosws.so || :
|
||||
|
||||
${csudo}rm -f ${log_link_dir} || :
|
||||
${csudo}rm -f ${data_link_dir} || :
|
||||
|
|
|
@ -12,6 +12,8 @@ RED='\033[0;31m'
|
|||
GREEN='\033[1;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
PREFIX="taos"
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
installDir="/usr/local/taos"
|
||||
bin_link_dir="/usr/bin"
|
||||
|
@ -32,7 +34,6 @@ else
|
|||
inc_link_dir="/usr/local/include"
|
||||
fi
|
||||
|
||||
PREFIX="taos"
|
||||
serverName="${PREFIX}d"
|
||||
clientName="${PREFIX}"
|
||||
uninstallScript="rm${PREFIX}"
|
||||
|
@ -46,8 +47,6 @@ explorerName="${PREFIX}-explorer"
|
|||
tarbitratorName="tarbitratord"
|
||||
productName="TDengine"
|
||||
|
||||
installDir="/usr/local/${PREFIX}"
|
||||
|
||||
#install main path
|
||||
install_main_dir=${installDir}
|
||||
data_link_dir=${installDir}/data
|
||||
|
|
|
@ -63,10 +63,13 @@ function clean_bin() {
|
|||
}
|
||||
|
||||
function clean_lib() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
#${csudo}rm -rf ${v15_java_app_dir} || :
|
||||
# Remove link
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
[ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || :
|
||||
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
[ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || :
|
||||
#${csudo}rm -rf ${v15_java_app_dir} || :
|
||||
}
|
||||
|
||||
function clean_header() {
|
||||
|
@ -76,6 +79,7 @@ function clean_header() {
|
|||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||
}
|
||||
|
||||
function clean_config() {
|
||||
|
|
|
@ -310,7 +310,7 @@ void setResPrecision(SReqResultInfo* pResInfo, int32_t precision);
|
|||
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4);
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows,
|
||||
bool convertUcs4);
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
int32_t setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
void doFreeReqResultInfo(SReqResultInfo* pResInfo);
|
||||
int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, SArray** pReq);
|
||||
void syncCatalogFn(SMetaData* pResult, void* param, int32_t code);
|
||||
|
@ -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);
|
||||
|
@ -349,15 +348,16 @@ __async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
|||
|
||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj);
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char* db, int32_t connType, SAppInstInfo* pAppInfo);
|
||||
int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo,
|
||||
STscObj **p);
|
||||
void destroyTscObj(void* pObj);
|
||||
STscObj* acquireTscObj(int64_t rid);
|
||||
int32_t releaseTscObj(int64_t rid);
|
||||
void releaseTscObj(int64_t rid);
|
||||
void destroyAppInst(void* pAppInfo);
|
||||
|
||||
uint64_t generateRequestId();
|
||||
|
||||
void* createRequest(uint64_t connId, int32_t type, int64_t reqid);
|
||||
int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj **pRequest);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
SRequestObj* acquireRequest(int64_t rid);
|
||||
int32_t releaseRequest(int64_t rid);
|
||||
|
@ -371,7 +371,7 @@ void resetConnectDB(STscObj* pTscObj);
|
|||
|
||||
int taos_options_imp(TSDB_OPTION option, const char* str);
|
||||
|
||||
void* openTransporter(const char* user, const char* auth, int32_t numOfThreads);
|
||||
int32_t openTransporter(const char* user, const char* auth, int32_t numOfThreads, void **pDnodeConn);
|
||||
void tscStopCrashReport();
|
||||
|
||||
typedef struct AsyncArg {
|
||||
|
@ -382,8 +382,8 @@ typedef struct AsyncArg {
|
|||
bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType);
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
||||
|
||||
STscObj* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType);
|
||||
int32_t taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType, STscObj** pObj);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb);
|
||||
|
||||
|
@ -396,11 +396,11 @@ void taos_close_internal(void* taos);
|
|||
|
||||
// --- heartbeat
|
||||
// global, called by mgmt
|
||||
int hbMgrInit();
|
||||
void hbMgrCleanUp();
|
||||
int32_t hbMgrInit();
|
||||
void hbMgrCleanUp();
|
||||
|
||||
// cluster level
|
||||
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
||||
int32_t appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key, SAppHbMgr **pAppHbMgr);
|
||||
void appHbMgrCleanup(void);
|
||||
void hbRemoveAppHbMrg(SAppHbMgr** pAppHbMgr);
|
||||
void destroyAllRequests(SHashObj* pRequests);
|
||||
|
@ -409,7 +409,7 @@ void stopAllRequests(SHashObj* pRequests);
|
|||
//SAppInstInfo* getAppInstInfo(const char* clusterKey);
|
||||
|
||||
// conn level
|
||||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
int32_t hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
void hbDeregisterConn(STscObj* pTscObj, SClientHbKey connKey);
|
||||
|
||||
typedef struct SSqlCallbackWrapper {
|
||||
|
@ -428,7 +428,7 @@ void doAsyncQuery(SRequestObj* pRequest, bool forceUpdateMeta);
|
|||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList, bool isView);
|
||||
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog);
|
||||
int32_t handleCreateTbExecRes(void* res, SCatalog* pCatalog);
|
||||
bool qnodeRequired(SRequestObj* pRequest);
|
||||
int32_t qnodeRequired(SRequestObj* pRequest, bool *required);
|
||||
void continueInsertFromCsv(SSqlCallbackWrapper* pWrapper, SRequestObj* pRequest);
|
||||
void destorySqlCallbackWrapper(SSqlCallbackWrapper* pWrapper);
|
||||
void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta, int32_t code);
|
||||
|
@ -444,6 +444,30 @@ void freeQueryParam(SSyncQueryParam* param);
|
|||
int32_t clientParseSqlImpl(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effeciveUser, SParseSqlRes* pRes);
|
||||
#endif
|
||||
|
||||
#define TSC_ERR_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while (0)
|
||||
#define TSC_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
} \
|
||||
return _code; \
|
||||
} while (0)
|
||||
#define TSC_ERR_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void slowQueryLog(int64_t rid, bool killed, int32_t code, int32_t cost);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "tversion.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
|
||||
#include "cus_name.h"
|
||||
|
@ -43,6 +44,26 @@
|
|||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
#define ENV_JSON_FALSE_CHECK(c) \
|
||||
do { \
|
||||
if (!c) { \
|
||||
tscError("faild to add item to JSON object");\
|
||||
code = TSDB_CODE_TSC_FAIL_GENERATE_JSON; \
|
||||
goto _end; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ENV_ERR_RET(c,info) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
errno = _code; \
|
||||
tscInitRes = _code; \
|
||||
tscError(info); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
STscDbg tscDbg = {0};
|
||||
SAppInfo appInfo;
|
||||
int64_t lastClusterId = 0;
|
||||
|
@ -56,8 +77,14 @@ static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
|||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
// connection has been released already, abort creating request.
|
||||
pRequest->self = taosAddRef(clientReqRefPool, pRequest);
|
||||
if (pRequest->self < 0) {
|
||||
tscError("failed to add ref to request");
|
||||
code = terrno;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t num = atomic_add_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
|
@ -71,19 +98,23 @@ static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) {
|
|||
pRequest->self, pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void concatStrings(SArray *list, char* buf, int size){
|
||||
int len = 0;
|
||||
for(int i = 0; i < taosArrayGetSize(list); i++){
|
||||
char* db = taosArrayGet(list, i);
|
||||
if (NULL == db) {
|
||||
tscError("get dbname failed, buf:%s", buf);
|
||||
break;
|
||||
}
|
||||
char* dot = strchr(db, '.');
|
||||
if (dot != NULL) {
|
||||
db = dot + 1;
|
||||
}
|
||||
if (i != 0){
|
||||
strcat(buf, ",");
|
||||
(void)strcat(buf, ",");
|
||||
len += 1;
|
||||
}
|
||||
int ret = snprintf(buf + len, size - len, "%s", db);
|
||||
|
@ -99,61 +130,70 @@ static void concatStrings(SArray *list, char* buf, int size){
|
|||
}
|
||||
}
|
||||
|
||||
static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_t reqType, int64_t duration){
|
||||
static int32_t generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_t reqType, int64_t duration){
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (json == NULL) {
|
||||
tscError("[monitor] cJSON_CreateObject failed");
|
||||
return;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
char clusterId[32] = {0};
|
||||
if (snprintf(clusterId, sizeof(clusterId), "%" PRId64, pTscObj->pAppInfo->clusterId) < 0){
|
||||
tscError("failed to generate clusterId:%" PRId64, pTscObj->pAppInfo->clusterId);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
char startTs[32] = {0};
|
||||
if (snprintf(startTs, sizeof(startTs), "%" PRId64, pRequest->metric.start/1000) < 0){
|
||||
tscError("failed to generate startTs:%" PRId64, pRequest->metric.start/1000);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
char requestId[32] = {0};
|
||||
if (snprintf(requestId, sizeof(requestId), "%" PRIu64, pRequest->requestId) < 0){
|
||||
tscError("failed to generate requestId:%" PRIu64, pRequest->requestId);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, "cluster_id", cJSON_CreateString(clusterId));
|
||||
cJSON_AddItemToObject(json, "start_ts", cJSON_CreateString(startTs));
|
||||
cJSON_AddItemToObject(json, "request_id", cJSON_CreateString(requestId));
|
||||
cJSON_AddItemToObject(json, "query_time", cJSON_CreateNumber(duration/1000));
|
||||
cJSON_AddItemToObject(json, "code", cJSON_CreateNumber(pRequest->code));
|
||||
cJSON_AddItemToObject(json, "error_info", cJSON_CreateString(tstrerror(pRequest->code)));
|
||||
cJSON_AddItemToObject(json, "type", cJSON_CreateNumber(reqType));
|
||||
cJSON_AddItemToObject(json, "rows_num", cJSON_CreateNumber(pRequest->body.resInfo.numOfRows + pRequest->body.resInfo.totalRows));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "cluster_id", cJSON_CreateString(clusterId)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "start_ts", cJSON_CreateString(startTs)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "request_id", cJSON_CreateString(requestId)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "query_time", cJSON_CreateNumber(duration/1000)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "code", cJSON_CreateNumber(pRequest->code)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "error_info", cJSON_CreateString(tstrerror(pRequest->code))));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "type", cJSON_CreateNumber(reqType)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "rows_num", cJSON_CreateNumber(pRequest->body.resInfo.numOfRows + pRequest->body.resInfo.totalRows)));
|
||||
if(pRequest->sqlstr != NULL && strlen(pRequest->sqlstr) > pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen){
|
||||
char tmp = pRequest->sqlstr[pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen];
|
||||
pRequest->sqlstr[pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen] = '\0';
|
||||
cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr)));
|
||||
pRequest->sqlstr[pTscObj->pAppInfo->monitorParas.tsSlowLogMaxLen] = tmp;
|
||||
}else{
|
||||
cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr)));
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json, "user", cJSON_CreateString(pTscObj->user));
|
||||
cJSON_AddItemToObject(json, "process_name", cJSON_CreateString(appInfo.appName));
|
||||
cJSON_AddItemToObject(json, "ip", cJSON_CreateString(tsLocalFqdn));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "user", cJSON_CreateString(pTscObj->user)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "process_name", cJSON_CreateString(appInfo.appName)));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "ip", cJSON_CreateString(tsLocalFqdn)));
|
||||
|
||||
char pid[32] = {0};
|
||||
if (snprintf(pid, sizeof(pid), "%d", appInfo.pid) < 0){
|
||||
tscError("failed to generate pid:%d", appInfo.pid);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json, "process_id", cJSON_CreateString(pid));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "process_id", cJSON_CreateString(pid)));
|
||||
if(pRequest->dbList != NULL){
|
||||
char dbList[1024] = {0};
|
||||
concatStrings(pRequest->dbList, dbList, sizeof(dbList) - 1);
|
||||
cJSON_AddItemToObject(json, "db", cJSON_CreateString(dbList));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString(dbList)));
|
||||
}else if(pRequest->pDb != NULL){
|
||||
cJSON_AddItemToObject(json, "db", cJSON_CreateString(pRequest->pDb));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString(pRequest->pDb)));
|
||||
}else{
|
||||
cJSON_AddItemToObject(json, "db", cJSON_CreateString(""));
|
||||
ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString("")));
|
||||
}
|
||||
|
||||
char* value = cJSON_PrintUnformatted(json);
|
||||
|
@ -161,11 +201,15 @@ static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_
|
|||
data.clusterId = pTscObj->pAppInfo->clusterId;
|
||||
data.type = SLOW_LOG_WRITE;
|
||||
data.data = value;
|
||||
if(monitorPutData2MonitorQueue(data) < 0){
|
||||
code = monitorPutData2MonitorQueue(data);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFree(value);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
_end:
|
||||
cJSON_Delete(json);
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool checkSlowLogExceptDb(SRequestObj *pRequest, char* exceptDb) {
|
||||
|
@ -175,6 +219,10 @@ static bool checkSlowLogExceptDb(SRequestObj *pRequest, char* exceptDb) {
|
|||
|
||||
for (int i = 0; i < taosArrayGetSize(pRequest->dbList); i++) {
|
||||
char *db = taosArrayGet(pRequest->dbList, i);
|
||||
if (NULL == db) {
|
||||
tscError("get dbname failed, exceptDb:%s", exceptDb);
|
||||
return false;
|
||||
}
|
||||
char *dot = strchr(db, '.');
|
||||
if (dot != NULL) {
|
||||
db = dot + 1;
|
||||
|
@ -214,7 +262,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
"us, planCost:%" PRId64 "us, exec:%" PRId64 "us",
|
||||
duration, pRequest->metric.parseCostUs, pRequest->metric.ctgCostUs, pRequest->metric.analyseCostUs,
|
||||
pRequest->metric.planCostUs, pRequest->metric.execCostUs);
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||
(void)atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||
reqType = SLOW_LOG_TYPE_INSERT;
|
||||
} else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
|
||||
tscDebug("query duration %" PRId64 "us: parseCost:%" PRId64 "us, ctgCost:%" PRId64 "us, analyseCost:%" PRId64
|
||||
|
@ -222,11 +270,13 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
duration, pRequest->metric.parseCostUs, pRequest->metric.ctgCostUs, pRequest->metric.analyseCostUs,
|
||||
pRequest->metric.planCostUs, pRequest->metric.execCostUs);
|
||||
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration);
|
||||
(void)atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration);
|
||||
reqType = SLOW_LOG_TYPE_QUERY;
|
||||
}
|
||||
|
||||
nodesSimReleaseAllocator(pRequest->allocatorRefId);
|
||||
if (TSDB_CODE_SUCCESS != nodesSimReleaseAllocator(pRequest->allocatorRefId)) {
|
||||
tscError("failed to release allocator");
|
||||
}
|
||||
}
|
||||
|
||||
if(pTscObj->pAppInfo->monitorParas.tsEnableMonitor){
|
||||
|
@ -241,14 +291,16 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
|
||||
if ((duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThreshold * 1000000UL || duration >= pTscObj->pAppInfo->monitorParas.tsSlowLogThresholdTest * 1000000UL) &&
|
||||
checkSlowLogExceptDb(pRequest, pTscObj->pAppInfo->monitorParas.tsSlowLogExceptDb)) {
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
||||
(void)atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
||||
if (pTscObj->pAppInfo->monitorParas.tsSlowLogScope & reqType) {
|
||||
taosPrintSlowLog("PID:%d, Conn:%u, QID:0x%" PRIx64 ", Start:%" PRId64 " us, Duration:%" PRId64 "us, SQL:%s",
|
||||
taosGetPId(), pTscObj->connId, pRequest->requestId, pRequest->metric.start, duration,
|
||||
pRequest->sqlstr);
|
||||
if(pTscObj->pAppInfo->monitorParas.tsEnableMonitor){
|
||||
slowQueryLog(pTscObj->id, pRequest->killed, pRequest->code, duration);
|
||||
generateWriteSlowLog(pTscObj, pRequest, reqType, duration);
|
||||
if (TSDB_CODE_SUCCESS != generateWriteSlowLog(pTscObj, pRequest, reqType, duration)) {
|
||||
tscError("failed to generate write slow log");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -288,9 +340,9 @@ static bool clientRpcTfp(int32_t code, tmsg_t msgType) {
|
|||
}
|
||||
|
||||
// TODO refactor
|
||||
void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
||||
int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, void **pDnodeConn) {
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
(void)memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "TSC";
|
||||
rpcInit.numOfThreads = tsNumOfRpcThreads;
|
||||
|
@ -314,15 +366,19 @@ void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
|||
rpcInit.connLimitNum = connLimitNum;
|
||||
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
|
||||
|
||||
taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
|
||||
void *pDnodeConn = rpcOpen(&rpcInit);
|
||||
if (pDnodeConn == NULL) {
|
||||
tscError("failed to init connection to server");
|
||||
return NULL;
|
||||
int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("invalid version string.");
|
||||
return code;
|
||||
}
|
||||
|
||||
return pDnodeConn;
|
||||
*pDnodeConn = rpcOpen(&rpcInit);
|
||||
if (*pDnodeConn == NULL) {
|
||||
tscError("failed to init connection to server.");
|
||||
code = TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void destroyAllRequests(SHashObj *pRequests) {
|
||||
|
@ -333,7 +389,7 @@ void destroyAllRequests(SHashObj *pRequests) {
|
|||
SRequestObj *pRequest = acquireRequest(*rid);
|
||||
if (pRequest) {
|
||||
destroyRequest(pRequest);
|
||||
releaseRequest(*rid);
|
||||
(void)releaseRequest(*rid); // ignore error
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pRequests, pIter);
|
||||
|
@ -348,7 +404,7 @@ void stopAllRequests(SHashObj *pRequests) {
|
|||
SRequestObj *pRequest = acquireRequest(*rid);
|
||||
if (pRequest) {
|
||||
taos_stop_query(pRequest);
|
||||
releaseRequest(*rid);
|
||||
(void)releaseRequest(*rid); // ignore error
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pRequests, pIter);
|
||||
|
@ -359,18 +415,31 @@ void destroyAppInst(void *info) {
|
|||
SAppInstInfo* pAppInfo = *(SAppInstInfo**)info;
|
||||
tscDebug("destroy app inst mgr %p", pAppInfo);
|
||||
|
||||
taosThreadMutexLock(&appInfo.mutex);
|
||||
int32_t code = taosThreadMutexLock(&appInfo.mutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to lock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
hbRemoveAppHbMrg(&pAppInfo->pAppHbMgr);
|
||||
|
||||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
code = taosThreadMutexUnlock(&appInfo.mutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to unlock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pAppInfo->instKey);
|
||||
closeTransporter(pAppInfo);
|
||||
|
||||
taosThreadMutexLock(&pAppInfo->qnodeMutex);
|
||||
code = taosThreadMutexLock(&pAppInfo->qnodeMutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to lock qnode mutex, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
taosArrayDestroy(pAppInfo->pQnodeList);
|
||||
taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
|
||||
code = taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to unlock qnode mutex, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
|
||||
}
|
||||
|
||||
taosMemoryFree(pAppInfo);
|
||||
}
|
||||
|
@ -395,97 +464,111 @@ void destroyTscObj(void *pObj) {
|
|||
pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
// In any cases, we should not free app inst here. Or an race condition rises.
|
||||
/*int64_t connNum = */ atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
/*int64_t connNum = */ (void)atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
taosThreadMutexDestroy(&pTscObj->mutex);
|
||||
(void)taosThreadMutexDestroy(&pTscObj->mutex);
|
||||
taosMemoryFree(pTscObj);
|
||||
|
||||
tscTrace("end to destroy tscObj %" PRIx64 " p:%p", tscId, pTscObj);
|
||||
}
|
||||
|
||||
void *createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo) {
|
||||
STscObj *pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj));
|
||||
if (NULL == pObj) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo,
|
||||
STscObj **pObj) {
|
||||
*pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj));
|
||||
if (NULL == *pObj) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pObj->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pObj->pRequests) {
|
||||
taosMemoryFree(pObj);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
(*pObj)->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == (*pObj)->pRequests) {
|
||||
taosMemoryFree(*pObj);
|
||||
return terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pObj->connType = connType;
|
||||
pObj->pAppInfo = pAppInfo;
|
||||
pObj->appHbMgrIdx = pAppInfo->pAppHbMgr->idx;
|
||||
tstrncpy(pObj->user, user, sizeof(pObj->user));
|
||||
memcpy(pObj->pass, auth, TSDB_PASSWORD_LEN);
|
||||
(*pObj)->connType = connType;
|
||||
(*pObj)->pAppInfo = pAppInfo;
|
||||
(*pObj)->appHbMgrIdx = pAppInfo->pAppHbMgr->idx;
|
||||
tstrncpy((*pObj)->user, user, sizeof((*pObj)->user));
|
||||
(void)memcpy((*pObj)->pass, auth, TSDB_PASSWORD_LEN);
|
||||
|
||||
if (db != NULL) {
|
||||
tstrncpy(pObj->db, db, tListLen(pObj->db));
|
||||
tstrncpy((*pObj)->db, db, tListLen((*pObj)->db));
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
TSC_ERR_RET(taosThreadMutexInit(&(*pObj)->mutex, NULL));
|
||||
|
||||
atomic_add_fetch_64(&pObj->pAppInfo->numOfConns, 1);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64 ",p:%p", pObj->id, pObj);
|
||||
return pObj;
|
||||
(*pObj)->id = taosAddRef(clientConnRefPool, *pObj);
|
||||
if ((*pObj)->id < 0) {
|
||||
tscError("failed to add object to clientConnRefPool");
|
||||
code = terrno;
|
||||
taosMemoryFree(*pObj);
|
||||
return code;
|
||||
}
|
||||
|
||||
(void)atomic_add_fetch_64(&(*pObj)->pAppInfo->numOfConns, 1);
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64 ",p:%p", (*pObj)->id, *pObj);
|
||||
return code;
|
||||
}
|
||||
|
||||
STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientConnRefPool, rid); }
|
||||
|
||||
int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); }
|
||||
void releaseTscObj(int64_t rid) {
|
||||
int32_t code = taosReleaseRef(clientConnRefPool, rid);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscWarn("failed to release TscObj, code:%s", tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
void *createRequest(uint64_t connId, int32_t type, int64_t reqid) {
|
||||
SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
|
||||
if (NULL == pRequest) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj **pRequest) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
*pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
|
||||
if (NULL == *pRequest) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = acquireTscObj(connId);
|
||||
if (pTscObj == NULL) {
|
||||
taosMemoryFree(pRequest);
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return NULL;
|
||||
code = TSDB_CODE_TSC_DISCONNECTED;
|
||||
goto _return;
|
||||
}
|
||||
SSyncQueryParam *interParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
||||
if (interParam == NULL) {
|
||||
releaseTscObj(connId);
|
||||
doDestroyRequest(pRequest);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _return;
|
||||
}
|
||||
tsem_init(&interParam->sem, 0, 0);
|
||||
interParam->pRequest = pRequest;
|
||||
pRequest->body.interParam = interParam;
|
||||
TSC_ERR_JRET(tsem_init(&interParam->sem, 0, 0));
|
||||
interParam->pRequest = *pRequest;
|
||||
(*pRequest)->body.interParam = interParam;
|
||||
|
||||
pRequest->resType = RES_TYPE__QUERY;
|
||||
pRequest->requestId = reqid == 0 ? generateRequestId() : reqid;
|
||||
pRequest->metric.start = taosGetTimestampUs();
|
||||
(*pRequest)->resType = RES_TYPE__QUERY;
|
||||
(*pRequest)->requestId = reqid == 0 ? generateRequestId() : reqid;
|
||||
(*pRequest)->metric.start = taosGetTimestampUs();
|
||||
|
||||
pRequest->body.resInfo.convertUcs4 = true; // convert ucs4 by default
|
||||
pRequest->type = type;
|
||||
pRequest->allocatorRefId = -1;
|
||||
(*pRequest)->body.resInfo.convertUcs4 = true; // convert ucs4 by default
|
||||
(*pRequest)->type = type;
|
||||
(*pRequest)->allocatorRefId = -1;
|
||||
|
||||
pRequest->pDb = getDbOfConnection(pTscObj);
|
||||
pRequest->pTscObj = pTscObj;
|
||||
pRequest->inCallback = false;
|
||||
(*pRequest)->pDb = getDbOfConnection(pTscObj);
|
||||
(*pRequest)->pTscObj = pTscObj;
|
||||
(*pRequest)->inCallback = false;
|
||||
|
||||
pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
|
||||
tsem_init(&pRequest->body.rspSem, 0, 0);
|
||||
|
||||
if (registerRequest(pRequest, pTscObj)) {
|
||||
doDestroyRequest(pRequest);
|
||||
return NULL;
|
||||
(*pRequest)->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
if (NULL == (*pRequest)->msgBuf) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _return;
|
||||
}
|
||||
(*pRequest)->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
|
||||
TSC_ERR_JRET(tsem_init(&(*pRequest)->body.rspSem, 0, 0));
|
||||
TSC_ERR_JRET(registerRequest(*pRequest, pTscObj));
|
||||
|
||||
return pRequest;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_return:
|
||||
doDestroyRequest(*pRequest);
|
||||
return code;
|
||||
}
|
||||
|
||||
void doFreeReqResultInfo(SReqResultInfo *pResInfo) {
|
||||
|
@ -520,12 +603,12 @@ int64_t removeFromMostPrevReq(SRequestObj* pRequest) {
|
|||
pTmp = acquireRequest(pTmp->relation.prevRefId);
|
||||
if (pTmp) {
|
||||
mostPrevReqRefId = pTmp->self;
|
||||
releaseRequest(mostPrevReqRefId);
|
||||
(void)releaseRequest(mostPrevReqRefId); // ignore error
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
removeRequest(mostPrevReqRefId);
|
||||
(void)removeRequest(mostPrevReqRefId); // ignore error
|
||||
return mostPrevReqRefId;
|
||||
}
|
||||
|
||||
|
@ -533,8 +616,8 @@ void destroyNextReq(int64_t nextRefId) {
|
|||
if (nextRefId) {
|
||||
SRequestObj* pObj = acquireRequest(nextRefId);
|
||||
if (pObj) {
|
||||
releaseRequest(nextRefId);
|
||||
releaseRequest(nextRefId);
|
||||
(void)releaseRequest(nextRefId); // ignore error
|
||||
(void)releaseRequest(nextRefId); // ignore error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -554,7 +637,7 @@ void destroySubRequests(SRequestObj *pRequest) {
|
|||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
pReqList[++reqIdx] = pTmp;
|
||||
releaseRequest(tmpRefId);
|
||||
(void)releaseRequest(tmpRefId); // ignore error
|
||||
} else {
|
||||
tscError("prev req ref 0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
|
@ -562,7 +645,7 @@ void destroySubRequests(SRequestObj *pRequest) {
|
|||
}
|
||||
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
removeRequest(pReqList[i]->self);
|
||||
(void)removeRequest(pReqList[i]->self); // ignore error
|
||||
}
|
||||
|
||||
tmpRefId = pRequest->relation.nextRefId;
|
||||
|
@ -570,8 +653,8 @@ void destroySubRequests(SRequestObj *pRequest) {
|
|||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
removeRequest(pTmp->self);
|
||||
releaseRequest(pTmp->self);
|
||||
(void)removeRequest(pTmp->self); // ignore error
|
||||
(void)releaseRequest(pTmp->self); // ignore error
|
||||
} else {
|
||||
tscError("next req ref 0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
|
@ -591,8 +674,10 @@ void doDestroyRequest(void *p) {
|
|||
|
||||
int64_t nextReqRefId = pRequest->relation.nextRefId;
|
||||
|
||||
taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||
|
||||
int32_t code = taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("failed to remove request from hash, code:%s", tstrerror(code));
|
||||
}
|
||||
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||
|
||||
destorySqlCallbackWrapper(pRequest->pWrapper);
|
||||
|
@ -600,7 +685,7 @@ void doDestroyRequest(void *p) {
|
|||
taosMemoryFreeClear(pRequest->msgBuf);
|
||||
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
tsem_destroy(&pRequest->body.rspSem);
|
||||
(void)tsem_destroy(&pRequest->body.rspSem);
|
||||
|
||||
taosArrayDestroy(pRequest->tableList);
|
||||
taosArrayDestroy(pRequest->targetTableList);
|
||||
|
@ -614,13 +699,15 @@ void doDestroyRequest(void *p) {
|
|||
taosMemoryFreeClear(pRequest->pDb);
|
||||
taosArrayDestroy(pRequest->dbList);
|
||||
if (pRequest->body.interParam) {
|
||||
tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem);
|
||||
(void)tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem);
|
||||
}
|
||||
taosMemoryFree(pRequest->body.interParam);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == nodesSimAcquireAllocator(pRequest->allocatorRefId)) {
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
nodesSimReleaseAllocator(pRequest->allocatorRefId);
|
||||
if (TSDB_CODE_SUCCESS != nodesSimReleaseAllocator(pRequest->allocatorRefId)) {
|
||||
tscError("failed to release allocator");
|
||||
}
|
||||
}
|
||||
nodesDestroyAllocator(pRequest->allocatorRefId);
|
||||
|
||||
|
@ -637,7 +724,7 @@ void destroyRequest(SRequestObj *pRequest) {
|
|||
}
|
||||
|
||||
taos_stop_query(pRequest);
|
||||
removeFromMostPrevReq(pRequest);
|
||||
(void)removeFromMostPrevReq(pRequest);
|
||||
}
|
||||
|
||||
void taosStopQueryImpl(SRequestObj *pRequest) {
|
||||
|
@ -676,7 +763,7 @@ void stopAllQueries(SRequestObj *pRequest) {
|
|||
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
taosStopQueryImpl(pReqList[i]);
|
||||
releaseRequest(pReqList[i]->self);
|
||||
(void)releaseRequest(pReqList[i]->self); // ignore error
|
||||
}
|
||||
|
||||
taosStopQueryImpl(pRequest);
|
||||
|
@ -687,7 +774,7 @@ void stopAllQueries(SRequestObj *pRequest) {
|
|||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
taosStopQueryImpl(pTmp);
|
||||
releaseRequest(pTmp->self);
|
||||
(void)releaseRequest(pTmp->self); // ignore error
|
||||
} else {
|
||||
tscError("next req ref 0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
|
@ -700,7 +787,7 @@ void crashReportThreadFuncUnexpectedStopped(void) { atomic_store_32(&clientStop,
|
|||
static void *tscCrashReportThreadFp(void *param) {
|
||||
setThreadName("client-crashReport");
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.taosCrashLog", tsLogDir, TD_DIRSEP);
|
||||
(void)snprintf(filepath, sizeof(filepath), "%s%s.taosCrashLog", tsLogDir, TD_DIRSEP);
|
||||
char *pMsg = NULL;
|
||||
int64_t msgLen = 0;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -769,20 +856,27 @@ static void *tscCrashReportThreadFp(void *param) {
|
|||
|
||||
int32_t tscCrashReportInit() {
|
||||
if (!tsEnableCrashReport) {
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
TSC_ERR_JRET(taosThreadAttrInit(&thAttr));
|
||||
TSC_ERR_JRET(taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE));
|
||||
TdThread crashReportThread;
|
||||
if (taosThreadCreate(&crashReportThread, &thAttr, tscCrashReportThreadFp, NULL) != 0) {
|
||||
tscError("failed to create crashReport thread since %s", strerror(errno));
|
||||
return -1;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
TSC_ERR_RET(errno);
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
return 0;
|
||||
(void)taosThreadAttrDestroy(&thAttr);
|
||||
_return:
|
||||
if (code) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
TSC_ERR_RET(terrno);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tscStopCrashReport() {
|
||||
|
@ -841,6 +935,11 @@ void taos_init_imp(void) {
|
|||
appInfo.startTime = taosGetTimestampMs();
|
||||
appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
appInfo.pInstMapByClusterId = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == appInfo.pInstMap || NULL == appInfo.pInstMapByClusterId) {
|
||||
tscError("failed to allocate memory when init appInfo");
|
||||
tscInitRes = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return;
|
||||
}
|
||||
taosHashSetFreeFp(appInfo.pInstMap, destroyAppInst);
|
||||
deltaToUtcInitOnce();
|
||||
|
||||
|
@ -848,7 +947,7 @@ void taos_init_imp(void) {
|
|||
#ifdef CUS_PROMPT
|
||||
snprintf(logDirName, 64, "%slog", CUS_PROMPT);
|
||||
#else
|
||||
snprintf(logDirName, 64, "taoslog");
|
||||
(void)snprintf(logDirName, 64, "taoslog");
|
||||
#endif
|
||||
if (taosCreateLog(logDirName, 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
printf(" WARING: Create %s failed:%s. configDir=%s\n", logDirName, strerror(errno), configDir);
|
||||
|
@ -856,46 +955,40 @@ void taos_init_imp(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
ENV_ERR_RET(taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1), "failed to init cfg");
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
ENV_ERR_RET(taosConvInit(), "failed to init conv");
|
||||
ENV_ERR_RET(monitorInit(), "failed to init monitor");
|
||||
ENV_ERR_RET(rpcInit(), "failed to init rpc");
|
||||
|
||||
if (taosConvInit() != 0) {
|
||||
if (InitRegexCache() != 0) {
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init conv");
|
||||
tscError("failed to init regex cache");
|
||||
return;
|
||||
}
|
||||
if (monitorInit() != 0){
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init monitor");
|
||||
return;
|
||||
}
|
||||
rpcInit();
|
||||
|
||||
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
||||
catalogInit(&cfg);
|
||||
ENV_ERR_RET(catalogInit(&cfg), "failed to init catalog");
|
||||
ENV_ERR_RET(schedulerInit(), "failed to init scheduler");
|
||||
|
||||
schedulerInit();
|
||||
tscDebug("starting to initialize TAOS driver");
|
||||
|
||||
#ifndef WINDOWS
|
||||
taosSetCoreDump(true);
|
||||
#endif
|
||||
|
||||
initTaskQueue();
|
||||
fmFuncMgtInit();
|
||||
nodesInitAllocatorSet();
|
||||
ENV_ERR_RET(initTaskQueue(), "failed to init task queue");
|
||||
ENV_ERR_RET(fmFuncMgtInit(), "failed to init funcMgt");
|
||||
ENV_ERR_RET(nodesInitAllocatorSet(), "failed to init allocator set");
|
||||
|
||||
clientConnRefPool = taosOpenRef(200, destroyTscObj);
|
||||
clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
|
||||
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
taosThreadMutexInit(&appInfo.mutex, NULL);
|
||||
|
||||
tscCrashReportInit();
|
||||
ENV_ERR_RET(taosGetAppName(appInfo.appName, NULL), "failed to get app name");
|
||||
ENV_ERR_RET(taosThreadMutexInit(&appInfo.mutex, NULL), "failed to init thread mutex");
|
||||
ENV_ERR_RET(tscCrashReportInit(), "failed to init crash report");
|
||||
ENV_ERR_RET(qInitKeywordsTable(), "failed to init parser keywords table");
|
||||
|
||||
tscDebug("client is initialized successfully");
|
||||
}
|
||||
|
@ -942,7 +1035,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
return -1;
|
||||
}
|
||||
newstr[0] = '"';
|
||||
memcpy(newstr+1, str, len);
|
||||
(void)memcpy(newstr+1, str, len);
|
||||
newstr[len + 1] = '"';
|
||||
newstr[len + 2] = '\0';
|
||||
str = newstr;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -73,7 +73,7 @@ void jniGetGlobalMethod(JNIEnv *env) {
|
|||
}
|
||||
|
||||
if (g_vm == NULL) {
|
||||
(*env)->GetJavaVM(env, &g_vm);
|
||||
(void)(*env)->GetJavaVM(env, &g_vm);
|
||||
}
|
||||
|
||||
jclass arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
|
||||
|
@ -582,20 +582,20 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
|
|||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
case TSDB_DATA_TYPE_GEOMETRY: {
|
||||
memcpy(tmp, row[i], length[i]); // handle the case that terminated does not exist
|
||||
(void)memcpy(tmp, row[i], length[i]); // handle the case that terminated does not exist
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetStringFp, i, (*env)->NewStringUTF(env, tmp));
|
||||
|
||||
memset(tmp, 0, length[i]);
|
||||
(void)memset(tmp, 0, length[i]);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteArrayFp, i,
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_JSON: {
|
||||
(*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteArrayFp, i,
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
jniFromNCharToByteArray(env, (char *)row[i], length[i]));
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
|
@ -680,6 +680,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab
|
|||
jsize len = (*env)->GetArrayLength(env, jsql);
|
||||
|
||||
char *str = (char *)taosMemoryCalloc(1, sizeof(char) * (len + 1));
|
||||
if (str == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, jsql, 0, len, (jbyte *)str);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// todo handle error
|
||||
|
@ -843,6 +847,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
|
||||
jsize len = (*env)->GetArrayLength(env, tags);
|
||||
char *tagsData = (char *)taosMemoryCalloc(1, len);
|
||||
if (tagsData == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, tags, 0, len, (jbyte *)tagsData);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// todo handle error
|
||||
|
@ -850,18 +858,30 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
|
||||
len = (*env)->GetArrayLength(env, lengthList);
|
||||
int32_t *lengthArray = (int32_t *)taosMemoryCalloc(1, len);
|
||||
if (lengthArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, lengthList, 0, len, (jbyte *)lengthArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
len = (*env)->GetArrayLength(env, typeList);
|
||||
char *typeArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (typeArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, typeList, 0, len, (jbyte *)typeArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
len = (*env)->GetArrayLength(env, nullList);
|
||||
char *nullArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (nullArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, nullList, 0, len, (jbyte *)nullArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
@ -870,6 +890,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
char *curTags = tagsData;
|
||||
|
||||
TAOS_MULTI_BIND *tagsBind = taosMemoryCalloc(numOfTags, sizeof(TAOS_MULTI_BIND));
|
||||
if (tagsBind == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tsconn);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
tagsBind[i].buffer_type = typeArray[i];
|
||||
tagsBind[i].buffer = curTags;
|
||||
|
@ -916,6 +940,10 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp(
|
|||
// todo refactor
|
||||
jsize len = (*env)->GetArrayLength(env, colDataList);
|
||||
char *colBuf = (char *)taosMemoryCalloc(1, len);
|
||||
if (colBuf == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, colDataList, 0, len, (jbyte *)colBuf);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// todo handle error
|
||||
|
@ -923,18 +951,30 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp(
|
|||
|
||||
len = (*env)->GetArrayLength(env, lengthList);
|
||||
char *lengthArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (lengthArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, lengthList, 0, len, (jbyte *)lengthArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
len = (*env)->GetArrayLength(env, nullList);
|
||||
char *nullArray = (char *)taosMemoryCalloc(1, len);
|
||||
if (nullArray == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, nullList, 0, len, (jbyte *)nullArray);
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
}
|
||||
|
||||
// bind multi-rows with only one invoke.
|
||||
TAOS_MULTI_BIND *b = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND));
|
||||
if (b == NULL) {
|
||||
jniError("jobj:%p, conn:%p, alloc memory failed", jobj, tscon);
|
||||
return JNI_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
b->num = numOfRows;
|
||||
b->buffer_type = dataType; // todo check data type
|
||||
|
@ -1043,14 +1083,14 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_stmtErrorMsgIm
|
|||
TAOS *tscon = (TAOS *)con;
|
||||
if (tscon == NULL) {
|
||||
jniError("jobj:%p, connection already closed", jobj);
|
||||
sprintf(errMsg, "jobj:%p, connection already closed", jobj);
|
||||
(void)sprintf(errMsg, "jobj:%p, connection already closed", jobj);
|
||||
return (*env)->NewStringUTF(env, errMsg);
|
||||
}
|
||||
|
||||
TAOS_STMT *pStmt = (TAOS_STMT *)stmt;
|
||||
if (pStmt == NULL) {
|
||||
jniError("jobj:%p, conn:%p, invalid stmt", jobj, tscon);
|
||||
sprintf(errMsg, "jobj:%p, conn:%p, invalid stmt", jobj, tscon);
|
||||
(void)sprintf(errMsg, "jobj:%p, conn:%p, invalid stmt", jobj, tscon);
|
||||
return (*env)->NewStringUTF(env, errMsg);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "version.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
@ -68,16 +69,23 @@ void taos_cleanup(void) {
|
|||
qCleanupKeywordsTable();
|
||||
nodesDestroyAllocatorSet();
|
||||
|
||||
cleanupTaskQueue();
|
||||
if (TSDB_CODE_SUCCESS != cleanupTaskQueue()) {
|
||||
tscWarn("failed to cleanup task queue");
|
||||
}
|
||||
|
||||
int32_t id = clientReqRefPool;
|
||||
clientReqRefPool = -1;
|
||||
taosCloseRef(id);
|
||||
if (TSDB_CODE_SUCCESS != taosCloseRef(id)) {
|
||||
tscWarn("failed to close clientReqRefPool");
|
||||
}
|
||||
|
||||
id = clientConnRefPool;
|
||||
clientConnRefPool = -1;
|
||||
taosCloseRef(id);
|
||||
if (TSDB_CODE_SUCCESS != taosCloseRef(id)) {
|
||||
tscWarn("failed to close clientReqRefPool");
|
||||
}
|
||||
|
||||
DestroyRegexCache();
|
||||
rpcCleanup();
|
||||
tscDebug("rpc cleanup");
|
||||
|
||||
|
@ -113,11 +121,19 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
|||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
STscObj *pObj = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY);
|
||||
if (pObj) {
|
||||
STscObj *pObj = NULL;
|
||||
int32_t code = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY, &pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t));
|
||||
if (NULL == rid) {
|
||||
tscError("out of memory when taos connect to %s:%u, user:%s db:%s", ip, port, user, db);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
*rid = pObj->id;
|
||||
return (TAOS *)rid;
|
||||
} else {
|
||||
terrno = code;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -138,24 +154,24 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)
|
|||
|
||||
switch (type) {
|
||||
case TAOS_NOTIFY_PASSVER: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexLock(&pObj->mutex));
|
||||
pObj->passInfo.fp = fp;
|
||||
pObj->passInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexUnlock(&pObj->mutex));
|
||||
break;
|
||||
}
|
||||
case TAOS_NOTIFY_WHITELIST_VER: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexLock(&pObj->mutex));
|
||||
pObj->whiteListInfo.fp = fp;
|
||||
pObj->whiteListInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexUnlock(&pObj->mutex));
|
||||
break;
|
||||
}
|
||||
case TAOS_NOTIFY_USER_DROPPED: {
|
||||
taosThreadMutexLock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexLock(&pObj->mutex));
|
||||
pObj->userDroppedInfo.fp = fp;
|
||||
pObj->userDroppedInfo.param = param;
|
||||
taosThreadMutexUnlock(&pObj->mutex);
|
||||
TSC_ERR_RET(taosThreadMutexUnlock(&pObj->mutex));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -187,7 +203,13 @@ int32_t fetchWhiteListCallbackFn(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
SGetUserWhiteListRsp wlRsp;
|
||||
tDeserializeSGetUserWhiteListRsp(pMsg->pData, pMsg->len, &wlRsp);
|
||||
if (TSDB_CODE_SUCCESS != tDeserializeSGetUserWhiteListRsp(pMsg->pData, pMsg->len, &wlRsp)) {
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
taosMemoryFree(pInfo);
|
||||
tFreeSGetUserWhiteListRsp(&wlRsp);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
uint64_t* pWhiteLists = taosMemoryMalloc(wlRsp.numWhiteLists * sizeof(uint64_t));
|
||||
if (pWhiteLists == NULL) {
|
||||
|
@ -227,8 +249,14 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa
|
|||
}
|
||||
|
||||
SGetUserWhiteListReq req;
|
||||
memcpy(req.user, pTsc->user, TSDB_USER_LEN);
|
||||
(void)memcpy(req.user, pTsc->user, TSDB_USER_LEN);
|
||||
int32_t msgLen = tSerializeSGetUserWhiteListReq(NULL, 0, &req);
|
||||
if (msgLen < 0) {
|
||||
fp(param, TSDB_CODE_INVALID_PARA, taos, 0, NULL);
|
||||
releaseTscObj(connId);
|
||||
return;
|
||||
}
|
||||
|
||||
void* pReq = taosMemoryMalloc(msgLen);
|
||||
if (pReq == NULL) {
|
||||
fp(param, TSDB_CODE_OUT_OF_MEMORY, taos, 0, NULL);
|
||||
|
@ -272,7 +300,9 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa
|
|||
|
||||
int64_t transportId = 0;
|
||||
SEpSet epSet = getEpSet_s(&pTsc->pAppInfo->mgmtEp);
|
||||
asyncSendMsgToServer(pTsc->pAppInfo->pTransporter, &epSet, &transportId, pSendInfo);
|
||||
if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pTsc->pAppInfo->pTransporter, &epSet, &transportId, pSendInfo)) {
|
||||
tscWarn("failed to async send msg to server");
|
||||
}
|
||||
releaseTscObj(connId);
|
||||
return;
|
||||
}
|
||||
|
@ -285,7 +315,7 @@ void taos_close_internal(void *taos) {
|
|||
STscObj *pTscObj = (STscObj *)taos;
|
||||
tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
|
||||
|
||||
taosRemoveRef(clientConnRefPool, pTscObj->id);
|
||||
(void)taosRemoveRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
void taos_close(TAOS *taos) {
|
||||
|
@ -424,9 +454,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);
|
||||
}
|
||||
|
@ -436,8 +468,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;
|
||||
}
|
||||
|
||||
|
@ -450,6 +481,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
} else {
|
||||
// assert to avoid un-initialization error
|
||||
tscError("invalid result passed to taos_fetch_row");
|
||||
terrno = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -518,7 +550,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
if(taosAscii2Hex(row[i], charLen, &data, &size) < 0){
|
||||
break;
|
||||
}
|
||||
memcpy(str + len, data, size);
|
||||
(void)memcpy(str + len, data, size);
|
||||
len += size;
|
||||
taosMemoryFree(data);
|
||||
}break;
|
||||
|
@ -536,7 +568,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
}
|
||||
}
|
||||
|
||||
memcpy(str + len, row[i], charLen);
|
||||
(void)memcpy(str + len, row[i], charLen);
|
||||
len += charLen;
|
||||
} break;
|
||||
|
||||
|
@ -683,7 +715,7 @@ int taos_select_db(TAOS *taos, const char *db) {
|
|||
}
|
||||
|
||||
char sql[256] = {0};
|
||||
snprintf(sql, tListLen(sql), "use %s", db);
|
||||
(void)snprintf(sql, tListLen(sql), "use %s", db);
|
||||
|
||||
TAOS_RES *pRequest = taos_query(taos, sql);
|
||||
int32_t code = taos_errno(pRequest);
|
||||
|
@ -739,10 +771,10 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
doAsyncFetchRows(pRequest, false, true);
|
||||
(void)doAsyncFetchRows(pRequest, false, true);
|
||||
|
||||
// TODO refactor
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -752,8 +784,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;
|
||||
|
@ -774,8 +807,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;
|
||||
}
|
||||
|
@ -790,10 +824,10 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
doAsyncFetchRows(pRequest, false, false);
|
||||
(void)doAsyncFetchRows(pRequest, false, false);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
|
@ -801,7 +835,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||
|
@ -859,26 +893,24 @@ const char *taos_get_server_info(TAOS *taos) {
|
|||
int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
|
||||
STscObj *pTscObj = acquireTscObj(*(int64_t *)taos);
|
||||
if (pTscObj == NULL) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_DISCONNECTED;
|
||||
}
|
||||
|
||||
int code = TSDB_CODE_SUCCESS;
|
||||
taosThreadMutexLock(&pTscObj->mutex);
|
||||
(void)taosThreadMutexLock(&pTscObj->mutex);
|
||||
if (database == NULL || len <= 0) {
|
||||
if (required != NULL) *required = strlen(pTscObj->db) + 1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = -1;
|
||||
TSC_ERR_JRET(TSDB_CODE_INVALID_PARA);
|
||||
} else if (len < strlen(pTscObj->db) + 1) {
|
||||
tstrncpy(database, pTscObj->db, len);
|
||||
if (required) *required = strlen(pTscObj->db) + 1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = -1;
|
||||
TSC_ERR_JRET(TSDB_CODE_INVALID_PARA);
|
||||
} else {
|
||||
strcpy(database, pTscObj->db);
|
||||
(void)strcpy(database, pTscObj->db);
|
||||
code = 0;
|
||||
}
|
||||
taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
_return:
|
||||
(void)taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
return code;
|
||||
}
|
||||
|
@ -919,8 +951,8 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t
|
|||
pRequest->metric.analyseCostUs += taosGetTimestampUs() - analyseStart;
|
||||
|
||||
if (pRequest->parseOnly) {
|
||||
memcpy(&pRequest->parseMeta, pResultMeta, sizeof(*pResultMeta));
|
||||
memset(pResultMeta, 0, sizeof(*pResultMeta));
|
||||
(void)memcpy(&pRequest->parseMeta, pResultMeta, sizeof(*pResultMeta));
|
||||
(void)memset(pResultMeta, 0, sizeof(*pResultMeta));
|
||||
}
|
||||
|
||||
handleQueryAnslyseRes(pWrapper, pResultMeta, code);
|
||||
|
@ -967,10 +999,9 @@ void handleSubQueryFromAnalyse(SSqlCallbackWrapper *pWrapper, SMetaData *pResult
|
|||
return;
|
||||
}
|
||||
|
||||
pNewRequest->pQuery = (SQuery *)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pNewRequest->pQuery) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pNewRequest->pQuery = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pNewRequest->pQuery);
|
||||
if (pNewRequest->pQuery) {
|
||||
pNewRequest->pQuery->pRoot = pRoot;
|
||||
pRoot = NULL;
|
||||
pNewRequest->pQuery->execStage = QUERY_EXEC_STAGE_ANALYSE;
|
||||
|
@ -1008,10 +1039,12 @@ void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta
|
|||
}
|
||||
|
||||
if (pQuery->haveResultSet) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols);
|
||||
code = setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, pQuery->precision);
|
||||
}
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
TSWAP(pRequest->dbList, (pQuery)->pDbList);
|
||||
TSWAP(pRequest->tableList, (pQuery)->pTableList);
|
||||
TSWAP(pRequest->targetTableList, (pQuery)->pTargetTableList);
|
||||
|
@ -1196,7 +1229,7 @@ int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *p
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pWrapper->pCatalogReq->forceUpdate = updateMetaForce;
|
||||
pWrapper->pCatalogReq->qNodeRequired = qnodeRequired(pRequest);
|
||||
TSC_ERR_RET(qnodeRequired(pRequest, &pWrapper->pCatalogReq->qNodeRequired));
|
||||
code = qParseSqlSyntax(pWrapper->pParseCtx, &pRequest->pQuery, pWrapper->pCatalogReq);
|
||||
}
|
||||
|
||||
|
@ -1239,7 +1272,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
if (NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId);
|
||||
refreshMeta(pRequest->pTscObj, pRequest);
|
||||
(void)refreshMeta(pRequest->pTscObj, pRequest); //ignore return code,try again
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
|
@ -1254,13 +1287,13 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
void restartAsyncQuery(SRequestObj *pRequest, int32_t code) {
|
||||
tscInfo("restart request: %s p: %p", pRequest->sqlstr, pRequest);
|
||||
SRequestObj* pUserReq = pRequest;
|
||||
acquireRequest(pRequest->self);
|
||||
(void)acquireRequest(pRequest->self);
|
||||
while (pUserReq) {
|
||||
if (pUserReq->self == pUserReq->relation.userRefId || pUserReq->relation.userRefId == 0) {
|
||||
break;
|
||||
} else {
|
||||
int64_t nextRefId = pUserReq->relation.nextRefId;
|
||||
releaseRequest(pUserReq->self);
|
||||
(void)releaseRequest(pUserReq->self);
|
||||
if (nextRefId) {
|
||||
pUserReq = acquireRequest(nextRefId);
|
||||
}
|
||||
|
@ -1270,16 +1303,16 @@ void restartAsyncQuery(SRequestObj *pRequest, int32_t code) {
|
|||
if (pUserReq) {
|
||||
destroyCtxInRequest(pUserReq);
|
||||
pUserReq->prevCode = code;
|
||||
memset(&pUserReq->relation, 0, sizeof(pUserReq->relation));
|
||||
(void)memset(&pUserReq->relation, 0, sizeof(pUserReq->relation));
|
||||
} else {
|
||||
tscError("User req is missing");
|
||||
removeFromMostPrevReq(pRequest);
|
||||
(void)removeFromMostPrevReq(pRequest);
|
||||
return;
|
||||
}
|
||||
if (hasSubRequest)
|
||||
removeFromMostPrevReq(pRequest);
|
||||
(void)removeFromMostPrevReq(pRequest);
|
||||
else
|
||||
releaseRequest(pUserReq->self);
|
||||
(void)releaseRequest(pUserReq->self);
|
||||
doAsyncQuery(pUserReq, true);
|
||||
}
|
||||
|
||||
|
@ -1369,7 +1402,7 @@ int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInf
|
|||
conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
snprintf(dbFName, sizeof(dbFName), "%d.%s", pTscObj->acctId, db);
|
||||
(void)snprintf(dbFName, sizeof(dbFName), "%d.%s", pTscObj->acctId, db);
|
||||
|
||||
code = catalogGetDBVgInfo(pCtg, &conn, dbFName, dbInfo);
|
||||
if (code) {
|
||||
|
@ -1419,7 +1452,7 @@ int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId
|
|||
conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
SName tableName;
|
||||
toName(pTscObj->acctId, db, table, &tableName);
|
||||
(void)toName(pTscObj->acctId, db, table, &tableName);
|
||||
|
||||
SVgroupInfo vgInfo;
|
||||
code = catalogGetTableHashVgroup(pCtg, &conn, &tableName, &vgInfo);
|
||||
|
@ -1540,7 +1573,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
}
|
||||
|
||||
SSyncQueryParam *pParam = pRequest->body.interParam;
|
||||
tsem_wait(&pParam->sem);
|
||||
(void)tsem_wait(&pParam->sem);
|
||||
|
||||
_return:
|
||||
destoryCatalogReq(&catalogReq);
|
||||
|
@ -1557,7 +1590,9 @@ TAOS_STMT *taos_stmt_init(TAOS *taos) {
|
|||
}
|
||||
|
||||
TAOS_STMT *pStmt = stmtInit(pObj, 0, NULL);
|
||||
|
||||
if (NULL == pStmt) {
|
||||
tscError("stmt init failed, errcode:%s", terrstr());
|
||||
}
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
||||
return pStmt;
|
||||
|
@ -1572,7 +1607,9 @@ TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid) {
|
|||
}
|
||||
|
||||
TAOS_STMT *pStmt = stmtInit(pObj, reqid, NULL);
|
||||
|
||||
if (NULL == pStmt) {
|
||||
tscError("stmt init failed, errcode:%s", terrstr());
|
||||
}
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
||||
return pStmt;
|
||||
|
@ -1587,7 +1624,9 @@ TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS *options) {
|
|||
}
|
||||
|
||||
TAOS_STMT *pStmt = stmtInit(pObj, options->reqId, options);
|
||||
|
||||
if (NULL == pStmt) {
|
||||
tscError("stmt init failed, errcode:%s", terrstr());
|
||||
}
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
|
||||
return pStmt;
|
||||
|
@ -1702,7 +1741,11 @@ int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
|||
}
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
int32_t code = stmtIsInsert(stmt, &insert);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("stmt insert failed, errcode:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
if (0 == insert && bind->num > 1) {
|
||||
tscError("only one row data allowed for query");
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -1726,7 +1769,11 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, in
|
|||
}
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
int32_t code = stmtIsInsert(stmt, &insert);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("stmt insert failed, errcode:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
if (0 == insert && bind->num > 1) {
|
||||
tscError("only one row data allowed for query");
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
|
|
@ -801,9 +801,8 @@ int32_t monitorInit() {
|
|||
}
|
||||
|
||||
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (tsem2_init(&monitorSem, 0, 0) != 0) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -197,8 +197,8 @@ static void smlDestroySTableMeta(void *para) {
|
|||
SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
|
||||
taosHashCleanup(meta->tagHash);
|
||||
taosHashCleanup(meta->colHash);
|
||||
(void)taosArrayDestroy(meta->tags);
|
||||
(void)taosArrayDestroy(meta->cols);
|
||||
taosArrayDestroy(meta->tags);
|
||||
taosArrayDestroy(meta->cols);
|
||||
taosMemoryFreeClear(meta->tableMeta);
|
||||
taosMemoryFree(meta);
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ int32_t smlSetCTableName(SSmlTableInfo *oneTable) {
|
|||
if (code != TSDB_CODE_SUCCESS){
|
||||
return code;
|
||||
}
|
||||
(void)taosArrayDestroy(dst);
|
||||
taosArrayDestroy(dst);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1198,25 +1198,25 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
SArray *pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
|
||||
if (pTags == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pColumns);
|
||||
goto end;
|
||||
}
|
||||
code = smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlBuildFieldsList tag1 failed. %s", info->id, pName.tname);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
code = smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlBuildFieldsList col1 failed. %s", info->id, pName.tname);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
code = smlSendMetaMsg(info, &pName, pColumns, pTags, NULL, SCHEMA_ACTION_CREATE_STABLE);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pColumns);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, pName.tname);
|
||||
goto end;
|
||||
|
@ -1271,7 +1271,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
SArray *pTags =
|
||||
taosArrayInit(taosArrayGetSize(sTableData->tags) + pTableMeta->tableInfo.numOfTags, sizeof(SField));
|
||||
if (pTags == NULL){
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pColumns);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
@ -1282,15 +1282,15 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
tstrncpy(field.name, pTableMeta->schema[i].name, sizeof(field.name));
|
||||
if (i < pTableMeta->tableInfo.numOfColumns) {
|
||||
if (taosArrayPush(pColumns, &field) == NULL){
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (taosArrayPush(pTags, &field) == NULL){
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
@ -1300,28 +1300,28 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
pTableMeta->tableInfo.numOfColumns, true);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlBuildFieldsList tag2 failed. %s", info->id, pName.tname);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pTags) + pTableMeta->tableInfo.numOfColumns > TSDB_MAX_COLUMNS) {
|
||||
uError("SML:0x%" PRIx64 " too many columns than 4096", info->id);
|
||||
code = TSDB_CODE_PAR_TOO_MANY_COLUMNS;
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
if (taosArrayGetSize(pTags) > TSDB_MAX_TAGS) {
|
||||
uError("SML:0x%" PRIx64 " too many tags than 128", info->id);
|
||||
code = TSDB_CODE_PAR_INVALID_TAGS_NUM;
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
|
||||
code = smlSendMetaMsg(info, &pName, pColumns, pTags, pTableMeta, action);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pColumns);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, pName.tname);
|
||||
goto end;
|
||||
|
@ -1367,7 +1367,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
SArray *pTags =
|
||||
taosArrayInit(taosArrayGetSize(sTableData->tags) + pTableMeta->tableInfo.numOfTags, sizeof(SField));
|
||||
if (pTags == NULL){
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pColumns);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
@ -1378,15 +1378,15 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
tstrncpy(field.name, pTableMeta->schema[i].name, sizeof(field.name));
|
||||
if (i < pTableMeta->tableInfo.numOfColumns) {
|
||||
if (taosArrayPush(pColumns, &field) == NULL){
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (taosArrayPush(pTags, &field) == NULL){
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
@ -1397,21 +1397,21 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
|
|||
pTableMeta->tableInfo.numOfColumns, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlBuildFieldsList col2 failed. %s", info->id, pName.tname);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pColumns) + pTableMeta->tableInfo.numOfTags > TSDB_MAX_COLUMNS) {
|
||||
uError("SML:0x%" PRIx64 " too many columns than 4096", info->id);
|
||||
code = TSDB_CODE_PAR_TOO_MANY_COLUMNS;
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
(void)taosArrayDestroy(pTags);
|
||||
taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pTags);
|
||||
goto end;
|
||||
}
|
||||
|
||||
code = smlSendMetaMsg(info, &pName, pColumns, pTags, pTableMeta, action);
|
||||
(void)taosArrayDestroy(pColumns);
|
||||
taosArrayDestroy(pColumns);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, pName.tname);
|
||||
goto end;
|
||||
|
@ -1555,7 +1555,7 @@ void smlDestroyTableInfo(void *para) {
|
|||
taosHashCleanup(kvHash);
|
||||
}
|
||||
|
||||
(void)taosArrayDestroy(tag->cols);
|
||||
taosArrayDestroy(tag->cols);
|
||||
taosArrayDestroyEx(tag->tags, freeSSmlKv);
|
||||
taosMemoryFree(tag);
|
||||
}
|
||||
|
@ -1581,13 +1581,13 @@ void smlDestroyInfo(SSmlHandle *info) {
|
|||
cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
|
||||
cJSON_Delete(tags);
|
||||
}
|
||||
(void)taosArrayDestroy(info->tagJsonArray);
|
||||
taosArrayDestroy(info->tagJsonArray);
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
|
||||
cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
|
||||
cJSON_Delete(value);
|
||||
}
|
||||
(void)taosArrayDestroy(info->valueJsonArray);
|
||||
taosArrayDestroy(info->valueJsonArray);
|
||||
|
||||
taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
|
||||
|
||||
|
@ -2137,8 +2137,8 @@ TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine,
|
|||
SSmlHandle *info = NULL;
|
||||
int cnt = 0;
|
||||
while (1) {
|
||||
request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, reqid);
|
||||
if (request == NULL) {
|
||||
code = createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, reqid, &request);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
uError("SML:taos_schemaless_insert error request is null");
|
||||
return NULL;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,11 +23,11 @@ TARGET_LINK_LIBRARIES(
|
|||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom geometry
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
clientMonitorTest
|
||||
PUBLIC os util common transport monitor parser catalog scheduler function gtest taos_static qcom executor
|
||||
)
|
||||
#ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp)
|
||||
#TARGET_LINK_LIBRARIES(
|
||||
# clientMonitorTest
|
||||
# PUBLIC os util common transport monitor parser catalog scheduler function gtest taos_static qcom executor
|
||||
#)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
clientTest
|
||||
|
@ -47,11 +47,11 @@ TARGET_INCLUDE_DIRECTORIES(
|
|||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
clientMonitorTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
#TARGET_INCLUDE_DIRECTORIES(
|
||||
# clientMonitorTest
|
||||
# PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
# PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
#)
|
||||
|
||||
add_test(
|
||||
NAME smlTest
|
||||
|
|
|
@ -65,7 +65,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 2 false
|
||||
|
@ -74,7 +74,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_NE(ret, 0);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 4 tag is null
|
||||
|
@ -95,7 +95,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 5 tag is null
|
||||
|
@ -115,7 +115,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
|
||||
ASSERT_EQ(elements.timestamp, sql + 1 + elements.measureTagsLen + 3 + elements.colsLen + 2);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 6
|
||||
|
@ -124,7 +124,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_EQ(ret, 0);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
ASSERT_EQ(smlClearForRerun(info), 0);
|
||||
|
||||
|
@ -134,7 +134,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_NE(ret, 0);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 8 false
|
||||
|
@ -143,7 +143,7 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_NE(ret, 0);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
taosMemoryFree(sql);
|
||||
|
@ -250,7 +250,7 @@ TEST(testCase, smlParseCols_Error_Test) {
|
|||
// printf("i:%d\n", i);
|
||||
ASSERT_NE(ret, TSDB_CODE_SUCCESS);
|
||||
taosMemoryFree(sql);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
}
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
ASSERT_EQ(kv->length, 4);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "iuwq", 4), 0);
|
||||
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
taosMemoryFree(sql);
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
|
|
@ -65,13 +65,13 @@ int32_t s3CheckCfg() {
|
|||
int32_t code = 0, lino = 0;
|
||||
|
||||
if (!tsS3Enabled) {
|
||||
fprintf(stderr, "s3 not configured.\n");
|
||||
(void)fprintf(stderr, "s3 not configured.\n");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = s3Begin();
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to initialize s3.\n");
|
||||
(void)fprintf(stderr, "failed to initialize s3.\n");
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -82,72 +82,72 @@ int32_t s3CheckCfg() {
|
|||
int ds_len = strlen(TD_DIRSEP);
|
||||
int tmp_len = strlen(tsTempDir);
|
||||
|
||||
snprintf(path, PATH_MAX, "%s", tsTempDir);
|
||||
(void)snprintf(path, PATH_MAX, "%s", tsTempDir);
|
||||
if (strncmp(tsTempDir + tmp_len - ds_len, TD_DIRSEP, ds_len) != 0) {
|
||||
snprintf(path + tmp_len, PATH_MAX - tmp_len, "%s", TD_DIRSEP);
|
||||
snprintf(path + tmp_len + ds_len, PATH_MAX - tmp_len - ds_len, "%s", objectname[0]);
|
||||
(void)snprintf(path + tmp_len, PATH_MAX - tmp_len, "%s", TD_DIRSEP);
|
||||
(void)snprintf(path + tmp_len + ds_len, PATH_MAX - tmp_len - ds_len, "%s", objectname[0]);
|
||||
} else {
|
||||
snprintf(path + tmp_len, PATH_MAX - tmp_len, "%s", objectname[0]);
|
||||
(void)snprintf(path + tmp_len, PATH_MAX - tmp_len, "%s", objectname[0]);
|
||||
}
|
||||
|
||||
TdFilePtr fp = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
if (!fp) {
|
||||
fprintf(stderr, "failed to open test file: %s.\n", path);
|
||||
(void)fprintf(stderr, "failed to open test file: %s.\n", path);
|
||||
// uError("ERROR: %s Failed to open %s", __func__, path);
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
||||
}
|
||||
if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) {
|
||||
fprintf(stderr, "failed to write test file: %s.\n", path);
|
||||
(void)fprintf(stderr, "failed to write test file: %s.\n", path);
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
||||
}
|
||||
if (taosFsyncFile(fp) < 0) {
|
||||
fprintf(stderr, "failed to fsync test file: %s.\n", path);
|
||||
(void)fprintf(stderr, "failed to fsync test file: %s.\n", path);
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
||||
}
|
||||
taosCloseFile(&fp);
|
||||
(void)taosCloseFile(&fp);
|
||||
|
||||
fprintf(stderr, "\nstart to put object: %s, file: %s content: %s\n", objectname[0], path, testdata);
|
||||
(void)fprintf(stderr, "\nstart to put object: %s, file: %s content: %s\n", objectname[0], path, testdata);
|
||||
code = s3PutObjectFromFileOffset(path, objectname[0], 0, 16);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "put object %s : failed.\n", objectname[0]);
|
||||
(void)fprintf(stderr, "put object %s : failed.\n", objectname[0]);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
fprintf(stderr, "put object %s: success.\n\n", objectname[0]);
|
||||
(void)fprintf(stderr, "put object %s: success.\n\n", objectname[0]);
|
||||
|
||||
// list buckets
|
||||
fprintf(stderr, "start to list bucket %s by prefix s3.\n", tsS3BucketName);
|
||||
(void)fprintf(stderr, "start to list bucket %s by prefix s3.\n", tsS3BucketName);
|
||||
code = s3ListBucket(tsS3BucketName);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "listing bucket %s : failed.\n", tsS3BucketName);
|
||||
(void)fprintf(stderr, "listing bucket %s : failed.\n", tsS3BucketName);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
fprintf(stderr, "listing bucket %s: success.\n\n", tsS3BucketName);
|
||||
(void)fprintf(stderr, "listing bucket %s: success.\n\n", tsS3BucketName);
|
||||
|
||||
// test range get
|
||||
uint8_t *pBlock = NULL;
|
||||
int c_offset = 10;
|
||||
int c_len = 6;
|
||||
|
||||
fprintf(stderr, "start to range get object %s offset: %d len: %d.\n", objectname[0], c_offset, c_len);
|
||||
(void)fprintf(stderr, "start to range get object %s offset: %d len: %d.\n", objectname[0], c_offset, c_len);
|
||||
code = s3GetObjectBlock(objectname[0], c_offset, c_len, true, &pBlock);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "get object %s : failed.\n", objectname[0]);
|
||||
(void)fprintf(stderr, "get object %s : failed.\n", objectname[0]);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
char buf[7] = {0};
|
||||
memcpy(buf, pBlock, c_len);
|
||||
(void)memcpy(buf, pBlock, c_len);
|
||||
taosMemoryFree(pBlock);
|
||||
fprintf(stderr, "object content: %s\n", buf);
|
||||
fprintf(stderr, "get object %s: success.\n\n", objectname[0]);
|
||||
(void)fprintf(stderr, "object content: %s\n", buf);
|
||||
(void)fprintf(stderr, "get object %s: success.\n\n", objectname[0]);
|
||||
|
||||
// delete test object
|
||||
fprintf(stderr, "start to delete object: %s.\n", objectname[0]);
|
||||
(void)fprintf(stderr, "start to delete object: %s.\n", objectname[0]);
|
||||
code = s3DeleteObjects(objectname, 1);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "delete object %s : failed.\n", objectname[0]);
|
||||
(void)fprintf(stderr, "delete object %s : failed.\n", objectname[0]);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
fprintf(stderr, "delete object %s: success.\n\n", objectname[0]);
|
||||
(void)fprintf(stderr, "delete object %s: success.\n\n", objectname[0]);
|
||||
|
||||
s3End();
|
||||
|
||||
|
@ -252,9 +252,9 @@ static int32_t s3ListBucket(char const *bucketname) {
|
|||
const char **object_name = TARRAY_DATA(objectArray);
|
||||
int size = TARRAY_SIZE(objectArray);
|
||||
|
||||
fprintf(stderr, "objects:\n");
|
||||
(void)fprintf(stderr, "objects:\n");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
fprintf(stderr, "%s\n", object_name[i]);
|
||||
(void)fprintf(stderr, "%s\n", object_name[i]);
|
||||
}
|
||||
|
||||
taosArrayDestroyEx(objectArray, s3FreeObjectKey);
|
||||
|
@ -300,7 +300,7 @@ static int growbuffer_append(growbuffer **gb, const char *data, int dataLen) {
|
|||
toCopy = dataLen;
|
||||
}
|
||||
|
||||
memcpy(&(buf->data[buf->size]), data, toCopy);
|
||||
(void)memcpy(&(buf->data[buf->size]), data, toCopy);
|
||||
|
||||
buf->size += toCopy, data += toCopy, dataLen -= toCopy;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ static void growbuffer_read(growbuffer **gb, int amt, int *amtReturn, char *buff
|
|||
|
||||
*amtReturn = (buf->size > amt) ? amt : buf->size;
|
||||
|
||||
memcpy(buffer, &(buf->data[buf->start]), *amtReturn);
|
||||
(void)memcpy(buffer, &(buf->data[buf->start]), *amtReturn);
|
||||
|
||||
buf->start += *amtReturn, buf->size -= *amtReturn;
|
||||
|
||||
|
@ -440,7 +440,7 @@ S3Status initial_multipart_callback(const char *upload_id, void *callbackData) {
|
|||
}
|
||||
|
||||
S3Status MultipartResponseProperiesCallback(const S3ResponseProperties *properties, void *callbackData) {
|
||||
responsePropertiesCallbackNull(properties, callbackData);
|
||||
(void)responsePropertiesCallbackNull(properties, callbackData);
|
||||
|
||||
MultipartPartData *data = (MultipartPartData *)callbackData;
|
||||
int seq = data->seq;
|
||||
|
@ -451,7 +451,7 @@ S3Status MultipartResponseProperiesCallback(const S3ResponseProperties *properti
|
|||
}
|
||||
|
||||
S3Status MultipartResponseProperiesCallbackWithCp(const S3ResponseProperties *properties, void *callbackData) {
|
||||
responsePropertiesCallbackNull(properties, callbackData);
|
||||
(void)responsePropertiesCallbackNull(properties, callbackData);
|
||||
|
||||
MultipartPartData *data = (MultipartPartData *)callbackData;
|
||||
int seq = data->seq;
|
||||
|
@ -624,7 +624,7 @@ static int32_t s3PutObjectFromFileWithoutCp(S3BucketContext *bucket_context, cha
|
|||
}
|
||||
|
||||
MultipartPartData partData;
|
||||
memset(&partData, 0, sizeof(MultipartPartData));
|
||||
(void)memset(&partData, 0, sizeof(MultipartPartData));
|
||||
int partContentLength = 0;
|
||||
|
||||
S3MultipartInitialHandler handler = {{&responsePropertiesCallbackNull, &responseCompleteCallback},
|
||||
|
@ -739,7 +739,7 @@ static int32_t s3PutObjectFromFileWithCp(S3BucketContext *bucket_context, const
|
|||
|
||||
bool need_init_upload = true;
|
||||
char file_cp_path[TSDB_FILENAME_LEN];
|
||||
snprintf(file_cp_path, TSDB_FILENAME_LEN, "%s.cp", file);
|
||||
(void)snprintf(file_cp_path, TSDB_FILENAME_LEN, "%s.cp", file);
|
||||
|
||||
SCheckpoint cp = {0};
|
||||
cp.parts = taosMemoryCalloc(max_part_num, sizeof(SCheckpointPart));
|
||||
|
@ -781,7 +781,7 @@ static int32_t s3PutObjectFromFileWithCp(S3BucketContext *bucket_context, const
|
|||
// cos_cp_get_undo_parts(&cp, &part_num, parts, &consume_bytes);
|
||||
|
||||
MultipartPartData partData;
|
||||
memset(&partData, 0, sizeof(MultipartPartData));
|
||||
(void)memset(&partData, 0, sizeof(MultipartPartData));
|
||||
int partContentLength = 0;
|
||||
|
||||
S3PutObjectHandler putObjectHandler = {{&MultipartResponseProperiesCallbackWithCp, &responseCompleteCallback},
|
||||
|
@ -920,7 +920,7 @@ int32_t s3PutObjectFromFile2(const char *file, const char *object_name, int8_t w
|
|||
char useServerSideEncryption = 0;
|
||||
put_object_callback_data data = {0};
|
||||
|
||||
if (taosStatFile(file, &contentLength, &lmtime, NULL) < 0) {
|
||||
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
|
||||
uError("ERROR: %s Failed to stat file %s: ", __func__, file);
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
@ -953,7 +953,7 @@ int32_t s3PutObjectFromFile2(const char *file, const char *object_name, int8_t w
|
|||
}
|
||||
|
||||
if (data.infileFD) {
|
||||
taosCloseFile(&data.infileFD);
|
||||
(void)taosCloseFile(&data.infileFD);
|
||||
} else if (data.gb) {
|
||||
growbuffer_destroy(data.gb);
|
||||
}
|
||||
|
@ -975,7 +975,7 @@ int32_t s3PutObjectFromFileOffset(const char *file, const char *object_name, int
|
|||
char useServerSideEncryption = 0;
|
||||
put_object_callback_data data = {0};
|
||||
|
||||
if (taosStatFile(file, &contentLength, &lmtime, NULL) < 0) {
|
||||
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
|
||||
uError("ERROR: %s Failed to stat file %s: ", __func__, file);
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
@ -987,7 +987,7 @@ int32_t s3PutObjectFromFileOffset(const char *file, const char *object_name, int
|
|||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) {
|
||||
taosCloseFile(&data.infileFD);
|
||||
(void)taosCloseFile(&data.infileFD);
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
|
@ -1010,7 +1010,7 @@ int32_t s3PutObjectFromFileOffset(const char *file, const char *object_name, int
|
|||
}
|
||||
|
||||
if (data.infileFD) {
|
||||
taosCloseFile(&data.infileFD);
|
||||
(void)taosCloseFile(&data.infileFD);
|
||||
} else if (data.gb) {
|
||||
growbuffer_destroy(data.gb);
|
||||
}
|
||||
|
@ -1038,7 +1038,7 @@ static S3Status listBucketCallback(int isTruncated, const char *nextMarker, int
|
|||
nextMarker = contents[contentsCount - 1].key;
|
||||
}
|
||||
if (nextMarker) {
|
||||
snprintf(data->nextMarker, sizeof(data->nextMarker), "%s", nextMarker);
|
||||
(void)snprintf(data->nextMarker, sizeof(data->nextMarker), "%s", nextMarker);
|
||||
} else {
|
||||
data->nextMarker[0] = 0;
|
||||
}
|
||||
|
@ -1052,7 +1052,7 @@ static S3Status listBucketCallback(int isTruncated, const char *nextMarker, int
|
|||
const S3ListBucketContent *content = &(contents[i]);
|
||||
// printf("%-50s", content->key);
|
||||
char *object_key = strdup(content->key);
|
||||
taosArrayPush(data->objectArray, &object_key);
|
||||
(void)taosArrayPush(data->objectArray, &object_key);
|
||||
}
|
||||
data->keyCount += contentsCount;
|
||||
|
||||
|
@ -1139,7 +1139,7 @@ int32_t s3DeleteObjects(const char *object_name[], int nobject) {
|
|||
void s3DeleteObjectsByPrefix(const char *prefix) {
|
||||
SArray *objectArray = getListByPrefix(prefix);
|
||||
if (objectArray == NULL) return;
|
||||
s3DeleteObjects(TARRAY_DATA(objectArray), TARRAY_SIZE(objectArray));
|
||||
(void)s3DeleteObjects(TARRAY_DATA(objectArray), TARRAY_SIZE(objectArray));
|
||||
taosArrayDestroyEx(objectArray, s3FreeObjectKey);
|
||||
}
|
||||
|
||||
|
@ -1156,7 +1156,7 @@ static S3Status getObjectDataCallback(int bufferSize, const char *buffer, void *
|
|||
}
|
||||
|
||||
if (cbd->buf) {
|
||||
memcpy(cbd->buf + cbd->buf_pos, buffer, bufferSize);
|
||||
(void)memcpy(cbd->buf + cbd->buf_pos, buffer, bufferSize);
|
||||
cbd->buf_pos += bufferSize;
|
||||
cbd->status = S3StatusOK;
|
||||
return S3StatusOK;
|
||||
|
@ -1196,7 +1196,7 @@ int32_t s3GetObjectBlock(const char *object_name, int64_t offset, int64_t size,
|
|||
TAOS_RETURN(TAOS_SYSTEM_ERROR(EIO));
|
||||
}
|
||||
|
||||
*ppBlock = cbd.buf;
|
||||
*ppBlock = (uint8_t *)cbd.buf;
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
@ -1231,11 +1231,11 @@ int32_t s3GetObjectToFile(const char *object_name, const char *fileName) {
|
|||
|
||||
if (cbd.status != S3StatusOK) {
|
||||
uError("%s: %d(%s)", __func__, cbd.status, cbd.err_msg);
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(EIO));
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
(void)taosCloseFile(&pFile);
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
@ -1250,9 +1250,9 @@ int32_t s3GetObjectsByPrefix(const char *prefix, const char *path) {
|
|||
tmp = (tmp == NULL) ? object : tmp + 1;
|
||||
char fileName[PATH_MAX] = {0};
|
||||
if (path[strlen(path) - 1] != TD_DIRSEP_CHAR) {
|
||||
snprintf(fileName, PATH_MAX, "%s%s%s", path, TD_DIRSEP, tmp);
|
||||
(void)snprintf(fileName, PATH_MAX, "%s%s%s", path, TD_DIRSEP, tmp);
|
||||
} else {
|
||||
snprintf(fileName, PATH_MAX, "%s%s", path, tmp);
|
||||
(void)snprintf(fileName, PATH_MAX, "%s%s", path, tmp);
|
||||
}
|
||||
if (s3GetObjectToFile(object, fileName) != 0) {
|
||||
taosArrayDestroyEx(objectArray, s3FreeObjectKey);
|
||||
|
|
|
@ -43,12 +43,12 @@ static int32_t cos_cp_parse_body(char* cp_body, SCheckpoint* cp) {
|
|||
|
||||
item = cJSON_GetObjectItem(json, "md5");
|
||||
if (cJSON_IsString(item)) {
|
||||
memcpy(cp->md5, item->valuestring, strlen(item->valuestring));
|
||||
(void)memcpy(cp->md5, item->valuestring, strlen(item->valuestring));
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(json, "upload_id");
|
||||
if (cJSON_IsString(item)) {
|
||||
strncpy(cp->upload_id, item->valuestring, 128);
|
||||
(void)strncpy(cp->upload_id, item->valuestring, 128);
|
||||
}
|
||||
|
||||
item2 = cJSON_GetObjectItem(json, "file");
|
||||
|
@ -65,12 +65,12 @@ static int32_t cos_cp_parse_body(char* cp_body, SCheckpoint* cp) {
|
|||
|
||||
item = cJSON_GetObjectItem(item2, "path");
|
||||
if (cJSON_IsString(item)) {
|
||||
strncpy(cp->file_path, item->valuestring, TSDB_FILENAME_LEN);
|
||||
(void)strncpy(cp->file_path, item->valuestring, TSDB_FILENAME_LEN);
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(item2, "file_md5");
|
||||
if (cJSON_IsString(item)) {
|
||||
strncpy(cp->file_md5, item->valuestring, 64);
|
||||
(void)strncpy(cp->file_md5, item->valuestring, 64);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,17 +83,17 @@ static int32_t cos_cp_parse_body(char* cp_body, SCheckpoint* cp) {
|
|||
|
||||
item = cJSON_GetObjectItem(item2, "object_name");
|
||||
if (cJSON_IsString(item)) {
|
||||
strncpy(cp->object_name, item->valuestring, 128);
|
||||
(void)strncpy(cp->object_name, item->valuestring, 128);
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(item2, "object_last_modified");
|
||||
if (cJSON_IsString(item)) {
|
||||
strncpy(cp->object_last_modified, item->valuestring, 64);
|
||||
(void)strncpy(cp->object_last_modified, item->valuestring, 64);
|
||||
}
|
||||
|
||||
item = cJSON_GetObjectItem(item2, "object_etag");
|
||||
if (cJSON_IsString(item)) {
|
||||
strncpy(cp->object_etag, item->valuestring, 128);
|
||||
(void)strncpy(cp->object_etag, item->valuestring, 128);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ static int32_t cos_cp_parse_body(char* cp_body, SCheckpoint* cp) {
|
|||
|
||||
item3 = cJSON_GetObjectItem(item, "etag");
|
||||
if (cJSON_IsString(item3)) {
|
||||
strncpy(cp->parts[index].etag, item3->valuestring, 128);
|
||||
(void)strncpy(cp->parts[index].etag, item3->valuestring, 128);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) {
|
|||
} else if (n != size) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit);
|
||||
}
|
||||
taosCloseFile(&fd);
|
||||
(void)taosCloseFile(&fd);
|
||||
cp_body[size] = '\0';
|
||||
|
||||
return cos_cp_parse_body(cp_body, checkpoint);
|
||||
|
@ -189,7 +189,7 @@ _exit:
|
|||
uError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
if (fd) {
|
||||
taosCloseFile(&fd);
|
||||
(void)taosCloseFile(&fd);
|
||||
}
|
||||
if (cp_body) {
|
||||
taosMemoryFree(cp_body);
|
||||
|
@ -309,7 +309,7 @@ int32_t cos_cp_dump(SCheckpoint* cp) {
|
|||
if (!item) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
cJSON_AddItemToArray(ajson, item);
|
||||
(void)cJSON_AddItemToArray(ajson, item);
|
||||
|
||||
if (NULL == cJSON_AddNumberToObject(item, "index", cp->parts[i].index)) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
|
@ -346,7 +346,7 @@ void cos_cp_get_undo_parts(SCheckpoint* checkpoint, int* part_num, SCheckpointPa
|
|||
|
||||
void cos_cp_update(SCheckpoint* checkpoint, int32_t part_index, char const* etag, uint64_t crc64) {
|
||||
checkpoint->parts[part_index].completed = 1;
|
||||
strncpy(checkpoint->parts[part_index].etag, etag, 127);
|
||||
(void)strncpy(checkpoint->parts[part_index].etag, etag, 127);
|
||||
checkpoint->parts[part_index].crc64 = crc64;
|
||||
}
|
||||
|
||||
|
@ -355,12 +355,12 @@ void cos_cp_build_upload(SCheckpoint* checkpoint, char const* filepath, int64_t
|
|||
int i = 0;
|
||||
|
||||
checkpoint->cp_type = COS_CP_TYPE_UPLOAD;
|
||||
memset(checkpoint->file_path, 0, TSDB_FILENAME_LEN);
|
||||
strncpy(checkpoint->file_path, filepath, TSDB_FILENAME_LEN - 1);
|
||||
(void)memset(checkpoint->file_path, 0, TSDB_FILENAME_LEN);
|
||||
(void)strncpy(checkpoint->file_path, filepath, TSDB_FILENAME_LEN - 1);
|
||||
|
||||
checkpoint->file_size = size;
|
||||
checkpoint->file_last_modified = mtime;
|
||||
strncpy(checkpoint->upload_id, upload_id, 127);
|
||||
(void)strncpy(checkpoint->upload_id, upload_id, 127);
|
||||
|
||||
checkpoint->part_size = part_size;
|
||||
for (; i * part_size < size; i++) {
|
||||
|
|
|
@ -54,10 +54,11 @@ static void changeDirFromWindowsToLinux(char* from, char* to) {
|
|||
#endif
|
||||
|
||||
static int32_t generateConfigFile(char* confDir) {
|
||||
int32_t code = 0;
|
||||
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -92,7 +93,8 @@ static int32_t generateConfigFile(char* confDir) {
|
|||
if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) {
|
||||
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
|
@ -129,11 +131,13 @@ void stopRsync() {
|
|||
taosMsleep(500); // sleep 500 ms to wait for the completion of kill operation.
|
||||
}
|
||||
|
||||
void startRsync() {
|
||||
int32_t startRsync() {
|
||||
int32_t code = 0;
|
||||
if (taosMulMkDir(tsCheckpointBackupDir) != 0) {
|
||||
uError("[rsync] build checkpoint backup dir failed, path:%s," ERRNO_ERR_FORMAT, tsCheckpointBackupDir,
|
||||
ERRNO_ERR_DATA);
|
||||
return;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
|
||||
removeEmptyDir();
|
||||
|
@ -141,9 +145,9 @@ void startRsync() {
|
|||
char confDir[PATH_MAX] = {0};
|
||||
snprintf(confDir, PATH_MAX, "%srsync.conf", tsCheckpointBackupDir);
|
||||
|
||||
int32_t code = generateConfigFile(confDir);
|
||||
code = generateConfigFile(confDir);
|
||||
if (code != 0) {
|
||||
return;
|
||||
return code;
|
||||
}
|
||||
|
||||
char cmd[PATH_MAX] = {0};
|
||||
|
@ -152,9 +156,11 @@ void startRsync() {
|
|||
code = system(cmd);
|
||||
if (code != 0) {
|
||||
uError("[rsync] cmd:%s start server failed, code:%d," ERRNO_ERR_FORMAT, cmd, code, ERRNO_ERR_DATA);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
uInfo("[rsync] cmd:%s start server successful", cmd);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t uploadByRsync(const char* id, const char* path) {
|
||||
|
@ -199,6 +205,7 @@ int32_t uploadByRsync(const char* id, const char* path) {
|
|||
if (code != 0) {
|
||||
uError("[rsync] s-task:%s prepare checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
||||
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
int64_t el = (taosGetTimestampMs() - st);
|
||||
uDebug("[rsync] s-task:%s prepare checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
||||
|
@ -242,6 +249,7 @@ int32_t uploadByRsync(const char* id, const char* path) {
|
|||
if (code != 0) {
|
||||
uError("[rsync] s-task:%s upload checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
||||
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
int64_t el = (taosGetTimestampMs() - st);
|
||||
uDebug("[rsync] s-task:%s upload checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
||||
|
@ -283,13 +291,13 @@ int32_t downloadRsync(const char* id, const char* path) {
|
|||
uError("[rsync] %s download checkpoint data:%s failed, retry after 1sec, times:%d, code:%d," ERRNO_ERR_FORMAT, id,
|
||||
path, times, code, ERRNO_ERR_DATA);
|
||||
taosSsleep(1);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
int32_t el = taosGetTimestampMs() - st;
|
||||
uDebug("[rsync] %s download checkpoint data:%s successfully, elapsed time:%dms", id, path, el);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -298,7 +306,7 @@ int32_t deleteRsync(const char* id) {
|
|||
int32_t code = taosMkDir(tmp);
|
||||
if (code != 0) {
|
||||
uError("[rsync] make tmp dir failed. code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
char command[PATH_MAX] = {0};
|
||||
|
@ -310,7 +318,7 @@ int32_t deleteRsync(const char* id) {
|
|||
taosRemoveDir(tmp);
|
||||
if (code != 0) {
|
||||
uError("[rsync] get failed code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
uDebug("[rsync] delete data:%s successful", id);
|
||||
|
|
|
@ -456,7 +456,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int
|
|||
int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows,
|
||||
const SDataBlockInfo* pBlockInfo) {
|
||||
if (pColumnInfoData->info.type != pSource->info.type || (pBlockInfo != NULL && pBlockInfo->capacity < numOfRows)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
if (numOfRows <= 0) {
|
||||
|
@ -1510,6 +1510,9 @@ int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) {
|
|||
}
|
||||
|
||||
void blockDataFreeRes(SSDataBlock* pBlock) {
|
||||
if (pBlock == NULL){
|
||||
return;
|
||||
}
|
||||
int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock);
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
@ -1990,14 +1993,14 @@ static void colDataKeepFirstNRows(SColumnInfoData* pColInfoData, size_t n, size_
|
|||
}
|
||||
}
|
||||
|
||||
int32_t blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n) {
|
||||
void blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n) {
|
||||
if (n == 0) {
|
||||
blockDataEmpty(pBlock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return ;
|
||||
}
|
||||
|
||||
if (pBlock->info.rows <= n) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return ;
|
||||
} else {
|
||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
|
@ -2007,7 +2010,7 @@ int32_t blockDataKeepFirstNRows(SSDataBlock* pBlock, size_t n) {
|
|||
|
||||
pBlock->info.rows = n;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return ;
|
||||
}
|
||||
|
||||
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) {
|
||||
|
@ -2491,7 +2494,7 @@ int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, cha
|
|||
.tags = tags, .stbFullName = stbFullName, .stbFullNameLen = strlen(stbFullName), .ctbShortName = cname};
|
||||
|
||||
int32_t code = buildChildTableName(&rname);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
taosArrayDestroy(tags);
|
||||
|
|
|
@ -310,7 +310,7 @@ static int32_t tRowBuildTupleRow(SArray *aColVal, const SRowBuildScanInfo *sinfo
|
|||
}
|
||||
} else {
|
||||
(void)memcpy(fixed + schema->columns[i].offset, &colValArray[colValIndex].value.val,
|
||||
tDataTypes[schema->columns[i].type].bytes);
|
||||
tDataTypes[schema->columns[i].type].bytes);
|
||||
}
|
||||
} else if (COL_VAL_IS_NULL(&colValArray[colValIndex])) { // NULL
|
||||
ROW_SET_BITMAP(bitmap, sinfo->tupleFlag, i - 1, BIT_FLG_NULL);
|
||||
|
@ -384,13 +384,14 @@ static int32_t tRowBuildKVRow(SArray *aColVal, const SRowBuildScanInfo *sinfo, c
|
|||
payloadSize += tPutI16v(payload + payloadSize, colValArray[colValIndex].cid);
|
||||
payloadSize += tPutU32v(payload + payloadSize, colValArray[colValIndex].value.nData);
|
||||
if (colValArray[colValIndex].value.nData > 0) {
|
||||
(void)memcpy(payload + payloadSize, colValArray[colValIndex].value.pData, colValArray[colValIndex].value.nData);
|
||||
(void)memcpy(payload + payloadSize, colValArray[colValIndex].value.pData,
|
||||
colValArray[colValIndex].value.nData);
|
||||
}
|
||||
payloadSize += colValArray[colValIndex].value.nData;
|
||||
} else {
|
||||
payloadSize += tPutI16v(payload + payloadSize, colValArray[colValIndex].cid);
|
||||
(void)memcpy(payload + payloadSize, &colValArray[colValIndex].value.val,
|
||||
tDataTypes[schema->columns[i].type].bytes);
|
||||
tDataTypes[schema->columns[i].type].bytes);
|
||||
payloadSize += tDataTypes[schema->columns[i].type].bytes;
|
||||
}
|
||||
} else if (COL_VAL_IS_NULL(&colValArray[colValIndex])) { // NULL
|
||||
|
@ -476,11 +477,14 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted,
|
|||
value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow;
|
||||
} else {
|
||||
(void)memcpy(&value.val, (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow,
|
||||
infos[iInfo].bind->buffer_length);
|
||||
infos[iInfo].bind->buffer_length);
|
||||
}
|
||||
colVal = COL_VAL_VALUE(infos[iInfo].columnId, value);
|
||||
}
|
||||
taosArrayPush(colValArray, &colVal);
|
||||
if (taosArrayPush(colValArray, &colVal) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
SRow *row;
|
||||
|
@ -689,7 +693,12 @@ static int32_t tRowMergeImpl(SArray *aRowP, STSchema *pTSchema, int32_t iStart,
|
|||
}
|
||||
}
|
||||
|
||||
if (pColVal) taosArrayPush(aColVal, pColVal);
|
||||
if (pColVal) {
|
||||
if (taosArrayPush(aColVal, pColVal) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// build
|
||||
|
@ -1750,7 +1759,10 @@ int32_t tTagToValArray(const STag *pTag, SArray **ppArray) {
|
|||
offset = pTag->idx[iTag];
|
||||
}
|
||||
tGetTagVal(p + offset, &tv, pTag->flags & TD_TAG_JSON);
|
||||
taosArrayPush(*ppArray, &tv);
|
||||
if (taosArrayPush(*ppArray, &tv) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -1783,6 +1795,7 @@ void tTagSetCid(const STag *pTag, int16_t iTag, int16_t cid) {
|
|||
STSchema *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version) {
|
||||
STSchema *pTSchema = taosMemoryCalloc(1, sizeof(STSchema) + sizeof(STColumn) * numOfCols);
|
||||
if (pTSchema == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -2592,7 +2605,8 @@ static FORCE_INLINE void tColDataGetValue4(SColData *pColData, int32_t iVal, SCo
|
|||
}
|
||||
value.pData = pColData->pData + pColData->aOffset[iVal];
|
||||
} else {
|
||||
(void)memcpy(&value.val, pColData->pData + tDataTypes[pColData->type].bytes * iVal, tDataTypes[pColData->type].bytes);
|
||||
(void)memcpy(&value.val, pColData->pData + tDataTypes[pColData->type].bytes * iVal,
|
||||
tDataTypes[pColData->type].bytes);
|
||||
}
|
||||
*pColVal = COL_VAL_VALUE(pColData->cid, value);
|
||||
}
|
||||
|
@ -3118,10 +3132,10 @@ static int32_t tColDataCopyRowCell(SColData *pFromColData, int32_t iFromRow, SCo
|
|||
}
|
||||
|
||||
(void)memcpy(pToColData->pData + pToColData->aOffset[iToRow], pFromColData->pData + pFromColData->aOffset[iFromRow],
|
||||
nData);
|
||||
nData);
|
||||
} else {
|
||||
(void)memcpy(&pToColData->pData[TYPE_BYTES[pToColData->type] * iToRow],
|
||||
&pFromColData->pData[TYPE_BYTES[pToColData->type] * iFromRow], TYPE_BYTES[pToColData->type]);
|
||||
&pFromColData->pData[TYPE_BYTES[pToColData->type] * iFromRow], TYPE_BYTES[pToColData->type]);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -3209,12 +3223,12 @@ static int32_t tColDataMergeSortMerge(SColData *aColData, int32_t start, int32_t
|
|||
|
||||
if (end > start) {
|
||||
aDstColData = taosMemoryCalloc(1, sizeof(SColData) * nColData);
|
||||
for (int c = 0; c < nColData; ++c) {
|
||||
tColDataInit(&aDstColData[c], aColData[c].cid, aColData[c].type, aColData[c].cflag);
|
||||
}
|
||||
if (aDstColData == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int c = 0; c < nColData; ++c) {
|
||||
tColDataInit(&aDstColData[c], aColData[c].cid, aColData[c].type, aColData[c].cflag);
|
||||
}
|
||||
}
|
||||
|
||||
tColDataArrGetRowKey(aColData, nColData, i, &keyi);
|
||||
|
@ -3360,7 +3374,7 @@ static void tColDataMergeImpl(SColData *pColData, int32_t iStart, int32_t iEnd /
|
|||
} else {
|
||||
if (iv != iStart) {
|
||||
(void)memcpy(&pColData->pData[TYPE_BYTES[pColData->type] * iStart],
|
||||
&pColData->pData[TYPE_BYTES[pColData->type] * iv], TYPE_BYTES[pColData->type]);
|
||||
&pColData->pData[TYPE_BYTES[pColData->type] * iv], TYPE_BYTES[pColData->type]);
|
||||
}
|
||||
memmove(&pColData->pData[TYPE_BYTES[pColData->type] * (iStart + 1)],
|
||||
&pColData->pData[TYPE_BYTES[pColData->type] * iEnd],
|
||||
|
@ -4476,6 +4490,9 @@ int32_t tDecompressData(void *input, // input
|
|||
buffer = &local;
|
||||
}
|
||||
code = tBufferEnsureCapacity(buffer, info->originalSize + COMP_OVERFLOW_BYTES);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t decompressedSize = tDataCompress[info->dataType].decompFunc(
|
||||
input, // input
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -150,7 +150,6 @@ int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) {
|
|||
cap -= nwrite;
|
||||
|
||||
for (int _i = 0; (_i < pEpSet->numOfEps) && (cap > 0); _i++) {
|
||||
int32_t ret = 0;
|
||||
if (_i == pEpSet->numOfEps - 1) {
|
||||
ret = snprintf(pBuf + nwrite, cap, "%d. %s:%d", _i, pEpSet->eps[_i].fqdn, pEpSet->eps[_i].port);
|
||||
} else {
|
||||
|
@ -271,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;
|
||||
|
@ -297,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++);
|
||||
|
@ -309,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++);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -181,7 +181,7 @@ int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t name
|
|||
int32_t tNameAddTbName(SName* dst, const char* tbName, size_t nameLen) {
|
||||
// too long account id or too long db name
|
||||
if (nameLen >= tListLen(dst->tname) || nameLen <= 0) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
dst->type = TSDB_TABLE_NAME_T;
|
||||
|
@ -225,14 +225,14 @@ bool tNameTbNameEqual(SName* left, SName* right) {
|
|||
|
||||
int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
||||
if (strlen(str) == 0) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
char* p = NULL;
|
||||
if ((type & T_NAME_ACCT) == T_NAME_ACCT) {
|
||||
p = strstr(str, TS_PATH_DELIMITER);
|
||||
if (p == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
dst->acctId = taosStr2Int32(str, NULL, 10);
|
||||
|
@ -252,7 +252,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
|
||||
// too long account id or too long db name
|
||||
if ((len >= tListLen(dst->dbname)) || (len <= 0)) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
memcpy(dst->dbname, start, len);
|
||||
|
@ -266,7 +266,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
// too long account id or too long db name
|
||||
int32_t len = (int32_t)strlen(start);
|
||||
if ((len >= tListLen(dst->tname)) || (len <= 0)) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
memcpy(dst->tname, start, len);
|
||||
|
@ -302,7 +302,7 @@ int32_t buildChildTableName(RandTableName* rName) {
|
|||
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
||||
taosStringBuilderAppendChar(&sb, ',');
|
||||
SSmlKv* tagKv = taosArrayGet(rName->tags, j);
|
||||
if(tagKv == NULL) {
|
||||
if (tagKv == NULL) {
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#include "trow.h"
|
||||
#include "tlog.h"
|
||||
|
||||
static bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
|
||||
static bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal);
|
||||
static bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
|
||||
static bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal);
|
||||
|
||||
void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) {
|
||||
pIter->pSchema = pSchema;
|
||||
|
@ -110,8 +110,7 @@ bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset,
|
|||
|
||||
int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||
|
@ -131,59 +130,15 @@ int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pVa
|
|||
*pValType = ((*pDestByte) & 0x03);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS_I;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR_I;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pValType = (((*pDestByte) & 0x80) >> 7);
|
||||
break;
|
||||
case 1:
|
||||
*pValType = (((*pDestByte) & 0x40) >> 6);
|
||||
break;
|
||||
case 2:
|
||||
*pValType = (((*pDestByte) & 0x20) >> 5);
|
||||
break;
|
||||
case 3:
|
||||
*pValType = (((*pDestByte) & 0x10) >> 4);
|
||||
break;
|
||||
case 4:
|
||||
*pValType = (((*pDestByte) & 0x08) >> 3);
|
||||
break;
|
||||
case 5:
|
||||
*pValType = (((*pDestByte) & 0x04) >> 2);
|
||||
break;
|
||||
case 6:
|
||||
*pValType = (((*pDestByte) & 0x02) >> 1);
|
||||
break;
|
||||
case 7:
|
||||
*pValType = ((*pDestByte) & 0x01);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
switch (bitmapMode) {
|
||||
case 0:
|
||||
tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
(void)tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
break;
|
||||
#if 0
|
||||
case -1:
|
||||
|
@ -192,10 +147,9 @@ int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValT
|
|||
break;
|
||||
#endif
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal) {
|
||||
|
@ -400,8 +354,8 @@ bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVa
|
|||
}
|
||||
|
||||
void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow));
|
||||
tdGetKvRowValOfCol(pVal, pRow, pBitmap, pColIdx->offset,
|
||||
POINTER_DISTANCE(pColIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx));
|
||||
(void)tdGetKvRowValOfCol(pVal, pRow, pBitmap, pColIdx->offset,
|
||||
POINTER_DISTANCE(pColIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -412,11 +366,10 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl
|
|||
return true;
|
||||
}
|
||||
void *pBitmap = tdGetBitmapAddrTp(pRow, flen);
|
||||
tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset, colIdx);
|
||||
(void)tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset, colIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
|
||||
if (pIter->colIdx >= pIter->pSchema->numOfCols) {
|
||||
return false;
|
||||
|
@ -432,9 +385,9 @@ bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
|
|||
}
|
||||
|
||||
if (TD_IS_TP_ROW(pIter->pRow)) {
|
||||
tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal);
|
||||
(void)tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal);
|
||||
} else if (TD_IS_KV_ROW(pIter->pRow)) {
|
||||
tdSTSRowIterGetKvVal(pIter, pCol->colId, &pIter->kvIdx, pVal);
|
||||
(void)tdSTSRowIterGetKvVal(pIter, pCol->colId, &pIter->kvIdx, pVal);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -452,6 +405,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
int32_t maxVarDataLen = 0;
|
||||
int32_t iColVal = 0;
|
||||
int32_t nBound = 0;
|
||||
int32_t code = 0;
|
||||
void *varBuf = NULL;
|
||||
bool isAlloc = false;
|
||||
|
||||
|
@ -481,7 +435,8 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
} else {
|
||||
varDataLen += sizeof(VarDataLenT);
|
||||
if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR || pTColumn->type == TSDB_DATA_TYPE_VARBINARY || pTColumn->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR || pTColumn->type == TSDB_DATA_TYPE_VARBINARY ||
|
||||
pTColumn->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
varDataLen += CHAR_BYTES;
|
||||
if (maxVarDataLen < CHAR_BYTES + sizeof(VarDataLenT)) {
|
||||
maxVarDataLen = CHAR_BYTES + sizeof(VarDataLenT);
|
||||
|
@ -494,7 +449,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if(pColVal && COL_VAL_IS_VALUE(pColVal)) {
|
||||
if (pColVal && COL_VAL_IS_VALUE(pColVal)) {
|
||||
nonVarDataLen += TYPE_BYTES[pTColumn->type];
|
||||
}
|
||||
}
|
||||
|
@ -516,8 +471,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
|
||||
if (!(*ppRow)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (maxVarDataLen > 0) {
|
||||
|
@ -526,15 +480,14 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
if (isAlloc) {
|
||||
taosMemoryFreeClear(*ppRow);
|
||||
}
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
SRowBuilder rb = {.rowType = rowType};
|
||||
tdSRowInit(&rb, pTSchema->version);
|
||||
tdSRowSetInfo(&rb, pTSchema->numOfCols, nBound, pTSchema->flen);
|
||||
tdSRowResetBuf(&rb, *ppRow);
|
||||
(void)tdSRowSetInfo(&rb, pTSchema->numOfCols, nBound, pTSchema->flen);
|
||||
(void)tdSRowResetBuf(&rb, *ppRow);
|
||||
int32_t iBound = 0;
|
||||
|
||||
iColVal = 0;
|
||||
|
@ -553,7 +506,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
} else if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
varDataSetLen(varBuf, pColVal->value.nData);
|
||||
if (pColVal->value.nData != 0) {
|
||||
memcpy(varDataVal(varBuf), pColVal->value.pData, pColVal->value.nData);
|
||||
(void)memcpy(varDataVal(varBuf), pColVal->value.pData, pColVal->value.nData);
|
||||
}
|
||||
val = varBuf;
|
||||
++iBound;
|
||||
|
@ -567,18 +520,28 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
|
|||
}
|
||||
|
||||
if (TD_IS_TP_ROW(rb.pBuf)) {
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, pTColumn->offset, iColVal);
|
||||
TAOS_CHECK_GOTO(
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, pTColumn->offset, iColVal),
|
||||
NULL, _exit);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, rb.offset, iBound - 1);
|
||||
TAOS_CHECK_GOTO(
|
||||
tdAppendColValToRow(&rb, pTColumn->colId, pTColumn->type, valType, val, true, rb.offset, iBound - 1), NULL,
|
||||
_exit);
|
||||
}
|
||||
|
||||
++iColVal;
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
|
||||
_exit:
|
||||
taosMemoryFreeClear(varBuf);
|
||||
if (code < 0) {
|
||||
if (isAlloc) {
|
||||
taosMemoryFreeClear(*ppRow);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdCompareColId(const void *arg1, const void *arg2) {
|
||||
|
@ -615,7 +578,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell
|
|||
#ifdef TD_SUPPORT_BITMAP
|
||||
colIdx = POINTER_DISTANCE(pCol, pSchema->columns) / sizeof(STColumn);
|
||||
#endif
|
||||
tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset, colIdx - 1);
|
||||
(void)tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset, colIdx - 1);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
SKvRowIdx *pIdx = (SKvRowIdx *)taosbsearch(&colId, TD_ROW_COL_IDX(pRow), tdRowGetNCols(pRow), sizeof(SKvRowIdx),
|
||||
compareKvRowColId, TD_EQ);
|
||||
|
@ -624,7 +587,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell
|
|||
colIdx = POINTER_DISTANCE(pIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx);
|
||||
}
|
||||
#endif
|
||||
tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx);
|
||||
(void)tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx);
|
||||
} else {
|
||||
if (COL_REACH_END(colId, pIter->maxColId)) return false;
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
|
@ -632,83 +595,31 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell
|
|||
|
||||
return true;
|
||||
}
|
||||
#if 0
|
||||
int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS_I;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR_I;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pDestByte = ((*pDestByte) & 0x7F) | (valType << 7);
|
||||
// set the value and clear other partitions for offset 0
|
||||
// *pDestByte |= (valType << 7);
|
||||
break;
|
||||
case 1:
|
||||
*pDestByte = ((*pDestByte) & 0xBF) | (valType << 6);
|
||||
// *pDestByte |= (valType << 6);
|
||||
break;
|
||||
case 2:
|
||||
*pDestByte = ((*pDestByte) & 0xDF) | (valType << 5);
|
||||
// *pDestByte |= (valType << 5);
|
||||
break;
|
||||
case 3:
|
||||
*pDestByte = ((*pDestByte) & 0xEF) | (valType << 4);
|
||||
// *pDestByte |= (valType << 4);
|
||||
break;
|
||||
case 4:
|
||||
*pDestByte = ((*pDestByte) & 0xF7) | (valType << 3);
|
||||
// *pDestByte |= (valType << 3);
|
||||
break;
|
||||
case 5:
|
||||
*pDestByte = ((*pDestByte) & 0xFB) | (valType << 2);
|
||||
// *pDestByte |= (valType << 2);
|
||||
break;
|
||||
case 6:
|
||||
*pDestByte = ((*pDestByte) & 0xFD) | (valType << 1);
|
||||
// *pDestByte |= (valType << 1);
|
||||
break;
|
||||
case 7:
|
||||
*pDestByte = ((*pDestByte) & 0xFE) | valType;
|
||||
// *pDestByte |= (valType);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_t offset, int16_t colIdx) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
ASSERT(colIdx < tdRowGetNCols(pRow) - 1);
|
||||
if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
int32_t code = 0;
|
||||
if ((code = tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0)) != TSDB_CODE_SUCCESS) {
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (tdValTypeIsNorm(output->valType)) {
|
||||
if (offset < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
output->val = POINTER_SHIFT(pRow, offset);
|
||||
}
|
||||
#else
|
||||
if (offset < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
output->val = POINTER_SHIFT(pRow, offset);
|
||||
output->valType = isNull(output->val, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t colType, int32_t offset,
|
||||
|
@ -720,12 +631,13 @@ int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t
|
|||
} else {
|
||||
output->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
int32_t code = 0;
|
||||
if ((code = tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0)) != TSDB_CODE_SUCCESS) {
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (output->valType == TD_VTYPE_NORM) {
|
||||
|
@ -736,7 +648,7 @@ int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t
|
|||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colType, TDRowValT valType, const void *val,
|
||||
|
@ -745,23 +657,21 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp
|
|||
if (!val) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (valType == TD_VTYPE_NORM) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
#else
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
d
|
||||
#endif
|
||||
}
|
||||
// TS KEY is stored in STSRow.ts and not included in STSRow.data field.
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
if (!val) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
TD_ROW_KEY(pRow) = *(TSKEY *)val;
|
||||
// The primary TS key is Norm all the time, thus its valType is not stored in bitmap.
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
// TODO: We can avoid the type judegement by FP, but would prevent the inline scheme.
|
||||
|
||||
|
@ -773,33 +683,29 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp
|
|||
break;
|
||||
case TD_VTYPE_NONE:
|
||||
if (!pBuilder->hasNone) pBuilder->hasNone = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset);
|
||||
(void)tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset);
|
||||
} else {
|
||||
tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId);
|
||||
(void)tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData,
|
||||
int8_t colType, int16_t colIdx, int32_t offset, col_id_t colId) {
|
||||
if (colIdx < 1) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
ASSERTS(0, "colIdx is %" PRIi64, colIdx);
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
--colIdx;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0));
|
||||
#endif
|
||||
|
||||
STSRow *row = pBuilder->pBuf;
|
||||
|
@ -812,30 +718,27 @@ int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const vo
|
|||
char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
if (isCopyVarData) {
|
||||
memcpy(ptr, val, varDataTLen(val));
|
||||
(void)memcpy(ptr, val, varDataTLen(val));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(val);
|
||||
} else {
|
||||
memcpy(ptr, val, TYPE_BYTES[colType]);
|
||||
(void)memcpy(ptr, val, TYPE_BYTES[colType]);
|
||||
TD_ROW_LEN(row) += TYPE_BYTES[colType];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData,
|
||||
int8_t colType, int16_t colIdx, int32_t offset) {
|
||||
if (colIdx < 1) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
--colIdx;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0));
|
||||
#endif
|
||||
|
||||
STSRow *row = pBuilder->pBuf;
|
||||
|
@ -849,59 +752,21 @@ int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const vo
|
|||
// ts key stored in STSRow.ts
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(row), offset) = TD_ROW_LEN(row);
|
||||
if (isCopyVarData) {
|
||||
memcpy(POINTER_SHIFT(row, TD_ROW_LEN(row)), val, varDataTLen(val));
|
||||
(void)memcpy(POINTER_SHIFT(row, TD_ROW_LEN(row)), val, varDataTLen(val));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(val);
|
||||
} else {
|
||||
memcpy(POINTER_SHIFT(TD_ROW_DATA(row), offset), val, TYPE_BYTES[colType]);
|
||||
(void)memcpy(POINTER_SHIFT(TD_ROW_DATA(row), offset), val, TYPE_BYTES[colType]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
#if 0
|
||||
int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen,
|
||||
int32_t allNullLen, int32_t boundNullLen) {
|
||||
if ((boundNullLen > 0) && (allNullLen > 0) && (nBoundCols > 0)) {
|
||||
uint32_t tpLen = allNullLen;
|
||||
uint32_t kvLen = sizeof(col_id_t) + sizeof(SKvRowIdx) * nBoundCols + boundNullLen;
|
||||
if (isSelectKVRow(kvLen, tpLen)) {
|
||||
pBuilder->rowType = TD_ROW_KV;
|
||||
} else {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
}
|
||||
|
||||
} else {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
}
|
||||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
pBuilder->nBoundCols = nBoundCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
pBuilder->nBitmaps = (col_id_t)TD_BITMAP_BYTES(pBuilder->nCols - 1);
|
||||
if (nBoundCols > 0) {
|
||||
pBuilder->nBoundBitmaps = (col_id_t)TD_BITMAP_BYTES(pBuilder->nBoundCols - 1);
|
||||
} else {
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
}
|
||||
#else
|
||||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
||||
pBuilder->pBuf = (STSRow *)pBuf;
|
||||
if (!pBuilder->pBuf) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (pBuilder->hasNone) pBuilder->hasNone = false;
|
||||
|
@ -917,7 +782,7 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
case TD_ROW_TP:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrTp(pBuilder->pBuf, pBuilder->flen);
|
||||
memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps);
|
||||
(void)memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps);
|
||||
#endif
|
||||
// the primary TS key is stored separatedly
|
||||
len = TD_ROW_HEAD_LEN + pBuilder->flen + pBuilder->nBitmaps;
|
||||
|
@ -927,7 +792,7 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
case TD_ROW_KV:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols);
|
||||
memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBoundBitmaps);
|
||||
(void)memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBoundBitmaps);
|
||||
#endif
|
||||
len = TD_ROW_HEAD_LEN + TD_ROW_NCOLS_LEN + (pBuilder->nBoundCols - 1) * sizeof(SKvRowIdx) +
|
||||
pBuilder->nBoundBitmaps; // add
|
||||
|
@ -937,18 +802,16 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
pBuilder->offset = 0;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
||||
pBuilder->pBuf = (STSRow *)pBuf;
|
||||
if (!pBuilder->pBuf) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
ASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0);
|
||||
|
@ -966,10 +829,9 @@ int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
#endif
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void tdSRowReset(SRowBuilder *pBuilder) {
|
||||
|
@ -985,8 +847,7 @@ int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) {
|
|||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
|
@ -995,7 +856,7 @@ int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) {
|
|||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen) {
|
||||
|
@ -1003,8 +864,7 @@ int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols,
|
|||
pBuilder->nCols = nCols;
|
||||
pBuilder->nBoundCols = nBoundCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
|
@ -1018,24 +878,12 @@ int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols,
|
|||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode) {
|
||||
TDRowValT valType = 0;
|
||||
tdGetBitmapValType(pBitmap, idx, &valType, bitmapMode);
|
||||
if (tdValTypeIsNorm(valType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||
|
@ -1060,10 +908,9 @@ int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
|||
// *pDestByte |= (valType);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int8_t bitmapMode) {
|
||||
|
@ -1078,14 +925,11 @@ int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int
|
|||
break;
|
||||
#endif
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColVal) {
|
||||
STColumn *pTColumn = &pTSchema->columns[iCol];
|
||||
SCellVal cv = {0};
|
||||
|
@ -1093,9 +937,9 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
|
|||
ASSERT((pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) || (iCol > 0));
|
||||
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv);
|
||||
(void)tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv);
|
||||
(void)tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -1113,7 +957,7 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
|
|||
pColVal->value.nData = varDataLen(cv.val);
|
||||
pColVal->value.pData = varDataVal(cv.val);
|
||||
} else {
|
||||
memcpy(&pColVal->value.val, cv.val, tDataTypes[pTColumn->type].bytes);
|
||||
(void)memcpy(&pColVal->value.val, cv.val, tDataTypes[pTColumn->type].bytes);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ void deltaToUtcInitOnce() {
|
|||
// printf("====delta:%lld\n\n", seconds);
|
||||
}
|
||||
|
||||
static int64_t parseFraction(char* str, char** end, int32_t timePrec);
|
||||
static int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFraction);
|
||||
static int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim);
|
||||
static int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim);
|
||||
static int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim);
|
||||
|
@ -95,7 +95,7 @@ char* forwardToTimeStringEnd(char* str) {
|
|||
return &str[i];
|
||||
}
|
||||
|
||||
int64_t parseFraction(char* str, char** end, int32_t timePrec) {
|
||||
int32_t parseFraction(char* str, char** end, int32_t timePrec, int64_t* pFraction) {
|
||||
int32_t i = 0;
|
||||
int64_t fraction = 0;
|
||||
|
||||
|
@ -112,7 +112,7 @@ int64_t parseFraction(char* str, char** end, int32_t timePrec) {
|
|||
|
||||
int32_t totalLen = i;
|
||||
if (totalLen <= 0) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
/* parse the fraction */
|
||||
|
@ -134,13 +134,14 @@ int64_t parseFraction(char* str, char** end, int32_t timePrec) {
|
|||
}
|
||||
times = NANO_SEC_FRACTION_LEN - i;
|
||||
} else {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
fraction = strnatoi(str, i) * factor[times];
|
||||
*end = str + totalLen;
|
||||
*pFraction = fraction;
|
||||
|
||||
return fraction;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
||||
|
@ -148,7 +149,7 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
|||
|
||||
int32_t i = 0;
|
||||
if (str[i] != '+' && str[i] != '-') {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
i++;
|
||||
|
@ -160,7 +161,7 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
|||
continue;
|
||||
}
|
||||
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
char* sep = strchr(&str[i], ':');
|
||||
|
@ -175,18 +176,18 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
|||
}
|
||||
|
||||
if (hour > 12 || hour < 0) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
// return error if there're illegal charaters after min(2 Digits)
|
||||
char* minStr = &str[i];
|
||||
if (minStr[1] != '\0' && minStr[2] != '\0') {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
int64_t minute = strnatoi(&str[i], 2);
|
||||
if (minute > 59 || (hour == 12 && minute > 0)) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (str[0] == '+') {
|
||||
|
@ -195,13 +196,13 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) {
|
|||
*tzOffset = hour * 3600 + minute * 60;
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t offsetOfTimezone(char* tzStr, int64_t* offset) {
|
||||
if (tzStr && (tzStr[0] == 'z' || tzStr[0] == 'Z')) {
|
||||
*offset = 0;
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return parseTimezone(tzStr, offset);
|
||||
}
|
||||
|
@ -234,7 +235,7 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
|
|||
}
|
||||
|
||||
if (str == NULL) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
/* mktime will be affected by TZ, set by using taos_options */
|
||||
|
@ -253,22 +254,18 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
|
|||
*time = seconds * factor;
|
||||
} else if (str[0] == '.') {
|
||||
str += 1;
|
||||
if ((fraction = parseFraction(str, &str, timePrec)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseFraction(str, &str, timePrec, &fraction));
|
||||
|
||||
*time = seconds * factor + fraction;
|
||||
|
||||
char seg = str[0];
|
||||
if (seg != 'Z' && seg != 'z' && seg != '+' && seg != '-') {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
} else if ((seg == 'Z' || seg == 'z') && str[1] != '\0') {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
} else if (seg == '+' || seg == '-') {
|
||||
// parse the timezone
|
||||
if (parseTimezone(str, &tzOffset) == -1) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseTimezone(str, &tzOffset));
|
||||
|
||||
*time += tzOffset * factor;
|
||||
}
|
||||
|
@ -277,16 +274,14 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
|
|||
*time = seconds * factor + fraction;
|
||||
|
||||
// parse the timezone
|
||||
if (parseTimezone(str, &tzOffset) == -1) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseTimezone(str, &tzOffset));
|
||||
|
||||
*time += tzOffset * factor;
|
||||
} else {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static FORCE_INLINE bool validateTm(struct tm* pTm) {
|
||||
|
@ -330,7 +325,7 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP
|
|||
// if parse failed, try "%Y-%m-%d" format
|
||||
str = taosStrpTime(timestr, "%Y-%m-%d", &tm);
|
||||
if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,13 +342,11 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timeP
|
|||
|
||||
if (*str == '.') {
|
||||
/* parse the second fraction part */
|
||||
if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseFraction(str + 1, &str, timePrec, &fraction));
|
||||
}
|
||||
|
||||
*utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) {
|
||||
|
@ -374,7 +367,7 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t ti
|
|||
// if parse failed, try "%Y-%m-%d" format
|
||||
str = taosStrpTime(timestr, "%Y-%m-%d", &tm);
|
||||
if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -384,13 +377,11 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t ti
|
|||
int64_t fraction = 0;
|
||||
if (*str == '.') {
|
||||
/* parse the second fraction part */
|
||||
if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseFraction(str + 1, &str, timePrec, &fraction));
|
||||
}
|
||||
|
||||
*utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction;
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
char getPrecisionUnit(int32_t precision) {
|
||||
|
@ -482,10 +473,10 @@ 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
|
||||
int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit) {
|
||||
int32_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit, int64_t* pRes) {
|
||||
if (fromPrecision != TSDB_TIME_PRECISION_MILLI && fromPrecision != TSDB_TIME_PRECISION_MICRO &&
|
||||
fromPrecision != TSDB_TIME_PRECISION_NANO) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
int64_t factors[3] = {NANOSECOND_PER_MSEC, NANOSECOND_PER_USEC, 1};
|
||||
|
@ -541,12 +532,18 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char
|
|||
time *= factors[fromPrecision];
|
||||
break;
|
||||
default: {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
}
|
||||
if (tmp >= (double)INT64_MAX) return INT64_MAX;
|
||||
if (tmp <= (double)INT64_MIN) return INT64_MIN;
|
||||
return time;
|
||||
if (tmp >= (double)INT64_MAX) {
|
||||
*pRes = INT64_MAX;
|
||||
} else if (tmp <= (double)INT64_MIN) {
|
||||
*pRes = INT64_MIN;
|
||||
} else {
|
||||
*pRes = time;
|
||||
}
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec, int64_t* timeVal) {
|
||||
|
@ -554,62 +551,68 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
|
|||
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);
|
||||
return TSDB_CODE_INVALID_TIMESTAMP;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_TIMESTAMP);
|
||||
}
|
||||
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);
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
newColData[len] = 0;
|
||||
int32_t ret = taosParseTime(newColData, timeVal, len, (int32_t)timePrec, tsDaylight);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(newColData);
|
||||
return ret;
|
||||
TAOS_RETURN(ret);
|
||||
}
|
||||
taosMemoryFree(newColData);
|
||||
} else {
|
||||
return TSDB_CODE_FAILED;
|
||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) {
|
||||
switch (unit) {
|
||||
case 's':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_SECOND) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
(*result) = convertTimePrecision(val * MILLISECOND_PER_SECOND, TSDB_TIME_PRECISION_MILLI, timePrecision);
|
||||
break;
|
||||
case 'm':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_MINUTE) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
(*result) = convertTimePrecision(val * MILLISECOND_PER_MINUTE, TSDB_TIME_PRECISION_MILLI, timePrecision);
|
||||
break;
|
||||
case 'h':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_MINUTE) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
(*result) = convertTimePrecision(val * MILLISECOND_PER_HOUR, TSDB_TIME_PRECISION_MILLI, timePrecision);
|
||||
break;
|
||||
case 'd':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_DAY) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
(*result) = convertTimePrecision(val * MILLISECOND_PER_DAY, TSDB_TIME_PRECISION_MILLI, timePrecision);
|
||||
break;
|
||||
case 'w':
|
||||
if (val > INT64_MAX / MILLISECOND_PER_WEEK) {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
(*result) = convertTimePrecision(val * MILLISECOND_PER_WEEK, TSDB_TIME_PRECISION_MILLI, timePrecision);
|
||||
break;
|
||||
|
@ -623,10 +626,10 @@ int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecisi
|
|||
(*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_NANO, timePrecision);
|
||||
break;
|
||||
default: {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -651,41 +654,40 @@ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* dura
|
|||
/* get the basic numeric value */
|
||||
int64_t timestamp = taosStr2Int64(token, &endPtr, 10);
|
||||
if ((timestamp == 0 && token[0] != '0') || errno != 0) {
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
/* natual month/year are not allowed in absolute duration */
|
||||
*unit = token[tokenlen - 1];
|
||||
if (*unit == 'n' || *unit == 'y') {
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
return getDuration(timestamp, *unit, duration, timePrecision);
|
||||
}
|
||||
|
||||
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision, bool negativeAllow) {
|
||||
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision,
|
||||
bool negativeAllow) {
|
||||
errno = 0;
|
||||
|
||||
/* get the basic numeric value */
|
||||
*duration = taosStr2Int64(token, NULL, 10);
|
||||
if ((*duration < 0 && !negativeAllow) || errno != 0) {
|
||||
return -1;
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
*unit = token[tokenLen - 1];
|
||||
if (*unit == 'n' || *unit == 'y') {
|
||||
return 0;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
if(isdigit(*unit)) {
|
||||
if (isdigit(*unit)) {
|
||||
*unit = getPrecisionUnit(timePrecision);
|
||||
}
|
||||
|
||||
return getDuration(*duration, *unit, duration, timePrecision);
|
||||
}
|
||||
|
||||
static bool taosIsLeapYear(int32_t year) {
|
||||
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
|
||||
}
|
||||
static bool taosIsLeapYear(int32_t year) { return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); }
|
||||
|
||||
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
||||
if (duration == 0) {
|
||||
|
@ -702,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;
|
||||
|
@ -763,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') {
|
||||
|
@ -792,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;
|
||||
|
@ -900,7 +902,8 @@ int64_t taosTimeTruncate(int64_t ts, const SInterval* pInterval) {
|
|||
// used together with taosTimeTruncate. when offset is great than zero, slide-start/slide-end is the anchor point
|
||||
int64_t taosTimeGetIntervalEnd(int64_t intervalStart, const SInterval* pInterval) {
|
||||
if (pInterval->offset > 0) {
|
||||
int64_t slideStart = taosTimeAdd(intervalStart, -1 * pInterval->offset, pInterval->offsetUnit, pInterval->precision);
|
||||
int64_t slideStart =
|
||||
taosTimeAdd(intervalStart, -1 * pInterval->offset, pInterval->offsetUnit, pInterval->precision);
|
||||
int64_t slideEnd = taosTimeAdd(slideStart, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1;
|
||||
int64_t result = taosTimeAdd(slideEnd, pInterval->offset, pInterval->offsetUnit, pInterval->precision);
|
||||
return result;
|
||||
|
@ -960,7 +963,7 @@ const char* fmtts(int64_t ts) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) {
|
||||
int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) {
|
||||
char ts[40] = {0};
|
||||
struct tm ptm;
|
||||
|
||||
|
@ -996,23 +999,26 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision)
|
|||
|
||||
default:
|
||||
fractionLen = 0;
|
||||
return;
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (taosLocalTime(", &ptm, buf) == NULL) {
|
||||
return;
|
||||
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);
|
||||
length += snprintf(ts + length, fractionLen, format, mod);
|
||||
length += (int32_t)strftime(ts + length, 40 - length, "%z", &ptm);
|
||||
|
||||
tstrncpy(buf, ts, bufLen);
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1061,7 @@ typedef enum {
|
|||
TSFKW_Mon,
|
||||
TSFKW_MS,
|
||||
TSFKW_NS,
|
||||
//TSFKW_OF,
|
||||
// TSFKW_OF,
|
||||
TSFKW_PM,
|
||||
TSFKW_P_M,
|
||||
TSFKW_SS,
|
||||
|
@ -1076,7 +1082,7 @@ typedef enum {
|
|||
TSFKW_day,
|
||||
TSFKW_ddd,
|
||||
TSFKW_dd,
|
||||
TSFKW_dy, // mon, tue
|
||||
TSFKW_dy, // mon, tue
|
||||
TSFKW_d,
|
||||
TSFKW_hh24,
|
||||
TSFKW_hh12,
|
||||
|
@ -1246,13 +1252,13 @@ static bool isSeperatorChar(char c) {
|
|||
return (c > 0x20 && c < 0x7F && !(c >= 'A' && c <= 'Z') && !(c >= 'a' && c <= 'z') && !(c >= '0' && c <= '9'));
|
||||
}
|
||||
|
||||
static void parseTsFormat(const char* formatStr, SArray* formats) {
|
||||
static int32_t parseTsFormat(const char* formatStr, SArray* formats) {
|
||||
TSFormatNode* lastOtherFormat = NULL;
|
||||
while (*formatStr) {
|
||||
const TSFormatKeyWord* key = keywordSearch(formatStr);
|
||||
if (key) {
|
||||
TSFormatNode format = {.key = key, .type = TS_FORMAT_NODE_TYPE_KEYWORD};
|
||||
taosArrayPush(formats, &format);
|
||||
if (NULL == taosArrayPush(formats, &format)) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
formatStr += key->len;
|
||||
lastOtherFormat = NULL;
|
||||
} else {
|
||||
|
@ -1268,7 +1274,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) {
|
|||
}
|
||||
if (*formatStr == '\\' && *(formatStr + 1)) {
|
||||
formatStr++;
|
||||
last = NULL; // stop expanding last format, create new format
|
||||
last = NULL; // stop expanding last format, create new format
|
||||
}
|
||||
if (last) {
|
||||
// expand
|
||||
|
@ -1280,7 +1286,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) {
|
|||
TSFormatNode format = {.type = TS_FORMAT_NODE_TYPE_CHAR, .key = NULL};
|
||||
format.c = formatStr;
|
||||
format.len = 1;
|
||||
taosArrayPush(formats, &format);
|
||||
if (NULL == taosArrayPush(formats, &format)) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
formatStr++;
|
||||
last = taosArrayGetLast(formats);
|
||||
}
|
||||
|
@ -1289,7 +1295,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) {
|
|||
// for other strings
|
||||
if (*formatStr == '\\' && *(formatStr + 1)) {
|
||||
formatStr++;
|
||||
lastOtherFormat = NULL; // stop expanding
|
||||
lastOtherFormat = NULL; // stop expanding
|
||||
} else {
|
||||
if (lastOtherFormat && !isSeperatorChar(*formatStr)) {
|
||||
// expanding
|
||||
|
@ -1304,27 +1310,28 @@ static void parseTsFormat(const char* formatStr, SArray* formats) {
|
|||
formatStr++;
|
||||
} else {
|
||||
TSFormatNode format = {
|
||||
.type = isSeperatorChar(*formatStr) ? TS_FORMAT_NODE_TYPE_SEPARATOR : TS_FORMAT_NODE_TYPE_CHAR,
|
||||
.key = NULL};
|
||||
.type = isSeperatorChar(*formatStr) ? TS_FORMAT_NODE_TYPE_SEPARATOR : TS_FORMAT_NODE_TYPE_CHAR,
|
||||
.key = NULL};
|
||||
format.c = formatStr;
|
||||
format.len = 1;
|
||||
taosArrayPush(formats, &format);
|
||||
if (NULL == taosArrayPush(formats, &format)) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
formatStr++;
|
||||
if (format.type == TS_FORMAT_NODE_TYPE_CHAR) lastOtherFormat = taosArrayGetLast(formats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int32_t outLen) {
|
||||
int32_t size = taosArrayGetSize(formats);
|
||||
int32_t size = taosArrayGetSize(formats);
|
||||
const char* start = s;
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
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;
|
||||
}
|
||||
|
@ -1333,37 +1340,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: {
|
||||
|
@ -1371,20 +1378,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;
|
||||
}
|
||||
|
@ -1393,13 +1400,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: {
|
||||
|
@ -1407,33 +1414,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;
|
||||
}
|
||||
|
@ -1441,68 +1448,68 @@ 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:
|
||||
sprintf(s, "%09" PRId64, tm->fsec);
|
||||
(void)sprintf(s, "%09" PRId64, tm->fsec);
|
||||
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:
|
||||
|
@ -1537,7 +1544,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) {
|
||||
|
@ -1916,20 +1923,26 @@ 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));
|
||||
parseTsFormat(format, *formats);
|
||||
if (!*formats){
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseTsFormat(format, *formats));
|
||||
}
|
||||
struct STm tm;
|
||||
taosTs2Tm(ts, precision, &tm);
|
||||
TAOS_CHECK_RETURN(taosTs2Tm(ts, precision, &tm));
|
||||
return tm2char(*formats, &tm, out, outLen);
|
||||
}
|
||||
|
||||
int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision, char* errMsg,
|
||||
int32_t errMsgLen) {
|
||||
int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int64_t* ts, int32_t precision,
|
||||
char* errMsg, int32_t errMsgLen) {
|
||||
const char* sErrPos;
|
||||
int32_t fErrIdx;
|
||||
if (!*formats) {
|
||||
*formats = taosArrayInit(4, sizeof(TSFormatNode));
|
||||
parseTsFormat(format, *formats);
|
||||
if (!*formats) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
TAOS_CHECK_RETURN(parseTsFormat(format, *formats));
|
||||
}
|
||||
int32_t code = char2ts(tsStr, *formats, ts, precision, &sErrPos, &fErrIdx);
|
||||
if (code == -1) {
|
||||
|
@ -1944,27 +1957,35 @@ 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));
|
||||
parseTsFormat(format, formats);
|
||||
if (!formats) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
TAOS_CHECK_RETURN(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) {
|
||||
const char* sErrPos;
|
||||
int32_t fErrIdx;
|
||||
SArray* formats = taosArrayInit(4, sizeof(TSFormatNode));
|
||||
parseTsFormat(format, formats);
|
||||
TAOS_CHECK_RETURN(parseTsFormat(format, formats));
|
||||
int32_t code = char2ts(tsStr, formats, ts, precision, &sErrPos, &fErrIdx);
|
||||
if (code == -1) {
|
||||
printf("failed position: %s\n", sErrPos);
|
||||
printf("failed format: %s\n", ((TSFormatNode*)taosArrayGet(formats, fErrIdx))->key->name);
|
||||
(void)printf("failed position: %s\n", sErrPos);
|
||||
(void)printf("failed format: %s\n", ((TSFormatNode*)taosArrayGet(formats, fErrIdx))->key->name);
|
||||
}
|
||||
taosArrayDestroy(formats);
|
||||
return code;
|
||||
|
@ -1977,6 +1998,7 @@ static int8_t UNIT_INDEX[26] = {/*a*/ 2, 0, -1, 6, -1, -1, -1,
|
|||
|
||||
#define GET_UNIT_INDEX(idx) UNIT_INDEX[(idx) - 97]
|
||||
|
||||
// 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},
|
||||
|
@ -1988,15 +2010,17 @@ static int64_t UNIT_MATRIX[10][11] = { /* ns, us, ms, s, min, h,
|
|||
/*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) {
|
||||
static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx,
|
||||
bool checkEq) {
|
||||
if (UNIT_MATRIX[baseIdx][idx] == -1) return false;
|
||||
if (baseIdx == idx) {
|
||||
if (interval < baseInterval) return false;
|
||||
if (checkEq && interval == baseInterval) return false;
|
||||
return interval % baseInterval == 0;
|
||||
}
|
||||
int8_t next = baseIdx + 1;
|
||||
int8_t next = baseIdx + 1;
|
||||
int64_t val = UNIT_MATRIX[baseIdx][next];
|
||||
while (val != 0 && next <= idx) {
|
||||
if (val == -1) {
|
||||
|
@ -2006,7 +2030,7 @@ static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, in
|
|||
}
|
||||
if (val % baseInterval == 0 || baseInterval % val == 0) {
|
||||
int8_t extra = baseInterval >= val ? 0 : 1;
|
||||
bool needCheckEq = baseInterval >= val && !(baseIdx < next && val == 1);
|
||||
bool needCheckEq = baseInterval >= val && !(baseIdx < next && val == 1);
|
||||
if (!recursiveTsmaCheckRecursive(baseInterval / val + extra, next, interval, idx, needCheckEq && checkEq)) {
|
||||
next++;
|
||||
val = UNIT_MATRIX[baseIdx][next];
|
||||
|
@ -2021,7 +2045,8 @@ static bool recursiveTsmaCheckRecursive(int64_t baseInterval, int8_t baseIdx, in
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx, bool checkEq) {
|
||||
static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t baseIdx, int64_t interval, int8_t idx,
|
||||
bool checkEq) {
|
||||
if (UNIT_MATRIX[baseIdx][idx] == -1) return false;
|
||||
|
||||
if (baseIdx == idx) {
|
||||
|
@ -2030,7 +2055,7 @@ static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t base
|
|||
return interval % baseInterval == 0;
|
||||
}
|
||||
|
||||
int8_t next = baseIdx - 1;
|
||||
int8_t next = baseIdx - 1;
|
||||
int64_t val = UNIT_MATRIX[baseIdx][next];
|
||||
while (val != 0 && next >= 0) {
|
||||
return recursiveTsmaCheckRecursiveReverse(baseInterval * val, next, interval, idx, checkEq);
|
||||
|
@ -2041,18 +2066,27 @@ static bool recursiveTsmaCheckRecursiveReverse(int64_t baseInterval, int8_t base
|
|||
/*
|
||||
* @breif check if tsma with param [interval], [unit] can create based on base tsma with baseInterval and baseUnit
|
||||
* @param baseInterval, baseUnit, interval/unit of base tsma
|
||||
* @param interval the tsma interval going to create. Not that if unit is not calander unit, then interval has already been
|
||||
* translated to TICKS of [precision]
|
||||
* @param interval the tsma interval going to create. Not that if unit is not calander unit, then interval has already
|
||||
* been translated to TICKS of [precision]
|
||||
* @param unit the tsma unit going to create
|
||||
* @param precision the precision of this db
|
||||
* @param checkEq pass true if same interval is not acceptable, false if acceptable.
|
||||
* @ret true the tsma can be created, else cannot
|
||||
* */
|
||||
bool checkRecursiveTsmaInterval(int64_t baseInterval, int8_t baseUnit, int64_t interval, int8_t unit, int8_t precision, bool checkEq) {
|
||||
bool checkRecursiveTsmaInterval(int64_t baseInterval, int8_t baseUnit, int64_t interval, int8_t unit, int8_t precision,
|
||||
bool checkEq) {
|
||||
bool baseIsCalendarDuration = IS_CALENDAR_TIME_DURATION(baseUnit);
|
||||
if (!baseIsCalendarDuration) baseInterval = convertTimeFromPrecisionToUnit(baseInterval, precision, baseUnit);
|
||||
if (!baseIsCalendarDuration) {
|
||||
if (TSDB_CODE_SUCCESS != convertTimeFromPrecisionToUnit(baseInterval, precision, baseUnit, &baseInterval)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool isCalendarDuration = IS_CALENDAR_TIME_DURATION(unit);
|
||||
if (!isCalendarDuration) interval = convertTimeFromPrecisionToUnit(interval, precision, unit);
|
||||
if (!isCalendarDuration) {
|
||||
if (TSDB_CODE_SUCCESS != convertTimeFromPrecisionToUnit(interval, precision, unit, &interval)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool needCheckEq = baseIsCalendarDuration == isCalendarDuration && checkEq;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -175,7 +175,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
|
|||
break;
|
||||
default: {
|
||||
if (len > 0) {
|
||||
memcpy(val, src, len);
|
||||
(void)memcpy(val, src, len);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -426,7 +426,7 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
|
|||
size_t lenInwchar = len / TSDB_NCHAR_SIZE;
|
||||
|
||||
pVar->ucs4 = taosMemoryCalloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE);
|
||||
memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE);
|
||||
(void)memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE);
|
||||
pVar->nLen = (int32_t)len;
|
||||
|
||||
break;
|
||||
|
@ -435,7 +435,7 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
|
|||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
case TSDB_DATA_TYPE_GEOMETRY: { // todo refactor, extract a method
|
||||
pVar->pz = taosMemoryCalloc(len + 1, sizeof(char));
|
||||
memcpy(pVar->pz, pz, len);
|
||||
(void)memcpy(pVar->pz, pz, len);
|
||||
pVar->nLen = (int32_t)len;
|
||||
break;
|
||||
}
|
||||
|
@ -470,10 +470,10 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
|
|||
char *p = taosMemoryRealloc(pDst->pz, len);
|
||||
ASSERT(p);
|
||||
|
||||
memset(p, 0, len);
|
||||
(void)memset(p, 0, len);
|
||||
pDst->pz = p;
|
||||
|
||||
memcpy(pDst->pz, pSrc->pz, pSrc->nLen);
|
||||
(void)memcpy(pDst->pz, pSrc->pz, pSrc->nLen);
|
||||
pDst->nLen = pSrc->nLen;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -732,16 +733,17 @@ TEST(AlreadyAddGroupIdTest, GroupIdAddedWithDifferentLength) {
|
|||
#define SLOW_LOG_TYPE_OTHERS 0x4
|
||||
#define SLOW_LOG_TYPE_ALL 0x7
|
||||
|
||||
static int32_t taosSetSlowLogScope(char *pScope) {
|
||||
if (NULL == pScope || 0 == strlen(pScope)) {
|
||||
return SLOW_LOG_TYPE_QUERY;
|
||||
static int32_t taosSetSlowLogScope(char* pScopeStr, int32_t* pScope) {
|
||||
if (NULL == pScopeStr || 0 == strlen(pScopeStr)) {
|
||||
*pScope = SLOW_LOG_TYPE_QUERY;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t slowScope = 0;
|
||||
|
||||
char* scope = NULL;
|
||||
char *tmp = NULL;
|
||||
while((scope = strsep(&pScope, "|")) != NULL){
|
||||
while((scope = strsep(&pScopeStr, "|")) != NULL){
|
||||
taosMemoryFreeClear(tmp);
|
||||
tmp = taosStrdup(scope);
|
||||
strtrim(tmp);
|
||||
|
@ -771,73 +773,94 @@ static int32_t taosSetSlowLogScope(char *pScope) {
|
|||
}
|
||||
|
||||
taosMemoryFreeClear(tmp);
|
||||
uError("Invalid slowLog scope value:%s", pScope);
|
||||
terrno = TSDB_CODE_INVALID_CFG_VALUE;
|
||||
return -1;
|
||||
uError("Invalid slowLog scope value:%s", pScopeStr);
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG_VALUE);
|
||||
}
|
||||
|
||||
*pScope = slowScope;
|
||||
taosMemoryFreeClear(tmp);
|
||||
return slowScope;
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, NullPointerInput) {
|
||||
char *pScope = NULL;
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
|
||||
char* pScopeStr = NULL;
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, EmptyStringInput) {
|
||||
char pScope[1] = "";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
|
||||
char pScopeStr[1] = "";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, AllScopeInput) {
|
||||
char pScope[] = "all";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_ALL);
|
||||
char pScopeStr[] = "all";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_ALL);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, QueryScopeInput) {
|
||||
char pScope[] = " query";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
|
||||
char pScopeStr[] = " query";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, InsertScopeInput) {
|
||||
char pScope[] = "insert";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_INSERT);
|
||||
char pScopeStr[] = "insert";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_INSERT);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, OthersScopeInput) {
|
||||
char pScope[] = "others";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_OTHERS);
|
||||
char pScopeStr[] = "others";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_OTHERS);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, NoneScopeInput) {
|
||||
char pScope[] = "none";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, SLOW_LOG_TYPE_NULL);
|
||||
char pScopeStr[] = "none";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, SLOW_LOG_TYPE_NULL);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, InvalidScopeInput) {
|
||||
char pScope[] = "invalid";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, -1);
|
||||
char pScopeStr[] = "invalid";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, -1);
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, MixedScopesInput) {
|
||||
char pScope[] = "query|insert|others|none";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
|
||||
char pScopeStr[] = "query|insert|others|none";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
|
||||
}
|
||||
|
||||
TEST(TaosSetSlowLogScopeTest, MixedScopesInputWithSpaces) {
|
||||
char pScope[] = "query | insert | others ";
|
||||
int32_t result = taosSetSlowLogScope(pScope);
|
||||
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
|
||||
char pScopeStr[] = "query | insert | others ";
|
||||
int32_t scope = 0;
|
||||
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
|
||||
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(scope, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
|
@ -74,7 +74,7 @@ static struct {
|
|||
char encryptKey[ENCRYPT_KEY_LEN + 1];
|
||||
} global = {0};
|
||||
|
||||
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { taosSetGlobalDebugFlag(143); }
|
||||
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { (void)taosSetGlobalDebugFlag(143); }
|
||||
static void dmSetAssert(int32_t signum, void *sigInfo, void *context) { tsAssert = 1; }
|
||||
|
||||
static void dmStopDnode(int signum, void *sigInfo, void *context) {
|
||||
|
@ -167,23 +167,23 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("config file path overflow");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-a") == 0) {
|
||||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("apollo url overflow");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-a' requires a parameter\n");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-s") == 0) {
|
||||
global.dumpSdb = true;
|
||||
|
@ -191,31 +191,31 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("env file path overflow");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(global.envFile, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-E' requires a parameter\n");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
global.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-y") == 0) {
|
||||
global.generateCode = true;
|
||||
if(i < argc - 1) {
|
||||
if (i < argc - 1) {
|
||||
int32_t len = strlen(argv[++i]);
|
||||
if (len < ENCRYPT_KEY_LEN_MIN) {
|
||||
printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
if (len > ENCRYPT_KEY_LEN) {
|
||||
printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN);
|
||||
} else {
|
||||
printf("'-y' requires a parameter\n");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
global.dumpConfig = true;
|
||||
|
@ -310,6 +310,7 @@ static void taosCleanupArgs() {
|
|||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
int32_t code = 0;
|
||||
#ifdef TD_JEMALLOC_ENABLED
|
||||
bool jeBackgroundThread = true;
|
||||
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
||||
|
@ -319,10 +320,10 @@ int main(int argc, char const *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dmParseArgs(argc, argv) != 0) {
|
||||
//printf("failed to start since parse args error\n");
|
||||
if ((code = dmParseArgs(argc, argv)) != 0) {
|
||||
// printf("failed to start since parse args error\n");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -335,6 +336,7 @@ int main(int argc, char const *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
int mainWindows(int argc, char **argv) {
|
||||
int32_t code = 0;
|
||||
#endif
|
||||
|
||||
if (global.generateGrant) {
|
||||
|
@ -357,7 +359,7 @@ int mainWindows(int argc, char **argv) {
|
|||
|
||||
#if defined(LINUX)
|
||||
if (global.memDbg) {
|
||||
int32_t code = taosMemoryDbgInit();
|
||||
code = taosMemoryDbgInit();
|
||||
if (code) {
|
||||
printf("failed to init memory dbg, error:%s\n", tstrerror(code));
|
||||
return code;
|
||||
|
@ -366,16 +368,18 @@ int mainWindows(int argc, char **argv) {
|
|||
printf("memory dbg enabled\n");
|
||||
}
|
||||
#endif
|
||||
if(global.generateCode) {
|
||||
if (global.generateCode) {
|
||||
bool toLogFile = false;
|
||||
if(taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs) != 0){
|
||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file");
|
||||
return -1;
|
||||
if ((code = taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs)) != 0) {
|
||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s",
|
||||
tstrerror(code));
|
||||
return code;
|
||||
};
|
||||
|
||||
if(dmCheckRunning(tsDataDir) == NULL) {
|
||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first");
|
||||
return -1;
|
||||
TdFilePtr pFile;
|
||||
if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
|
||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
|
||||
tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
||||
taosCloseLog();
|
||||
|
@ -383,30 +387,30 @@ int mainWindows(int argc, char **argv) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (dmInitLog() != 0) {
|
||||
if ((code = dmInitLog()) != 0) {
|
||||
printf("failed to start since init log error\n");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
dmPrintArgs(argc, argv);
|
||||
|
||||
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||
if ((code = taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0)) != 0) {
|
||||
dError("failed to start since read config error");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (taosConvInit() != 0) {
|
||||
if ((code = taosConvInit()) != 0) {
|
||||
dError("failed to init conv");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (global.checkS3) {
|
||||
int32_t code = dmCheckS3();
|
||||
code = dmCheckS3();
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
|
@ -435,31 +439,32 @@ int mainWindows(int argc, char **argv) {
|
|||
osSetProcPath(argc, (char **)argv);
|
||||
taosCleanupArgs();
|
||||
|
||||
if(dmGetEncryptKey() != 0){
|
||||
if ((code = dmGetEncryptKey()) != 0) {
|
||||
dError("failed to start since failed to get encrypt key");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
};
|
||||
|
||||
if (dmInit() != 0) {
|
||||
if (terrno == TSDB_CODE_NOT_FOUND) {
|
||||
if ((code = dmInit()) != 0) {
|
||||
if (code == TSDB_CODE_NOT_FOUND) {
|
||||
dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support");
|
||||
} else {
|
||||
dError("failed to init dnode since %s", terrstr());
|
||||
dError("failed to init dnode since %s", tstrerror(code));
|
||||
}
|
||||
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosConvDestroy();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
dInfo("start to init service");
|
||||
dmSetSignalHandle();
|
||||
tsDndStart = taosGetTimestampMs();
|
||||
tsDndStartOsUptime = taosGetOsUptime();
|
||||
int32_t code = dmRun();
|
||||
|
||||
code = dmRun();
|
||||
dInfo("shutting down the service");
|
||||
|
||||
dmCleanup();
|
||||
|
|
|
@ -45,7 +45,7 @@ static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) {
|
|||
|
||||
SRetrieveIpWhiteReq req = {.ipWhiteVer = oldVer};
|
||||
int32_t contLen = tSerializeRetrieveIpWhite(NULL, 0, &req);
|
||||
void * pHead = rpcMallocCont(contLen);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeRetrieveIpWhite(pHead, contLen, &req);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead,
|
||||
|
@ -116,7 +116,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
req.clusterCfg.ttlChangeOnWrite = tsTtlChangeOnWrite;
|
||||
req.clusterCfg.enableWhiteList = tsEnableWhiteList ? 1 : 0;
|
||||
req.clusterCfg.encryptionKeyStat = tsEncryptionKeyStat;
|
||||
req.clusterCfg.encryptionKeyChksum = tsEncryptionKeyChksum;
|
||||
req.clusterCfg.encryptionKeyChksum = tsEncryptionKeyChksum;
|
||||
req.clusterCfg.monitorParas.tsEnableMonitor = tsEnableMonitor;
|
||||
req.clusterCfg.monitorParas.tsMonitorInterval = tsMonitorInterval;
|
||||
req.clusterCfg.monitorParas.tsSlowLogScope = tsSlowLogScope;
|
||||
|
@ -146,7 +146,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
req.ipWhiteVer = pMgmt->pData->ipWhiteVer;
|
||||
|
||||
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
|
||||
void * pHead = rpcMallocCont(contLen);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
tFreeSStatusReq(&req);
|
||||
|
||||
|
@ -207,18 +207,26 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDCfgDnodeReq cfgReq = {0};
|
||||
if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
||||
taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
||||
return 0;
|
||||
|
||||
code = cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
||||
if (code != 0) {
|
||||
if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
|
||||
code = 0;
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
||||
}
|
||||
|
||||
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
|
@ -251,7 +259,7 @@ static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
|
|||
pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK;
|
||||
pStatus->details[0] = 0;
|
||||
|
||||
SMonMloadInfo minfo = {0};
|
||||
SMonMloadInfo minfo = {0};
|
||||
(*pMgmt->getMnodeLoadsFp)(&minfo);
|
||||
if (minfo.isMnode &&
|
||||
(minfo.load.syncState == TAOS_SYNC_STATE_ERROR || minfo.load.syncState == TAOS_SYNC_STATE_OFFLINE)) {
|
||||
|
@ -276,32 +284,49 @@ static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
|
|||
}
|
||||
|
||||
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
dDebug("server run status req is received");
|
||||
SServerStatusRsp statusRsp = {0};
|
||||
dmGetServerRunStatus(pMgmt, &statusRsp);
|
||||
|
||||
pMsg->info.rsp = NULL;
|
||||
pMsg->info.rspLen = 0;
|
||||
|
||||
SRpcMsg rspMsg = {.info = pMsg->info};
|
||||
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
|
||||
if (rspLen < 0) {
|
||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// return rspMsg.code;
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// return rspMsg.code;
|
||||
}
|
||||
|
||||
rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
||||
if (rspLen < 0) {
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
||||
pMsg->info.rsp = pRsp;
|
||||
pMsg->info.rspLen = rspLen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSDataBlock *dmBuildVariablesBlock(void) {
|
||||
SSDataBlock * pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
size_t size = 0;
|
||||
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
|
||||
int32_t code = 0;
|
||||
|
||||
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
if (pBlock == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
|
||||
const SSysTableMeta *pMeta = NULL;
|
||||
getInfosDbMeta(&pMeta, &size);
|
||||
|
||||
|
@ -314,52 +339,74 @@ SSDataBlock *dmBuildVariablesBlock(void) {
|
|||
}
|
||||
|
||||
pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
|
||||
if (pBlock->pDataBlock == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
||||
SColumnInfoData colInfoData = {0};
|
||||
colInfoData.info.colId = i + 1;
|
||||
colInfoData.info.type = pMeta[index].schema[i].type;
|
||||
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->info.hasVarCol = true;
|
||||
|
||||
return pBlock;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
blockDataDestroy(pBlock);
|
||||
} else {
|
||||
*ppBlock = pBlock;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
|
||||
/*int32_t code = */dumpConfToDataBlock(pBlock, 1);
|
||||
int32_t code = dumpConfToDataBlock(pBlock, 1);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
||||
if (pColInfo == NULL) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
||||
}
|
||||
|
||||
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
int32_t code = 0;
|
||||
SRetrieveTableReq retrieveReq = {0};
|
||||
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
#if 0
|
||||
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
SSDataBlock *pBlock = dmBuildVariablesBlock();
|
||||
SSDataBlock *pBlock = NULL;
|
||||
if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
||||
code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
||||
if (code != 0) {
|
||||
blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols +
|
||||
|
@ -367,10 +414,10 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to retrieve data since %s", terrstr());
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to retrieve data since %s", tstrerror(code));
|
||||
blockDataDestroy(pBlock);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
char *pStart = pRsp->data;
|
||||
|
@ -404,7 +451,9 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
SArray *dmGetMsgHandles() {
|
||||
int32_t code = -1;
|
||||
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
|
||||
if (pArray == NULL) goto _OVER;
|
||||
if (pArray == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Requests handled by DNODE
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -18,22 +18,23 @@
|
|||
#include "libs/function/tudf.h"
|
||||
|
||||
static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
||||
if (dmStartStatusThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = dmStartStatusThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
#if defined(TD_ENTERPRISE)
|
||||
if (dmStartNotifyThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartNotifyThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
if (dmStartMonitorThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartMonitorThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
if (dmStartAuditThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartAuditThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
if (dmStartCrashReportThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartCrashReportThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -50,10 +51,10 @@ static void dmStopMgmt(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
int32_t code = 0;
|
||||
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -70,12 +71,11 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
|
||||
pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
|
||||
|
||||
// pMgmt->pData->ipWhiteVer = 0;
|
||||
if (dmStartWorker(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartWorker(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (udfStartUdfd(pMgmt->pData->dnodeId) != 0) {
|
||||
if ((code = udfStartUdfd(pMgmt->pData->dnodeId)) != 0) {
|
||||
dError("failed to start udfd");
|
||||
}
|
||||
|
||||
|
|
|
@ -264,12 +264,14 @@ static void *dmCrashReportThreadFp(void *param) {
|
|||
}
|
||||
|
||||
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create status thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create status thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -285,12 +287,14 @@ void dmStopStatusThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create notify thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create notify thread since %s", strerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -308,12 +312,14 @@ void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create monitor thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create monitor thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -322,12 +328,14 @@ int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create audit thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create audit thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -350,6 +358,7 @@ void dmStopAuditThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
if (!tsEnableCrashReport) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -358,8 +367,9 @@ int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
|||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create crashReport thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create crashReport thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -431,8 +441,8 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed in mgmt queue", pMsg);
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
|||
int32_t code = 0;
|
||||
|
||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
||||
if (code < 0) return 0;
|
||||
if (code < 0) return code;
|
||||
tjsonGetInt32ValueFromDouble(pJson, "lastIndex", pOption->lastIndex, code);
|
||||
if (code < 0) return 0;
|
||||
if (code < 0) return code;
|
||||
|
||||
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
||||
if (replicas == NULL) return 0;
|
||||
|
@ -35,17 +35,17 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
|||
|
||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||
SJson *replica = tjsonGetArrayItem(replicas, i);
|
||||
if (replica == NULL) return -1;
|
||||
if (replica == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
|
||||
SReplica *pReplica = pOption->replicas + i;
|
||||
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
|
||||
pOption->numOfReplicas++;
|
||||
}
|
||||
|
@ -63,36 +63,41 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
|||
char *pData = NULL;
|
||||
SJson *pJson = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dInfo("mnode file:%s not exist", file);
|
||||
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pData = taosMemoryMalloc(size + 1);
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, pData, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -100,12 +105,11 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
|||
|
||||
pJson = tjsonParse(pData);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mmDecodeOption(pJson, pOption) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
if ((code = mmDecodeOption(pJson, pOption)) < 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -118,37 +122,42 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
||||
int32_t code = 0;
|
||||
if (pOption->deploy && pOption->numOfTotalReplicas > 0) {
|
||||
if (tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex)) < 0) return code;
|
||||
|
||||
SJson *replicas = tjsonCreateArray();
|
||||
if (replicas == NULL) return -1;
|
||||
if (tjsonAddItemToObject(pJson, "replicas", replicas) < 0) return -1;
|
||||
if (replicas == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if ((code = tjsonAddItemToObject(pJson, "replicas", replicas)) < 0) return code;
|
||||
|
||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||
SJson *replica = tjsonCreateObject();
|
||||
if (replica == NULL) return -1;
|
||||
if (replica == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
const SReplica *pReplica = pOption->replicas + i;
|
||||
if (tjsonAddDoubleToObject(replica, "id", pReplica->id) < 0) return -1;
|
||||
if (tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(replica, "port", pReplica->port) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i]) < 0) return -1;
|
||||
if (tjsonAddItemToArray(replicas, replica) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(replica, "id", pReplica->id)) < 0) return code;
|
||||
if ((code = tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(replica, "port", pReplica->port)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i])) < 0) return code;
|
||||
if ((code = tjsonAddItemToArray(replicas, replica)) < 0) return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex)) < 0) return code;
|
||||
|
||||
if (tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy)) < 0) return code;
|
||||
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||
|
@ -158,28 +167,59 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
|||
TdFilePtr pFile = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
nBytes = snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (mmEncodeOption(pJson, pOption) != 0) goto _OVER;
|
||||
if (pJson == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
TAOS_CHECK_GOTO(mmEncodeOption(pJson, pOption), NULL, _OVER);
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosCloseFile(&pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
||||
|
||||
_OVER:
|
||||
|
@ -188,8 +228,7 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, terrstr(), pOption->deploy);
|
||||
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, tstrerror(code), pOption->deploy);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -26,11 +26,12 @@ void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) {
|
|||
}
|
||||
|
||||
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnodeOpt option = {.deploy = true,
|
||||
|
@ -56,43 +57,45 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
if (option.selfIndex == -1) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to create mnode since %s, selfIndex is -1", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to create mnode since %s, selfIndex is -1", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
||||
dGError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to drop mnode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to drop mnode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnodeOpt option = {.deploy = false};
|
||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
||||
dGError("failed to write mnode file since %s", terrstr());
|
||||
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
SArray *mmGetMsgHandles() {
|
||||
|
|
|
@ -25,9 +25,10 @@ static bool mmDeployRequired(const SMgmtInputOpt *pInput) {
|
|||
}
|
||||
|
||||
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
||||
int32_t code = 0;
|
||||
SMnodeOpt option = {0};
|
||||
if (mmReadFile(pInput->path, &option) != 0) {
|
||||
return -1;
|
||||
if ((code = mmReadFile(pInput->path, &option)) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!option.deploy) {
|
||||
|
@ -41,7 +42,7 @@ static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
|||
dInfo("deploy mnode required. option deploy:%d", option.deploy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
|
||||
|
@ -73,22 +74,31 @@ static void mmClose(SMnodeMgmt *pMgmt) {
|
|||
|
||||
taosMemoryFree(pMgmt);
|
||||
}
|
||||
|
||||
static int32_t mndOpenWrapper(const char *path, SMnodeOpt *opt, SMnode **pMnode) {
|
||||
int32_t code = 0;
|
||||
*pMnode = mndOpen(path, opt);
|
||||
if (*pMnode == NULL) {
|
||||
code = terrno;
|
||||
}
|
||||
///*pMnode = pNode;
|
||||
return code;
|
||||
}
|
||||
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal since %s", terrstr());
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = walInit()) != 0) {
|
||||
dError("failed to init wal since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (syncInit() != 0) {
|
||||
dError("failed to init sync since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = syncInit()) != 0) {
|
||||
dError("failed to init sync since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -100,10 +110,10 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (mmReadFile(pMgmt->path, &option) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
if ((code = mmReadFile(pMgmt->path, &option)) != 0) {
|
||||
dError("failed to read file since %s", tstrerror(code));
|
||||
mmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!option.deploy) {
|
||||
|
@ -115,18 +125,18 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
mmBuildOptionForOpen(pMgmt, &option);
|
||||
}
|
||||
|
||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
code = mndOpenWrapper(pMgmt->path, &option, &pMgmt->pMnode);
|
||||
if (code != 0) {
|
||||
dError("failed to open mnode since %s", tstrerror(code));
|
||||
mmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("mnode-impl", "initialized");
|
||||
|
||||
if (mmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
if ((code = mmStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to start mnode worker since %s", tstrerror(code));
|
||||
mmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("mnode-worker", "initialized");
|
||||
|
||||
|
@ -134,9 +144,9 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
option.deploy = true;
|
||||
option.numOfReplicas = 0;
|
||||
option.numOfTotalReplicas = 0;
|
||||
if (mmWriteFile(pMgmt->path, &option) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = mmWriteFile(pMgmt->path, &option)) != 0) {
|
||||
dError("failed to write mnode file since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,13 +170,9 @@ static void mmStop(SMnodeMgmt *pMgmt) {
|
|||
mndStop(pMgmt->pMnode);
|
||||
}
|
||||
|
||||
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) {
|
||||
return mndIsCatchUp(pMgmt->pMnode);
|
||||
}
|
||||
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) { return mndIsCatchUp(pMgmt->pMnode); }
|
||||
|
||||
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) {
|
||||
return mndGetRole(pMgmt->pMnode);
|
||||
}
|
||||
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) { return mndGetRole(pMgmt->pMnode); }
|
||||
|
||||
SMgmtFunc mmGetMgmtFunc() {
|
||||
SMgmtFunc mgmtFunc = {0};
|
||||
|
|
|
@ -179,13 +179,15 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
pWorker = &pMgmt->syncRdWorker;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
if (pWorker == NULL) return -1;
|
||||
if (pWorker == NULL) return code;
|
||||
|
||||
SRpcMsg *pMsg;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) return code;
|
||||
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
|
@ -201,6 +203,7 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
SSingleWorkerCfg qCfg = {
|
||||
.min = tsNumOfMnodeQueryThreads,
|
||||
.max = tsNumOfMnodeQueryThreads,
|
||||
|
@ -209,9 +212,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) {
|
||||
dError("failed to start mnode-query worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &qCfg)) != 0) {
|
||||
dError("failed to start mnode-query worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg fCfg = {
|
||||
|
@ -221,9 +224,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg) != 0) {
|
||||
dError("failed to start mnode-fetch worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg)) != 0) {
|
||||
dError("failed to start mnode-fetch worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg rCfg = {
|
||||
|
@ -233,9 +236,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->readWorker, &rCfg) != 0) {
|
||||
dError("failed to start mnode-read worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->readWorker, &rCfg)) != 0) {
|
||||
dError("failed to start mnode-read worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg wCfg = {
|
||||
|
@ -245,9 +248,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->writeWorker, &wCfg) != 0) {
|
||||
dError("failed to start mnode-write worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->writeWorker, &wCfg)) != 0) {
|
||||
dError("failed to start mnode-write worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg sCfg = {
|
||||
|
@ -257,9 +260,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessSyncMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) {
|
||||
dError("failed to start mnode mnode-sync worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->syncWorker, &sCfg)) != 0) {
|
||||
dError("failed to start mnode mnode-sync worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg scCfg = {
|
||||
|
@ -269,9 +272,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessSyncMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg) != 0) {
|
||||
dError("failed to start mnode mnode-sync-rd worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg)) != 0) {
|
||||
dError("failed to start mnode mnode-sync-rd worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg arbCfg = {
|
||||
|
@ -281,13 +284,13 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg) != 0) {
|
||||
dError("failed to start mnode mnode-arb worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg)) != 0) {
|
||||
dError("failed to start mnode mnode-arb worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dDebug("mnode workers are initialized");
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
||||
|
|
|
@ -30,24 +30,25 @@ void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) {
|
|||
}
|
||||
|
||||
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDCreateQnodeReq createReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write qnode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
|
@ -55,24 +56,25 @@ int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDDropQnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write qnode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
|
|
|
@ -33,11 +33,15 @@ static void qmClose(SQnodeMgmt *pMgmt) {
|
|||
taosMemoryFree(pMgmt);
|
||||
}
|
||||
|
||||
static int32_t qndOpenWrapper(SQnodeOpt *pOption, SQnode **pQnode) {
|
||||
int32_t code = qndOpen(pOption, pQnode);
|
||||
return code;
|
||||
}
|
||||
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
int32_t code = 0;
|
||||
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -50,29 +54,30 @@ static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
|
||||
SQnodeOpt option = {0};
|
||||
qmInitOption(pMgmt, &option);
|
||||
pMgmt->pQnode = qndOpen(&option);
|
||||
if (pMgmt->pQnode == NULL) {
|
||||
dError("failed to open qnode since %s", terrstr());
|
||||
|
||||
code = qndOpenWrapper(&option, &pMgmt->pQnode);
|
||||
if (code != 0) {
|
||||
dError("failed to open qnode since %s", tstrerror(code));
|
||||
qmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("qnode-impl", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
if ((code = udfcOpen()) != 0) {
|
||||
dError("qnode can not open udfc");
|
||||
qmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (qmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start qnode worker since %s", terrstr());
|
||||
if ((code = qmStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to start qnode worker since %s", tstrerror(code));
|
||||
qmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("qnode-worker", "initialized");
|
||||
|
||||
pOutput->pMgmt = pMgmt;
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMgmtFunc qmGetMgmtFunc() {
|
||||
|
|
|
@ -48,8 +48,8 @@ static int32_t qmPutNodeMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t qmPutNodeMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
qndPreprocessQueryMsg(pMgmt->pQnode, pMsg);
|
||||
|
||||
int32_t code = qndPreprocessQueryMsg(pMgmt->pQnode, pMsg);
|
||||
if (code) return code;
|
||||
return qmPutNodeMsgToWorker(&pMgmt->queryWorker, pMsg);
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,8 @@ int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
}
|
||||
|
||||
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
|
||||
SSingleWorkerCfg queryCfg = {
|
||||
.min = tsNumOfVnodeQueryThreads,
|
||||
.max = tsNumOfVnodeQueryThreads,
|
||||
|
@ -111,9 +113,9 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
|||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||
};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
||||
dError("failed to start qnode-query worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg)) != 0) {
|
||||
dError("failed to start qnode-query worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg fetchCfg = {
|
||||
|
@ -124,13 +126,13 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg) != 0) {
|
||||
dError("failed to start qnode-fetch worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg)) != 0) {
|
||||
dError("failed to start qnode-fetch worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dDebug("qnode workers are initialized");
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void qmStopWorker(SQnodeMgmt *pMgmt) {
|
||||
|
|
|
@ -19,24 +19,25 @@
|
|||
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
|
||||
|
||||
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDCreateSnodeReq createReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write snode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
|
@ -44,24 +45,26 @@ int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDDropSnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write snode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
|
|
|
@ -33,12 +33,19 @@ static void smClose(SSnodeMgmt *pMgmt) {
|
|||
|
||||
taosMemoryFree(pMgmt);
|
||||
}
|
||||
|
||||
int32_t sndOpenWrapper(const char *path, SSnodeOpt *pOption, SSnode **pNode) {
|
||||
*pNode = sndOpen(path, pOption);
|
||||
if (*pNode == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
int32_t code = 0;
|
||||
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -50,35 +57,34 @@ int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
|
||||
SSnodeOpt option = {0};
|
||||
smInitOption(pMgmt, &option);
|
||||
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pSnode == NULL) {
|
||||
dError("failed to open snode since %s", terrstr());
|
||||
|
||||
code = sndOpenWrapper(pMgmt->path, &option, &pMgmt->pSnode);
|
||||
if (code != 0) {
|
||||
dError("failed to open snode since %s", tstrerror(code));
|
||||
smClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tmsgReportStartup("snode-impl", "initialized");
|
||||
|
||||
if (smStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start snode worker since %s", terrstr());
|
||||
if ((code = smStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to start snode worker since %s", tstrerror(code));
|
||||
smClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("snode-worker", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in snode");
|
||||
if ((code = udfcOpen()) != 0) {
|
||||
dError("failed to open udfc in snode since:%s", tstrerror(code));
|
||||
smClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
pOutput->pMgmt = pMgmt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) {
|
||||
return sndInit(pMgmt->pSnode);
|
||||
}
|
||||
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) { return sndInit(pMgmt->pSnode); }
|
||||
|
||||
SMgmtFunc smGetMgmtFunc() {
|
||||
SMgmtFunc mgmtFunc = {0};
|
||||
|
|
|
@ -68,17 +68,18 @@ static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *));
|
||||
if (pMgmt->writeWroker == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) {
|
||||
SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker));
|
||||
if (pWriteWorker == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMultiWorkerCfg cfg = {
|
||||
|
@ -87,13 +88,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
|||
.fp = smProcessWriteQueue,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tMultiWorkerInit(pWriteWorker, &cfg) != 0) {
|
||||
dError("failed to start snode-unique worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tMultiWorkerInit(pWriteWorker, &cfg)) != 0) {
|
||||
dError("failed to start snode-unique worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,13 +106,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) {
|
||||
dError("failed to start snode shared-worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) != 0) {
|
||||
dError("failed to start snode shared-worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dDebug("snode workers are initialized");
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void smStopWorker(SSnodeMgmt *pMgmt) {
|
||||
|
@ -133,17 +134,18 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return code = terrno;
|
||||
}
|
||||
|
||||
SSnode *pSnode = pMgmt->pSnode;
|
||||
if (pSnode == NULL) {
|
||||
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, terrstr(),
|
||||
code = terrno;
|
||||
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, tstrerror(code),
|
||||
TMSG_INFO(pMsg->msgType), qtype, pRpc->contLen);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
|
@ -154,48 +156,44 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
|
||||
switch (qtype) {
|
||||
case STREAM_QUEUE:
|
||||
smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
||||
code = smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
||||
break;
|
||||
case WRITE_QUEUE:
|
||||
smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||
code = smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||
if (pWorker == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||
if (pWorker == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SSingleWorker *pWorker = &pMgmt->streamWorker;
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
}
|
||||
|
|
|
@ -54,24 +54,24 @@ typedef struct {
|
|||
} SWrapperCfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t vgVersion;
|
||||
int32_t refCount;
|
||||
int8_t dropped;
|
||||
int8_t failed;
|
||||
int8_t disable;
|
||||
int32_t diskPrimary;
|
||||
int32_t toVgId;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
SMultiWorker pWriteW;
|
||||
SMultiWorker pSyncW;
|
||||
SMultiWorker pSyncRdW;
|
||||
SMultiWorker pApplyW;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue *pStreamQ;
|
||||
STaosQueue *pFetchQ;
|
||||
STaosQueue *pMultiMgmQ;
|
||||
int32_t vgId;
|
||||
int32_t vgVersion;
|
||||
int32_t refCount;
|
||||
int8_t dropped;
|
||||
int8_t failed;
|
||||
int8_t disable;
|
||||
int32_t diskPrimary;
|
||||
int32_t toVgId;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
SMultiWorker pWriteW;
|
||||
SMultiWorker pSyncW;
|
||||
SMultiWorker pSyncRdW;
|
||||
SMultiWorker pApplyW;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue *pStreamQ;
|
||||
STaosQueue *pFetchQ;
|
||||
STaosQueue *pMultiMgmQ;
|
||||
} SVnodeObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -107,9 +107,9 @@ int32_t vmProcessCheckLearnCatchupReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
|||
int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
|
||||
// vmFile.c
|
||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes);
|
||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
||||
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes);
|
||||
|
||||
// vmWorker.c
|
||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt);
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
|
||||
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
||||
|
||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
||||
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) {
|
||||
taosThreadRwlockRdlock(&pMgmt->lock);
|
||||
|
||||
int32_t num = 0;
|
||||
int32_t size = taosHashGetSize(pMgmt->hash);
|
||||
SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *));
|
||||
if (pVnodes == NULL) {
|
||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -42,8 +46,9 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
|||
|
||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||
*numOfVnodes = num;
|
||||
*ppVnodes = pVnodes;
|
||||
|
||||
return pVnodes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
||||
|
@ -52,29 +57,32 @@ static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **
|
|||
*ppCfgs = NULL;
|
||||
|
||||
SJson *vnodes = tjsonGetObjectItem(pJson, "vnodes");
|
||||
if (vnodes == NULL) return -1;
|
||||
if (vnodes == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
|
||||
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
||||
if (vnodesNum > 0) {
|
||||
pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg));
|
||||
if (pCfgs == NULL) return -1;
|
||||
if (pCfgs == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||
SJson *vnode = tjsonGetArrayItem(vnodes, i);
|
||||
if (vnode == NULL) goto _OVER;
|
||||
if (vnode == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SWrapperCfg *pCfg = &pCfgs[i];
|
||||
tjsonGetInt32ValueFromDouble(vnode, "vgId", pCfg->vgId, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "dropped", pCfg->dropped, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "diskPrimary", pCfg->diskPrimary, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
||||
}
|
||||
|
@ -98,33 +106,35 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
|||
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dInfo("vnode file:%s not exist", file);
|
||||
return 0;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||
code = 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open vnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open vnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pData = taosMemoryMalloc(size + 1);
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, pData, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -132,12 +142,12 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
|||
|
||||
pJson = tjsonParse(pData);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (vmDecodeVnodeList(pJson, pMgmt, ppCfgs, numOfVnodes) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -150,28 +160,36 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
||||
SJson *vnodes = tjsonCreateArray();
|
||||
if (vnodes == NULL) return -1;
|
||||
if (tjsonAddItemToObject(pJson, "vnodes", vnodes) < 0) return -1;
|
||||
int32_t code = 0;
|
||||
SJson *vnodes = tjsonCreateArray();
|
||||
if (vnodes == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if ((code = tjsonAddItemToObject(pJson, "vnodes", vnodes)) < 0) {
|
||||
tjsonDelete(vnodes);
|
||||
return code;
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
SVnodeObj *pVnode = ppVnodes[i];
|
||||
if (pVnode == NULL) continue;
|
||||
|
||||
SJson *vnode = tjsonCreateObject();
|
||||
if (vnode == NULL) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary) < 0) return -1;
|
||||
if (pVnode->toVgId && tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId) < 0) return -1;
|
||||
if (tjsonAddItemToArray(vnodes, vnode) < 0) return -1;
|
||||
if (vnode == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary)) < 0) return code;
|
||||
if (pVnode->toVgId) {
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId)) < 0) return code;
|
||||
}
|
||||
if ((code = tjsonAddItemToArray(vnodes, vnode)) < 0) return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -185,30 +203,60 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
|||
SVnodeObj **ppVnodes = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
nBytes = snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
int32_t numOfVnodes = 0;
|
||||
ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
if (ppVnodes == NULL) goto _OVER;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code) goto _OVER;
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes) != 0) goto _OVER;
|
||||
if (pJson == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
if ((code = vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes)) != 0) goto _OVER;
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
code = taosCloseFile(&pFile);
|
||||
if (code != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
||||
|
@ -228,8 +276,7 @@ _OVER:
|
|||
}
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, terrstr(), numOfVnodes);
|
||||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, tstrerror(code), numOfVnodes);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -256,8 +256,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
char path[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
if (tDeserializeSCreateVnodeReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
if (req.learnerReplica == 0) {
|
||||
|
@ -298,25 +297,24 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
|
||||
strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode", req.vgId, pReplica->id, pReplica->fqdn,
|
||||
pReplica->port);
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode, reason:%s", req.vgId, pReplica->id,
|
||||
pReplica->fqdn, pReplica->port, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (req.encryptAlgorithm == DND_CA_SM4) {
|
||||
if (strlen(tsEncryptKey) == 0) {
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("vgId:%d, failed to create vnode since encrypt key is empty", req.vgId);
|
||||
return -1;
|
||||
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("vgId:%d, failed to create vnode since encrypt key is empty, reason:%s", req.vgId, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
||||
|
||||
if (vmTsmaAdjustDays(&vnodeCfg, &req) < 0) {
|
||||
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, terrstr());
|
||||
code = terrno != 0 ? terrno : -1;
|
||||
if ((code = vmTsmaAdjustDays(&vnodeCfg, &req)) < 0) {
|
||||
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -327,8 +325,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
dError("vgId:%d, already exist", req.vgId);
|
||||
tFreeSCreateVnodeReq(&req);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
terrno = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ int32_t vmGetPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
|||
}
|
||||
|
||||
int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||
int32_t code = 0;
|
||||
STfs *pTfs = pMgmt->pTfs;
|
||||
int32_t diskId = 0;
|
||||
if (!pTfs) {
|
||||
|
@ -59,7 +60,12 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
|||
// alloc
|
||||
int32_t disks[TFS_MAX_DISKS_PER_TIER] = {0};
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
for (int32_t v = 0; v < numOfVnodes; v++) {
|
||||
SVnodeObj *pVnode = ppVnodes[v];
|
||||
disks[pVnode->diskPrimary] += 1;
|
||||
|
@ -436,6 +442,7 @@ static void *vmCloseVnodeInThread(void *param) {
|
|||
}
|
||||
|
||||
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
dInfo("start to close all vnodes");
|
||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||
dInfo("vnodes mgmt worker is stopped");
|
||||
|
@ -443,7 +450,12 @@ static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
|||
dInfo("vnodes multiple mgmt worker is stopped");
|
||||
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
dError("failed to get vnode list since %s", tstrerror(code));
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t threadNum = tsNumOfCores / 2;
|
||||
if (threadNum < 1) threadNum = 1;
|
||||
|
@ -513,8 +525,14 @@ static void vmCleanup(SVnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
static void vmCheckSyncTimeout(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
dError("failed to get vnode list since %s", tstrerror(code));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ppVnodes != NULL) {
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
|
@ -549,12 +567,14 @@ static void *vmThreadFp(void *param) {
|
|||
}
|
||||
|
||||
static int32_t vmInitTimer(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create vnode timer thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create vnode timer thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -573,7 +593,10 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
int32_t code = -1;
|
||||
|
||||
SVnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodeMgmt));
|
||||
if (pMgmt == NULL) goto _OVER;
|
||||
if (pMgmt == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
pMgmt->path = pInput->path;
|
||||
|
@ -582,8 +605,18 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
|
||||
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
|
||||
pMgmt->msgCb.mgmt = pMgmt;
|
||||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||
taosThreadMutexInit(&pMgmt->createLock, NULL);
|
||||
|
||||
code = taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||
if (code != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = taosThreadMutexInit(&pMgmt->createLock, NULL);
|
||||
if (code != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pMgmt->pTfs = pInput->pTfs;
|
||||
if (pMgmt->pTfs == NULL) {
|
||||
|
@ -592,38 +625,39 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
}
|
||||
tmsgReportStartup("vnode-tfs", "initialized");
|
||||
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal since %s", terrstr());
|
||||
if ((code = walInit()) != 0) {
|
||||
dError("failed to init wal since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tmsgReportStartup("vnode-wal", "initialized");
|
||||
|
||||
if (syncInit() != 0) {
|
||||
dError("failed to open sync since %s", terrstr());
|
||||
if ((code = syncInit()) != 0) {
|
||||
dError("failed to open sync since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-sync", "initialized");
|
||||
|
||||
if (vnodeInit(tsNumOfCommitThreads) != 0) {
|
||||
dError("failed to init vnode since %s", terrstr());
|
||||
if ((code = vnodeInit(tsNumOfCommitThreads)) != 0) {
|
||||
dError("failed to init vnode since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-commit", "initialized");
|
||||
|
||||
if (vmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to init workers since %s", terrstr());
|
||||
if ((code = vmStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to init workers since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-worker", "initialized");
|
||||
|
||||
if (vmOpenVnodes(pMgmt) != 0) {
|
||||
dError("failed to open all vnodes since %s", terrstr());
|
||||
if ((code = vmOpenVnodes(pMgmt)) != 0) {
|
||||
dError("failed to open all vnodes since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-vnodes", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in vnode");
|
||||
if ((code = udfcOpen()) != 0) {
|
||||
dError("failed to open udfc in vnode since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -633,7 +667,7 @@ _OVER:
|
|||
if (code == 0) {
|
||||
pOutput->pMgmt = pMgmt;
|
||||
} else {
|
||||
dError("failed to init vnodes-mgmt since %s", terrstr());
|
||||
dError("failed to init vnodes-mgmt since %s", tstrerror(code));
|
||||
vmCleanup(pMgmt);
|
||||
}
|
||||
|
||||
|
@ -683,18 +717,32 @@ static void *vmRestoreVnodeInThread(void *param) {
|
|||
}
|
||||
|
||||
static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
dError("failed to get vnode list since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t threadNum = tsNumOfCores / 2;
|
||||
if (threadNum < 1) threadNum = 1;
|
||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||
|
||||
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
||||
if (threads == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
threads[t].threadIndex = t;
|
||||
threads[t].pMgmt = pMgmt;
|
||||
threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
|
||||
if (threads[t].ppVnodes == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||
|
@ -717,6 +765,7 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
|||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) {
|
||||
dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno));
|
||||
ASSERT(errno == 0);
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -742,6 +791,14 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
return vmInitTimer(pMgmt);
|
||||
|
||||
_exit:
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SVnodeThread *pThread = &threads[t];
|
||||
taosMemoryFree(pThread->ppVnodes);
|
||||
}
|
||||
taosMemoryFree(threads);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void vmStop(SVnodeMgmt *pMgmt) { vmCleanupTimer(pMgmt); }
|
||||
|
|
|
@ -200,26 +200,33 @@ static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
|
||||
*pNode = vmAcquireVnode(pMgt, vgId);
|
||||
if (*pNode == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||
int32_t code = 0;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
if (pMsg->contLen < sizeof(SMsgHead)) {
|
||||
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
||||
pMsg->contLen);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
int32_t code = 0;
|
||||
|
||||
pHead->contLen = ntohl(pHead->contLen);
|
||||
pHead->vgId = ntohl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
SVnodeObj *pVnode = NULL;
|
||||
code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
|
||||
if (code != 0) {
|
||||
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
terrno = (terrno != 0) ? terrno : -1;
|
||||
return terrno;
|
||||
tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
return code;
|
||||
}
|
||||
|
||||
switch (qtype) {
|
||||
|
@ -234,49 +241,45 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
break;
|
||||
case STREAM_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||
code = taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||
break;
|
||||
case FETCH_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||
code = taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||
break;
|
||||
case WRITE_QUEUE:
|
||||
if (!vmDataSpaceSufficient(pVnode)) {
|
||||
terrno = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
||||
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
||||
terrno = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
||||
terrno = TSDB_CODE_VND_STOPPED;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_VND_STOPPED;
|
||||
break;
|
||||
}
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
||||
break;
|
||||
case SYNC_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
||||
break;
|
||||
case SYNC_RD_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
||||
break;
|
||||
case APPLY_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
||||
break;
|
||||
default:
|
||||
code = -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -299,15 +302,13 @@ int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMs
|
|||
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
|
||||
taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
||||
taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
|
@ -317,7 +318,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
pRpc->contLen);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
||||
|
@ -326,7 +327,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
|
@ -383,6 +384,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
}
|
||||
|
||||
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
int32_t code = 0;
|
||||
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
|
||||
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||
|
@ -398,8 +400,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
|
||||
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
|
||||
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
|
||||
|
@ -428,26 +429,27 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
}
|
||||
|
||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
|
||||
pQPool->name = "vnode-query";
|
||||
pQPool->min = tsNumOfVnodeQueryThreads;
|
||||
pQPool->max = tsNumOfVnodeQueryThreads;
|
||||
if (tQueryAutoQWorkerInit(pQPool) != 0) return -1;
|
||||
if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
|
||||
|
||||
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||
pStreamPool->name = "vnode-stream";
|
||||
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
||||
if (tAutoQWorkerInit(pStreamPool) != 0) return -1;
|
||||
if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
|
||||
|
||||
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||
pFPool->name = "vnode-fetch";
|
||||
pFPool->max = tsNumOfVnodeFetchThreads;
|
||||
if (tWWorkerInit(pFPool) != 0) return -1;
|
||||
if ((code = tWWorkerInit(pFPool)) != 0) return code;
|
||||
|
||||
SSingleWorkerCfg mgmtCfg = {
|
||||
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
|
||||
|
||||
int32_t threadNum = 0;
|
||||
if (tsNumOfCores == 1) {
|
||||
|
@ -461,7 +463,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)vmProcessMultiMgmtQueue,
|
||||
.param = pMgmt};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg) != 0) return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
|
||||
|
||||
dDebug("vnode workers are initialized");
|
||||
return 0;
|
||||
|
|
|
@ -98,6 +98,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
|||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||
int32_t dmInitVars(SDnode *pDnode);
|
||||
int32_t dmInitVarsWrapper(SDnode *pDnode);
|
||||
void dmClearVars(SDnode *pDnode);
|
||||
int32_t dmInitModule(SDnode *pDnode);
|
||||
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue