Merge branch '3.0' into cpwu/3.0
This commit is contained in:
commit
0236141480
|
@ -168,13 +168,6 @@ pipeline {
|
|||
stages {
|
||||
stage('run test') {
|
||||
parallel {
|
||||
stage('windows test') {
|
||||
agent {label " windows11 "}
|
||||
steps {
|
||||
pre_test_win()
|
||||
pre_test_build_win()
|
||||
}
|
||||
}
|
||||
stage('linux test') {
|
||||
agent{label " slave3_0 || slave15 || slave16 || slave17 "}
|
||||
options { skipDefaultCheckout() }
|
||||
|
|
|
@ -62,7 +62,7 @@ ELSE ()
|
|||
MESSAGE(STATUS "Will compile with Address Sanitizer!")
|
||||
ELSE ()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-literal-suffix -Werror=return-type -fpermissive -fPIC -gdwarf-2 -g3")
|
||||
ENDIF ()
|
||||
|
||||
MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
|
|
@ -81,10 +81,10 @@ int32_t create_stream() {
|
|||
/*const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1";*/
|
||||
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
|
||||
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
||||
pRes =
|
||||
taos_query(pConn,
|
||||
"create stream stream1 trigger window_close as select _wstartts, min(k), max(k), sum(k) as sum_of_k "
|
||||
"from tu1 interval(10m)");
|
||||
pRes = taos_query(
|
||||
pConn,
|
||||
"create stream stream1 trigger window_close into outstb as select _wstartts, min(k), max(k), sum(k) as sum_of_k "
|
||||
"from tu1 interval(10m)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
|
|
@ -45,6 +45,12 @@ enum {
|
|||
STREAM_TRIGGER__BY_EVENT_TIME,
|
||||
};
|
||||
|
||||
typedef enum EStreamType {
|
||||
STREAM_NORMAL = 1,
|
||||
STREAM_INVERT,
|
||||
STREAM_INVALID,
|
||||
} EStreamType;
|
||||
|
||||
typedef struct {
|
||||
uint32_t numOfTables;
|
||||
SArray* pGroupList;
|
||||
|
@ -71,6 +77,7 @@ typedef struct SDataBlockInfo {
|
|||
int16_t numOfCols;
|
||||
int16_t hasVarCol;
|
||||
int32_t capacity;
|
||||
EStreamType type;
|
||||
} SDataBlockInfo;
|
||||
|
||||
typedef struct SSDataBlock {
|
||||
|
@ -115,8 +122,6 @@ void* tDecodeDataBlocks(const void* buf, SArray** blocks);
|
|||
void colDataDestroy(SColumnInfoData* pColData);
|
||||
|
||||
static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) {
|
||||
// WARNING: do not use info.numOfCols,
|
||||
// sometimes info.numOfCols != array size
|
||||
int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock);
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
@ -194,6 +199,21 @@ typedef struct SExprInfo {
|
|||
struct tExprNode* pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
typedef struct {
|
||||
const char* key;
|
||||
int32_t keyLen;
|
||||
uint8_t type;
|
||||
int16_t length;
|
||||
union{
|
||||
const char* value;
|
||||
int64_t i;
|
||||
uint64_t u;
|
||||
double d;
|
||||
float f;
|
||||
};
|
||||
int32_t valueLen;
|
||||
} SSmlKv;
|
||||
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
#define QUERY_DESC_FORWARD_STEP -1
|
||||
|
||||
|
|
|
@ -372,10 +372,9 @@ static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSche
|
|||
// ----------------- Data column structure
|
||||
// SDataCol arrangement: data => bitmap => dataOffset
|
||||
typedef struct SDataCol {
|
||||
int8_t type; // column type
|
||||
uint8_t bitmap : 1; // 0: no bitmap if all rows are NORM, 1: has bitmap if has NULL/NORM rows
|
||||
uint8_t bitmapMode : 1; // default is 0(2 bits), otherwise 1(1 bit)
|
||||
uint8_t reserve : 6;
|
||||
int8_t type; // column type
|
||||
uint8_t bitmap : 1; // 0: no bitmap if all rows are NORM, 1: has bitmap if has NULL/NORM rows
|
||||
uint8_t reserve : 7;
|
||||
int16_t colId; // column ID
|
||||
int32_t bytes; // column data bytes defined
|
||||
int32_t offset; // data offset in a SDataRow (including the header size)
|
||||
|
@ -387,8 +386,6 @@ typedef struct SDataCol {
|
|||
TSKEY ts; // only used in last NULL column
|
||||
} SDataCol;
|
||||
|
||||
|
||||
|
||||
#define isAllRowsNull(pCol) ((pCol)->len == 0)
|
||||
#define isAllRowsNone(pCol) ((pCol)->len == 0)
|
||||
static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
|
||||
|
@ -482,7 +479,7 @@ void tdResetDataCols(SDataCols *pCols);
|
|||
int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
|
||||
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
|
||||
SDataCols *tdFreeDataCols(SDataCols *pCols);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull, TDRowVerT maxVer);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool update, TDRowVerT maxVer);
|
||||
|
||||
// ----------------- K-V data row structure
|
||||
/* |<-------------------------------------- len -------------------------------------------->|
|
||||
|
|
|
@ -135,6 +135,8 @@ typedef enum _mgmt_table {
|
|||
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x6
|
||||
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x7
|
||||
#define TSDB_ALTER_USER_CLEAR_WRITE_DB 0x8
|
||||
#define TSDB_ALTER_USER_ADD_ALL_DB 0x9
|
||||
#define TSDB_ALTER_USER_REMOVE_ALL_DB 0xA
|
||||
|
||||
#define TSDB_ALTER_USER_PRIVILEGES 0x2
|
||||
|
||||
|
@ -326,11 +328,11 @@ typedef struct {
|
|||
int8_t alterType;
|
||||
int32_t numOfFields;
|
||||
SArray* pFields;
|
||||
} SMAltertbReq;
|
||||
} SMAlterStbReq;
|
||||
|
||||
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAltertbReq* pReq);
|
||||
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAltertbReq* pReq);
|
||||
void tFreeSMAltertbReq(SMAltertbReq* pReq);
|
||||
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
|
||||
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
|
||||
void tFreeSMAltertbReq(SMAlterStbReq* pReq);
|
||||
|
||||
typedef struct SEpSet {
|
||||
int8_t inUse;
|
||||
|
@ -338,8 +340,8 @@ typedef struct SEpSet {
|
|||
SEp eps[TSDB_MAX_REPLICA];
|
||||
} SEpSet;
|
||||
|
||||
int32_t tEncodeSEpSet(SCoder* pEncoder, const SEpSet* pEp);
|
||||
int32_t tDecodeSEpSet(SCoder* pDecoder, SEpSet* pEp);
|
||||
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
|
||||
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
|
||||
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
|
||||
void* taosDecodeSEpSet(const void* buf, SEpSet* pEp);
|
||||
|
||||
|
@ -611,8 +613,8 @@ typedef struct {
|
|||
|
||||
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
|
||||
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
|
||||
int32_t tSerializeSUseDbRspImp(SCoder* pEncoder, const SUseDbRsp* pRsp);
|
||||
int32_t tDeserializeSUseDbRspImp(SCoder* pDecoder, SUseDbRsp* pRsp);
|
||||
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
|
||||
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
|
||||
void tFreeSUsedbRsp(SUseDbRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
|
@ -672,7 +674,6 @@ typedef struct {
|
|||
SArray* pArray; // Array of SUseDbRsp
|
||||
} SUseDbBatchRsp;
|
||||
|
||||
|
||||
int32_t tSerializeSUseDbBatchRsp(void* buf, int32_t bufLen, SUseDbBatchRsp* pRsp);
|
||||
int32_t tDeserializeSUseDbBatchRsp(void* buf, int32_t bufLen, SUseDbBatchRsp* pRsp);
|
||||
void tFreeSUseDbBatchRsp(SUseDbBatchRsp* pRsp);
|
||||
|
@ -685,7 +686,6 @@ int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp
|
|||
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
|
||||
void tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
|
||||
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
} SCompactDbReq;
|
||||
|
@ -1529,8 +1529,8 @@ typedef struct {
|
|||
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||
} SRSmaParam;
|
||||
|
||||
int32_t tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam);
|
||||
int32_t tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam);
|
||||
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
|
||||
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
|
||||
|
||||
// TDMT_VND_CREATE_STB ==============
|
||||
typedef struct SVCreateStbReq {
|
||||
|
@ -1542,8 +1542,8 @@ typedef struct SVCreateStbReq {
|
|||
SRSmaParam pRSmaParam;
|
||||
} SVCreateStbReq;
|
||||
|
||||
int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq);
|
||||
int tDecodeSVCreateStbReq(SCoder* pCoder, SVCreateStbReq* pReq);
|
||||
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
|
||||
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
|
||||
|
||||
// TDMT_VND_DROP_STB ==============
|
||||
typedef struct SVDropStbReq {
|
||||
|
@ -1551,10 +1551,12 @@ typedef struct SVDropStbReq {
|
|||
tb_uid_t suid;
|
||||
} SVDropStbReq;
|
||||
|
||||
int32_t tEncodeSVDropStbReq(SCoder* pCoder, const SVDropStbReq* pReq);
|
||||
int32_t tDecodeSVDropStbReq(SCoder* pCoder, SVDropStbReq* pReq);
|
||||
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
|
||||
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
|
||||
|
||||
#define TD_CREATE_IF_NOT_EXISTS 0x1
|
||||
typedef struct SVCreateTbReq {
|
||||
int32_t flags;
|
||||
tb_uid_t uid;
|
||||
int64_t ctime;
|
||||
const char* name;
|
||||
|
@ -1562,8 +1564,8 @@ typedef struct SVCreateTbReq {
|
|||
int8_t type;
|
||||
union {
|
||||
struct {
|
||||
tb_uid_t suid;
|
||||
const void* pTag;
|
||||
tb_uid_t suid;
|
||||
const uint8_t* pTag;
|
||||
} ctb;
|
||||
struct {
|
||||
SSchemaWrapper schema;
|
||||
|
@ -1571,8 +1573,8 @@ typedef struct SVCreateTbReq {
|
|||
};
|
||||
} SVCreateTbReq;
|
||||
|
||||
int tEncodeSVCreateTbReq(SCoder* pCoder, const SVCreateTbReq* pReq);
|
||||
int tDecodeSVCreateTbReq(SCoder* pCoder, SVCreateTbReq* pReq);
|
||||
int tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
|
||||
int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t nReqs;
|
||||
|
@ -1582,15 +1584,15 @@ typedef struct {
|
|||
};
|
||||
} SVCreateTbBatchReq;
|
||||
|
||||
int tEncodeSVCreateTbBatchReq(SCoder* pCoder, const SVCreateTbBatchReq* pReq);
|
||||
int tDecodeSVCreateTbBatchReq(SCoder* pCoder, SVCreateTbBatchReq* pReq);
|
||||
int tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
|
||||
int tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
} SVCreateTbRsp, SVUpdateTbRsp;
|
||||
|
||||
int tEncodeSVCreateTbRsp(SCoder* pCoder, const SVCreateTbRsp* pRsp);
|
||||
int tDecodeSVCreateTbRsp(SCoder* pCoder, SVCreateTbRsp* pRsp);
|
||||
int tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
|
||||
int tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
|
||||
|
||||
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
|
||||
void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
|
||||
|
@ -1603,8 +1605,8 @@ typedef struct {
|
|||
};
|
||||
} SVCreateTbBatchRsp;
|
||||
|
||||
int tEncodeSVCreateTbBatchRsp(SCoder* pCoder, const SVCreateTbBatchRsp* pRsp);
|
||||
int tDecodeSVCreateTbBatchRsp(SCoder* pCoder, SVCreateTbBatchRsp* pRsp);
|
||||
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
|
||||
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
|
||||
|
||||
int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
|
||||
int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
|
||||
|
@ -1627,8 +1629,8 @@ typedef struct {
|
|||
};
|
||||
} SVDropTbBatchReq;
|
||||
|
||||
int32_t tEncodeSVDropTbBatchReq(SCoder* pCoder, const SVDropTbBatchReq* pReq);
|
||||
int32_t tDecodeSVDropTbBatchReq(SCoder* pCoder, SVDropTbBatchReq* pReq);
|
||||
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
|
||||
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t nRsps;
|
||||
|
@ -1638,8 +1640,8 @@ typedef struct {
|
|||
};
|
||||
} SVDropTbBatchRsp;
|
||||
|
||||
int32_t tEncodeSVDropTbBatchRsp(SCoder* pCoder, const SVDropTbBatchRsp* pRsp);
|
||||
int32_t tDecodeSVDropTbBatchRsp(SCoder* pCoder, SVDropTbBatchRsp* pRsp);
|
||||
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
|
||||
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
|
@ -1821,14 +1823,14 @@ static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
|
|||
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
|
||||
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSKv(SCoder* pEncoder, const SKv* pKv) {
|
||||
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, (const char*)pKv->value, pKv->valueLen) < 0) return -1;
|
||||
if (tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSKv(SCoder* pDecoder, SKv* pKv) {
|
||||
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;
|
||||
pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
|
||||
|
@ -1837,13 +1839,13 @@ static FORCE_INLINE int32_t tDecodeSKv(SCoder* pDecoder, SKv* pKv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSClientHbKey(SCoder* pEncoder, const SClientHbKey* pKey) {
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSClientHbKey(SCoder* pDecoder, SClientHbKey* pKey) {
|
||||
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;
|
||||
return 0;
|
||||
|
@ -2046,10 +2048,10 @@ typedef struct {
|
|||
int32_t reserved;
|
||||
} SMqCMCommitOffsetRsp;
|
||||
|
||||
int32_t tEncodeSMqOffset(SCoder* encoder, const SMqOffset* pOffset);
|
||||
int32_t tDecodeSMqOffset(SCoder* decoder, SMqOffset* pOffset);
|
||||
int32_t tEncodeSMqCMCommitOffsetReq(SCoder* encoder, const SMqCMCommitOffsetReq* pReq);
|
||||
int32_t tDecodeSMqCMCommitOffsetReq(SCoder* decoder, SMqCMCommitOffsetReq* pReq);
|
||||
int32_t tEncodeSMqOffset(SEncoder* encoder, const SMqOffset* pOffset);
|
||||
int32_t tDecodeSMqOffset(SDecoder* decoder, SMqOffset* pOffset);
|
||||
int32_t tEncodeSMqCMCommitOffsetReq(SEncoder* encoder, const SMqCMCommitOffsetReq* pReq);
|
||||
int32_t tDecodeSMqCMCommitOffsetReq(SDecoder* decoder, SMqCMCommitOffsetReq* pReq);
|
||||
|
||||
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||
|
@ -2089,7 +2091,7 @@ static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
|
|||
return (void*)buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const 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;
|
||||
|
@ -2098,7 +2100,7 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) {
|
||||
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;
|
||||
|
@ -2131,7 +2133,7 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapp
|
|||
return (void*)buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
if (tEncodeI32v(pEncoder, pSW->nCols) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pSW->sver) < 0) return -1;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
|
@ -2141,7 +2143,7 @@ static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchem
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
if (tDecodeI32v(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSW->sver) < 0) return -1;
|
||||
|
||||
|
@ -2593,12 +2595,12 @@ static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
|
|||
|
||||
#define TD_AUTO_CREATE_TABLE 0x1
|
||||
typedef struct {
|
||||
int64_t suid;
|
||||
int64_t uid;
|
||||
int32_t sver;
|
||||
uint64_t nData;
|
||||
const void* pData;
|
||||
SVCreateTbReq cTbReq;
|
||||
int64_t suid;
|
||||
int64_t uid;
|
||||
int32_t sver;
|
||||
uint32_t nData;
|
||||
const uint8_t* pData;
|
||||
SVCreateTbReq cTbReq;
|
||||
} SVSubmitBlk;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2610,8 +2612,8 @@ typedef struct {
|
|||
};
|
||||
} SVSubmitReq;
|
||||
|
||||
int32_t tEncodeSVSubmitReq(SCoder* pCoder, const SVSubmitReq* pReq);
|
||||
int32_t tDecodeSVSubmitReq(SCoder* pCoder, SVSubmitReq* pReq);
|
||||
int32_t tEncodeSVSubmitReq(SEncoder* pCoder, const SVSubmitReq* pReq);
|
||||
int32_t tDecodeSVSubmitReq(SDecoder* pCoder, SVSubmitReq* pReq);
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
* @brief value type
|
||||
* - for data from client input and STSRow in memory, 3 types of value none/null/norm available
|
||||
*/
|
||||
#define TD_VTYPE_NORM 0x00U // normal val: not none, not null(no need assign value)
|
||||
#define TD_VTYPE_NORM 0x00U // normal val: not none, not null
|
||||
#define TD_VTYPE_NULL 0x01U // null val
|
||||
#define TD_VTYPE_NONE 0x02U // none or unknown/undefined
|
||||
#define TD_VTYPE_MAX 0x03U //
|
||||
|
@ -140,8 +140,6 @@ typedef struct {
|
|||
};
|
||||
/// row total length
|
||||
uint32_t len;
|
||||
/// row version
|
||||
uint64_t ver;
|
||||
/// the inline data, maybe a tuple or a k-v tuple
|
||||
char data[];
|
||||
} STSRow;
|
||||
|
@ -176,7 +174,7 @@ typedef struct {
|
|||
#define TD_ROW_DATA(r) ((r)->data)
|
||||
#define TD_ROW_LEN(r) ((r)->len)
|
||||
#define TD_ROW_KEY(r) ((r)->ts)
|
||||
#define TD_ROW_VER(r) ((r)->ver)
|
||||
// #define TD_ROW_VER(r) ((r)->ver)
|
||||
#define TD_ROW_KEY_ADDR(r) (r)
|
||||
|
||||
// N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and
|
||||
|
@ -241,13 +239,13 @@ static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colI
|
|||
static FORCE_INLINE bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode);
|
||||
bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode);
|
||||
int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t maxPoints,
|
||||
int8_t bitmapMode);
|
||||
int8_t bitmapMode, bool isMerge);
|
||||
static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val,
|
||||
bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset);
|
||||
static FORCE_INLINE 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);
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols);
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
@ -718,6 +716,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,201 +51,208 @@
|
|||
#define TK_USER 33
|
||||
#define TK_PRIVILEGE 34
|
||||
#define TK_DROP 35
|
||||
#define TK_DNODE 36
|
||||
#define TK_PORT 37
|
||||
#define TK_NK_INTEGER 38
|
||||
#define TK_DNODES 39
|
||||
#define TK_NK_IPTOKEN 40
|
||||
#define TK_LOCAL 41
|
||||
#define TK_QNODE 42
|
||||
#define TK_ON 43
|
||||
#define TK_BNODE 44
|
||||
#define TK_SNODE 45
|
||||
#define TK_MNODE 46
|
||||
#define TK_DATABASE 47
|
||||
#define TK_USE 48
|
||||
#define TK_IF 49
|
||||
#define TK_NOT 50
|
||||
#define TK_EXISTS 51
|
||||
#define TK_BUFFER 52
|
||||
#define TK_CACHELAST 53
|
||||
#define TK_COMP 54
|
||||
#define TK_DAYS 55
|
||||
#define TK_NK_VARIABLE 56
|
||||
#define TK_FSYNC 57
|
||||
#define TK_MAXROWS 58
|
||||
#define TK_MINROWS 59
|
||||
#define TK_KEEP 60
|
||||
#define TK_PAGES 61
|
||||
#define TK_PAGESIZE 62
|
||||
#define TK_PRECISION 63
|
||||
#define TK_REPLICA 64
|
||||
#define TK_STRICT 65
|
||||
#define TK_WAL 66
|
||||
#define TK_VGROUPS 67
|
||||
#define TK_SINGLE_STABLE 68
|
||||
#define TK_RETENTIONS 69
|
||||
#define TK_NK_COMMA 70
|
||||
#define TK_NK_COLON 71
|
||||
#define TK_TABLE 72
|
||||
#define TK_NK_LP 73
|
||||
#define TK_NK_RP 74
|
||||
#define TK_STABLE 75
|
||||
#define TK_ADD 76
|
||||
#define TK_COLUMN 77
|
||||
#define TK_MODIFY 78
|
||||
#define TK_RENAME 79
|
||||
#define TK_TAG 80
|
||||
#define TK_SET 81
|
||||
#define TK_NK_EQ 82
|
||||
#define TK_USING 83
|
||||
#define TK_TAGS 84
|
||||
#define TK_NK_DOT 85
|
||||
#define TK_COMMENT 86
|
||||
#define TK_BOOL 87
|
||||
#define TK_TINYINT 88
|
||||
#define TK_SMALLINT 89
|
||||
#define TK_INT 90
|
||||
#define TK_INTEGER 91
|
||||
#define TK_BIGINT 92
|
||||
#define TK_FLOAT 93
|
||||
#define TK_DOUBLE 94
|
||||
#define TK_BINARY 95
|
||||
#define TK_TIMESTAMP 96
|
||||
#define TK_NCHAR 97
|
||||
#define TK_UNSIGNED 98
|
||||
#define TK_JSON 99
|
||||
#define TK_VARCHAR 100
|
||||
#define TK_MEDIUMBLOB 101
|
||||
#define TK_BLOB 102
|
||||
#define TK_VARBINARY 103
|
||||
#define TK_DECIMAL 104
|
||||
#define TK_DELAY 105
|
||||
#define TK_FILE_FACTOR 106
|
||||
#define TK_NK_FLOAT 107
|
||||
#define TK_ROLLUP 108
|
||||
#define TK_TTL 109
|
||||
#define TK_SMA 110
|
||||
#define TK_SHOW 111
|
||||
#define TK_DATABASES 112
|
||||
#define TK_TABLES 113
|
||||
#define TK_STABLES 114
|
||||
#define TK_MNODES 115
|
||||
#define TK_MODULES 116
|
||||
#define TK_QNODES 117
|
||||
#define TK_FUNCTIONS 118
|
||||
#define TK_INDEXES 119
|
||||
#define TK_FROM 120
|
||||
#define TK_ACCOUNTS 121
|
||||
#define TK_APPS 122
|
||||
#define TK_CONNECTIONS 123
|
||||
#define TK_LICENCE 124
|
||||
#define TK_GRANTS 125
|
||||
#define TK_QUERIES 126
|
||||
#define TK_SCORES 127
|
||||
#define TK_TOPICS 128
|
||||
#define TK_VARIABLES 129
|
||||
#define TK_BNODES 130
|
||||
#define TK_SNODES 131
|
||||
#define TK_CLUSTER 132
|
||||
#define TK_LIKE 133
|
||||
#define TK_INDEX 134
|
||||
#define TK_FULLTEXT 135
|
||||
#define TK_FUNCTION 136
|
||||
#define TK_INTERVAL 137
|
||||
#define TK_TOPIC 138
|
||||
#define TK_AS 139
|
||||
#define TK_WITH 140
|
||||
#define TK_SCHEMA 141
|
||||
#define TK_DESC 142
|
||||
#define TK_DESCRIBE 143
|
||||
#define TK_RESET 144
|
||||
#define TK_QUERY 145
|
||||
#define TK_CACHE 146
|
||||
#define TK_EXPLAIN 147
|
||||
#define TK_ANALYZE 148
|
||||
#define TK_VERBOSE 149
|
||||
#define TK_NK_BOOL 150
|
||||
#define TK_RATIO 151
|
||||
#define TK_COMPACT 152
|
||||
#define TK_VNODES 153
|
||||
#define TK_IN 154
|
||||
#define TK_OUTPUTTYPE 155
|
||||
#define TK_AGGREGATE 156
|
||||
#define TK_BUFSIZE 157
|
||||
#define TK_STREAM 158
|
||||
#define TK_INTO 159
|
||||
#define TK_TRIGGER 160
|
||||
#define TK_AT_ONCE 161
|
||||
#define TK_WINDOW_CLOSE 162
|
||||
#define TK_WATERMARK 163
|
||||
#define TK_KILL 164
|
||||
#define TK_CONNECTION 165
|
||||
#define TK_MERGE 166
|
||||
#define TK_VGROUP 167
|
||||
#define TK_REDISTRIBUTE 168
|
||||
#define TK_SPLIT 169
|
||||
#define TK_SYNCDB 170
|
||||
#define TK_NULL 171
|
||||
#define TK_NK_QUESTION 172
|
||||
#define TK_NK_ARROW 173
|
||||
#define TK_ROWTS 174
|
||||
#define TK_TBNAME 175
|
||||
#define TK_QSTARTTS 176
|
||||
#define TK_QENDTS 177
|
||||
#define TK_WSTARTTS 178
|
||||
#define TK_WENDTS 179
|
||||
#define TK_WDURATION 180
|
||||
#define TK_CAST 181
|
||||
#define TK_NOW 182
|
||||
#define TK_TODAY 183
|
||||
#define TK_TIMEZONE 184
|
||||
#define TK_COUNT 185
|
||||
#define TK_FIRST 186
|
||||
#define TK_LAST 187
|
||||
#define TK_LAST_ROW 188
|
||||
#define TK_BETWEEN 189
|
||||
#define TK_IS 190
|
||||
#define TK_NK_LT 191
|
||||
#define TK_NK_GT 192
|
||||
#define TK_NK_LE 193
|
||||
#define TK_NK_GE 194
|
||||
#define TK_NK_NE 195
|
||||
#define TK_MATCH 196
|
||||
#define TK_NMATCH 197
|
||||
#define TK_CONTAINS 198
|
||||
#define TK_JOIN 199
|
||||
#define TK_INNER 200
|
||||
#define TK_SELECT 201
|
||||
#define TK_DISTINCT 202
|
||||
#define TK_WHERE 203
|
||||
#define TK_PARTITION 204
|
||||
#define TK_BY 205
|
||||
#define TK_SESSION 206
|
||||
#define TK_STATE_WINDOW 207
|
||||
#define TK_SLIDING 208
|
||||
#define TK_FILL 209
|
||||
#define TK_VALUE 210
|
||||
#define TK_NONE 211
|
||||
#define TK_PREV 212
|
||||
#define TK_LINEAR 213
|
||||
#define TK_NEXT 214
|
||||
#define TK_GROUP 215
|
||||
#define TK_HAVING 216
|
||||
#define TK_ORDER 217
|
||||
#define TK_SLIMIT 218
|
||||
#define TK_SOFFSET 219
|
||||
#define TK_LIMIT 220
|
||||
#define TK_OFFSET 221
|
||||
#define TK_ASC 222
|
||||
#define TK_NULLS 223
|
||||
#define TK_ID 224
|
||||
#define TK_NK_BITNOT 225
|
||||
#define TK_INSERT 226
|
||||
#define TK_VALUES 227
|
||||
#define TK_IMPORT 228
|
||||
#define TK_NK_SEMI 229
|
||||
#define TK_FILE 230
|
||||
#define TK_GRANT 36
|
||||
#define TK_ON 37
|
||||
#define TK_TO 38
|
||||
#define TK_REVOKE 39
|
||||
#define TK_FROM 40
|
||||
#define TK_NK_COMMA 41
|
||||
#define TK_READ 42
|
||||
#define TK_WRITE 43
|
||||
#define TK_NK_DOT 44
|
||||
#define TK_DNODE 45
|
||||
#define TK_PORT 46
|
||||
#define TK_NK_INTEGER 47
|
||||
#define TK_DNODES 48
|
||||
#define TK_NK_IPTOKEN 49
|
||||
#define TK_LOCAL 50
|
||||
#define TK_QNODE 51
|
||||
#define TK_BNODE 52
|
||||
#define TK_SNODE 53
|
||||
#define TK_MNODE 54
|
||||
#define TK_DATABASE 55
|
||||
#define TK_USE 56
|
||||
#define TK_IF 57
|
||||
#define TK_NOT 58
|
||||
#define TK_EXISTS 59
|
||||
#define TK_BUFFER 60
|
||||
#define TK_CACHELAST 61
|
||||
#define TK_COMP 62
|
||||
#define TK_DAYS 63
|
||||
#define TK_NK_VARIABLE 64
|
||||
#define TK_FSYNC 65
|
||||
#define TK_MAXROWS 66
|
||||
#define TK_MINROWS 67
|
||||
#define TK_KEEP 68
|
||||
#define TK_PAGES 69
|
||||
#define TK_PAGESIZE 70
|
||||
#define TK_PRECISION 71
|
||||
#define TK_REPLICA 72
|
||||
#define TK_STRICT 73
|
||||
#define TK_WAL 74
|
||||
#define TK_VGROUPS 75
|
||||
#define TK_SINGLE_STABLE 76
|
||||
#define TK_RETENTIONS 77
|
||||
#define TK_NK_COLON 78
|
||||
#define TK_TABLE 79
|
||||
#define TK_NK_LP 80
|
||||
#define TK_NK_RP 81
|
||||
#define TK_STABLE 82
|
||||
#define TK_ADD 83
|
||||
#define TK_COLUMN 84
|
||||
#define TK_MODIFY 85
|
||||
#define TK_RENAME 86
|
||||
#define TK_TAG 87
|
||||
#define TK_SET 88
|
||||
#define TK_NK_EQ 89
|
||||
#define TK_USING 90
|
||||
#define TK_TAGS 91
|
||||
#define TK_COMMENT 92
|
||||
#define TK_BOOL 93
|
||||
#define TK_TINYINT 94
|
||||
#define TK_SMALLINT 95
|
||||
#define TK_INT 96
|
||||
#define TK_INTEGER 97
|
||||
#define TK_BIGINT 98
|
||||
#define TK_FLOAT 99
|
||||
#define TK_DOUBLE 100
|
||||
#define TK_BINARY 101
|
||||
#define TK_TIMESTAMP 102
|
||||
#define TK_NCHAR 103
|
||||
#define TK_UNSIGNED 104
|
||||
#define TK_JSON 105
|
||||
#define TK_VARCHAR 106
|
||||
#define TK_MEDIUMBLOB 107
|
||||
#define TK_BLOB 108
|
||||
#define TK_VARBINARY 109
|
||||
#define TK_DECIMAL 110
|
||||
#define TK_DELAY 111
|
||||
#define TK_FILE_FACTOR 112
|
||||
#define TK_NK_FLOAT 113
|
||||
#define TK_ROLLUP 114
|
||||
#define TK_TTL 115
|
||||
#define TK_SMA 116
|
||||
#define TK_SHOW 117
|
||||
#define TK_DATABASES 118
|
||||
#define TK_TABLES 119
|
||||
#define TK_STABLES 120
|
||||
#define TK_MNODES 121
|
||||
#define TK_MODULES 122
|
||||
#define TK_QNODES 123
|
||||
#define TK_FUNCTIONS 124
|
||||
#define TK_INDEXES 125
|
||||
#define TK_ACCOUNTS 126
|
||||
#define TK_APPS 127
|
||||
#define TK_CONNECTIONS 128
|
||||
#define TK_LICENCE 129
|
||||
#define TK_GRANTS 130
|
||||
#define TK_QUERIES 131
|
||||
#define TK_SCORES 132
|
||||
#define TK_TOPICS 133
|
||||
#define TK_VARIABLES 134
|
||||
#define TK_BNODES 135
|
||||
#define TK_SNODES 136
|
||||
#define TK_CLUSTER 137
|
||||
#define TK_TRANSACTIONS 138
|
||||
#define TK_LIKE 139
|
||||
#define TK_INDEX 140
|
||||
#define TK_FULLTEXT 141
|
||||
#define TK_FUNCTION 142
|
||||
#define TK_INTERVAL 143
|
||||
#define TK_TOPIC 144
|
||||
#define TK_AS 145
|
||||
#define TK_WITH 146
|
||||
#define TK_SCHEMA 147
|
||||
#define TK_DESC 148
|
||||
#define TK_DESCRIBE 149
|
||||
#define TK_RESET 150
|
||||
#define TK_QUERY 151
|
||||
#define TK_CACHE 152
|
||||
#define TK_EXPLAIN 153
|
||||
#define TK_ANALYZE 154
|
||||
#define TK_VERBOSE 155
|
||||
#define TK_NK_BOOL 156
|
||||
#define TK_RATIO 157
|
||||
#define TK_COMPACT 158
|
||||
#define TK_VNODES 159
|
||||
#define TK_IN 160
|
||||
#define TK_OUTPUTTYPE 161
|
||||
#define TK_AGGREGATE 162
|
||||
#define TK_BUFSIZE 163
|
||||
#define TK_STREAM 164
|
||||
#define TK_INTO 165
|
||||
#define TK_TRIGGER 166
|
||||
#define TK_AT_ONCE 167
|
||||
#define TK_WINDOW_CLOSE 168
|
||||
#define TK_WATERMARK 169
|
||||
#define TK_KILL 170
|
||||
#define TK_CONNECTION 171
|
||||
#define TK_TRANSACTION 172
|
||||
#define TK_MERGE 173
|
||||
#define TK_VGROUP 174
|
||||
#define TK_REDISTRIBUTE 175
|
||||
#define TK_SPLIT 176
|
||||
#define TK_SYNCDB 177
|
||||
#define TK_NULL 178
|
||||
#define TK_NK_QUESTION 179
|
||||
#define TK_NK_ARROW 180
|
||||
#define TK_ROWTS 181
|
||||
#define TK_TBNAME 182
|
||||
#define TK_QSTARTTS 183
|
||||
#define TK_QENDTS 184
|
||||
#define TK_WSTARTTS 185
|
||||
#define TK_WENDTS 186
|
||||
#define TK_WDURATION 187
|
||||
#define TK_CAST 188
|
||||
#define TK_NOW 189
|
||||
#define TK_TODAY 190
|
||||
#define TK_TIMEZONE 191
|
||||
#define TK_COUNT 192
|
||||
#define TK_FIRST 193
|
||||
#define TK_LAST 194
|
||||
#define TK_LAST_ROW 195
|
||||
#define TK_BETWEEN 196
|
||||
#define TK_IS 197
|
||||
#define TK_NK_LT 198
|
||||
#define TK_NK_GT 199
|
||||
#define TK_NK_LE 200
|
||||
#define TK_NK_GE 201
|
||||
#define TK_NK_NE 202
|
||||
#define TK_MATCH 203
|
||||
#define TK_NMATCH 204
|
||||
#define TK_CONTAINS 205
|
||||
#define TK_JOIN 206
|
||||
#define TK_INNER 207
|
||||
#define TK_SELECT 208
|
||||
#define TK_DISTINCT 209
|
||||
#define TK_WHERE 210
|
||||
#define TK_PARTITION 211
|
||||
#define TK_BY 212
|
||||
#define TK_SESSION 213
|
||||
#define TK_STATE_WINDOW 214
|
||||
#define TK_SLIDING 215
|
||||
#define TK_FILL 216
|
||||
#define TK_VALUE 217
|
||||
#define TK_NONE 218
|
||||
#define TK_PREV 219
|
||||
#define TK_LINEAR 220
|
||||
#define TK_NEXT 221
|
||||
#define TK_GROUP 222
|
||||
#define TK_HAVING 223
|
||||
#define TK_ORDER 224
|
||||
#define TK_SLIMIT 225
|
||||
#define TK_SOFFSET 226
|
||||
#define TK_LIMIT 227
|
||||
#define TK_OFFSET 228
|
||||
#define TK_ASC 229
|
||||
#define TK_NULLS 230
|
||||
#define TK_ID 231
|
||||
#define TK_NK_BITNOT 232
|
||||
#define TK_INSERT 233
|
||||
#define TK_VALUES 234
|
||||
#define TK_IMPORT 235
|
||||
#define TK_NK_SEMI 236
|
||||
#define TK_FILE 237
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -186,14 +186,14 @@ typedef struct {
|
|||
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
|
||||
#define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
|
||||
|
||||
#define IS_VALID_TINYINT(_t) ((_t) > INT8_MIN && (_t) <= INT8_MAX)
|
||||
#define IS_VALID_SMALLINT(_t) ((_t) > INT16_MIN && (_t) <= INT16_MAX)
|
||||
#define IS_VALID_INT(_t) ((_t) > INT32_MIN && (_t) <= INT32_MAX)
|
||||
#define IS_VALID_BIGINT(_t) ((_t) > INT64_MIN && (_t) <= INT64_MAX)
|
||||
#define IS_VALID_UTINYINT(_t) ((_t) >= 0 && (_t) < UINT8_MAX)
|
||||
#define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) < UINT16_MAX)
|
||||
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) < UINT32_MAX)
|
||||
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) < UINT64_MAX)
|
||||
#define IS_VALID_TINYINT(_t) ((_t) >= INT8_MIN && (_t) <= INT8_MAX)
|
||||
#define IS_VALID_SMALLINT(_t) ((_t) >= INT16_MIN && (_t) <= INT16_MAX)
|
||||
#define IS_VALID_INT(_t) ((_t) >= INT32_MIN && (_t) <= INT32_MAX)
|
||||
#define IS_VALID_BIGINT(_t) ((_t) >= INT64_MIN && (_t) <= INT64_MAX)
|
||||
#define IS_VALID_UTINYINT(_t) ((_t) >= 0 && (_t) <= UINT8_MAX)
|
||||
#define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) <= UINT16_MAX)
|
||||
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) <= UINT32_MAX)
|
||||
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) <= UINT64_MAX)
|
||||
#define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX)
|
||||
#define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX)
|
||||
|
||||
|
|
|
@ -165,15 +165,6 @@ int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t
|
|||
*/
|
||||
int32_t qUpdateQueriedTableIdList(qTaskInfo_t tinfo, int64_t uid, int32_t type);
|
||||
|
||||
/**
|
||||
* release the query handle and decrease the reference count in cache
|
||||
* @param pMgmt
|
||||
* @param pQInfo
|
||||
* @param freeHandle
|
||||
* @return
|
||||
*/
|
||||
void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle);
|
||||
|
||||
void qProcessFetchRsp(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet);
|
||||
|
||||
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, int32_t *resNum, SExplainExecInfo **pRes);
|
||||
|
|
|
@ -168,6 +168,9 @@ EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin
|
|||
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
|
||||
int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
bool fmIsInvertible(int32_t funcId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -29,7 +29,11 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define UDF_LISTEN_PIPE_NAME_LEN 32
|
||||
#define UDF_LISTEN_PIPE_NAME_PREFIX "udfd.sock."
|
||||
#ifdef _WIN32
|
||||
#define UDF_LISTEN_PIPE_NAME_PREFIX "\\\\?\\pipe\\udfd.sock"
|
||||
#else
|
||||
#define UDF_LISTEN_PIPE_NAME_PREFIX ".udfd.sock."
|
||||
#endif
|
||||
#define UDF_DNODE_ID_ENV_NAME "DNODE_ID"
|
||||
|
||||
//======================================================================================
|
||||
|
@ -129,8 +133,8 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock);
|
|||
// begin API to UDF writer.
|
||||
|
||||
// dynamic lib init and destroy
|
||||
typedef int32_t (*TUdfSetupFunc)();
|
||||
typedef int32_t (*TUdfTeardownFunc)();
|
||||
typedef int32_t (*TUdfInitFunc)();
|
||||
typedef int32_t (*TUdfDestroyFunc)();
|
||||
|
||||
//TODO: add API to check function arguments type, number etc.
|
||||
|
||||
|
@ -242,7 +246,6 @@ static FORCE_INLINE int32_t udfColSetRow(SUdfColumn* pColumn, uint32_t currentRo
|
|||
return 0;
|
||||
}
|
||||
|
||||
typedef int32_t (*TUdfFreeUdfColumnFunc)(SUdfColumn* column);
|
||||
typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock* block, SUdfColumn *resultCol);
|
||||
|
||||
typedef int32_t (*TUdfAggStartFunc)(SUdfInterBuf *buf);
|
||||
|
|
|
@ -56,7 +56,8 @@ typedef enum {
|
|||
QUERY_LESS_EQUAL,
|
||||
QUERY_GREATER_THAN,
|
||||
QUERY_GREATER_EQUAL,
|
||||
QUERY_RANGE
|
||||
QUERY_RANGE,
|
||||
QUERY_MAX
|
||||
} EIndexQueryType;
|
||||
|
||||
/*
|
||||
|
@ -178,8 +179,8 @@ void indexOptsDestroy(SIndexOpts* opts);
|
|||
* @param:
|
||||
*/
|
||||
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, int8_t qType, uint8_t colType,
|
||||
const char* colName, int32_t nColName, const char* colVal, int32_t nColVal);
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType, const char* colName,
|
||||
int32_t nColName, const char* colVal, int32_t nColVal);
|
||||
void indexTermDestroy(SIndexTerm* p);
|
||||
|
||||
/*
|
||||
|
|
|
@ -310,6 +310,29 @@ typedef struct SCreateFunctionStmt {
|
|||
int32_t bufSize;
|
||||
} SCreateFunctionStmt;
|
||||
|
||||
typedef struct SDropFunctionStmt {
|
||||
ENodeType type;
|
||||
char funcName[TSDB_FUNC_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropFunctionStmt;
|
||||
|
||||
#define PRIVILEGE_TYPE_MASK(n) (1 << n)
|
||||
|
||||
#define PRIVILEGE_TYPE_ALL PRIVILEGE_TYPE_MASK(0)
|
||||
#define PRIVILEGE_TYPE_READ PRIVILEGE_TYPE_MASK(1)
|
||||
#define PRIVILEGE_TYPE_WRITE PRIVILEGE_TYPE_MASK(2)
|
||||
|
||||
#define PRIVILEGE_TYPE_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
typedef struct SGrantStmt {
|
||||
ENodeType type;
|
||||
char userName[TSDB_USER_LEN];
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
int64_t privileges;
|
||||
} SGrantStmt;
|
||||
|
||||
typedef SGrantStmt SRevokeStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -143,6 +143,8 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
|
||||
QUERY_NODE_SPLIT_VGROUP_STMT,
|
||||
QUERY_NODE_SYNCDB_STMT,
|
||||
QUERY_NODE_GRANT_STMT,
|
||||
QUERY_NODE_REVOKE_STMT,
|
||||
QUERY_NODE_SHOW_DNODES_STMT,
|
||||
QUERY_NODE_SHOW_MNODES_STMT,
|
||||
QUERY_NODE_SHOW_MODULES_STMT,
|
||||
|
@ -174,8 +176,10 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
||||
QUERY_NODE_SHOW_TRANSACTIONS_STMT,
|
||||
QUERY_NODE_KILL_CONNECTION_STMT,
|
||||
QUERY_NODE_KILL_QUERY_STMT,
|
||||
QUERY_NODE_KILL_TRANSACTION_STMT,
|
||||
|
||||
// logic plan node
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN,
|
||||
|
|
|
@ -91,17 +91,23 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
|
|||
void qFreeStmtDataBlock(void* pDataBlock);
|
||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc);
|
||||
void qDestroyStmtDataBlock(void* pBlock);
|
||||
|
||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||
int32_t rowNum);
|
||||
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_MULTI_BIND* bind,
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tName, TAOS_MULTI_BIND* bind,
|
||||
char* msgBuf, int32_t msgBufLen);
|
||||
void destroyBoundColumnInfo(void* pBoundInfo);
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||
int32_t msgBufLen);
|
||||
|
||||
void* smlInitHandle(SQuery *pQuery);
|
||||
void smlDestroyHandle(void *pHandle);
|
||||
int32_t smlBindData(void *handle, SArray *tags, SArray *colsFormat, SHashObj *colsHash, SArray *cols, bool format, STableMeta *pTableMeta, char *tableName, char *msgBuf, int16_t msgBufLen);
|
||||
int32_t smlBuildOutput(void* handle, SHashObj* pVgHash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -25,20 +25,18 @@ extern "C" {
|
|||
|
||||
typedef struct SPlanContext {
|
||||
uint64_t queryId;
|
||||
int32_t acctId;
|
||||
SEpSet mgmtEpSet;
|
||||
SNode* pAstRoot;
|
||||
bool topicQuery;
|
||||
bool streamQuery;
|
||||
bool rSmaQuery;
|
||||
bool showRewrite;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
int32_t placeholderNum;
|
||||
void* pTransporter;
|
||||
struct SCatalog* pCatalog;
|
||||
char* pMsg;
|
||||
int32_t msgLen;
|
||||
int32_t acctId;
|
||||
SEpSet mgmtEpSet;
|
||||
SNode* pAstRoot;
|
||||
bool topicQuery;
|
||||
bool streamQuery;
|
||||
bool rSmaQuery;
|
||||
bool showRewrite;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
int32_t placeholderNum;
|
||||
char* pMsg;
|
||||
int32_t msgLen;
|
||||
} SPlanContext;
|
||||
|
||||
// Create the physical plan for the query, according to the AST.
|
||||
|
@ -47,7 +45,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
|
|||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @pSubplan subplan to be schedule
|
||||
// @groupId id of a group of datasource subplans of this @pSubplan
|
||||
// @pSource one execution location of this group of datasource subplans
|
||||
// @pSource one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
||||
|
||||
int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colIdx, uint64_t queryId);
|
||||
|
@ -56,7 +54,7 @@ int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colI
|
|||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
|
||||
int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan);
|
||||
|
||||
char* qQueryPlanToString(const SQueryPlan* pPlan);
|
||||
char* qQueryPlanToString(const SQueryPlan* pPlan);
|
||||
SQueryPlan* qStringToQueryPlan(const char* pStr);
|
||||
|
||||
void qDestroyQueryPlan(SQueryPlan* pPlan);
|
||||
|
|
|
@ -91,6 +91,8 @@ int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
int32_t qStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t qEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -154,8 +154,8 @@ typedef struct {
|
|||
} SStreamTask;
|
||||
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId);
|
||||
int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask);
|
||||
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
void tFreeSStreamTask(SStreamTask* pTask);
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -36,7 +36,7 @@ typedef struct SUpdateInfo {
|
|||
|
||||
SUpdateInfo *updateInfoInitP(SInterval* pInterval, int64_t watermark);
|
||||
SUpdateInfo *updateInfoInit(int64_t interval, int32_t precision, int64_t watermark);
|
||||
bool isUpdated(SUpdateInfo *pInfo, tb_uid_t tableId, TSKEY ts);
|
||||
bool updateInfoIsUpdated(SUpdateInfo *pInfo, tb_uid_t tableId, TSKEY ts);
|
||||
void updateInfoDestroy(SUpdateInfo *pInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -327,29 +327,32 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0601)
|
||||
#define TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION TAOS_DEF_ERROR_CODE(0, 0x0602)
|
||||
#define TSDB_CODE_TDB_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0603)
|
||||
#define TSDB_CODE_TDB_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0604)
|
||||
#define TSDB_CODE_TDB_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0605)
|
||||
#define TSDB_CODE_TDB_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0606)
|
||||
#define TSDB_CODE_TDB_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0607)
|
||||
#define TSDB_CODE_TDB_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0608)
|
||||
#define TSDB_CODE_TDB_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0609)
|
||||
#define TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE TAOS_DEF_ERROR_CODE(0, 0x060A)
|
||||
#define TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x060B)
|
||||
#define TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x060C)
|
||||
#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x060D)
|
||||
#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x060E)
|
||||
#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x060F)
|
||||
#define TSDB_CODE_TDB_FILE_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0610)
|
||||
#define TSDB_CODE_TDB_TABLE_RECONFIGURE TAOS_DEF_ERROR_CODE(0, 0x0611)
|
||||
#define TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO TAOS_DEF_ERROR_CODE(0, 0x0612)
|
||||
#define TSDB_CODE_TDB_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0613)
|
||||
#define TSDB_CODE_TDB_MESSED_MSG TAOS_DEF_ERROR_CODE(0, 0x0614)
|
||||
#define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615)
|
||||
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616)
|
||||
#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x0617)
|
||||
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0618)
|
||||
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0619)
|
||||
#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x0620)
|
||||
#define TSDB_CODE_TDB_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0604)
|
||||
#define TSDB_CODE_TDB_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0605)
|
||||
#define TSDB_CODE_TDB_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0606)
|
||||
#define TSDB_CODE_TDB_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0607)
|
||||
#define TSDB_CODE_TDB_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0608)
|
||||
#define TSDB_CODE_TDB_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0609)
|
||||
#define TSDB_CODE_TDB_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x060A)
|
||||
#define TSDB_CODE_TDB_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x060B)
|
||||
#define TSDB_CODE_TDB_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x060C)
|
||||
#define TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE TAOS_DEF_ERROR_CODE(0, 0x060D)
|
||||
#define TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x060E)
|
||||
#define TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x060F)
|
||||
#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||
#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0601)
|
||||
#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0602)
|
||||
#define TSDB_CODE_TDB_FILE_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0613)
|
||||
#define TSDB_CODE_TDB_TABLE_RECONFIGURE TAOS_DEF_ERROR_CODE(0, 0x0614)
|
||||
#define TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO TAOS_DEF_ERROR_CODE(0, 0x0615)
|
||||
#define TSDB_CODE_TDB_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0616)
|
||||
#define TSDB_CODE_TDB_MESSED_MSG TAOS_DEF_ERROR_CODE(0, 0x0617)
|
||||
#define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0618)
|
||||
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0619)
|
||||
#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x061A)
|
||||
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061B)
|
||||
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x061C)
|
||||
#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x062D)
|
||||
|
||||
// query
|
||||
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
||||
|
@ -621,6 +624,15 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INVALID_TOPIC_QUERY TAOS_DEF_ERROR_CODE(0, 0x2639)
|
||||
#define TSDB_CODE_PAR_INVALID_DROP_STABLE TAOS_DEF_ERROR_CODE(0, 0x263A)
|
||||
#define TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE TAOS_DEF_ERROR_CODE(0, 0x263B)
|
||||
#define TSDB_CODE_PAR_DUPLICATED_COLUMN TAOS_DEF_ERROR_CODE(0, 0x263C)
|
||||
#define TSDB_CODE_PAR_INVALID_TAGS_LENGTH TAOS_DEF_ERROR_CODE(0, 0x263D)
|
||||
#define TSDB_CODE_PAR_INVALID_ROW_LENGTH TAOS_DEF_ERROR_CODE(0, 0x263E)
|
||||
#define TSDB_CODE_PAR_INVALID_COLUMNS_NUM TAOS_DEF_ERROR_CODE(0, 0x263F)
|
||||
#define TSDB_CODE_PAR_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x2640)
|
||||
#define TSDB_CODE_PAR_INVALID_FIRST_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2641)
|
||||
#define TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN TAOS_DEF_ERROR_CODE(0, 0x2642)
|
||||
#define TSDB_CODE_PAR_INVALID_TAGS_NUM TAOS_DEF_ERROR_CODE(0, 0x2643)
|
||||
#define TSDB_CODE_PAR_PERMISSION_DENIED TAOS_DEF_ERROR_CODE(0, 0x2644)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
@ -634,6 +646,10 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
|
||||
#define TSDB_CODE_FUNC_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||
|
||||
#define TSDB_CODE_SML_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x3000)
|
||||
#define TSDB_CODE_SML_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x3001)
|
||||
#define TSDB_CODE_SML_INVALID_DATA TAOS_DEF_ERROR_CODE(0, 0x3002)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,8 @@ extern "C" {
|
|||
#define TSKEY_MAX (INT64_MAX - 1)
|
||||
#define TSKEY_INITIAL_VAL TSKEY_MIN
|
||||
|
||||
#define TD_VER_MAX UINT64_MAX // TODO: use the real max version from query handle
|
||||
|
||||
// Bytes for each type.
|
||||
extern const int32_t TYPE_BYTES[15];
|
||||
|
||||
|
@ -84,9 +86,13 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TS_PATH_DELIMITER "."
|
||||
#define TS_ESCAPE_CHAR '`'
|
||||
|
||||
|
||||
#define TSDB_TIME_PRECISION_MILLI 0
|
||||
#define TSDB_TIME_PRECISION_MICRO 1
|
||||
#define TSDB_TIME_PRECISION_NANO 2
|
||||
#define TSDB_TIME_PRECISION_HOURS 3
|
||||
#define TSDB_TIME_PRECISION_MINUTES 4
|
||||
#define TSDB_TIME_PRECISION_SECONDS 5
|
||||
|
||||
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
|
||||
#define TSDB_TIME_PRECISION_MICRO_STR "us"
|
||||
|
|
|
@ -24,6 +24,29 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SEncoderNode SEncoderNode;
|
||||
typedef struct SDecoderNode SDecoderNode;
|
||||
|
||||
typedef struct SCoderMem {
|
||||
struct SCoderMem* next;
|
||||
} SCoderMem;
|
||||
|
||||
typedef struct {
|
||||
uint8_t* data;
|
||||
uint32_t size;
|
||||
uint32_t pos;
|
||||
SCoderMem* mList;
|
||||
SEncoderNode* eStack;
|
||||
} SEncoder;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* data;
|
||||
uint32_t size;
|
||||
uint32_t pos;
|
||||
SCoderMem* mList;
|
||||
SDecoderNode* dStack;
|
||||
} SDecoder;
|
||||
|
||||
#define tPut(TYPE, BUF, VAL) ((TYPE*)(BUF))[0] = (VAL)
|
||||
#define tGet(TYPE, BUF, VAL) (VAL) = ((TYPE*)(BUF))[0]
|
||||
|
||||
|
@ -51,131 +74,84 @@ extern "C" {
|
|||
#define tRGet32 tRPut32
|
||||
#define tRGet64 tRPut64
|
||||
|
||||
typedef enum { TD_ENCODER, TD_DECODER } td_coder_t;
|
||||
|
||||
#define CODER_NODE_FIELDS \
|
||||
uint8_t* data; \
|
||||
int32_t size; \
|
||||
int32_t pos;
|
||||
|
||||
struct SCoderNode {
|
||||
TD_SLIST_NODE(SCoderNode);
|
||||
CODER_NODE_FIELDS
|
||||
};
|
||||
|
||||
typedef struct SCoderMem {
|
||||
struct SCoderMem* next;
|
||||
} SCoderMem;
|
||||
|
||||
typedef struct {
|
||||
td_coder_t type;
|
||||
td_endian_t endian;
|
||||
SCoderMem* mList;
|
||||
CODER_NODE_FIELDS
|
||||
TD_SLIST(SCoderNode) stack;
|
||||
} SCoder;
|
||||
|
||||
#define TD_CODER_POS(CODER) ((CODER)->pos)
|
||||
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
||||
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
||||
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
||||
static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) {
|
||||
void* ptr = NULL;
|
||||
SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(SCoderMem*) + size);
|
||||
if (pMem) {
|
||||
pMem->next = pCoder->mList;
|
||||
pCoder->mList = pMem;
|
||||
ptr = (void*)&pMem[1];
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#define tEncodeSize(E, S, SIZE, RET) \
|
||||
do { \
|
||||
SCoder coder = {0}; \
|
||||
RET = 0; \
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \
|
||||
if ((E)(&coder, S) == 0) { \
|
||||
SIZE = coder.pos; \
|
||||
} else { \
|
||||
RET = -1; \
|
||||
} \
|
||||
tCoderClear(&coder); \
|
||||
#define tEncodeSize(E, S, SIZE, RET) \
|
||||
do { \
|
||||
SEncoder coder = {0}; \
|
||||
tEncoderInit(&coder, NULL, 0); \
|
||||
if ((E)(&coder, S) == 0) { \
|
||||
SIZE = coder.pos; \
|
||||
RET = 0; \
|
||||
} else { \
|
||||
RET = -1; \
|
||||
} \
|
||||
tEncoderClear(&coder); \
|
||||
} while (0)
|
||||
// #define tEncodeSize(E, S, SIZE) \
|
||||
// ({ \
|
||||
// SCoder coder = {0}; \
|
||||
// int ret = 0; \
|
||||
// tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \
|
||||
// if ((E)(&coder, S) == 0) { \
|
||||
// SIZE = coder.pos; \
|
||||
// } else { \
|
||||
// ret = -1; \
|
||||
// } \
|
||||
// tCoderClear(&coder); \
|
||||
// ret; \
|
||||
// })
|
||||
|
||||
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
|
||||
void tCoderClear(SCoder* pCoder);
|
||||
static void* tEncoderMalloc(SEncoder* pCoder, int32_t size);
|
||||
static void* tDecoderMalloc(SDecoder* pCoder, int32_t size);
|
||||
|
||||
/* ------------------------ ENCODE ------------------------ */
|
||||
int32_t tStartEncode(SCoder* pEncoder);
|
||||
void tEndEncode(SCoder* pEncoder);
|
||||
static int32_t tEncodeU8(SCoder* pEncoder, uint8_t val);
|
||||
static int32_t tEncodeI8(SCoder* pEncoder, int8_t val);
|
||||
static int32_t tEncodeU16(SCoder* pEncoder, uint16_t val);
|
||||
static int32_t tEncodeI16(SCoder* pEncoder, int16_t val);
|
||||
static int32_t tEncodeU32(SCoder* pEncoder, uint32_t val);
|
||||
static int32_t tEncodeI32(SCoder* pEncoder, int32_t val);
|
||||
static int32_t tEncodeU64(SCoder* pEncoder, uint64_t val);
|
||||
static int32_t tEncodeI64(SCoder* pEncoder, int64_t val);
|
||||
static int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val);
|
||||
static int32_t tEncodeI16v(SCoder* pEncoder, int16_t val);
|
||||
static int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val);
|
||||
static int32_t tEncodeI32v(SCoder* pEncoder, int32_t val);
|
||||
static int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val);
|
||||
static int32_t tEncodeI64v(SCoder* pEncoder, int64_t val);
|
||||
static int32_t tEncodeFloat(SCoder* pEncoder, float val);
|
||||
static int32_t tEncodeDouble(SCoder* pEncoder, double val);
|
||||
static int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len);
|
||||
static int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len);
|
||||
static int32_t tEncodeCStr(SCoder* pEncoder, const char* val);
|
||||
void tEncoderInit(SEncoder* pCoder, uint8_t* data, uint32_t size);
|
||||
void tEncoderClear(SEncoder* pCoder);
|
||||
int32_t tStartEncode(SEncoder* pCoder);
|
||||
void tEndEncode(SEncoder* pCoder);
|
||||
static int32_t tEncodeU8(SEncoder* pCoder, uint8_t val);
|
||||
static int32_t tEncodeI8(SEncoder* pCoder, int8_t val);
|
||||
static int32_t tEncodeU16(SEncoder* pCoder, uint16_t val);
|
||||
static int32_t tEncodeI16(SEncoder* pCoder, int16_t val);
|
||||
static int32_t tEncodeU32(SEncoder* pCoder, uint32_t val);
|
||||
static int32_t tEncodeI32(SEncoder* pCoder, int32_t val);
|
||||
static int32_t tEncodeU64(SEncoder* pCoder, uint64_t val);
|
||||
static int32_t tEncodeI64(SEncoder* pCoder, int64_t val);
|
||||
static int32_t tEncodeU16v(SEncoder* pCoder, uint16_t val);
|
||||
static int32_t tEncodeI16v(SEncoder* pCoder, int16_t val);
|
||||
static int32_t tEncodeU32v(SEncoder* pCoder, uint32_t val);
|
||||
static int32_t tEncodeI32v(SEncoder* pCoder, int32_t val);
|
||||
static int32_t tEncodeU64v(SEncoder* pCoder, uint64_t val);
|
||||
static int32_t tEncodeI64v(SEncoder* pCoder, int64_t val);
|
||||
static int32_t tEncodeFloat(SEncoder* pCoder, float val);
|
||||
static int32_t tEncodeDouble(SEncoder* pCoder, double val);
|
||||
static int32_t tEncodeBinary(SEncoder* pCoder, const uint8_t* val, uint32_t len);
|
||||
static int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t len);
|
||||
static int32_t tEncodeCStr(SEncoder* pCoder, const char* val);
|
||||
|
||||
/* ------------------------ DECODE ------------------------ */
|
||||
int32_t tStartDecode(SCoder* pDecoder);
|
||||
void tEndDecode(SCoder* pDecoder);
|
||||
static bool tDecodeIsEnd(SCoder* pCoder);
|
||||
static int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val);
|
||||
static int32_t tDecodeI8(SCoder* pDecoder, int8_t* val);
|
||||
static int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val);
|
||||
static int32_t tDecodeI16(SCoder* pDecoder, int16_t* val);
|
||||
static int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val);
|
||||
static int32_t tDecodeI32(SCoder* pDecoder, int32_t* val);
|
||||
static int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val);
|
||||
static int32_t tDecodeI64(SCoder* pDecoder, int64_t* val);
|
||||
static int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val);
|
||||
static int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val);
|
||||
static int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val);
|
||||
static int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val);
|
||||
static int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val);
|
||||
static int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val);
|
||||
static int32_t tDecodeFloat(SCoder* pDecoder, float* val);
|
||||
static int32_t tDecodeDouble(SCoder* pDecoder, double* val);
|
||||
static int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len);
|
||||
static int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len);
|
||||
static int32_t tDecodeCStr(SCoder* pDecoder, const char** val);
|
||||
static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
|
||||
void tDecoderInit(SDecoder* pCoder, const uint8_t* data, uint32_t size);
|
||||
void tDecoderClear(SDecoder* SDecoder);
|
||||
int32_t tStartDecode(SDecoder* pCoder);
|
||||
void tEndDecode(SDecoder* pCoder);
|
||||
static bool tDecodeIsEnd(SDecoder* pCoder);
|
||||
static int32_t tDecodeU8(SDecoder* pCoder, uint8_t* val);
|
||||
static int32_t tDecodeI8(SDecoder* pCoder, int8_t* val);
|
||||
static int32_t tDecodeU16(SDecoder* pCoder, uint16_t* val);
|
||||
static int32_t tDecodeI16(SDecoder* pCoder, int16_t* val);
|
||||
static int32_t tDecodeU32(SDecoder* pCoder, uint32_t* val);
|
||||
static int32_t tDecodeI32(SDecoder* pCoder, int32_t* val);
|
||||
static int32_t tDecodeU64(SDecoder* pCoder, uint64_t* val);
|
||||
static int32_t tDecodeI64(SDecoder* pCoder, int64_t* val);
|
||||
static int32_t tDecodeU16v(SDecoder* pCoder, uint16_t* val);
|
||||
static int32_t tDecodeI16v(SDecoder* pCoder, int16_t* val);
|
||||
static int32_t tDecodeU32v(SDecoder* pCoder, uint32_t* val);
|
||||
static int32_t tDecodeI32v(SDecoder* pCoder, int32_t* val);
|
||||
static int32_t tDecodeU64v(SDecoder* pCoder, uint64_t* val);
|
||||
static int32_t tDecodeI64v(SDecoder* pCoder, int64_t* val);
|
||||
static int32_t tDecodeFloat(SDecoder* pCoder, float* val);
|
||||
static int32_t tDecodeDouble(SDecoder* pCoder, double* val);
|
||||
static int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val, uint32_t* len);
|
||||
static int32_t tDecodeCStrAndLen(SDecoder* pCoder, const char** val, uint32_t* len);
|
||||
static int32_t tDecodeCStr(SDecoder* pCoder, const char** val);
|
||||
static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val);
|
||||
|
||||
/* ------------------------ IMPL ------------------------ */
|
||||
#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \
|
||||
if ((CODER)->data) { \
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, sizeof(VAL))) return -1; \
|
||||
if (TD_RT_ENDIAN() == (CODER)->endian) { \
|
||||
tPut(TYPE, TD_CODER_CURRENT(CODER), (VAL)); \
|
||||
} else { \
|
||||
tRPut##BITS(TD_CODER_CURRENT(CODER), &(VAL)); \
|
||||
} \
|
||||
tPut(TYPE, TD_CODER_CURRENT(CODER), (VAL)); \
|
||||
} \
|
||||
TD_CODER_MOVE_POS(CODER, sizeof(VAL)); \
|
||||
return 0;
|
||||
|
@ -200,12 +176,7 @@ static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
|
|||
|
||||
#define TD_DECODE_MACRO(CODER, PVAL, TYPE, BITS) \
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, sizeof(*(PVAL)))) return -1; \
|
||||
if (TD_RT_ENDIAN() == (CODER)->endian) { \
|
||||
tGet(TYPE, TD_CODER_CURRENT(CODER), *(PVAL)); \
|
||||
} else { \
|
||||
tRGet##BITS(PVAL, TD_CODER_CURRENT(CODER)); \
|
||||
} \
|
||||
\
|
||||
tGet(TYPE, TD_CODER_CURRENT(CODER), *(PVAL)); \
|
||||
TD_CODER_MOVE_POS(CODER, sizeof(*(PVAL))); \
|
||||
return 0;
|
||||
|
||||
|
@ -217,140 +188,134 @@ static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
|
|||
TYPE tval = TD_CODER_CURRENT(CODER)[0]; \
|
||||
if (tval < ENCODE_LIMIT) { \
|
||||
*(PVAL) |= (tval << (7 * i)); \
|
||||
TD_CODER_MOVE_POS(pDecoder, 1); \
|
||||
TD_CODER_MOVE_POS(pCoder, 1); \
|
||||
break; \
|
||||
} else { \
|
||||
*(PVAL) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); \
|
||||
i++; \
|
||||
TD_CODER_MOVE_POS(pDecoder, 1); \
|
||||
TD_CODER_MOVE_POS(pCoder, 1); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return 0;
|
||||
|
||||
// 8
|
||||
static FORCE_INLINE int32_t tEncodeU8(SCoder* pEncoder, uint8_t val) {
|
||||
if (pEncoder->data) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
|
||||
static FORCE_INLINE int32_t tEncodeU8(SEncoder* pCoder, uint8_t val) {
|
||||
if (pCoder->data) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, sizeof(val))) return -1;
|
||||
tPut(uint8_t, TD_CODER_CURRENT(pCoder), val);
|
||||
}
|
||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
||||
TD_CODER_MOVE_POS(pCoder, sizeof(val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeI8(SCoder* pEncoder, int8_t val) {
|
||||
if (pEncoder->data) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
|
||||
static FORCE_INLINE int32_t tEncodeI8(SEncoder* pCoder, int8_t val) {
|
||||
if (pCoder->data) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, sizeof(val))) return -1;
|
||||
tPut(int8_t, TD_CODER_CURRENT(pCoder), val);
|
||||
}
|
||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
||||
TD_CODER_MOVE_POS(pCoder, sizeof(val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 16
|
||||
static FORCE_INLINE int32_t tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); }
|
||||
static FORCE_INLINE int32_t tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); }
|
||||
static FORCE_INLINE int32_t tEncodeU16(SEncoder* pCoder, uint16_t val) { TD_ENCODE_MACRO(pCoder, val, uint16_t, 16); }
|
||||
static FORCE_INLINE int32_t tEncodeI16(SEncoder* pCoder, int16_t val) { TD_ENCODE_MACRO(pCoder, val, int16_t, 16); }
|
||||
// 32
|
||||
static FORCE_INLINE int32_t tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); }
|
||||
static FORCE_INLINE int32_t tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); }
|
||||
static FORCE_INLINE int32_t tEncodeU32(SEncoder* pCoder, uint32_t val) { TD_ENCODE_MACRO(pCoder, val, uint32_t, 32); }
|
||||
static FORCE_INLINE int32_t tEncodeI32(SEncoder* pCoder, int32_t val) { TD_ENCODE_MACRO(pCoder, val, int32_t, 32); }
|
||||
// 64
|
||||
static FORCE_INLINE int32_t tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); }
|
||||
static FORCE_INLINE int32_t tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); }
|
||||
static FORCE_INLINE int32_t tEncodeU64(SEncoder* pCoder, uint64_t val) { TD_ENCODE_MACRO(pCoder, val, uint64_t, 64); }
|
||||
static FORCE_INLINE int32_t tEncodeI64(SEncoder* pCoder, int64_t val) { TD_ENCODE_MACRO(pCoder, val, int64_t, 64); }
|
||||
// 16v
|
||||
static FORCE_INLINE int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||
static FORCE_INLINE int32_t tEncodeI16v(SCoder* pEncoder, int16_t val) {
|
||||
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
|
||||
static FORCE_INLINE int32_t tEncodeU16v(SEncoder* pCoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pCoder, val); }
|
||||
static FORCE_INLINE int32_t tEncodeI16v(SEncoder* pCoder, int16_t val) {
|
||||
return tEncodeU16v(pCoder, ZIGZAGE(int16_t, val));
|
||||
}
|
||||
// 32v
|
||||
static FORCE_INLINE int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||
static FORCE_INLINE int32_t tEncodeI32v(SCoder* pEncoder, int32_t val) {
|
||||
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
|
||||
static FORCE_INLINE int32_t tEncodeU32v(SEncoder* pCoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pCoder, val); }
|
||||
static FORCE_INLINE int32_t tEncodeI32v(SEncoder* pCoder, int32_t val) {
|
||||
return tEncodeU32v(pCoder, ZIGZAGE(int32_t, val));
|
||||
}
|
||||
// 64v
|
||||
static FORCE_INLINE int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||
static FORCE_INLINE int32_t tEncodeI64v(SCoder* pEncoder, int64_t val) {
|
||||
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
|
||||
static FORCE_INLINE int32_t tEncodeU64v(SEncoder* pCoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pCoder, val); }
|
||||
static FORCE_INLINE int32_t tEncodeI64v(SEncoder* pCoder, int64_t val) {
|
||||
return tEncodeU64v(pCoder, ZIGZAGE(int64_t, val));
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) {
|
||||
static FORCE_INLINE int32_t tEncodeFloat(SEncoder* pCoder, float val) {
|
||||
union {
|
||||
uint32_t ui;
|
||||
float f;
|
||||
} v;
|
||||
v.f = val;
|
||||
|
||||
return tEncodeU32(pEncoder, v.ui);
|
||||
return tEncodeU32(pCoder, v.ui);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
|
||||
static FORCE_INLINE int32_t tEncodeDouble(SEncoder* pCoder, double val) {
|
||||
union {
|
||||
uint64_t ui;
|
||||
double d;
|
||||
} v;
|
||||
v.d = val;
|
||||
|
||||
return tEncodeU64(pEncoder, v.ui);
|
||||
return tEncodeU64(pCoder, v.ui);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) {
|
||||
if (tEncodeU64v(pEncoder, len) < 0) return -1;
|
||||
if (pEncoder->data) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
|
||||
memcpy(TD_CODER_CURRENT(pEncoder), val, len);
|
||||
static FORCE_INLINE int32_t tEncodeBinary(SEncoder* pCoder, const uint8_t* val, uint32_t len) {
|
||||
if (tEncodeU32v(pCoder, len) < 0) return -1;
|
||||
if (pCoder->data) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, len)) return -1;
|
||||
memcpy(TD_CODER_CURRENT(pCoder), val, len);
|
||||
}
|
||||
|
||||
TD_CODER_MOVE_POS(pEncoder, len);
|
||||
TD_CODER_MOVE_POS(pCoder, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) {
|
||||
return tEncodeBinary(pEncoder, (void*)val, len + 1);
|
||||
static FORCE_INLINE int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t len) {
|
||||
return tEncodeBinary(pCoder, (uint8_t*)val, len + 1);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeCStr(SCoder* pEncoder, const char* val) {
|
||||
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val));
|
||||
static FORCE_INLINE int32_t tEncodeCStr(SEncoder* pCoder, const char* val) {
|
||||
return tEncodeCStrWithLen(pCoder, val, (uint32_t)strlen(val));
|
||||
}
|
||||
|
||||
/* ------------------------ FOR DECODER ------------------------ */
|
||||
// 8
|
||||
static FORCE_INLINE int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
||||
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
|
||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
||||
static FORCE_INLINE int32_t tDecodeU8(SDecoder* pCoder, uint8_t* val) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, sizeof(*val))) return -1;
|
||||
tGet(uint8_t, TD_CODER_CURRENT(pCoder), *val);
|
||||
TD_CODER_MOVE_POS(pCoder, sizeof(*val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeI8(SCoder* pDecoder, int8_t* val) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
||||
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
|
||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
||||
static FORCE_INLINE int32_t tDecodeI8(SDecoder* pCoder, int8_t* val) {
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, sizeof(*val))) return -1;
|
||||
tGet(int8_t, TD_CODER_CURRENT(pCoder), *val);
|
||||
TD_CODER_MOVE_POS(pCoder, sizeof(*val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 16
|
||||
static FORCE_INLINE int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val) {
|
||||
TD_DECODE_MACRO(pDecoder, val, uint16_t, 16);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); }
|
||||
static FORCE_INLINE int32_t tDecodeU16(SDecoder* pCoder, uint16_t* val) { TD_DECODE_MACRO(pCoder, val, uint16_t, 16); }
|
||||
static FORCE_INLINE int32_t tDecodeI16(SDecoder* pCoder, int16_t* val) { TD_DECODE_MACRO(pCoder, val, int16_t, 16); }
|
||||
// 32
|
||||
static FORCE_INLINE int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val) {
|
||||
TD_DECODE_MACRO(pDecoder, val, uint32_t, 32);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); }
|
||||
static FORCE_INLINE int32_t tDecodeU32(SDecoder* pCoder, uint32_t* val) { TD_DECODE_MACRO(pCoder, val, uint32_t, 32); }
|
||||
static FORCE_INLINE int32_t tDecodeI32(SDecoder* pCoder, int32_t* val) { TD_DECODE_MACRO(pCoder, val, int32_t, 32); }
|
||||
// 64
|
||||
static FORCE_INLINE int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val) {
|
||||
TD_DECODE_MACRO(pDecoder, val, uint64_t, 64);
|
||||
}
|
||||
static FORCE_INLINE int32_t tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); }
|
||||
static FORCE_INLINE int32_t tDecodeU64(SDecoder* pCoder, uint64_t* val) { TD_DECODE_MACRO(pCoder, val, uint64_t, 64); }
|
||||
static FORCE_INLINE int32_t tDecodeI64(SDecoder* pCoder, int64_t* val) { TD_DECODE_MACRO(pCoder, val, int64_t, 64); }
|
||||
|
||||
// 16v
|
||||
static FORCE_INLINE int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val) {
|
||||
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t);
|
||||
static FORCE_INLINE int32_t tDecodeU16v(SDecoder* pCoder, uint16_t* val) {
|
||||
TD_DECODE_VARIANT_MACRO(pCoder, val, uint16_t);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val) {
|
||||
static FORCE_INLINE int32_t tDecodeI16v(SDecoder* pCoder, int16_t* val) {
|
||||
uint16_t tval;
|
||||
if (tDecodeU16v(pDecoder, &tval) < 0) {
|
||||
if (tDecodeU16v(pCoder, &tval) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*val = ZIGZAGD(int16_t, tval);
|
||||
|
@ -358,13 +323,13 @@ static FORCE_INLINE int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val) {
|
|||
}
|
||||
|
||||
// 32v
|
||||
static FORCE_INLINE int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val) {
|
||||
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t);
|
||||
static FORCE_INLINE int32_t tDecodeU32v(SDecoder* pCoder, uint32_t* val) {
|
||||
TD_DECODE_VARIANT_MACRO(pCoder, val, uint32_t);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val) {
|
||||
static FORCE_INLINE int32_t tDecodeI32v(SDecoder* pCoder, int32_t* val) {
|
||||
uint32_t tval;
|
||||
if (tDecodeU32v(pDecoder, &tval) < 0) {
|
||||
if (tDecodeU32v(pCoder, &tval) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*val = ZIGZAGD(int32_t, tval);
|
||||
|
@ -372,26 +337,26 @@ static FORCE_INLINE int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val) {
|
|||
}
|
||||
|
||||
// 64v
|
||||
static FORCE_INLINE int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val) {
|
||||
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t);
|
||||
static FORCE_INLINE int32_t tDecodeU64v(SDecoder* pCoder, uint64_t* val) {
|
||||
TD_DECODE_VARIANT_MACRO(pCoder, val, uint64_t);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val) {
|
||||
static FORCE_INLINE int32_t tDecodeI64v(SDecoder* pCoder, int64_t* val) {
|
||||
uint64_t tval;
|
||||
if (tDecodeU64v(pDecoder, &tval) < 0) {
|
||||
if (tDecodeU64v(pCoder, &tval) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*val = ZIGZAGD(int64_t, tval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeFloat(SCoder* pDecoder, float* val) {
|
||||
static FORCE_INLINE int32_t tDecodeFloat(SDecoder* pCoder, float* val) {
|
||||
union {
|
||||
uint32_t ui;
|
||||
float f;
|
||||
} v;
|
||||
|
||||
if (tDecodeU32(pDecoder, &(v.ui)) < 0) {
|
||||
if (tDecodeU32(pCoder, &(v.ui)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -399,13 +364,13 @@ static FORCE_INLINE int32_t tDecodeFloat(SCoder* pDecoder, float* val) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) {
|
||||
static FORCE_INLINE int32_t tDecodeDouble(SDecoder* pCoder, double* val) {
|
||||
union {
|
||||
uint64_t ui;
|
||||
double d;
|
||||
} v;
|
||||
|
||||
if (tDecodeU64(pDecoder, &(v.ui)) < 0) {
|
||||
if (tDecodeU64(pCoder, &(v.ui)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -413,62 +378,84 @@ static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) {
|
||||
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
||||
static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val, uint32_t* len) {
|
||||
if (tDecodeU32v(pCoder, len) < 0) return -1;
|
||||
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, *len)) return -1;
|
||||
if (val) {
|
||||
*val = (void*)TD_CODER_CURRENT(pDecoder);
|
||||
*val = (uint8_t*)TD_CODER_CURRENT(pCoder);
|
||||
}
|
||||
|
||||
TD_CODER_MOVE_POS(pDecoder, *len);
|
||||
TD_CODER_MOVE_POS(pCoder, *len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) {
|
||||
if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1;
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLen(SDecoder* pCoder, const char** val, uint32_t* len) {
|
||||
if (tDecodeBinary(pCoder, (const uint8_t**)val, len) < 0) return -1;
|
||||
(*len) -= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStr(SCoder* pDecoder, const char** val) {
|
||||
uint64_t len;
|
||||
return tDecodeCStrAndLen(pDecoder, val, &len);
|
||||
static FORCE_INLINE int32_t tDecodeCStr(SDecoder* pCoder, const char** val) {
|
||||
uint32_t len;
|
||||
return tDecodeCStrAndLen(pCoder, val, &len);
|
||||
}
|
||||
|
||||
static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
|
||||
static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val) {
|
||||
const char* pStr;
|
||||
uint64_t len;
|
||||
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
|
||||
uint32_t len;
|
||||
if (tDecodeCStrAndLen(pCoder, &pStr, &len) < 0) return -1;
|
||||
|
||||
memcpy(val, pStr, len + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeBinaryAlloc(SCoder* pDecoder, void** val, uint64_t* len) {
|
||||
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
||||
static FORCE_INLINE int32_t tDecodeBinaryAlloc(SDecoder* pCoder, void** val, uint64_t* len) {
|
||||
if (tDecodeU64v(pCoder, len) < 0) return -1;
|
||||
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, *len)) return -1;
|
||||
*val = taosMemoryMalloc(*len);
|
||||
if (*val == NULL) return -1;
|
||||
memcpy(*val, TD_CODER_CURRENT(pDecoder), *len);
|
||||
memcpy(*val, TD_CODER_CURRENT(pCoder), *len);
|
||||
|
||||
TD_CODER_MOVE_POS(pDecoder, *len);
|
||||
TD_CODER_MOVE_POS(pCoder, *len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLenAlloc(SCoder* pDecoder, char** val, uint64_t* len) {
|
||||
if (tDecodeBinaryAlloc(pDecoder, (void**)val, len) < 0) return -1;
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLenAlloc(SDecoder* pCoder, char** val, uint64_t* len) {
|
||||
if (tDecodeBinaryAlloc(pCoder, (void**)val, len) < 0) return -1;
|
||||
(*len) -= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStrAlloc(SCoder* pDecoder, char** val) {
|
||||
static FORCE_INLINE int32_t tDecodeCStrAlloc(SDecoder* pCoder, char** val) {
|
||||
uint64_t len;
|
||||
return tDecodeCStrAndLenAlloc(pDecoder, val, &len);
|
||||
return tDecodeCStrAndLenAlloc(pCoder, val, &len);
|
||||
}
|
||||
|
||||
static FORCE_INLINE bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); }
|
||||
static FORCE_INLINE bool tDecodeIsEnd(SDecoder* pCoder) { return (pCoder->size == pCoder->pos); }
|
||||
|
||||
static FORCE_INLINE void* tEncoderMalloc(SEncoder* pCoder, int32_t size) {
|
||||
void* p = NULL;
|
||||
SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(*pMem) + size);
|
||||
if (pMem) {
|
||||
pMem->next = pCoder->mList;
|
||||
pCoder->mList = pMem;
|
||||
p = (void*)&pMem[1];
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecoderMalloc(SDecoder* pCoder, int32_t size) {
|
||||
void* p = NULL;
|
||||
SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(*pMem) + size);
|
||||
if (pMem) {
|
||||
pMem->next = pCoder->mList;
|
||||
pCoder->mList = pMem;
|
||||
p = (void*)&pMem[1];
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -162,18 +162,17 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj*
|
|||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb) {
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
|
||||
SParseContext cxt = {
|
||||
.requestId = pRequest->requestId,
|
||||
.acctId = pTscObj->acctId,
|
||||
.db = pRequest->pDb,
|
||||
.topicQuery = topicQuery,
|
||||
.pSql = pRequest->sqlstr,
|
||||
.sqlLen = pRequest->sqlLen,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
||||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||
.pStmtCb = pStmtCb,
|
||||
};
|
||||
SParseContext cxt = {.requestId = pRequest->requestId,
|
||||
.acctId = pTscObj->acctId,
|
||||
.db = pRequest->pDb,
|
||||
.topicQuery = topicQuery,
|
||||
.pSql = pRequest->sqlstr,
|
||||
.sqlLen = pRequest->sqlLen,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
||||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||
.pStmtCb = pStmtCb,
|
||||
.pUser = pTscObj->user};
|
||||
|
||||
cxt.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
int32_t code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
||||
|
@ -232,11 +231,15 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
|
|||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||
.pAstRoot = pQuery->pRoot,
|
||||
.showRewrite = pQuery->showRewrite,
|
||||
.pTransporter = pRequest->pTscObj->pAppInfo->pTransporter,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
||||
.placeholderNum = pQuery->placeholderNum};
|
||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
||||
SEpSet mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
||||
SCatalog* pCatalog = NULL;
|
||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetQnodeList(pCatalog, pRequest->pTscObj->pAppInfo->pTransporter, &mgmtEpSet, pNodeList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||
}
|
||||
|
|
|
@ -787,8 +787,3 @@ int taos_stmt_close(TAOS_STMT *stmt) {
|
|||
return stmtClose(stmt);
|
||||
}
|
||||
|
||||
TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -458,7 +458,7 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags) {
|
|||
STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, &pStmt->bInfo.sname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
|
||||
STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -547,21 +547,21 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in
|
|||
req.offsets = (SMqOffset*)offsets->container.pData;
|
||||
}
|
||||
|
||||
SCoder encoder;
|
||||
SEncoder encoder;
|
||||
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER);
|
||||
tEncoderInit(&encoder, NULL, 0);
|
||||
tEncodeSMqCMCommitOffsetReq(&encoder, &req);
|
||||
int32_t tlen = encoder.pos;
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) {
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
return -1;
|
||||
}
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, tlen, TD_ENCODER);
|
||||
tEncoderInit(&encoder, buf, tlen);
|
||||
tEncodeSMqCMCommitOffsetReq(&encoder, &req);
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_MND_MQ_COMMIT_OFFSET);
|
||||
if (pRequest == NULL) {
|
||||
|
|
|
@ -17,14 +17,27 @@ TARGET_LINK_LIBRARIES(
|
|||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(smlTest smlTest.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
smlTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
clientTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/libs/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/libs/client/inc"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
tmqTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/libs/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/libs/client/inc"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
smlTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
|
|
|
@ -587,15 +587,34 @@ TEST(testCase, projection_query_tables) {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create stable st2 (ts timestamp, k int) tags(a int)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tu using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
for(int32_t i = 0; i < 10000; ++i) {
|
||||
char sql[512] = {0};
|
||||
sprintf(sql, "insert into tu values(now+%da, %d)", i, i);
|
||||
pRes = taos_query(pConn, "create table tu2 using st2 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
for(int32_t i = 0; i < 10000000; i += 20) {
|
||||
char sql[1024] = {0};
|
||||
sprintf(sql,
|
||||
"insert into tu values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
"(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
"(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
"(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)",
|
||||
i, i, i + 1, i + 1, i + 2, i + 2, i + 3, i + 3, i + 4, i + 4, i + 5, i + 5, i + 6, i + 6, i + 7, i + 7,
|
||||
i + 8, i + 8, i + 9, i + 9, i + 10, i + 10, i + 11, i + 11, i + 12, i + 12, i + 13, i + 13, i + 14, i + 14,
|
||||
i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19);
|
||||
TAOS_RES* p = taos_query(pConn, sql);
|
||||
if (taos_errno(p) != 0) {
|
||||
printf("failed to insert data, reason:%s\n", taos_errstr(p));
|
||||
|
@ -604,24 +623,44 @@ TEST(testCase, projection_query_tables) {
|
|||
taos_free_result(p);
|
||||
}
|
||||
|
||||
pRes = taos_query(pConn, "select * from tu");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
printf("start to insert next table\n");
|
||||
|
||||
for(int32_t i = 0; i < 10000000; i += 20) {
|
||||
char sql[1024] = {0};
|
||||
sprintf(sql,
|
||||
"insert into tu2 values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
"(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
"(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
"(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)",
|
||||
i, i, i + 1, i + 1, i + 2, i + 2, i + 3, i + 3, i + 4, i + 4, i + 5, i + 5, i + 6, i + 6, i + 7, i + 7,
|
||||
i + 8, i + 8, i + 9, i + 9, i + 10, i + 10, i + 11, i + 11, i + 12, i + 12, i + 13, i + 13, i + 14, i + 14,
|
||||
i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19);
|
||||
TAOS_RES* p = taos_query(pConn, sql);
|
||||
if (taos_errno(p) != 0) {
|
||||
printf("failed to insert data, reason:%s\n", taos_errstr(p));
|
||||
}
|
||||
|
||||
taos_free_result(p);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
// pRes = taos_query(pConn, "select * from tu");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
|
||||
// taos_free_result(pRes);
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
|
||||
taos_free_result(pRes);
|
||||
// taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
|
@ -659,7 +698,7 @@ TEST(testCase, agg_query_tables) {
|
|||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use db");
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
|
|
|
@ -0,0 +1,498 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <taoserror.h>
|
||||
#include <tglobal.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
#include "../src/clientSml.c"
|
||||
#include "taos.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseString_Test) {
|
||||
char msg[256] = {0};
|
||||
SSmlMsgBuf msgBuf;
|
||||
msgBuf.buf = msg;
|
||||
msgBuf.len = 256;
|
||||
SSmlLineInfo elements = {0};
|
||||
|
||||
// case 1
|
||||
char *sql = "st,t1=3,t2=4,t3=t3 c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000 ,32,c=3";
|
||||
int ret = smlParseString(sql, &elements, &msgBuf);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.measure, sql);
|
||||
ASSERT_EQ(elements.measureLen, strlen("st"));
|
||||
ASSERT_EQ(elements.measureTagsLen, strlen("st,t1=3,t2=4,t3=t3"));
|
||||
|
||||
ASSERT_EQ(elements.tags, sql + elements.measureLen + 1);
|
||||
ASSERT_EQ(elements.tagsLen, strlen("t1=3,t2=4,t3=t3"));
|
||||
|
||||
ASSERT_EQ(elements.cols, sql + elements.measureTagsLen + 1);
|
||||
ASSERT_EQ(elements.colsLen, strlen("c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64"));
|
||||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
|
||||
// case 2 false
|
||||
sql = "st,t1=3,t2=4,t3=t3 c1=3i64,c3=\"passit hello,c1=2,c2=false,c4=4f64 1626006833639000000";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
// case 3 false
|
||||
sql = "st, t1=3,t2=4,t3=t3 c1=3i64,c3=\"passit hello,c1=2,c2=false,c4=4f64 1626006833639000000";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.cols, sql + elements.measureTagsLen + 2);
|
||||
ASSERT_EQ(elements.colsLen, strlen("t1=3,t2=4,t3=t3"));
|
||||
|
||||
// case 4 tag is null
|
||||
sql = "st, c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.measure, sql);
|
||||
ASSERT_EQ(elements.measureLen, strlen("st"));
|
||||
ASSERT_EQ(elements.measureTagsLen, strlen("st"));
|
||||
|
||||
ASSERT_EQ(elements.tags, sql + elements.measureLen + 1);
|
||||
ASSERT_EQ(elements.tagsLen, 0);
|
||||
|
||||
ASSERT_EQ(elements.cols, sql + elements.measureTagsLen + 2);
|
||||
ASSERT_EQ(elements.colsLen, strlen("c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64"));
|
||||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 2 + elements.colsLen + 1);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
|
||||
// case 5 tag is null
|
||||
sql = " st c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000 ";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
sql++;
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.measure, sql);
|
||||
ASSERT_EQ(elements.measureLen, strlen("st"));
|
||||
ASSERT_EQ(elements.measureTagsLen, strlen("st"));
|
||||
|
||||
ASSERT_EQ(elements.tags, sql + elements.measureLen);
|
||||
ASSERT_EQ(elements.tagsLen, 0);
|
||||
|
||||
ASSERT_EQ(elements.cols, sql + elements.measureTagsLen + 3);
|
||||
ASSERT_EQ(elements.colsLen, strlen("c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64"));
|
||||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 3 + elements.colsLen + 2);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
|
||||
// case 6
|
||||
sql = " st c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 ";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
// case 7
|
||||
sql = " st , ";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
sql++;
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.cols, sql + elements.measureTagsLen + 3);
|
||||
ASSERT_EQ(elements.colsLen, strlen(","));
|
||||
|
||||
// case 8 false
|
||||
sql = ", st , ";
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseString(sql, &elements, &msgBuf);
|
||||
ASSERT_NE(ret, 0);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseCols_Error_Test) {
|
||||
const char *data[] = {
|
||||
"c=\"89sd", // binary, nchar
|
||||
"c=j\"89sd\"",
|
||||
"c=\"89sd\"k",
|
||||
"c=u", // bool
|
||||
"c=truet",
|
||||
"c=f64", // double
|
||||
"c=8f64f",
|
||||
"c=8ef64",
|
||||
"c=1.7976931348623158e+390f64",
|
||||
"c=f32", // float
|
||||
"c=8f32f",
|
||||
"c=8wef32",
|
||||
"c=-3.402823466e+39f32",
|
||||
"c=", // float
|
||||
"c=8f",
|
||||
"c=8we",
|
||||
"c=3.402823466e+39",
|
||||
"c=i8", // tiny int
|
||||
"c=-8i8f",
|
||||
"c=8wei8",
|
||||
"c=-999i8",
|
||||
"c=u8", // u tiny int
|
||||
"c=8fu8",
|
||||
"c=8weu8",
|
||||
"c=999u8",
|
||||
"c=-8u8",
|
||||
"c=i16", // small int
|
||||
"c=8fi16u",
|
||||
"c=8wei16",
|
||||
"c=-67787i16",
|
||||
"c=u16", // u small int
|
||||
"c=8u16f",
|
||||
"c=8weu16",
|
||||
"c=-9u16",
|
||||
"c=67787u16",
|
||||
"c=i32", // int
|
||||
"c=8i32f",
|
||||
"c=8wei32",
|
||||
"c=2147483649i32",
|
||||
"c=u32", // u int
|
||||
"c=8u32f",
|
||||
"c=8weu32",
|
||||
"c=-4u32",
|
||||
"c=42949672958u32",
|
||||
"c=i64", // big int
|
||||
"c=8i64i",
|
||||
"c=8wei64",
|
||||
"c=-9223372036854775809i64",
|
||||
"c=i", // big int
|
||||
"c=8fi",
|
||||
"c=8wei",
|
||||
"c=9223372036854775808i",
|
||||
"c=u64", // u big int
|
||||
"c=8u64f",
|
||||
"c=8weu64",
|
||||
"c=-3.402823466e+39u64",
|
||||
"c=-339u64",
|
||||
"c=18446744073709551616u64",
|
||||
};
|
||||
|
||||
for(int i = 0; i < sizeof(data)/sizeof(data[0]); i++){
|
||||
char msg[256] = {0};
|
||||
SSmlMsgBuf msgBuf;
|
||||
msgBuf.buf = msg;
|
||||
msgBuf.len = 256;
|
||||
int32_t len = strlen(data[i]);
|
||||
int32_t ret = smlParseCols(data[i], len, NULL, false, &msgBuf);
|
||||
ASSERT_NE(ret, TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseCols_tag_Test) {
|
||||
char msg[256] = {0};
|
||||
SSmlMsgBuf msgBuf;
|
||||
msgBuf.buf = msg;
|
||||
msgBuf.len = 256;
|
||||
|
||||
SArray *cols = taosArrayInit(16, POINTER_BYTES);
|
||||
ASSERT_NE(cols, NULL);
|
||||
|
||||
const char *data =
|
||||
"cbin=\"passit hello,c=2\",cnch=L\"iisdfsf\",cbool=false,cf64=4.31f64,cf32_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l\"iuwq\"";
|
||||
int32_t len = strlen(data);
|
||||
int32_t ret = smlParseCols(data, len, cols, true, &msgBuf);
|
||||
ASSERT_EQ(ret, TSDB_CODE_SUCCESS);
|
||||
int32_t size = taosArrayGetSize(cols);
|
||||
ASSERT_EQ(size, 19);
|
||||
|
||||
// nchar
|
||||
SSmlKv *kv = taosArrayGetP(cols, 0);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cbin", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->valueLen, 18);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "\"passit", 7), 0);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// nchar
|
||||
kv = taosArrayGetP(cols, 3);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->valueLen, 7);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "4.31f64", 7), 0);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
taosArrayClear(cols);
|
||||
data = "t=3e";
|
||||
len = 0;
|
||||
memset(msgBuf.buf, 0, msgBuf.len);
|
||||
ret = smlParseCols(data, len, cols, true, &msgBuf);
|
||||
ASSERT_EQ(ret, TSDB_CODE_SUCCESS);
|
||||
size = taosArrayGetSize(cols);
|
||||
ASSERT_EQ(size, 1);
|
||||
|
||||
// nchar
|
||||
kv = taosArrayGetP(cols, 0);
|
||||
ASSERT_EQ(strncasecmp(kv->key, TAG, strlen(TAG)), 0);
|
||||
ASSERT_EQ(kv->keyLen, strlen(TAG));
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->valueLen, strlen(TAG));
|
||||
ASSERT_EQ(strncasecmp(kv->value, TAG, strlen(TAG)), 0);
|
||||
taosMemoryFree(kv);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseCols_Test) {
|
||||
char msg[256] = {0};
|
||||
SSmlMsgBuf msgBuf;
|
||||
msgBuf.buf = msg;
|
||||
msgBuf.len = 256;
|
||||
|
||||
SArray *cols = taosArrayInit(16, POINTER_BYTES);
|
||||
ASSERT_NE(cols, NULL);
|
||||
|
||||
const char *data = "cbin=\"passit hello,c=2\",cnch=L\"iisdfsf\",cbool=false,cf64=4.31f64,cf32_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l\"iuwq\"";
|
||||
int32_t len = strlen(data);
|
||||
int32_t ret = smlParseCols(data, len, cols, false, &msgBuf);
|
||||
ASSERT_EQ(ret, TSDB_CODE_SUCCESS);
|
||||
int32_t size = taosArrayGetSize(cols);
|
||||
ASSERT_EQ(size, 19);
|
||||
|
||||
// binary
|
||||
SSmlKv *kv = taosArrayGetP(cols, 0);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cbin", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BINARY);
|
||||
ASSERT_EQ(kv->length, 16);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "passit", 6), 0);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// nchar
|
||||
kv = taosArrayGetP(cols, 1);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cnch", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->length, 7);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "iisd", 4), 0);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// bool
|
||||
kv = taosArrayGetP(cols, 2);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cbool", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(kv->length, 1);
|
||||
ASSERT_EQ(kv->i, false);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// double
|
||||
kv = taosArrayGetP(cols, 3);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_DOUBLE);
|
||||
ASSERT_EQ(kv->length, 8);
|
||||
//ASSERT_EQ(kv->d, 4.31);
|
||||
printf("4.31 = kv->f:%f\n", kv->d);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// float
|
||||
kv = taosArrayGetP(cols, 4);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf32_", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_FLOAT);
|
||||
ASSERT_EQ(kv->length, 4);
|
||||
//ASSERT_EQ(kv->f, 8.32);
|
||||
printf("8.32 = kv->f:%f\n", kv->f);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// float
|
||||
kv = taosArrayGetP(cols, 5);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf32", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_FLOAT);
|
||||
ASSERT_EQ(kv->length, 4);
|
||||
//ASSERT_EQ(kv->f, 8.23);
|
||||
printf("8.23 = kv->f:%f\n", kv->f);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// tiny int
|
||||
kv = taosArrayGetP(cols, 6);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci8", 3), 0);
|
||||
ASSERT_EQ(kv->keyLen, 3);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_TINYINT);
|
||||
ASSERT_EQ(kv->length, 1);
|
||||
ASSERT_EQ(kv->i, -34);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// unsigned tiny int
|
||||
kv = taosArrayGetP(cols, 7);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu8", 3), 0);
|
||||
ASSERT_EQ(kv->keyLen, 3);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_UTINYINT);
|
||||
ASSERT_EQ(kv->length, 1);
|
||||
ASSERT_EQ(kv->u, 89);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// small int
|
||||
kv = taosArrayGetP(cols, 8);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci16", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_SMALLINT);
|
||||
ASSERT_EQ(kv->length, 2);
|
||||
ASSERT_EQ(kv->u, 233);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// unsigned smallint
|
||||
kv = taosArrayGetP(cols, 9);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu16", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_USMALLINT);
|
||||
ASSERT_EQ(kv->length, 2);
|
||||
ASSERT_EQ(kv->u, 898);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// int
|
||||
kv = taosArrayGetP(cols, 10);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci32", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_INT);
|
||||
ASSERT_EQ(kv->length, 4);
|
||||
ASSERT_EQ(kv->u, 98289);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// unsigned int
|
||||
kv = taosArrayGetP(cols, 11);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu32", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_UINT);
|
||||
ASSERT_EQ(kv->length, 4);
|
||||
ASSERT_EQ(kv->u, 12323);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
|
||||
// bigint
|
||||
kv = taosArrayGetP(cols, 12);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_EQ(kv->length, 8);
|
||||
ASSERT_EQ(kv->i, -89238);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// bigint
|
||||
kv = taosArrayGetP(cols, 13);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci", 2), 0);
|
||||
ASSERT_EQ(kv->keyLen, 2);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_EQ(kv->length, 8);
|
||||
ASSERT_EQ(kv->i, 989);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// unsigned bigint
|
||||
kv = taosArrayGetP(cols, 14);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_UBIGINT);
|
||||
ASSERT_EQ(kv->length, 8);
|
||||
ASSERT_EQ(kv->u, 8989323);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// bool
|
||||
kv = taosArrayGetP(cols, 15);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cbooltrue", 9), 0);
|
||||
ASSERT_EQ(kv->keyLen, 9);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(kv->length, 1);
|
||||
ASSERT_EQ(kv->i, true);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
|
||||
// bool
|
||||
kv = taosArrayGetP(cols, 16);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cboolt", 6), 0);
|
||||
ASSERT_EQ(kv->keyLen, 6);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(kv->length, 1);
|
||||
ASSERT_EQ(kv->i, true);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// bool
|
||||
kv = taosArrayGetP(cols, 17);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cboolf", 6), 0);
|
||||
ASSERT_EQ(kv->keyLen, 6);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(kv->length, 1);
|
||||
ASSERT_EQ(kv->i, false);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
// nchar
|
||||
kv = taosArrayGetP(cols, 18);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cnch_", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->length, 4);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "iuwq", 4), 0);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
taosArrayDestroy(cols);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseLine_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = createRequest(taos, NULL, NULL, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, NULL);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS, true);
|
||||
ASSERT_NE(info, NULL);
|
||||
|
||||
const char *sql[3] = {
|
||||
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0,fuel_consumption=25 1451606400000000000",
|
||||
"readings,name=truck_1,fleet=South,driver=Albert,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=72.45258,longitude=68.83761,elevation=255,velocity=0,heading=181,grade=0,fuel_consumption=25 1451606400000000000",
|
||||
"readings,name=truck_2,fleet=North,driver=Derek,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=24.5208,longitude=28.09377,elevation=428,velocity=0,heading=304,grade=0,fuel_consumption=25 1451606400000000000"
|
||||
};
|
||||
smlInsertLines(info, sql, 3);
|
||||
// for (int i = 0; i < 3; i++) {
|
||||
// smlParseLine(info, sql[i]);
|
||||
// }
|
||||
}
|
||||
|
||||
// TEST(testCase, smlParseTS_Test) {
|
||||
// char msg[256] = {0};
|
||||
// SSmlMsgBuf msgBuf;
|
||||
// msgBuf.buf = msg;
|
||||
// msgBuf.len = 256;
|
||||
// SSmlLineInfo elements = {0};
|
||||
//
|
||||
// SSmlHandle* info = smlBuildSmlInfo(taos, request, protocol, precision, dataFormat);
|
||||
// if(!info){
|
||||
// return (TAOS_RES*)request;
|
||||
// }
|
||||
// ret = smlParseTS(info, elements.timestamp, elements.timestampLen, cols);
|
||||
// if(ret != TSDB_CODE_SUCCESS){
|
||||
// uError("SML:0x%"PRIx64" smlParseTS failed", info->id);
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
|
@ -363,9 +363,9 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pInd
|
|||
|
||||
for (int32_t i = 0; i < pDest->info.numOfCols; ++i) {
|
||||
int32_t mapIndex = i;
|
||||
if (pIndexMap) {
|
||||
mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i);
|
||||
}
|
||||
// if (pIndexMap) {
|
||||
// mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i);
|
||||
// }
|
||||
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i);
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, mapIndex);
|
||||
|
@ -493,12 +493,12 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3
|
|||
for (int32_t j = startIndex; j < (startIndex + rowCount); ++j) {
|
||||
bool isNull = false;
|
||||
if (pBlock->pBlockAgg == NULL) {
|
||||
isNull = colDataIsNull(pColData, pBlock->info.rows, j, NULL);
|
||||
isNull = colDataIsNull_s(pColData, pBlock->info.rows);
|
||||
} else {
|
||||
isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg[i]);
|
||||
}
|
||||
char* p = colDataGetData(pColData, j);
|
||||
|
||||
char* p = colDataGetData(pColData, j);
|
||||
colDataAppend(pDstCol, j - startIndex, p, isNull);
|
||||
}
|
||||
}
|
||||
|
@ -1478,11 +1478,11 @@ void blockDebugShowData(const SArray* dataBlocks) {
|
|||
* @param uid set as parameter temporarily // TODO: remove this parameter, and the executor should set uid in
|
||||
* SDataBlock->info.uid
|
||||
* @param suid // TODO: check with Liao whether suid response is reasonable
|
||||
*
|
||||
*
|
||||
* TODO: colId should be set
|
||||
*/
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema *pTSchema, int32_t vgId, tb_uid_t uid,
|
||||
tb_uid_t suid) {
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId,
|
||||
tb_uid_t uid, tb_uid_t suid) {
|
||||
int32_t sz = taosArrayGetSize(pDataBlocks);
|
||||
int32_t bufSize = sizeof(SSubmitReq);
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
|
@ -1494,16 +1494,16 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
ASSERT(bufSize < 3 * 1024 * 1024);
|
||||
|
||||
*pReq = taosMemoryCalloc(1, bufSize);
|
||||
if(!(*pReq)) {
|
||||
if (!(*pReq)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
void* pDataBuf = *pReq;
|
||||
|
||||
int32_t msgLen = sizeof(SSubmitReq);
|
||||
int32_t msgLen = sizeof(SSubmitReq);
|
||||
int32_t numOfBlks = 0;
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, 0); // TODO: use the latest version
|
||||
tdSRowInit(&rb, 0); // TODO: use the latest version
|
||||
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pDataBlocks, i);
|
||||
|
@ -1511,8 +1511,8 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
int32_t rows = pDataBlock->info.rows;
|
||||
int32_t rowSize = pDataBlock->info.rowSize;
|
||||
int64_t groupId = pDataBlock->info.groupId;
|
||||
|
||||
if(rb.nCols != colNum) {
|
||||
|
||||
if (rb.nCols != colNum) {
|
||||
tdSRowSetTpInfo(&rb, colNum, pTSchema->flen);
|
||||
}
|
||||
|
||||
|
@ -1525,10 +1525,10 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
|
||||
msgLen += sizeof(SSubmitBlk);
|
||||
int32_t dataLen = 0;
|
||||
for (int32_t j = 0; j < rows; ++j) { // iterate by row
|
||||
tdSRowResetBuf(&rb, POINTER_SHIFT(pDataBuf, msgLen)); // set row buf
|
||||
for (int32_t j = 0; j < rows; ++j) { // iterate by row
|
||||
tdSRowResetBuf(&rb, POINTER_SHIFT(pDataBuf, msgLen)); // set row buf
|
||||
printf("|");
|
||||
bool isStartKey = false;
|
||||
bool isStartKey = false;
|
||||
for (int32_t k = 0; k < colNum; ++k) { // iterate by column
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
|
@ -1536,7 +1536,8 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
if (!isStartKey) {
|
||||
isStartKey = true;
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true, 0, 0);
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true,
|
||||
0, 0);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, 2, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true, 8, k);
|
||||
break;
|
||||
|
@ -1629,14 +1630,14 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema) {
|
|||
blkHead->uid = htobe64(pDataBlock->info.uid);
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
||||
/*int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);*/
|
||||
/*blkHead->dataLen = htonl(rows * maxLen);*/
|
||||
blkHead->dataLen = 0;
|
||||
|
||||
void* blockData = POINTER_SHIFT(submitBlk, sizeof(SSubmitBlk));
|
||||
STSRow* rowData = blockData;
|
||||
|
||||
for (int32_t j = 0; j < pDataBlock->info.rows; j++) {
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, pTSchema->version);
|
||||
tdSRowSetTpInfo(&rb, pTSchema->numOfCols, pTSchema->flen);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,7 +24,8 @@ const uint8_t tdVTypeByte[2][3] = {{
|
|||
},
|
||||
{
|
||||
// 1 bit
|
||||
TD_VTYPE_NORM_BYTE_I, TD_VTYPE_NULL_BYTE_I,
|
||||
TD_VTYPE_NORM_BYTE_I, // normal
|
||||
TD_VTYPE_NULL_BYTE_I,
|
||||
TD_VTYPE_NULL_BYTE_I, // padding
|
||||
}
|
||||
|
||||
|
@ -33,6 +34,24 @@ const uint8_t tdVTypeByte[2][3] = {{
|
|||
// declaration
|
||||
static uint8_t tdGetBitmapByte(uint8_t byte);
|
||||
|
||||
// static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
|
||||
/**
|
||||
* @brief src2 data has more priority than src1
|
||||
*
|
||||
* @param target
|
||||
* @param src1
|
||||
* @param iter1
|
||||
* @param limit1
|
||||
* @param src2
|
||||
* @param iter2
|
||||
* @param limit2
|
||||
* @param tRows
|
||||
* @param update
|
||||
*/
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows, bool update);
|
||||
|
||||
// implementation
|
||||
/**
|
||||
* @brief Compress bitmap bytes comprised of 2-bits to counterpart of 1-bit.
|
||||
|
@ -229,23 +248,23 @@ static uint8_t tdGetMergedBitmapByte(uint8_t byte) {
|
|||
void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) {
|
||||
int32_t i = 0, j = 0;
|
||||
int32_t nBytes = TD_BITMAP_BYTES(nBits);
|
||||
int32_t nStrictBytes = nBits / 4;
|
||||
int32_t nPartialBits = nBits - nStrictBytes * 4;
|
||||
int32_t nRoundBytes = nBits / 4;
|
||||
int32_t nRemainderBits = nBits - nRoundBytes * 4;
|
||||
|
||||
switch (nPartialBits) {
|
||||
switch (nRemainderBits) {
|
||||
case 0:
|
||||
// NOTHING TODO
|
||||
break;
|
||||
case 1: {
|
||||
void *lastByte = POINTER_SHIFT(srcBitmap, nStrictBytes);
|
||||
void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes);
|
||||
*(uint8_t *)lastByte &= 0xC0;
|
||||
} break;
|
||||
case 2: {
|
||||
void *lastByte = POINTER_SHIFT(srcBitmap, nStrictBytes);
|
||||
void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes);
|
||||
*(uint8_t *)lastByte &= 0xF0;
|
||||
} break;
|
||||
case 3: {
|
||||
void *lastByte = POINTER_SHIFT(srcBitmap, nStrictBytes);
|
||||
void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes);
|
||||
*(uint8_t *)lastByte &= 0xFC;
|
||||
} break;
|
||||
default:
|
||||
|
@ -266,10 +285,6 @@ void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) {
|
|||
}
|
||||
}
|
||||
|
||||
// static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows, bool forceSetNull);
|
||||
|
||||
static FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index, bool setBitmap, int8_t bitmapMode) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->dataOff[index] = pCol->len;
|
||||
|
@ -329,7 +344,7 @@ bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode
|
|||
if (*((uint8_t *)pBitmap) != vTypeByte) {
|
||||
return false;
|
||||
}
|
||||
pBitmap = POINTER_SHIFT(pBitmap, 1);
|
||||
pBitmap = POINTER_SHIFT(pBitmap, i);
|
||||
}
|
||||
|
||||
int32_t nLeft = numOfBits - nBytes * (bitmapMode == 0 ? TD_VTYPE_BITS : TD_VTYPE_BITS_I);
|
||||
|
@ -410,11 +425,12 @@ STSRow *tdRowDup(STSRow *row) {
|
|||
* @param val
|
||||
* @param numOfRows
|
||||
* @param maxPoints
|
||||
* @param bitmapMode default is 0(2 bits), otherwise 1(1 bit)
|
||||
* @param bitmapMode default is 0(2 bits), otherwise 1(1 bit)
|
||||
* @param isMerge merge to current row
|
||||
* @return int
|
||||
*/
|
||||
int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int numOfRows, int maxPoints,
|
||||
int8_t bitmapMode) {
|
||||
int8_t bitmapMode, bool isMerge) {
|
||||
TASSERT(pCol != NULL);
|
||||
|
||||
// Assume that the columns not specified during insert/upsert mean None.
|
||||
|
@ -430,33 +446,58 @@ int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int
|
|||
dataColSetNEleNone(pCol, numOfRows, bitmapMode);
|
||||
}
|
||||
}
|
||||
if (!tdValTypeIsNorm(valType)) {
|
||||
const void *value = val;
|
||||
if (!tdValTypeIsNorm(valType) || !val) {
|
||||
// TODO:
|
||||
// 1. back compatibility and easy to debug with codes of 2.0 to save NULL values.
|
||||
// 2. later on, considering further optimization, don't save Null/None for VarType.
|
||||
val = getNullValue(pCol->type);
|
||||
value = getNullValue(pCol->type);
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// set offset
|
||||
pCol->dataOff[numOfRows] = pCol->len;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), val, varDataTLen(val));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(val);
|
||||
} else {
|
||||
ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), val, pCol->bytes);
|
||||
pCol->len += pCol->bytes;
|
||||
if (!isMerge) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// set offset
|
||||
pCol->dataOff[numOfRows] = pCol->len;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
} else {
|
||||
ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
||||
pCol->len += pCol->bytes;
|
||||
}
|
||||
} else if (!tdValTypeIsNone(valType)) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// keep the last offset
|
||||
// discard the last var data
|
||||
int32_t lastVarLen = varDataTLen(POINTER_SHIFT(pCol->pData, pCol->dataOff[numOfRows]));
|
||||
pCol->len -= lastVarLen;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
} else {
|
||||
ASSERT(pCol->len - TYPE_BYTES[pCol->type] == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len - TYPE_BYTES[pCol->type]), value, pCol->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode);
|
||||
if (!isMerge || !tdValTypeIsNone(valType)) {
|
||||
tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
// internal
|
||||
static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols) {
|
||||
static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) {
|
||||
#if 0
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < TD_ROW_KEY(pRow));
|
||||
#endif
|
||||
|
||||
// Multi-Version rows with the same key and different versions supported
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) <= TD_ROW_KEY(pRow));
|
||||
|
||||
int rcol = 1;
|
||||
int dcol = 1;
|
||||
|
@ -464,12 +505,14 @@ static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols
|
|||
|
||||
SDataCol *pDataCol = &(pCols->cols[0]);
|
||||
ASSERT(pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= schemaNCols(pSchema)) {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
continue;
|
||||
}
|
||||
|
@ -480,22 +523,26 @@ static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols
|
|||
if (tdGetTpRowValOfCol(&sVal, pRow, pBitmap, pRowCol->type, pRowCol->offset - sizeof(TSKEY), rcol - 1) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
++rcol;
|
||||
} else if (pRowCol->colId < pDataCol->colId) {
|
||||
++rcol;
|
||||
} else {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
++pCols->numOfRows;
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
// internal
|
||||
static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols) {
|
||||
static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) {
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < TD_ROW_KEY(pRow));
|
||||
|
||||
int rcol = 0;
|
||||
|
@ -506,12 +553,14 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols
|
|||
|
||||
SDataCol *pDataCol = &(pCols->cols[0]);
|
||||
ASSERT(pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= tRowCols || rcol >= tSchemaCols) {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
continue;
|
||||
}
|
||||
|
@ -527,17 +576,21 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols
|
|||
if (tdGetKvRowValOfCol(&sVal, pRow, pBitmap, pIdx->offset, colIdx) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
++rcol;
|
||||
} else if (pIdx->colId < pDataCol->colId) {
|
||||
++rcol;
|
||||
} else {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
++pCols->numOfRows;
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -548,20 +601,30 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols
|
|||
* @param pRow
|
||||
* @param pSchema
|
||||
* @param pCols
|
||||
* @param forceSetNull
|
||||
*/
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols) {
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) {
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
return tdAppendTpRowToDataCol(pRow, pSchema, pCols);
|
||||
return tdAppendTpRowToDataCol(pRow, pSchema, pCols, isMerge);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
return tdAppendKvRowToDataCol(pRow, pSchema, pCols);
|
||||
return tdAppendKvRowToDataCol(pRow, pSchema, pCols, isMerge);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull,
|
||||
/**
|
||||
* @brief source data has more priority than target
|
||||
*
|
||||
* @param target
|
||||
* @param source
|
||||
* @param rowsToMerge
|
||||
* @param pOffset
|
||||
* @param update
|
||||
* @param maxVer
|
||||
* @return int
|
||||
*/
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool update,
|
||||
TDRowVerT maxVer) {
|
||||
ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows);
|
||||
ASSERT(target->numOfCols == source->numOfCols);
|
||||
|
@ -576,17 +639,38 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *
|
|||
if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap
|
||||
ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints);
|
||||
// TODO: filter the maxVer
|
||||
for (int i = 0; i < rowsToMerge; i++) {
|
||||
TSKEY lastKey = TSKEY_INITIAL_VAL;
|
||||
for (int i = 0; i < rowsToMerge; ++i) {
|
||||
bool merge = false;
|
||||
for (int j = 0; j < source->numOfCols; j++) {
|
||||
if (source->cols[j].len > 0 || target->cols[j].len > 0) {
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, source->cols + j, i + (*pOffset), source->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
|
||||
if (j == 0) {
|
||||
if (lastKey == *(TSKEY *)sVal.val) {
|
||||
if (!update) {
|
||||
break;
|
||||
}
|
||||
merge = true;
|
||||
} else if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
|
||||
lastKey = *(TSKEY *)sVal.val;
|
||||
}
|
||||
if (i == 0) {
|
||||
(target->cols + j)->bitmap = (source->cols + j)->bitmap;
|
||||
}
|
||||
|
||||
tdAppendValToDataCol(target->cols + j, sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode);
|
||||
target->bitmapMode, merge);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
(*pOffset) += rowsToMerge;
|
||||
|
@ -596,7 +680,7 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *
|
|||
|
||||
int iter1 = 0;
|
||||
tdMergeTwoDataCols(target, pTarget, &iter1, pTarget->numOfRows, source, pOffset, source->numOfRows,
|
||||
pTarget->numOfRows + rowsToMerge, forceSetNull);
|
||||
pTarget->numOfRows + rowsToMerge, update);
|
||||
}
|
||||
|
||||
tdFreeDataCols(pTarget);
|
||||
|
@ -607,67 +691,95 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
// src2 data has more priority than src1
|
||||
static void tdAppendValToDataCols(SDataCols *target, SDataCols *src, int iter, bool isMerge) {
|
||||
for (int i = 0; i < src->numOfCols; ++i) {
|
||||
ASSERT(target->cols[i].type == src->cols[i].type);
|
||||
if (src->cols[i].len > 0 || target->cols[i].len > 0) {
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, src->cols + i, iter, src->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
if (isMerge) {
|
||||
if (!tdValTypeIsNone(sVal.valType)) {
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode, isMerge);
|
||||
} else {
|
||||
// Keep the origin value for None
|
||||
}
|
||||
} else {
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode, isMerge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief src2 data has more priority than src1
|
||||
*
|
||||
* @param target
|
||||
* @param src1
|
||||
* @param iter1
|
||||
* @param limit1
|
||||
* @param src2
|
||||
* @param iter2
|
||||
* @param limit2
|
||||
* @param tRows
|
||||
* @param update
|
||||
*/
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows, bool forceSetNull) {
|
||||
int limit2, int tRows, bool update) {
|
||||
tdResetDataCols(target);
|
||||
target->bitmapMode = src1->bitmapMode;
|
||||
ASSERT(limit1 <= src1->numOfRows && limit2 <= src2->numOfRows);
|
||||
int32_t nRows = 0;
|
||||
|
||||
while (target->numOfRows < tRows) {
|
||||
// TODO: filter the maxVer
|
||||
// TODO: handle the delete function
|
||||
TSKEY lastKey = TSKEY_INITIAL_VAL;
|
||||
while (nRows < tRows) {
|
||||
if (*iter1 >= limit1 && *iter2 >= limit2) break;
|
||||
|
||||
TSKEY key1 = (*iter1 >= limit1) ? INT64_MAX : dataColsKeyAt(src1, *iter1);
|
||||
TKEY tkey1 = (*iter1 >= limit1) ? TKEY_NULL : dataColsTKeyAt(src1, *iter1);
|
||||
// TKEY tkey1 = (*iter1 >= limit1) ? TKEY_NULL : dataColsTKeyAt(src1, *iter1);
|
||||
TSKEY key2 = (*iter2 >= limit2) ? INT64_MAX : dataColsKeyAt(src2, *iter2);
|
||||
// TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2);
|
||||
|
||||
ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1)));
|
||||
// TODO: filter the maxVer
|
||||
if (key1 < key2) {
|
||||
for (int i = 0; i < src1->numOfCols; ++i) {
|
||||
ASSERT(target->cols[i].type == src1->cols[i].type);
|
||||
if (src1->cols[i].len > 0 || target->cols[i].len > 0) {
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1, src1->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode);
|
||||
}
|
||||
}
|
||||
// ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1)));
|
||||
|
||||
++target->numOfRows;
|
||||
if (key1 <= key2) {
|
||||
// select key1 if not delete
|
||||
if (update && (lastKey == key1)) {
|
||||
tdAppendValToDataCols(target, src1, *iter1, true);
|
||||
} else if (lastKey != key1) {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
tdAppendValToDataCols(target, src1, *iter1, false);
|
||||
}
|
||||
++nRows;
|
||||
++(*iter1);
|
||||
} else if (key1 >= key2) {
|
||||
// TODO: filter the maxVer
|
||||
if ((key1 > key2) || ((key1 == key2) && !TKEY_IS_DELETED(key2))) {
|
||||
for (int i = 0; i < src2->numOfCols; ++i) {
|
||||
SCellVal sVal = {0};
|
||||
ASSERT(target->cols[i].type == src2->cols[i].type);
|
||||
if (tdGetColDataOfRow(&sVal, src2->cols + i, *iter2, src2->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
if (src2->cols[i].len > 0 && !tdValTypeIsNull(sVal.valType)) {
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode);
|
||||
} else if (!forceSetNull && key1 == key2 && src1->cols[i].len > 0) {
|
||||
if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1, src1->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode);
|
||||
} else if (target->cols[i].len > 0) {
|
||||
dataColSetNullAt(&target->cols[i], target->numOfRows, true, target->bitmapMode);
|
||||
}
|
||||
lastKey = key1;
|
||||
} else {
|
||||
// use key2 if not deleted
|
||||
// TODO: handle the delete function
|
||||
if (update && (lastKey == key2)) {
|
||||
tdAppendValToDataCols(target, src2, *iter2, true);
|
||||
} else if (lastKey != key2) {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
++target->numOfRows;
|
||||
tdAppendValToDataCols(target, src2, *iter2, false);
|
||||
}
|
||||
|
||||
++nRows;
|
||||
++(*iter2);
|
||||
if (key1 == key2) ++(*iter1);
|
||||
lastKey = key2;
|
||||
}
|
||||
|
||||
ASSERT(target->numOfRows <= target->maxPoints);
|
||||
ASSERT(target->numOfRows <= target->maxPoints - 1);
|
||||
}
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -777,7 +889,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
|||
pRet->sversion = pDataCols->sversion;
|
||||
if (keepData) pRet->numOfRows = pDataCols->numOfRows;
|
||||
|
||||
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
pRet->cols[i].type = pDataCols->cols[i].type;
|
||||
pRet->cols[i].bitmap = pDataCols->cols[i].bitmap;
|
||||
pRet->cols[i].colId = pDataCols->cols[i].colId;
|
||||
|
@ -797,8 +909,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
|||
memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, dataOffSize);
|
||||
}
|
||||
if (!TD_COL_ROWS_NORM(pRet->cols + i)) {
|
||||
int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(pDataCols->numOfRows);
|
||||
memcpy(pRet->cols[i].pBitmap, pDataCols->cols[i].pBitmap, nBitmapBytes);
|
||||
memcpy(pRet->cols[i].pBitmap, pDataCols->cols[i].pBitmap, TD_BITMAP_BYTES(pDataCols->numOfRows));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -557,7 +557,7 @@ static const void *nullValues[] = {
|
|||
};
|
||||
|
||||
const void *getNullValue(int32_t type) {
|
||||
assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT);
|
||||
assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT); // TODO: extend the types
|
||||
return nullValues[type - 1];
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ void qmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
|||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
|
|
|
@ -293,14 +293,10 @@ void vmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
|||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, vmProcessMergeMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_VNODE, vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_COMPACT_VNODE, vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
// dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
// dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
|
||||
// sync integration
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_SYNC_TIMEOUT, (NodeMsgFp)vmProcessSyncMsg, DEFAULT_HANDLE);
|
||||
|
|
|
@ -31,6 +31,7 @@ int32_t mndCheckDropUserAuth(SUserObj *pOperUser);
|
|||
|
||||
int32_t mndCheckNodeAuth(SUserObj *pOperUser);
|
||||
int32_t mndCheckFuncAuth(SUserObj *pOperUser);
|
||||
int32_t mndCheckTransAuth(SUserObj *pOperUser);
|
||||
|
||||
int32_t mndCheckCreateDbAuth(SUserObj *pOperUser);
|
||||
int32_t mndCheckAlterDropCompactDbAuth(SUserObj *pOperUser, SDbObj *pDb);
|
||||
|
|
|
@ -72,7 +72,7 @@ typedef enum {
|
|||
TRN_TYPE_DROP_USER = 1003,
|
||||
TRN_TYPE_CREATE_FUNC = 1004,
|
||||
TRN_TYPE_DROP_FUNC = 1005,
|
||||
|
||||
|
||||
TRN_TYPE_CREATE_SNODE = 1006,
|
||||
TRN_TYPE_DROP_SNODE = 1007,
|
||||
TRN_TYPE_CREATE_QNODE = 1008,
|
||||
|
@ -115,7 +115,10 @@ typedef enum {
|
|||
TRN_TYPE_STB_SCOPE_END,
|
||||
} ETrnType;
|
||||
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
|
||||
typedef enum {
|
||||
TRN_POLICY_ROLLBACK = 0,
|
||||
TRN_POLICY_RETRY = 1,
|
||||
} ETrnPolicy;
|
||||
|
||||
typedef enum {
|
||||
DND_REASON_ONLINE = 0,
|
||||
|
@ -131,6 +134,15 @@ typedef enum {
|
|||
DND_REASON_OTHERS
|
||||
} EDndReason;
|
||||
|
||||
typedef enum {
|
||||
CONSUMER_UPDATE__TOUCH = 1,
|
||||
CONSUMER_UPDATE__ADD,
|
||||
CONSUMER_UPDATE__REMOVE,
|
||||
CONSUMER_UPDATE__LOST,
|
||||
CONSUMER_UPDATE__RECOVER,
|
||||
CONSUMER_UPDATE__MODIFY,
|
||||
} ECsmUpdateType;
|
||||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
ETrnStage stage;
|
||||
|
@ -386,7 +398,6 @@ typedef struct {
|
|||
int32_t codeSize;
|
||||
char* pComment;
|
||||
char* pCode;
|
||||
char pData[];
|
||||
} SFuncObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -425,18 +436,8 @@ typedef struct {
|
|||
int64_t offset;
|
||||
} SMqOffsetObj;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqOffsetObj(void** buf, const SMqOffsetObj* pOffset) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeString(buf, pOffset->key);
|
||||
tlen += taosEncodeFixedI64(buf, pOffset->offset);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqOffsetObj(void* buf, SMqOffsetObj* pOffset) {
|
||||
buf = taosDecodeStringTo(buf, pOffset->key);
|
||||
buf = taosDecodeFixedI64(buf, &pOffset->offset);
|
||||
return buf;
|
||||
}
|
||||
int32_t tEncodeSMqOffsetObj(void** buf, const SMqOffsetObj* pOffset);
|
||||
void* tDecodeSMqOffsetObj(void* buf, SMqOffsetObj* pOffset);
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
|
@ -459,26 +460,15 @@ typedef struct {
|
|||
SSchemaWrapper schema;
|
||||
} SMqTopicObj;
|
||||
|
||||
enum {
|
||||
CONSUMER_UPDATE__TOUCH = 1,
|
||||
CONSUMER_UPDATE__ADD,
|
||||
CONSUMER_UPDATE__REMOVE,
|
||||
CONSUMER_UPDATE__LOST,
|
||||
CONSUMER_UPDATE__RECOVER,
|
||||
CONSUMER_UPDATE__MODIFY,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
char appId[TSDB_CGROUP_LEN];
|
||||
int8_t updateType; // used only for update
|
||||
int32_t epoch;
|
||||
int32_t status;
|
||||
// hbStatus is not applicable to serialization
|
||||
int32_t hbStatus;
|
||||
// lock is used for topics update
|
||||
SRWLatch lock;
|
||||
int64_t consumerId;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
char appId[TSDB_CGROUP_LEN];
|
||||
int8_t updateType; // used only for update
|
||||
int32_t epoch;
|
||||
int32_t status;
|
||||
int32_t hbStatus; // hbStatus is not applicable to serialization
|
||||
SRWLatch lock; // lock is used for topics update
|
||||
SArray* currentTopics; // SArray<char*>
|
||||
SArray* rebNewTopics; // SArray<char*>
|
||||
SArray* rebRemovedTopics; // SArray<char*>
|
||||
|
@ -492,7 +482,6 @@ typedef struct {
|
|||
int64_t upTime;
|
||||
int64_t subscribeTime;
|
||||
int64_t rebalanceTime;
|
||||
|
||||
} SMqConsumerObj;
|
||||
|
||||
SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]);
|
||||
|
@ -581,19 +570,18 @@ typedef struct {
|
|||
} SMqRebOutputObj;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char sourceDb[TSDB_DB_FNAME_LEN];
|
||||
char targetDb[TSDB_DB_FNAME_LEN];
|
||||
char targetSTbName[TSDB_TABLE_FNAME_LEN];
|
||||
int64_t createTime;
|
||||
int64_t updateTime;
|
||||
int64_t uid;
|
||||
int64_t dbUid;
|
||||
int32_t version;
|
||||
int32_t vgNum;
|
||||
SRWLatch lock;
|
||||
int8_t status;
|
||||
// int32_t sqlLen;
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char sourceDb[TSDB_DB_FNAME_LEN];
|
||||
char targetDb[TSDB_DB_FNAME_LEN];
|
||||
char targetSTbName[TSDB_TABLE_FNAME_LEN];
|
||||
int64_t createTime;
|
||||
int64_t updateTime;
|
||||
int64_t uid;
|
||||
int64_t dbUid;
|
||||
int32_t version;
|
||||
int32_t vgNum;
|
||||
SRWLatch lock;
|
||||
int8_t status;
|
||||
int8_t createdBy; // STREAM_CREATED_BY__USER or SMA
|
||||
int32_t fixedSinkVgId; // 0 for shuffle
|
||||
int64_t smaId; // 0 for unused
|
||||
|
@ -601,14 +589,13 @@ typedef struct {
|
|||
int32_t triggerParam;
|
||||
int64_t waterMark;
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SArray* tasks; // SArray<SArray<SStreamTask>>
|
||||
SSchemaWrapper outputSchema;
|
||||
} SStreamObj;
|
||||
|
||||
int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj);
|
||||
int32_t tDecodeSStreamObj(SCoder* pDecoder, SStreamObj* pObj);
|
||||
int32_t tEncodeSStreamObj(SEncoder* pEncoder, const SStreamObj* pObj);
|
||||
int32_t tDecodeSStreamObj(SDecoder* pDecoder, SStreamObj* pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableMetaVersion *pStbs, int32_t n
|
|||
int32_t *pRspLen);
|
||||
int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs);
|
||||
|
||||
int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate);
|
||||
SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName);
|
||||
int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreate, SDbObj *pDb);
|
||||
int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,8 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
|||
|
||||
// for trans test
|
||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp, int32_t *pRspLen);
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||
int32_t *pRspLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,10 +27,14 @@ void mndCleanupVgroup(SMnode *pMnode);
|
|||
SVgObj *mndAcquireVgroup(SMnode *pMnode, int32_t vgId);
|
||||
void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode);
|
||||
int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray);
|
||||
int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *del1, SVnodeGid *del2);
|
||||
|
||||
void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildAlterVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
|
|
|
@ -74,10 +74,7 @@ static int32_t mndProcessAuthReq(SNodeMsg *pReq) {
|
|||
}
|
||||
|
||||
int32_t mndCheckCreateUserAuth(SUserObj *pOperUser) {
|
||||
if (pOperUser->superUser) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pOperUser->superUser) return 0;
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
|
@ -118,28 +115,25 @@ int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb,
|
|||
}
|
||||
|
||||
int32_t mndCheckDropUserAuth(SUserObj *pOperUser) {
|
||||
if (pOperUser->superUser) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pOperUser->superUser) return 0;
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndCheckNodeAuth(SUserObj *pOperUser) {
|
||||
if (pOperUser->superUser) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pOperUser->superUser) return 0;
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndCheckFuncAuth(SUserObj *pOperUser) {
|
||||
if (pOperUser->superUser) {
|
||||
return 0;
|
||||
}
|
||||
if (pOperUser->superUser) return 0;
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndCheckTransAuth(SUserObj *pOperUser) {
|
||||
if (pOperUser->superUser) return 0;
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#include "mndCluster.h"
|
||||
#include "mndShow.h"
|
||||
|
||||
#define TSDB_CLUSTER_VER_NUMBE 1
|
||||
#define TSDB_CLUSTER_RESERVE_SIZE 64
|
||||
#define CLUSTER_VER_NUMBE 1
|
||||
#define CLUSTER_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
|
||||
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
|
||||
|
@ -30,14 +30,16 @@ static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock
|
|||
static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitCluster(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_CLUSTER,
|
||||
.keyType = SDB_KEY_INT64,
|
||||
.deployFp = (SdbDeployFp)mndCreateDefaultCluster,
|
||||
.encodeFp = (SdbEncodeFp)mndClusterActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndClusterActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndClusterActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndClusterActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndClusterActionDelete};
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_CLUSTER,
|
||||
.keyType = SDB_KEY_INT64,
|
||||
.deployFp = (SdbDeployFp)mndCreateDefaultCluster,
|
||||
.encodeFp = (SdbEncodeFp)mndClusterActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndClusterActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndClusterActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndClusterActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndClusterActionDelete,
|
||||
};
|
||||
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster);
|
||||
|
@ -79,19 +81,19 @@ int64_t mndGetClusterId(SMnode *pMnode) {
|
|||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, TSDB_CLUSTER_VER_NUMBE, sizeof(SClusterObj) + TSDB_CLUSTER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) goto CLUSTER_ENCODE_OVER;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->id, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->id, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
CLUSTER_ENCODE_OVER:
|
||||
_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("cluster:%" PRId64 ", failed to encode to raw:%p since %s", pCluster->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
|
@ -106,29 +108,29 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CLUSTER_DECODE_OVER;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != TSDB_CLUSTER_VER_NUMBE) {
|
||||
if (sver != CLUSTER_VER_NUMBE) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto CLUSTER_DECODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj));
|
||||
if (pRow == NULL) goto CLUSTER_DECODE_OVER;
|
||||
if (pRow == NULL) goto _OVER;
|
||||
|
||||
SClusterObj *pCluster = sdbGetRowObj(pRow);
|
||||
if (pCluster == NULL) goto CLUSTER_DECODE_OVER;
|
||||
if (pCluster == NULL) goto _OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->id, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->id, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
CLUSTER_DECODE_OVER:
|
||||
_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster->id, pRaw, terrstr());
|
||||
taosMemoryFreeClear(pRow);
|
||||
|
@ -161,7 +163,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
|
||||
int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN);
|
||||
if (code != 0) {
|
||||
strcpy(clusterObj.name, "tdengine2.0");
|
||||
strcpy(clusterObj.name, "tdengine3.0");
|
||||
mError("failed to get name from system, set to default val %s", clusterObj.name);
|
||||
}
|
||||
|
||||
|
@ -190,8 +192,8 @@ static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock
|
|||
if (pShow->pIter == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char*) &pCluster->id, false);
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pCluster->id, false);
|
||||
|
||||
char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->pMeta->pSchemas[cols].bytes);
|
||||
|
@ -200,7 +202,7 @@ static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock
|
|||
colDataAppend(pColInfo, numOfRows, buf, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char*) &pCluster->createdTime, false);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pCluster->createdTime, false);
|
||||
|
||||
sdbRelease(pSdb, pCluster);
|
||||
numOfRows++;
|
||||
|
|
|
@ -261,6 +261,104 @@ void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
|
|||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
|
||||
static int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool isRedo) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (isRedo) {
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool isRedo) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildAlterVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_ALTER_VNODE;
|
||||
|
||||
if (isRedo) {
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool isRedo) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
|
||||
if (isRedo) {
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) {
|
||||
char *pos = strstr(dbName, TS_PATH_DELIMITER);
|
||||
if (pos == NULL) {
|
||||
|
@ -278,6 +376,8 @@ static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) {
|
|||
}
|
||||
|
||||
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
|
||||
if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1;
|
||||
if (pCfg->numOfStables < TSDB_DB_STREAM_MODE_OFF || pCfg->numOfStables > TSDB_DB_STREAM_MODE_ON) return -1;
|
||||
if (pCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1;
|
||||
|
@ -299,10 +399,12 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
|||
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1;
|
||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA || pCfg->replications > TSDB_MAX_DB_REPLICA) return -1;
|
||||
if (pCfg->replications > mndGetDnodeSize(pMnode)) return -1;
|
||||
if (pCfg->replications != 1 && pCfg->replications != 3) return -1;
|
||||
if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1;
|
||||
if (pCfg->strict > pCfg->replications) return -1;
|
||||
if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1;
|
||||
if (pCfg->hashMethod != 1) return -1;
|
||||
|
||||
terrno = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -381,24 +483,8 @@ static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
SVgObj *pVgroup = pVgroups + vg;
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
STransAction action = {0};
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pVgid, true) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -412,24 +498,8 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
SVgObj *pVgroup = pVgroups + vg;
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
STransAction action = {0};
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, pVgid, false) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -482,7 +552,6 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate
|
|||
}
|
||||
|
||||
if (mndCheckDbCfg(pMnode, &dbObj.cfg) != 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -570,37 +639,37 @@ _OVER:
|
|||
static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
|
||||
terrno = TSDB_CODE_MND_DB_OPTION_UNCHANGED;
|
||||
|
||||
if (pAlter->buffer >= 0 && pAlter->buffer != pDb->cfg.buffer) {
|
||||
if (pAlter->buffer > 0 && pAlter->buffer != pDb->cfg.buffer) {
|
||||
pDb->cfg.buffer = pAlter->buffer;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->pages >= 0 && pAlter->pages != pDb->cfg.pages) {
|
||||
if (pAlter->pages > 0 && pAlter->pages != pDb->cfg.pages) {
|
||||
pDb->cfg.pages = pAlter->pages;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->pageSize >= 0 && pAlter->pageSize != pDb->cfg.pageSize) {
|
||||
if (pAlter->pageSize > 0 && pAlter->pageSize != pDb->cfg.pageSize) {
|
||||
pDb->cfg.pageSize = pAlter->pageSize;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysPerFile >= 0 && pAlter->daysPerFile != pDb->cfg.daysPerFile) {
|
||||
if (pAlter->daysPerFile > 0 && pAlter->daysPerFile != pDb->cfg.daysPerFile) {
|
||||
pDb->cfg.daysPerFile = pAlter->daysPerFile;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysToKeep0 >= 0 && pAlter->daysToKeep0 != pDb->cfg.daysToKeep0) {
|
||||
if (pAlter->daysToKeep0 > 0 && pAlter->daysToKeep0 != pDb->cfg.daysToKeep0) {
|
||||
pDb->cfg.daysToKeep0 = pAlter->daysToKeep0;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysToKeep1 >= 0 && pAlter->daysToKeep1 != pDb->cfg.daysToKeep1) {
|
||||
if (pAlter->daysToKeep1 > 0 && pAlter->daysToKeep1 != pDb->cfg.daysToKeep1) {
|
||||
pDb->cfg.daysToKeep1 = pAlter->daysToKeep1;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysToKeep2 >= 0 && pAlter->daysToKeep2 != pDb->cfg.daysToKeep2) {
|
||||
if (pAlter->daysToKeep2 > 0 && pAlter->daysToKeep2 != pDb->cfg.daysToKeep2) {
|
||||
pDb->cfg.daysToKeep2 = pAlter->daysToKeep2;
|
||||
terrno = 0;
|
||||
}
|
||||
|
@ -625,8 +694,9 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
|
|||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->replications >= 0 && pAlter->replications != pDb->cfg.replications) {
|
||||
if (pAlter->replications > 0 && pAlter->replications != pDb->cfg.replications) {
|
||||
pDb->cfg.replications = pAlter->replications;
|
||||
pDb->vgVersion++;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
|
@ -651,35 +721,57 @@ static int32_t mndSetAlterDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *p
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
STransAction action = {0};
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildAlterVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_ALTER_VNODE;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
static int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray) {
|
||||
if (pVgroup->replica <= 0 || pVgroup->replica == pDb->cfg.replications) {
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, pVgid, true) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SVgObj newVgroup = {0};
|
||||
memcpy(&newVgroup, pVgroup, sizeof(SVgObj));
|
||||
if (newVgroup.replica < pDb->cfg.replications) {
|
||||
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
|
||||
pVgroup->vnodeGid[0].dnodeId);
|
||||
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) {
|
||||
mError("db:%s, failed to add vnode to vgId:%d since %s", pDb->name, newVgroup.vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
newVgroup.replica = pDb->cfg.replications;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, &newVgroup.vnodeGid[0], true) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVgroup, &newVgroup.vnodeGid[1], true) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVgroup, &newVgroup.vnodeGid[2], true) != 0) return -1;
|
||||
} else {
|
||||
mInfo("db:%s, vgId:%d, will remove 2 vnodes", pVgroup->dbName, pVgroup->vgId);
|
||||
|
||||
SVnodeGid del1 = {0};
|
||||
SVnodeGid del2 = {0};
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1, &del2) != 0) {
|
||||
mError("db:%s, failed to remove vnode from vgId:%d since %s", pDb->name, newVgroup.vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
newVgroup.replica = pDb->cfg.replications;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, &newVgroup.vnodeGid[0], true) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del1, true) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del2, true) != 0) return -1;
|
||||
}
|
||||
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode);
|
||||
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
|
@ -687,9 +779,10 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
if (pIter == NULL) break;
|
||||
|
||||
if (pVgroup->dbUid == pNew->uid) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pNew, pVgroup) != 0) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pNew, pVgroup, pArray) != 0) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayDestroy(pArray);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -697,6 +790,7 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -726,6 +820,7 @@ static int32_t mndProcessAlterDbReq(SNodeMsg *pReq) {
|
|||
SDbObj *pDb = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
SAlterDbReq alterReq = {0};
|
||||
SDbObj dbObj = {0};
|
||||
|
||||
if (tDeserializeSAlterDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
@ -749,15 +844,17 @@ static int32_t mndProcessAlterDbReq(SNodeMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
SDbObj dbObj = {0};
|
||||
memcpy(&dbObj, pDb, sizeof(SDbObj));
|
||||
dbObj.cfg.numOfRetensions = 0;
|
||||
dbObj.cfg.pRetensions = NULL;
|
||||
if (dbObj.cfg.pRetensions != NULL) {
|
||||
dbObj.cfg.pRetensions = taosArrayDup(pDb->cfg.pRetensions);
|
||||
if (dbObj.cfg.pRetensions == NULL) goto _OVER;
|
||||
}
|
||||
|
||||
code = mndSetDbCfgFromAlterDbReq(&dbObj, &alterReq);
|
||||
if (code != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (code != 0) goto _OVER;
|
||||
|
||||
code = mndCheckDbCfg(pMnode, &dbObj.cfg);
|
||||
if (code != 0) goto _OVER;
|
||||
|
||||
dbObj.cfgVersion++;
|
||||
dbObj.updateTime = taosGetTimestampMs();
|
||||
|
@ -771,6 +868,7 @@ _OVER:
|
|||
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
taosArrayDestroy(dbObj.cfg.pRetensions);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -899,24 +997,8 @@ static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
|
||||
static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
STransAction action = {0};
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, pVgid, true) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -988,6 +1070,17 @@ static int32_t mndDropDb(SMnode *pMnode, SNodeMsg *pReq, SDbObj *pDb) {
|
|||
/*if (mndDropTopicByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/
|
||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pDb->createUser);
|
||||
if (pUser != NULL) {
|
||||
pUser->authVersion++;
|
||||
SSdbRaw *pCommitRaw = mndUserActionEncode(pUser);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
}
|
||||
|
||||
int32_t rspLen = 0;
|
||||
void *pRsp = NULL;
|
||||
if (mndBuildDropDbRsp(pDb, &rspLen, &pRsp, false) < 0) goto _OVER;
|
||||
|
|
|
@ -13,12 +13,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndDef.h"
|
||||
#include "mndConsumer.h"
|
||||
|
||||
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]) {
|
||||
SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
|
||||
if (pConsumer == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -409,7 +411,7 @@ void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) {
|
|||
return (void *)buf;
|
||||
}
|
||||
|
||||
int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
||||
int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) {
|
||||
int32_t sz = 0;
|
||||
/*int32_t outputNameSz = 0;*/
|
||||
if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1;
|
||||
|
@ -460,7 +462,7 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
|||
return pEncoder->pos;
|
||||
}
|
||||
|
||||
int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
||||
int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj) {
|
||||
if (tDecodeCStrTo(pDecoder, pObj->name) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pObj->sourceDb) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pObj->createTime) < 0) return -1;
|
||||
|
@ -515,3 +517,16 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSMqOffsetObj(void **buf, const SMqOffsetObj *pOffset) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeString(buf, pOffset->key);
|
||||
tlen += taosEncodeFixedI64(buf, pOffset->offset);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDecodeSMqOffsetObj(void *buf, SMqOffsetObj *pOffset) {
|
||||
buf = taosDecodeStringTo(buf, pOffset->key);
|
||||
buf = taosDecodeFixedI64(buf, &pOffset->offset);
|
||||
return buf;
|
||||
}
|
|
@ -157,8 +157,8 @@ static int32_t mndProcessCommitOffsetReq(SNodeMsg *pMsg) {
|
|||
SMnode *pMnode = pMsg->pNode;
|
||||
char *msgStr = pMsg->rpcMsg.pCont;
|
||||
SMqCMCommitOffsetReq commitOffsetReq;
|
||||
SCoder decoder;
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, msgStr, pMsg->rpcMsg.contLen, TD_DECODER);
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, msgStr, pMsg->rpcMsg.contLen);
|
||||
|
||||
tDecodeSMqCMCommitOffsetReq(&decoder, &commitOffsetReq);
|
||||
|
||||
|
|
|
@ -83,12 +83,12 @@ END:
|
|||
}
|
||||
|
||||
int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type, int32_t nodeId) {
|
||||
SCoder encoder;
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER);
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, NULL, 0);
|
||||
tEncodeSStreamTask(&encoder, pTask);
|
||||
int32_t size = encoder.pos;
|
||||
int32_t tlen = sizeof(SMsgHead) + size;
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -96,9 +96,9 @@ int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet
|
|||
}
|
||||
((SMsgHead*)buf)->vgId = htonl(nodeId);
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, abuf, size, TD_ENCODER);
|
||||
tEncoderInit(&encoder, abuf, size);
|
||||
tEncodeSStreamTask(&encoder, pTask);
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
STransAction action = {0};
|
||||
memcpy(&action.epSet, pEpSet, sizeof(SEpSet));
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "mndInfoSchema.h"
|
||||
#include "mndMnode.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndStb.c"
|
||||
#include "mndStb.h"
|
||||
#include "mndStream.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
|
@ -419,7 +419,6 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
|
|||
streamObj.fixedSinkVgId = smaObj.dstVgId;
|
||||
streamObj.smaId = smaObj.uid;
|
||||
/*streamObj.physicalPlan = "";*/
|
||||
streamObj.logicalPlan = "not implemented";
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_SMA, &pReq->rpcMsg);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndStb.h"
|
||||
#include "mndAuth.h"
|
||||
#include "mndDb.h"
|
||||
|
@ -27,8 +28,8 @@
|
|||
#include "mndVgroup.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define TSDB_STB_VER_NUMBER 1
|
||||
#define TSDB_STB_RESERVE_SIZE 64
|
||||
#define STB_VER_NUMBER 1
|
||||
#define STB_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb);
|
||||
|
@ -45,13 +46,15 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
|||
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitStb(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_STB,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.encodeFp = (SdbEncodeFp)mndStbActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndStbActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndStbActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndStbActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndStbActionDelete};
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_STB,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.encodeFp = (SdbEncodeFp)mndStbActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndStbActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndStbActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndStbActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndStbActionDelete,
|
||||
};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STB, mndProcessMCreateStbReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessMAlterStbReq);
|
||||
|
@ -73,8 +76,8 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + +pStb->commentLen +
|
||||
pStb->ast1Len + pStb->ast2Len + TSDB_STB_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUMBER, size);
|
||||
pStb->ast1Len + pStb->ast2Len + STB_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, STB_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -98,6 +101,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pStb->pColumns[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->flags, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
|
@ -106,6 +110,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pStb->pTags[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->flags, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
|
@ -120,7 +125,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
if (pStb->ast2Len > 0) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->pAst2, pStb->ast2Len, _OVER)
|
||||
}
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, STB_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
@ -142,7 +147,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != TSDB_STB_VER_NUMBER) {
|
||||
if (sver != STB_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -182,6 +187,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pStb->pColumns[i];
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->flags, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
|
@ -190,6 +196,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pStb->pTags[i];
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->flags, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
|
@ -210,7 +217,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
if (pStb->pAst2 == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pStb->pAst2, pStb->ast2Len, _OVER)
|
||||
}
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, _OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, STB_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
|
@ -342,7 +349,7 @@ void mndReleaseStb(SMnode *pMnode, SStbObj *pStb) {
|
|||
sdbRelease(pSdb, pStb);
|
||||
}
|
||||
|
||||
static SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) {
|
||||
SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) {
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
|
@ -362,7 +369,7 @@ static FORCE_INLINE int schemaExColIdCompare(const void *colId, const void *pSch
|
|||
}
|
||||
|
||||
static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) {
|
||||
SCoder coder = {0};
|
||||
SEncoder encoder = {0};
|
||||
int32_t contLen;
|
||||
SName name = {0};
|
||||
SVCreateStbReq req = {0};
|
||||
|
@ -415,11 +422,11 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
|
||||
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, contLen - sizeof(SMsgHead), TD_ENCODER);
|
||||
if (tEncodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead));
|
||||
if (tEncodeSVCreateStbReq(&encoder, &req) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
tCoderClear(&coder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
*pContLen = contLen;
|
||||
taosMemoryFreeClear(req.pRSmaParam.qmsg1);
|
||||
|
@ -433,7 +440,7 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb,
|
|||
int32_t contLen = 0;
|
||||
int32_t ret = 0;
|
||||
SMsgHead *pHead = NULL;
|
||||
SCoder coder = {0};
|
||||
SEncoder encoder = {0};
|
||||
|
||||
tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
|
@ -455,15 +462,15 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb,
|
|||
|
||||
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, contLen - sizeof(SMsgHead), TD_ENCODER);
|
||||
tEncodeSVDropStbReq(&coder, &req);
|
||||
tCoderClear(&coder);
|
||||
tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead));
|
||||
tEncodeSVDropStbReq(&encoder, &req);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
*pContLen = contLen;
|
||||
return pHead;
|
||||
}
|
||||
|
||||
static int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate) {
|
||||
int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate) {
|
||||
if (pCreate->igExists < 0 || pCreate->igExists > 1) {
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
|
@ -487,7 +494,7 @@ static int32_t mndCheckCreateStbReq(SMCreateStbReq *pCreate) {
|
|||
|
||||
for (int32_t i = 0; i < pCreate->numOfColumns; ++i) {
|
||||
SField *pField1 = taosArrayGet(pCreate->pColumns, i);
|
||||
if (pField->type < 0) {
|
||||
if (pField1->type < 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
|
@ -573,6 +580,7 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_CREATE_STB;
|
||||
action.acceptableCode = TSDB_CODE_TDB_STB_ALREADY_EXIST;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
|
@ -612,6 +620,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_DROP_STB;
|
||||
action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
|
@ -634,91 +643,96 @@ static SSchema *mndFindStbColumns(const SStbObj *pStb, const char *colName) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCreate, SDbObj *pDb) {
|
||||
SStbObj stbObj = {0};
|
||||
memcpy(stbObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
memcpy(stbObj.db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
stbObj.createdTime = taosGetTimestampMs();
|
||||
stbObj.updateTime = stbObj.createdTime;
|
||||
stbObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
stbObj.dbUid = pDb->uid;
|
||||
stbObj.version = 1;
|
||||
stbObj.nextColId = 1;
|
||||
stbObj.xFilesFactor = pCreate->xFilesFactor;
|
||||
stbObj.delay = pCreate->delay;
|
||||
stbObj.ttl = pCreate->ttl;
|
||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||
stbObj.numOfTags = pCreate->numOfTags;
|
||||
stbObj.commentLen = pCreate->commentLen;
|
||||
if (stbObj.commentLen > 0) {
|
||||
stbObj.comment = taosMemoryCalloc(stbObj.commentLen, 1);
|
||||
if (stbObj.comment == NULL) {
|
||||
int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreate, SDbObj *pDb) {
|
||||
memcpy(pDst->name, pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
memcpy(pDst->db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
pDst->createdTime = taosGetTimestampMs();
|
||||
pDst->updateTime = pDst->createdTime;
|
||||
pDst->uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
pDst->dbUid = pDb->uid;
|
||||
pDst->version = 1;
|
||||
pDst->nextColId = 1;
|
||||
pDst->xFilesFactor = pCreate->xFilesFactor;
|
||||
pDst->delay = pCreate->delay;
|
||||
pDst->ttl = pCreate->ttl;
|
||||
pDst->numOfColumns = pCreate->numOfColumns;
|
||||
pDst->numOfTags = pCreate->numOfTags;
|
||||
pDst->commentLen = pCreate->commentLen;
|
||||
if (pDst->commentLen > 0) {
|
||||
pDst->comment = taosMemoryCalloc(pDst->commentLen, 1);
|
||||
if (pDst->comment == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
memcpy(stbObj.comment, pCreate->comment, stbObj.commentLen);
|
||||
memcpy(pDst->comment, pCreate->comment, pDst->commentLen);
|
||||
}
|
||||
|
||||
stbObj.ast1Len = pCreate->ast1Len;
|
||||
if (stbObj.ast1Len > 0) {
|
||||
stbObj.pAst1 = taosMemoryCalloc(stbObj.ast1Len, 1);
|
||||
if (stbObj.pAst1 == NULL) {
|
||||
pDst->ast1Len = pCreate->ast1Len;
|
||||
if (pDst->ast1Len > 0) {
|
||||
pDst->pAst1 = taosMemoryCalloc(pDst->ast1Len, 1);
|
||||
if (pDst->pAst1 == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
memcpy(stbObj.pAst1, pCreate->pAst1, stbObj.ast1Len);
|
||||
memcpy(pDst->pAst1, pCreate->pAst1, pDst->ast1Len);
|
||||
}
|
||||
|
||||
stbObj.ast2Len = pCreate->ast2Len;
|
||||
if (stbObj.ast2Len > 0) {
|
||||
stbObj.pAst2 = taosMemoryCalloc(stbObj.ast2Len, 1);
|
||||
if (stbObj.pAst2 == NULL) {
|
||||
pDst->ast2Len = pCreate->ast2Len;
|
||||
if (pDst->ast2Len > 0) {
|
||||
pDst->pAst2 = taosMemoryCalloc(pDst->ast2Len, 1);
|
||||
if (pDst->pAst2 == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
memcpy(stbObj.pAst2, pCreate->pAst2, stbObj.ast2Len);
|
||||
memcpy(pDst->pAst2, pCreate->pAst2, pDst->ast2Len);
|
||||
}
|
||||
|
||||
stbObj.pColumns = taosMemoryCalloc(1, stbObj.numOfColumns * sizeof(SSchema));
|
||||
stbObj.pTags = taosMemoryCalloc(1, stbObj.numOfTags * sizeof(SSchema));
|
||||
if (stbObj.pColumns == NULL || stbObj.pTags == NULL) {
|
||||
pDst->pColumns = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SSchema));
|
||||
pDst->pTags = taosMemoryCalloc(1, pDst->numOfTags * sizeof(SSchema));
|
||||
if (pDst->pColumns == NULL || pDst->pTags == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < stbObj.numOfColumns; ++i) {
|
||||
for (int32_t i = 0; i < pDst->numOfColumns; ++i) {
|
||||
SField *pField = taosArrayGet(pCreate->pColumns, i);
|
||||
SSchema *pSchema = &stbObj.pColumns[i];
|
||||
SSchema *pSchema = &pDst->pColumns[i];
|
||||
pSchema->type = pField->type;
|
||||
pSchema->bytes = pField->bytes;
|
||||
pSchema->flags = pField->flags;
|
||||
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->colId = stbObj.nextColId;
|
||||
stbObj.nextColId++;
|
||||
pSchema->colId = pDst->nextColId;
|
||||
pDst->nextColId++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < stbObj.numOfTags; ++i) {
|
||||
for (int32_t i = 0; i < pDst->numOfTags; ++i) {
|
||||
SField *pField = taosArrayGet(pCreate->pTags, i);
|
||||
SSchema *pSchema = &stbObj.pTags[i];
|
||||
SSchema *pSchema = &pDst->pTags[i];
|
||||
pSchema->type = pField->type;
|
||||
pSchema->bytes = pField->bytes;
|
||||
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->colId = stbObj.nextColId;
|
||||
stbObj.nextColId++;
|
||||
pSchema->colId = pDst->nextColId;
|
||||
pDst->nextColId++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCreate, SDbObj *pDb) {
|
||||
SStbObj stbObj = {0};
|
||||
|
||||
int32_t code = -1;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STB, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
mDebug("trans:%d, used to create stb:%s", pTrans->id, pCreate->name);
|
||||
mndTransSetDbInfo(pTrans, pDb);
|
||||
|
||||
if (mndSetCreateStbRedoLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER;
|
||||
if (mndSetCreateStbUndoLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER;
|
||||
if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER;
|
||||
if (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER;
|
||||
if (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER;
|
||||
if (mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj) < 0) goto _OVER;
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
@ -728,6 +742,16 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
mndTransSetDbInfo(pTrans, pDb);
|
||||
if (mndSetCreateStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
if (mndSetCreateStbUndoLogs(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
if (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
if (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessMCreateStbReq(SNodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
int32_t code = -1;
|
||||
|
@ -777,7 +801,10 @@ static int32_t mndProcessMCreateStbReq(SNodeMsg *pReq) {
|
|||
}
|
||||
|
||||
int32_t numOfStbs = -1;
|
||||
mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs);
|
||||
if (mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) {
|
||||
terrno = TSDB_CODE_MND_SINGLE_STB_MODE_DB;
|
||||
goto _OVER;
|
||||
|
@ -804,7 +831,7 @@ static int32_t mndProcessVCreateStbRsp(SNodeMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCheckAlterStbReq(SMAltertbReq *pAlter) {
|
||||
static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) {
|
||||
if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) {
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
|
@ -1155,7 +1182,7 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAlterStb(SMnode *pMnode, SNodeMsg *pReq, const SMAltertbReq *pAlter, SDbObj *pDb, SStbObj *pOld) {
|
||||
static int32_t mndAlterStb(SMnode *pMnode, SNodeMsg *pReq, const SMAlterStbReq *pAlter, SDbObj *pDb, SStbObj *pOld) {
|
||||
SStbObj stbObj = {0};
|
||||
taosRLockLatch(&pOld->lock);
|
||||
memcpy(&stbObj, pOld, sizeof(SStbObj));
|
||||
|
@ -1219,12 +1246,12 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessMAlterStbReq(SNodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
int32_t code = -1;
|
||||
SDbObj *pDb = NULL;
|
||||
SStbObj *pStb = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
SMAltertbReq alterReq = {0};
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
int32_t code = -1;
|
||||
SDbObj *pDb = NULL;
|
||||
SStbObj *pStb = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
SMAlterStbReq alterReq = {0};
|
||||
|
||||
if (tDeserializeSMAlterStbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
|
|
@ -70,14 +70,14 @@ SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
void *buf = NULL;
|
||||
|
||||
SCoder encoder;
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER);
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, NULL, 0);
|
||||
if (tEncodeSStreamObj(&encoder, pStream) < 0) {
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
goto STREAM_ENCODE_OVER;
|
||||
}
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
int32_t size = sizeof(int32_t) + tlen + MND_STREAM_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STREAM, MND_STREAM_VER_NUMBER, size);
|
||||
|
@ -86,12 +86,12 @@ SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) {
|
|||
buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) goto STREAM_ENCODE_OVER;
|
||||
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, tlen, TD_ENCODER);
|
||||
tEncoderInit(&encoder, buf, tlen);
|
||||
if (tEncodeSStreamObj(&encoder, pStream) < 0) {
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
goto STREAM_ENCODE_OVER;
|
||||
}
|
||||
tCoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, tlen, STREAM_ENCODE_OVER);
|
||||
|
@ -138,8 +138,8 @@ SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) {
|
|||
if (buf == NULL) goto STREAM_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, tlen, STREAM_DECODE_OVER);
|
||||
|
||||
SCoder decoder;
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, tlen + 1, TD_DECODER);
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, buf, tlen + 1);
|
||||
if (tDecodeSStreamObj(&decoder, pStream) < 0) {
|
||||
goto STREAM_DECODE_OVER;
|
||||
}
|
||||
|
@ -290,6 +290,86 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStreamObj *pStream, const char *user) {
|
||||
SStbObj *pStb = NULL;
|
||||
SDbObj *pDb = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
|
||||
SMCreateStbReq createReq = {0};
|
||||
tstrncpy(createReq.name, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN);
|
||||
createReq.numOfColumns = pStream->outputSchema.nCols;
|
||||
createReq.numOfTags = 1; // group id
|
||||
createReq.pColumns = taosArrayInit(createReq.numOfColumns, sizeof(SField));
|
||||
// build fields
|
||||
taosArraySetSize(createReq.pColumns, createReq.numOfColumns);
|
||||
for (int32_t i = 0; i < createReq.numOfColumns; i++) {
|
||||
SField *pField = taosArrayGet(createReq.pColumns, i);
|
||||
tstrncpy(pField->name, pStream->outputSchema.pSchema[i].name, TSDB_COL_NAME_LEN);
|
||||
pField->flags = pStream->outputSchema.pSchema[i].flags;
|
||||
pField->type = pStream->outputSchema.pSchema[i].type;
|
||||
pField->bytes = pStream->outputSchema.pSchema[i].bytes;
|
||||
}
|
||||
createReq.pTags = taosArrayInit(createReq.numOfTags, sizeof(SField));
|
||||
taosArraySetSize(createReq.pTags, 1);
|
||||
// build tags
|
||||
SField *pField = taosArrayGet(createReq.pTags, 0);
|
||||
strcpy(pField->name, "group_id");
|
||||
pField->type = TSDB_DATA_TYPE_UBIGINT;
|
||||
pField->flags = 0;
|
||||
pField->bytes = 8;
|
||||
|
||||
if (mndCheckCreateStbReq(&createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pStb = mndAcquireStb(pMnode, createReq.name);
|
||||
if (pStb != NULL) {
|
||||
terrno = TSDB_CODE_MND_STB_ALREADY_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pDb = mndAcquireDbByStb(pMnode, createReq.name);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, user);
|
||||
if (pUser == NULL) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckWriteAuth(pUser, pDb) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t numOfStbs = -1;
|
||||
if (mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) {
|
||||
terrno = TSDB_CODE_MND_SINGLE_STB_MODE_DB;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SStbObj stbObj = {0};
|
||||
|
||||
if (mndBuildStbFromReq(pMnode, &stbObj, &createReq, pDb) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj) < 0) goto _OVER;
|
||||
|
||||
return 0;
|
||||
_OVER:
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamReq *pCreate, SDbObj *pDb) {
|
||||
mDebug("stream:%s to create", pCreate->name);
|
||||
SStreamObj streamObj = {0};
|
||||
|
@ -307,11 +387,10 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
|
|||
streamObj.fixedSinkVgId = 0;
|
||||
streamObj.smaId = 0;
|
||||
/*streamObj.physicalPlan = "";*/
|
||||
streamObj.logicalPlan = "not implemented";
|
||||
streamObj.trigger = pCreate->triggerType;
|
||||
streamObj.waterMark = pCreate->watermark;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("stream:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
|
@ -324,6 +403,12 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (streamObj.targetSTbName[0] && mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->user) < 0) {
|
||||
mError("trans:%d, failed to create stb for stream since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
|
|
|
@ -1336,8 +1336,7 @@ static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!pUser->superUser) {
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
if (mndCheckTransAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superUser, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pUser->authVersion, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadDbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteDbs, _OVER)
|
||||
|
||||
|
@ -161,6 +162,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT64(pRaw, dataPos, &pUser->createdTime, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->updateTime, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pUser->authVersion, _OVER)
|
||||
|
||||
int32_t numOfReadDbs = 0;
|
||||
int32_t numOfWriteDbs = 0;
|
||||
|
@ -410,7 +412,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.pass[0] == 0) {
|
||||
if (TSDB_ALTER_USER_PASSWD == alterReq.alterType && alterReq.pass[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -588,7 +590,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) {
|
||||
static int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) {
|
||||
memcpy(pRsp->user, pUser->user, TSDB_USER_LEN);
|
||||
pRsp->superAuth = pUser->superUser;
|
||||
pRsp->version = pUser->authVersion;
|
||||
|
@ -601,7 +603,7 @@ static int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUser
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -659,7 +661,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
|
|||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
||||
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
tFreeSGetUserAuthRsp(&authRsp);
|
||||
|
||||
|
@ -711,7 +713,8 @@ static void mndCancelGetNextUser(SMnode *pMnode, void *pIter) {
|
|||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp, int32_t *pRspLen) {
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||
int32_t *pRspLen) {
|
||||
SUserAuthBatchRsp batchRsp = {0};
|
||||
batchRsp.pArray = taosArrayInit(numOfUses, sizeof(SGetUserAuthRsp));
|
||||
if (batchRsp.pArray == NULL) {
|
||||
|
@ -731,7 +734,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
|
|||
mndReleaseUser(pMnode, pUser);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
SGetUserAuthRsp rsp = {0};
|
||||
code = mndSetUserAuthRsp(pMnode, pUser, &rsp);
|
||||
if (code) {
|
||||
|
@ -740,7 +743,6 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
|
||||
taosArrayPush(batchRsp.pArray, &rsp);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
}
|
||||
|
@ -748,7 +750,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
|
|||
if (taosArrayGetSize(batchRsp.pArray) <= 0) {
|
||||
*ppRsp = NULL;
|
||||
*pRspLen = 0;
|
||||
|
||||
|
||||
tFreeSUserAuthBatchRsp(&batchRsp);
|
||||
return 0;
|
||||
}
|
||||
|
@ -772,10 +774,7 @@ _OVER:
|
|||
|
||||
*ppRsp = NULL;
|
||||
*pRspLen = 0;
|
||||
|
||||
|
||||
tFreeSUserAuthBatchRsp(&batchRsp);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -370,7 +370,7 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
|||
return true;
|
||||
}
|
||||
|
||||
static SArray *mndBuildDnodesArray(SMnode *pMnode) {
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfDnodes = mndGetDnodeSize(pMnode);
|
||||
|
||||
|
@ -421,7 +421,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr
|
|||
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
||||
}
|
||||
|
||||
mDebug("db:%s, vgId:%d, vn:%d dnode:%d is alloced", pVgroup->dbName, pVgroup->vgId, v, pVgid->dnodeId);
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is alloced", pVgroup->dbName, pVgroup->vgId, v, pVgid->dnodeId);
|
||||
pDnode->numOfVnodes++;
|
||||
}
|
||||
|
||||
|
@ -440,12 +440,10 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
}
|
||||
|
||||
pArray = mndBuildDnodesArray(pMnode);
|
||||
if (pArray == NULL) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (pArray == NULL) goto _OVER;
|
||||
|
||||
mDebug("db:%s, total %d dnodes used to create %d vgroups (%d vnodes)", pDb->name, (int32_t)taosArrayGetSize(pArray),
|
||||
pDb->cfg.numOfVgroups, pDb->cfg.numOfVgroups * pDb->cfg.replications);
|
||||
mInfo("db:%s, total %d dnodes used to create %d vgroups (%d vnodes)", pDb->name, (int32_t)taosArrayGetSize(pArray),
|
||||
pDb->cfg.numOfVgroups, pDb->cfg.numOfVgroups * pDb->cfg.replications);
|
||||
|
||||
int32_t allocedVgroups = 0;
|
||||
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
|
||||
|
@ -483,7 +481,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
*ppVgroups = pVgroups;
|
||||
code = 0;
|
||||
|
||||
mDebug("db:%s, %d vgroups is alloced, replica:%d", pDb->name, pDb->cfg.numOfVgroups, pDb->cfg.replications);
|
||||
mInfo("db:%s, %d vgroups is alloced, replica:%d", pDb->name, pDb->cfg.numOfVgroups, pDb->cfg.replications);
|
||||
|
||||
_OVER:
|
||||
if (code != 0) taosMemoryFree(pVgroups);
|
||||
|
@ -491,6 +489,88 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
}
|
||||
|
||||
int32_t maxPos = 1;
|
||||
for (int32_t d = 0; d < taosArrayGetSize(pArray); ++d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
bool used = false;
|
||||
for (int32_t vn = 0; vn < maxPos; ++vn) {
|
||||
if (pDnode->id == pVgroup->vnodeGid[vn].dnodeId) {
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (used) continue;
|
||||
|
||||
if (pDnode == NULL || pDnode->numOfVnodes > pDnode->numOfSupportVnodes) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[maxPos];
|
||||
pVgid->dnodeId = pDnode->id;
|
||||
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
||||
pDnode->numOfVnodes++;
|
||||
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is added", pVgroup->dbName, pVgroup->vgId, maxPos, pVgid->dnodeId);
|
||||
maxPos++;
|
||||
if (maxPos == 3) return 0;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *del1, SVnodeGid *del2) {
|
||||
int32_t removedNum = 0;
|
||||
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
}
|
||||
|
||||
for (int32_t d = taosArrayGetSize(pArray) - 1; d >= 0; --d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
for (int32_t vn = 0; vn < TSDB_MAX_REPLICA; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
if (pVgid->dnodeId == pDnode->id) {
|
||||
if (removedNum == 0) *del1 = *pVgid;
|
||||
if (removedNum == 1) *del2 = *pVgid;
|
||||
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is removed", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
||||
memset(pVgid, 0, sizeof(SVnodeGid));
|
||||
removedNum++;
|
||||
pDnode->numOfVnodes--;
|
||||
|
||||
if (removedNum == 2) goto _OVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (removedNum != 2) return -1;
|
||||
|
||||
for (int32_t vn = 1; vn < TSDB_MAX_REPLICA; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
if (pVgid->dnodeId != 0) {
|
||||
memcpy(&pVgroup->vnodeGid[0], pVgid, sizeof(SVnodeGid));
|
||||
memset(pVgid, 0, sizeof(SVnodeGid));
|
||||
}
|
||||
}
|
||||
|
||||
mInfo("db:%s, vgId:%d, dnode:%d is keeped", pVgroup->dbName, pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) {
|
||||
SEpSet epset = {0};
|
||||
|
||||
|
|
|
@ -73,14 +73,19 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
{
|
||||
SAlterDbReq alterdbReq = {0};
|
||||
strcpy(alterdbReq.db, "1.d1");
|
||||
|
||||
alterdbReq.buffer = 12;
|
||||
alterdbReq.daysToKeep0 = 300;
|
||||
alterdbReq.daysToKeep1 = 400;
|
||||
alterdbReq.daysToKeep2 = 500;
|
||||
alterdbReq.pageSize = -1;
|
||||
alterdbReq.pages = -1;
|
||||
alterdbReq.daysPerFile = -1;
|
||||
alterdbReq.daysToKeep0 = -1;
|
||||
alterdbReq.daysToKeep1 = -1;
|
||||
alterdbReq.daysToKeep2 = -1;
|
||||
alterdbReq.fsyncPeriod = 4000;
|
||||
alterdbReq.walLevel = 2;
|
||||
alterdbReq.strict = 2;
|
||||
alterdbReq.strict = 1;
|
||||
alterdbReq.cacheLastRow = 1;
|
||||
alterdbReq.replications = 1;
|
||||
|
||||
int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
|
|
|
@ -266,4 +266,96 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) {
|
|||
taosMsleep(1300);
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// alter replica
|
||||
#if 0
|
||||
{
|
||||
SCreateDbReq createReq = {0};
|
||||
strcpy(createReq.db, "1.d2");
|
||||
createReq.numOfVgroups = 2;
|
||||
createReq.buffer = -1;
|
||||
createReq.pageSize = -1;
|
||||
createReq.pages = -1;
|
||||
createReq.daysPerFile = 1000;
|
||||
createReq.daysToKeep0 = 3650;
|
||||
createReq.daysToKeep1 = 3650;
|
||||
createReq.daysToKeep2 = 3650;
|
||||
createReq.minRows = 100;
|
||||
createReq.maxRows = 4096;
|
||||
createReq.fsyncPeriod = 3000;
|
||||
createReq.walLevel = 1;
|
||||
createReq.precision = 0;
|
||||
createReq.compression = 2;
|
||||
createReq.replications = 1;
|
||||
createReq.strict = 1;
|
||||
createReq.cacheLastRow = 0;
|
||||
createReq.ignoreExist = 1;
|
||||
createReq.numOfStables = 0;
|
||||
createReq.numOfRetensions = 0;
|
||||
|
||||
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSCreateDbReq(pReq, contLen, &createReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_DB, "user_databases", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 3);
|
||||
}
|
||||
|
||||
{
|
||||
SAlterDbReq alterdbReq = {0};
|
||||
strcpy(alterdbReq.db, "1.d2");
|
||||
|
||||
alterdbReq.buffer = 12;
|
||||
alterdbReq.pageSize = -1;
|
||||
alterdbReq.pages = -1;
|
||||
alterdbReq.daysPerFile = -1;
|
||||
alterdbReq.daysToKeep0 = -1;
|
||||
alterdbReq.daysToKeep1 = -1;
|
||||
alterdbReq.daysToKeep2 = -1;
|
||||
alterdbReq.fsyncPeriod = 4000;
|
||||
alterdbReq.walLevel = 2;
|
||||
alterdbReq.strict = 1;
|
||||
alterdbReq.cacheLastRow = 1;
|
||||
alterdbReq.replications = 3;
|
||||
|
||||
int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SAlterDbReq alterdbReq = {0};
|
||||
strcpy(alterdbReq.db, "1.d2");
|
||||
|
||||
alterdbReq.buffer = 12;
|
||||
alterdbReq.pageSize = -1;
|
||||
alterdbReq.pages = -1;
|
||||
alterdbReq.daysPerFile = -1;
|
||||
alterdbReq.daysToKeep0 = -1;
|
||||
alterdbReq.daysToKeep1 = -1;
|
||||
alterdbReq.daysToKeep2 = -1;
|
||||
alterdbReq.fsyncPeriod = 4000;
|
||||
alterdbReq.walLevel = 2;
|
||||
alterdbReq.strict = 1;
|
||||
alterdbReq.cacheLastRow = 1;
|
||||
alterdbReq.replications = 1;
|
||||
|
||||
int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ void* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pContLen) {
|
|||
}
|
||||
|
||||
void* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 1;
|
||||
req.pFields = taosArrayInit(1, sizeof(SField));
|
||||
|
@ -158,7 +158,7 @@ void* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagnam
|
|||
}
|
||||
|
||||
void* MndTestStb::BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 1;
|
||||
req.pFields = taosArrayInit(1, sizeof(SField));
|
||||
|
@ -180,7 +180,7 @@ void* MndTestStb::BuildAlterStbDropTagReq(const char* stbname, const char* tagna
|
|||
|
||||
void* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname,
|
||||
int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 2;
|
||||
req.pFields = taosArrayInit(2, sizeof(SField));
|
||||
|
@ -208,7 +208,7 @@ void* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char*
|
|||
|
||||
void* MndTestStb::BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes,
|
||||
int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 1;
|
||||
req.pFields = taosArrayInit(1, sizeof(SField));
|
||||
|
@ -229,7 +229,7 @@ void* MndTestStb::BuildAlterStbUpdateTagBytesReq(const char* stbname, const char
|
|||
}
|
||||
|
||||
void* MndTestStb::BuildAlterStbAddColumnReq(const char* stbname, const char* colname, int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 1;
|
||||
req.pFields = taosArrayInit(1, sizeof(SField));
|
||||
|
@ -250,7 +250,7 @@ void* MndTestStb::BuildAlterStbAddColumnReq(const char* stbname, const char* col
|
|||
}
|
||||
|
||||
void* MndTestStb::BuildAlterStbDropColumnReq(const char* stbname, const char* colname, int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 1;
|
||||
req.pFields = taosArrayInit(1, sizeof(SField));
|
||||
|
@ -272,7 +272,7 @@ void* MndTestStb::BuildAlterStbDropColumnReq(const char* stbname, const char* co
|
|||
|
||||
void* MndTestStb::BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes,
|
||||
int32_t* pContLen) {
|
||||
SMAltertbReq req = {0};
|
||||
SMAlterStbReq req = {0};
|
||||
strcpy(req.name, stbname);
|
||||
req.numOfFields = 1;
|
||||
req.pFields = taosArrayInit(1, sizeof(SField));
|
||||
|
|
|
@ -84,6 +84,8 @@ int32_t qndProcessFetchMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
|||
// return vnodeGetTableMeta(pQnode, pMsg);
|
||||
case TDMT_VND_CONSUME:
|
||||
// return tqProcessConsumeReq(pQnode->pTq, pMsg);
|
||||
case TDMT_VND_QUERY_HEARTBEAT:
|
||||
return qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg);
|
||||
default:
|
||||
qError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
|
|
|
@ -99,10 +99,10 @@ void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
|||
ASSERT(0);
|
||||
return;
|
||||
}
|
||||
SCoder decoder;
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, msg, pMsg->contLen - sizeof(SMsgHead), TD_DECODER);
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, msg, pMsg->contLen - sizeof(SMsgHead));
|
||||
tDecodeSStreamTask(&decoder, pTask);
|
||||
tCoderClear(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
sndMetaDeployTask(pSnode->pMeta, pTask);
|
||||
} else if (pMsg->msgType == TDMT_SND_TASK_EXEC) {
|
||||
|
|
|
@ -90,7 +90,7 @@ int metaTbCursorNext(SMTbCursor *pTbCur);
|
|||
|
||||
// tsdb
|
||||
// typedef struct STsdb STsdb;
|
||||
typedef void *tsdbReaderT;
|
||||
typedef void *tsdbReaderT;
|
||||
|
||||
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
|
||||
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||
|
@ -108,12 +108,12 @@ int32_t tsdbQuerySTableByTagCond(void *pMeta, uint64_t uid, TSKEY skey, con
|
|||
int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle);
|
||||
bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
|
||||
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg ***pBlockStatis, bool* allHave);
|
||||
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
|
||||
void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond *pCond);
|
||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
||||
int32_t tsdbGetTableGroupFromIdList(SVnode *pVnode, SArray *pTableIdList, STableGroupInfo *pGroupInfo);
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg ***pBlockStatis, bool *allHave);
|
||||
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
|
||||
void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond *pCond);
|
||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
||||
int32_t tsdbGetTableGroupFromIdList(SVnode *pVnode, SArray *pTableIdList, STableGroupInfo *pGroupInfo);
|
||||
|
||||
// tq
|
||||
|
||||
|
@ -126,8 +126,8 @@ int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList
|
|||
int tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
|
||||
int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver);
|
||||
bool tqNextDataBlock(STqReadHandle *pHandle);
|
||||
int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, int32_t *pNumOfRows,
|
||||
int16_t *pNumOfCols);
|
||||
int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, uint64_t *pUid,
|
||||
int32_t *pNumOfRows, int16_t *pNumOfCols);
|
||||
|
||||
// need to reposition
|
||||
|
||||
|
@ -189,10 +189,10 @@ struct SMetaEntry {
|
|||
SSchemaWrapper schemaTag;
|
||||
} stbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
tb_uid_t suid;
|
||||
const void *pTags;
|
||||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
tb_uid_t suid;
|
||||
const uint8_t *pTags;
|
||||
} ctbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
|
@ -205,7 +205,7 @@ struct SMetaEntry {
|
|||
struct SMetaReader {
|
||||
int32_t flags;
|
||||
SMeta *pMeta;
|
||||
SCoder coder;
|
||||
SDecoder coder;
|
||||
SMetaEntry me;
|
||||
void *pBuf;
|
||||
int szBuf;
|
||||
|
|
|
@ -39,8 +39,8 @@ typedef struct SMSmaCursor SMSmaCursor;
|
|||
// metaOpen ==================
|
||||
|
||||
// metaEntry ==================
|
||||
int metaEncodeEntry(SCoder* pCoder, const SMetaEntry* pME);
|
||||
int metaDecodeEntry(SCoder* pCoder, SMetaEntry* pME);
|
||||
int metaEncodeEntry(SEncoder* pCoder, const SMetaEntry* pME);
|
||||
int metaDecodeEntry(SDecoder* pCoder, SMetaEntry* pME);
|
||||
|
||||
// metaTable ==================
|
||||
|
||||
|
|
|
@ -273,7 +273,8 @@ typedef enum {
|
|||
|
||||
typedef struct {
|
||||
uint8_t last : 1;
|
||||
uint8_t blkVer : 7;
|
||||
uint8_t hasDupKey : 1; // 0: no dup TS key, 1: has dup TS key(since supporting Multi-Version)
|
||||
uint8_t blkVer : 6;
|
||||
uint8_t numOfSubBlocks;
|
||||
col_id_t numOfCols; // not including timestamp column
|
||||
uint32_t len; // data block length
|
||||
|
@ -324,9 +325,8 @@ typedef struct {
|
|||
typedef struct {
|
||||
int16_t colId;
|
||||
uint16_t type : 6;
|
||||
uint16_t blen : 10; // bitmap length(TODO: full UT for the bitmap compress of various data input)
|
||||
uint32_t bitmap : 1; // 0: no bitmap if all rows are NORM, 1: has bitmap if has NULL/NORM rows
|
||||
uint32_t len : 31; // data length + bitmap length
|
||||
uint16_t blen : 10; // 0 no bitmap if all rows are NORM, > 0 bitmap length
|
||||
uint32_t len; // data length + bitmap length
|
||||
uint32_t offset;
|
||||
} SBlockColV0;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "meta.h"
|
||||
|
||||
int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
|
||||
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pME->version) < 0) return -1;
|
||||
|
@ -43,8 +43,8 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) {
|
||||
uint64_t len;
|
||||
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
||||
uint32_t len;
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pME->version) < 0) return -1;
|
||||
|
|
|
@ -22,7 +22,7 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) {
|
|||
}
|
||||
|
||||
void metaReaderClear(SMetaReader *pReader) {
|
||||
tCoderClear(&pReader->coder);
|
||||
tDecoderClear(&pReader->coder);
|
||||
tdbFree(pReader->pBuf);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t u
|
|||
}
|
||||
|
||||
// decode the entry
|
||||
tCoderInit(&pReader->coder, TD_LITTLE_ENDIAN, pReader->pBuf, pReader->szBuf, TD_DECODER);
|
||||
tDecoderInit(&pReader->coder, pReader->pBuf, pReader->szBuf);
|
||||
|
||||
if (metaDecodeEntry(&pReader->coder, &pReader->me) < 0) {
|
||||
goto _err;
|
||||
|
@ -147,7 +147,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo
|
|||
SSchemaWrapper *pSW = NULL;
|
||||
SSchema *pSchema = NULL;
|
||||
void *pBuf;
|
||||
SCoder coder = {0};
|
||||
SDecoder coder = {0};
|
||||
|
||||
// fetch
|
||||
skmDbKey.uid = uid;
|
||||
|
@ -163,11 +163,11 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo
|
|||
pBuf = pVal;
|
||||
pSW = taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_DECODER);
|
||||
tDecoderInit(&coder, pVal, vLen);
|
||||
tDecodeSSchemaWrapper(&coder, pSW);
|
||||
pSchema = taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
|
||||
memcpy(pSchema, pSW->pSchema, sizeof(SSchema) * pSW->nCols);
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&coder);
|
||||
|
||||
pSW->pSchema = pSchema;
|
||||
|
||||
|
|
|
@ -1,843 +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/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifndef META_REFACT
|
||||
|
||||
typedef struct SPoolMem {
|
||||
int64_t size;
|
||||
struct SPoolMem *prev;
|
||||
struct SPoolMem *next;
|
||||
} SPoolMem;
|
||||
|
||||
#define META_TDB_SMA_TEST
|
||||
|
||||
static SPoolMem *openPool();
|
||||
static void clearPool(SPoolMem *pPool);
|
||||
static void closePool(SPoolMem *pPool);
|
||||
static void *poolMalloc(void *arg, size_t size);
|
||||
static void poolFree(void *arg, void *ptr);
|
||||
|
||||
struct SMetaDB {
|
||||
TXN txn;
|
||||
TENV *pEnv;
|
||||
TDB *pTbDB;
|
||||
TDB *pSchemaDB;
|
||||
TDB *pNameIdx;
|
||||
TDB *pStbIdx;
|
||||
TDB *pNtbIdx;
|
||||
TDB *pCtbIdx;
|
||||
SPoolMem *pPool;
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
TDB *pSmaDB;
|
||||
TDB *pSmaIdx;
|
||||
#endif
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int32_t sver;
|
||||
} SSchemaDbKey;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
tb_uid_t uid;
|
||||
} SNameIdxKey;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t suid;
|
||||
tb_uid_t uid;
|
||||
} SCtbIdxKey;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int64_t smaUid;
|
||||
} SSmaIdxKey;
|
||||
|
||||
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
|
||||
static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
|
||||
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW);
|
||||
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW);
|
||||
static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW);
|
||||
static void *metaDecodeSchemaEx(void *buf, SSchemaWrapper *pSW, bool isGetEx);
|
||||
|
||||
static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx);
|
||||
|
||||
static inline int metaUidCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||
tb_uid_t uid1, uid2;
|
||||
|
||||
ASSERT(len1 == sizeof(tb_uid_t));
|
||||
ASSERT(len2 == sizeof(tb_uid_t));
|
||||
|
||||
uid1 = ((tb_uid_t *)arg1)[0];
|
||||
uid2 = ((tb_uid_t *)arg2)[0];
|
||||
|
||||
if (uid1 < uid2) {
|
||||
return -1;
|
||||
}
|
||||
if (uid1 == uid2) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int metaSchemaKeyCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||
int c;
|
||||
SSchemaDbKey *pKey1 = (SSchemaDbKey *)arg1;
|
||||
SSchemaDbKey *pKey2 = (SSchemaDbKey *)arg2;
|
||||
|
||||
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
|
||||
if (c) return c;
|
||||
|
||||
if (pKey1->sver > pKey2->sver) {
|
||||
return 1;
|
||||
} else if (pKey1->sver == pKey2->sver) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int metaNameIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||
return strcmp((char *)arg1, (char *)arg2);
|
||||
}
|
||||
|
||||
static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||
int c;
|
||||
SCtbIdxKey *pKey1 = (SCtbIdxKey *)arg1;
|
||||
SCtbIdxKey *pKey2 = (SCtbIdxKey *)arg2;
|
||||
|
||||
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
|
||||
if (c) return c;
|
||||
|
||||
return metaUidCmpr(&pKey1->uid, sizeof(tb_uid_t), &pKey2->uid, sizeof(tb_uid_t));
|
||||
}
|
||||
|
||||
static inline int metaSmaIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||
int c;
|
||||
SSmaIdxKey *pKey1 = (SSmaIdxKey *)arg1;
|
||||
SSmaIdxKey *pKey2 = (SSmaIdxKey *)arg2;
|
||||
|
||||
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
|
||||
if (c) return c;
|
||||
|
||||
return metaUidCmpr(&pKey1->smaUid, sizeof(int64_t), &pKey2->smaUid, sizeof(int64_t));
|
||||
}
|
||||
|
||||
int metaOpenDB(SMeta *pMeta) {
|
||||
SMetaDB *pMetaDb;
|
||||
int ret;
|
||||
|
||||
// allocate DB handle
|
||||
pMetaDb = taosMemoryCalloc(1, sizeof(*pMetaDb));
|
||||
if (pMetaDb == NULL) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// open the ENV
|
||||
ret = tdbEnvOpen(pMeta->path, 4096, 256, &(pMetaDb->pEnv));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// open table DB
|
||||
ret = tdbDbOpen("table.db", sizeof(tb_uid_t), TDB_VARIANT_LEN, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pTbDB));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
ret = tdbDbOpen("sma.db", sizeof(int64_t), TDB_VARIANT_LEN, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pSmaDB));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// open schema DB
|
||||
ret = tdbDbOpen("schema.db", sizeof(SSchemaDbKey), TDB_VARIANT_LEN, metaSchemaKeyCmpr, pMetaDb->pEnv,
|
||||
&(pMetaDb->pSchemaDB));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbDbOpen("name.idx", TDB_VARIANT_LEN, 0, metaNameIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pNameIdx));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbDbOpen("stb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pStbIdx));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbDbOpen("ntb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pNtbIdx));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbDbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, metaCtbIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pCtbIdx));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
ret = tdbDbOpen("sma.idx", sizeof(SSmaIdxKey), 0, metaSmaIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pSmaIdx));
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
pMetaDb->pPool = openPool();
|
||||
tdbTxnOpen(&pMetaDb->txn, 0, poolMalloc, poolFree, pMetaDb->pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
tdbBegin(pMetaDb->pEnv, NULL);
|
||||
|
||||
pMeta->pDB = pMetaDb;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaCloseDB(SMeta *pMeta) {
|
||||
if (pMeta->pDB) {
|
||||
tdbCommit(pMeta->pDB->pEnv, &pMeta->pDB->txn);
|
||||
tdbTxnClose(&pMeta->pDB->txn);
|
||||
clearPool(pMeta->pDB->pPool);
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
tdbDbClose(pMeta->pDB->pSmaIdx);
|
||||
#endif
|
||||
tdbDbClose(pMeta->pDB->pCtbIdx);
|
||||
tdbDbClose(pMeta->pDB->pNtbIdx);
|
||||
tdbDbClose(pMeta->pDB->pStbIdx);
|
||||
tdbDbClose(pMeta->pDB->pNameIdx);
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
tdbDbClose(pMeta->pDB->pSmaDB);
|
||||
#endif
|
||||
tdbDbClose(pMeta->pDB->pSchemaDB);
|
||||
tdbDbClose(pMeta->pDB->pTbDB);
|
||||
taosMemoryFree(pMeta->pDB);
|
||||
}
|
||||
}
|
||||
|
||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||
tb_uid_t uid;
|
||||
SMetaDB *pMetaDb;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
int ret;
|
||||
char buf[512];
|
||||
void *pBuf;
|
||||
SCtbIdxKey ctbIdxKey;
|
||||
SSchemaDbKey schemaDbKey;
|
||||
SSchemaWrapper schemaWrapper;
|
||||
|
||||
pMetaDb = pMeta->pDB;
|
||||
|
||||
// TODO: make this operation pre-process
|
||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||
uid = pTbCfg->stbCfg.suid;
|
||||
} else {
|
||||
uid = metaGenerateUid(pMeta);
|
||||
}
|
||||
|
||||
// check name and uid unique
|
||||
if (tdbDbGet(pMetaDb->pTbDB, &uid, sizeof(uid), NULL, NULL) == 0) {
|
||||
return -1;
|
||||
}
|
||||
if (tdbDbGet(pMetaDb->pNameIdx, pTbCfg->name, strlen(pTbCfg->name) + 1, NULL, NULL) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// save to table.db
|
||||
pKey = &uid;
|
||||
kLen = sizeof(uid);
|
||||
pVal = pBuf = buf;
|
||||
metaEncodeTbInfo(&pBuf, pTbCfg);
|
||||
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||
ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// save to schema.db for META_SUPER_TABLE and META_NORMAL_TABLE
|
||||
if (pTbCfg->type != META_CHILD_TABLE) {
|
||||
schemaDbKey.uid = uid;
|
||||
schemaDbKey.sver = 0; // TODO
|
||||
pKey = &schemaDbKey;
|
||||
kLen = sizeof(schemaDbKey);
|
||||
|
||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||
schemaWrapper.nCols = pTbCfg->stbCfg.nCols;
|
||||
schemaWrapper.pSchema = pTbCfg->stbCfg.pSchema;
|
||||
} else {
|
||||
schemaWrapper.nCols = pTbCfg->ntbCfg.nCols;
|
||||
schemaWrapper.pSchema = pTbCfg->ntbCfg.pSchema;
|
||||
}
|
||||
pVal = pBuf = buf;
|
||||
metaEncodeSchemaEx(&pBuf, &schemaWrapper);
|
||||
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||
ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// update name.idx
|
||||
int nameLen = strlen(pTbCfg->name);
|
||||
memcpy(buf, pTbCfg->name, nameLen + 1);
|
||||
((tb_uid_t *)(buf + nameLen + 1))[0] = uid;
|
||||
pKey = buf;
|
||||
kLen = nameLen + 1 + sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// update other index
|
||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||
pKey = &uid;
|
||||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||
ctbIdxKey.suid = pTbCfg->ctbCfg.suid;
|
||||
ctbIdxKey.uid = uid;
|
||||
pKey = &ctbIdxKey;
|
||||
kLen = sizeof(ctbIdxKey);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
// child table handle for rsma
|
||||
if (pHandle && pHandle->fp) {
|
||||
if (((*pHandle->fp)(pHandle->ahandle, &pHandle->result, &ctbIdxKey.suid, &uid)) < 0) {
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||
pKey = &uid;
|
||||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pMeta->pDB->pPool->size > 0) {
|
||||
metaCommit(pMeta);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx) {
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
int ret;
|
||||
SSchemaDbKey schemaDbKey;
|
||||
SSchemaWrapper *pSchemaWrapper;
|
||||
void *pBuf;
|
||||
|
||||
// fetch
|
||||
schemaDbKey.uid = uid;
|
||||
schemaDbKey.sver = sver;
|
||||
pKey = &schemaDbKey;
|
||||
kLen = sizeof(schemaDbKey);
|
||||
pVal = NULL;
|
||||
ret = tdbDbGet(pMeta->pDB->pSchemaDB, pKey, kLen, &pVal, &vLen);
|
||||
if (ret < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// decode
|
||||
pBuf = pVal;
|
||||
pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper));
|
||||
metaDecodeSchemaEx(pBuf, pSchemaWrapper, isGetEx);
|
||||
|
||||
tdbFree(pVal);
|
||||
|
||||
return pSchemaWrapper;
|
||||
}
|
||||
|
||||
struct SMSmaCursor {
|
||||
TDBC *pCur;
|
||||
tb_uid_t uid;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
};
|
||||
|
||||
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
// return NULL;
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
STSmaWrapper *pSW = NULL;
|
||||
|
||||
SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid);
|
||||
if (pCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pBuf = NULL;
|
||||
SSmaIdxKey *pSmaIdxKey = NULL;
|
||||
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
|
||||
void *pSmaVal = metaGetSmaInfoByIndex(pMeta, pSmaIdxKey->smaUid, false);
|
||||
|
||||
if (pSmaVal == NULL) {
|
||||
tsdbWarn("no tsma exists for indexUid: %" PRIi64, pSmaIdxKey->smaUid);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((pSW == NULL) && ((pSW = taosMemoryCalloc(1, sizeof(*pSW))) == NULL)) {
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
++pSW->number;
|
||||
STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma));
|
||||
if (tptr == NULL) {
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
return NULL;
|
||||
}
|
||||
pSW->tSma = tptr;
|
||||
pBuf = pSmaVal;
|
||||
if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) {
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
return NULL;
|
||||
}
|
||||
tdbFree(pSmaVal);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
metaCloseSmaCursor(pCur);
|
||||
|
||||
return pSW;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
#ifndef META_TDB_SMA_TEST
|
||||
DBT key = {0};
|
||||
|
||||
key.data = (void *)indexName;
|
||||
key.size = strlen(indexName);
|
||||
|
||||
metaDBWLock(pMeta->pDB);
|
||||
// TODO: No guarantee of consistence.
|
||||
// Use transaction or DB->sync() for some guarantee.
|
||||
pMeta->pDB->pSmaDB->del(pMeta->pDB->pSmaDB, NULL, &key, 0);
|
||||
metaDBULock(pMeta->pDB);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
int32_t ret = 0;
|
||||
SMetaDB *pMetaDb = pMeta->pDB;
|
||||
void *pBuf = NULL, *qBuf = NULL;
|
||||
void *key = {0}, *val = {0};
|
||||
|
||||
// save sma info
|
||||
int32_t len = tEncodeTSma(NULL, pSmaCfg);
|
||||
pBuf = taosMemoryCalloc(1, len);
|
||||
if (pBuf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
key = (void *)&pSmaCfg->indexUid;
|
||||
qBuf = pBuf;
|
||||
tEncodeTSma(&qBuf, pSmaCfg);
|
||||
val = pBuf;
|
||||
|
||||
int32_t kLen = sizeof(pSmaCfg->indexUid);
|
||||
int32_t vLen = POINTER_DISTANCE(qBuf, pBuf);
|
||||
|
||||
ret = tdbDbInsert(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
taosMemoryFreeClear(pBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// add sma idx
|
||||
SSmaIdxKey smaIdxKey;
|
||||
smaIdxKey.uid = pSmaCfg->tableUid;
|
||||
smaIdxKey.smaUid = pSmaCfg->indexUid;
|
||||
key = &smaIdxKey;
|
||||
kLen = sizeof(smaIdxKey);
|
||||
val = NULL;
|
||||
vLen = 0;
|
||||
|
||||
ret = tdbDbInsert(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
taosMemoryFreeClear(pBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// release
|
||||
taosMemoryFreeClear(pBuf);
|
||||
|
||||
if (pMeta->pDB->pPool->size > 0) {
|
||||
metaCommit(pMeta);
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pMeta
|
||||
* @param uid 0 means iterate all uids.
|
||||
* @return SMSmaCursor*
|
||||
*/
|
||||
SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
// return NULL;
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
SMSmaCursor *pCur = NULL;
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
int ret;
|
||||
|
||||
pCur = (SMSmaCursor *)taosMemoryCalloc(1, sizeof(*pCur));
|
||||
if (pCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCur->uid = uid;
|
||||
ret = tdbDbcOpen(pDB->pSmaIdx, &(pCur->pCur));
|
||||
if ((ret != 0) || (pCur->pCur == NULL)) {
|
||||
taosMemoryFree(pCur);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (uid != 0) {
|
||||
// TODO: move to the specific uid
|
||||
}
|
||||
|
||||
return pCur;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pCur
|
||||
* @return int64_t smaIndexUid
|
||||
*/
|
||||
int64_t metaSmaCursorNext(SMSmaCursor *pCur) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
// return NULL;
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
int ret;
|
||||
void *pBuf;
|
||||
SSmaIdxKey *smaIdxKey;
|
||||
|
||||
ret = tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, &pCur->pVal, &pCur->vLen);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
smaIdxKey = pCur->pKey;
|
||||
return smaIdxKey->smaUid;
|
||||
#endif
|
||||
}
|
||||
|
||||
void metaCloseSmaCursor(SMSmaCursor *pCur) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
if (pCur) {
|
||||
if (pCur->pCur) {
|
||||
tdbDbcClose(pCur->pCur);
|
||||
}
|
||||
|
||||
taosMemoryFree(pCur);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
|
||||
int tlen = 0;
|
||||
SSchema *pSchema;
|
||||
|
||||
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->flags);
|
||||
tlen += taosEncodeFixedI16(buf, pSchema->colId);
|
||||
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
|
||||
tlen += taosEncodeString(buf, pSchema->name);
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) {
|
||||
SSchema *pSchema;
|
||||
|
||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||
pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||
buf = taosSkipFixedLen(buf, sizeof(int8_t));
|
||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int metaEncodeSchemaEx(void **buf, SSchemaWrapper *pSW) {
|
||||
int tlen = 0;
|
||||
SSchema *pSchema;
|
||||
|
||||
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||
for (int i = 0; i < pSW->nCols; ++i) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->flags);
|
||||
tlen += taosEncodeFixedI16(buf, pSchema->colId);
|
||||
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
|
||||
tlen += taosEncodeString(buf, pSchema->name);
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static void *metaDecodeSchemaEx(void *buf, SSchemaWrapper *pSW, bool isGetEx) {
|
||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||
if (isGetEx) {
|
||||
pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
SSchema *pSchema = pSW->pSchema + i;
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->flags);
|
||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||
}
|
||||
} else {
|
||||
pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
SSchema *pSchema = pSW->pSchema + i;
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||
buf = taosSkipFixedLen(buf, sizeof(int8_t));
|
||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
|
||||
int tsize = 0;
|
||||
|
||||
tsize += taosEncodeString(buf, pTbCfg->name);
|
||||
tsize += taosEncodeFixedU32(buf, pTbCfg->ttl);
|
||||
tsize += taosEncodeFixedU32(buf, pTbCfg->keep);
|
||||
tsize += taosEncodeFixedU8(buf, pTbCfg->info);
|
||||
|
||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||
SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema};
|
||||
tsize += metaEncodeSchema(buf, &sw);
|
||||
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||
tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid);
|
||||
tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag);
|
||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||
// TODO
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return tsize;
|
||||
}
|
||||
|
||||
static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
|
||||
buf = taosDecodeString(buf, &(pTbCfg->name));
|
||||
buf = taosDecodeFixedU32(buf, &(pTbCfg->ttl));
|
||||
buf = taosDecodeFixedU32(buf, &(pTbCfg->keep));
|
||||
buf = taosDecodeFixedU8(buf, &(pTbCfg->info));
|
||||
|
||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||
SSchemaWrapper sw;
|
||||
buf = metaDecodeSchema(buf, &sw);
|
||||
pTbCfg->stbCfg.nTagCols = sw.nCols;
|
||||
pTbCfg->stbCfg.pTagSchema = sw.pSchema;
|
||||
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||
buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid));
|
||||
buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag));
|
||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||
// TODO
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
int metaCommit(SMeta *pMeta) {
|
||||
TXN *pTxn = &pMeta->pDB->txn;
|
||||
|
||||
// Commit current txn
|
||||
tdbCommit(pMeta->pDB->pEnv, pTxn);
|
||||
tdbTxnClose(pTxn);
|
||||
clearPool(pMeta->pDB->pPool);
|
||||
|
||||
// start a new txn
|
||||
tdbTxnOpen(&pMeta->pDB->txn, 0, poolMalloc, poolFree, pMeta->pDB->pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
tdbBegin(pMeta->pDB->pEnv, pTxn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SPoolMem *openPool() {
|
||||
SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool));
|
||||
|
||||
pPool->prev = pPool->next = pPool;
|
||||
pPool->size = 0;
|
||||
|
||||
return pPool;
|
||||
}
|
||||
|
||||
static void clearPool(SPoolMem *pPool) {
|
||||
SPoolMem *pMem;
|
||||
|
||||
do {
|
||||
pMem = pPool->next;
|
||||
|
||||
if (pMem == pPool) break;
|
||||
|
||||
pMem->next->prev = pMem->prev;
|
||||
pMem->prev->next = pMem->next;
|
||||
pPool->size -= pMem->size;
|
||||
|
||||
tdbOsFree(pMem);
|
||||
} while (1);
|
||||
|
||||
assert(pPool->size == 0);
|
||||
}
|
||||
|
||||
static void closePool(SPoolMem *pPool) {
|
||||
clearPool(pPool);
|
||||
tdbOsFree(pPool);
|
||||
}
|
||||
|
||||
static void *poolMalloc(void *arg, size_t size) {
|
||||
void *ptr = NULL;
|
||||
SPoolMem *pPool = (SPoolMem *)arg;
|
||||
SPoolMem *pMem;
|
||||
|
||||
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
||||
if (pMem == NULL) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
pMem->size = sizeof(*pMem) + size;
|
||||
pMem->next = pPool->next;
|
||||
pMem->prev = pPool;
|
||||
|
||||
pPool->next->prev = pMem;
|
||||
pPool->next = pMem;
|
||||
pPool->size += pMem->size;
|
||||
|
||||
ptr = (void *)(&pMem[1]);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void poolFree(void *arg, void *ptr) {
|
||||
SPoolMem *pPool = (SPoolMem *)arg;
|
||||
SPoolMem *pMem;
|
||||
|
||||
pMem = &(((SPoolMem *)ptr)[-1]);
|
||||
|
||||
pMem->next->prev = pMem->prev;
|
||||
pMem->prev->next = pMem->next;
|
||||
pPool->size -= pMem->size;
|
||||
|
||||
tdbOsFree(pMem);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -33,7 +33,6 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
void *pBuf = NULL;
|
||||
int32_t szBuf = 0;
|
||||
void *p = NULL;
|
||||
SCoder coder = {0};
|
||||
SMetaReader mr = {0};
|
||||
|
||||
// validate req
|
||||
|
@ -192,16 +191,16 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
|
|||
tb_uid_t uid;
|
||||
int64_t tver;
|
||||
SMetaEntry me = {0};
|
||||
SCoder coder = {0};
|
||||
SDecoder coder = {0};
|
||||
int8_t type;
|
||||
int64_t ctime;
|
||||
tb_uid_t suid;
|
||||
int c, ret;
|
||||
int c = 0, ret;
|
||||
|
||||
// search & delete the name idx
|
||||
tdbDbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c);
|
||||
if (ret < 0 || c) {
|
||||
if (ret < 0 || !tdbDbcIsValid(pNameIdxc) || c) {
|
||||
tdbDbcClose(pNameIdxc);
|
||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
|
@ -253,7 +252,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
|
|||
// decode entry
|
||||
void *pDataCopy = taosMemoryMalloc(nData); // remove the copy (todo)
|
||||
memcpy(pDataCopy, pData, nData);
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pDataCopy, nData, TD_DECODER);
|
||||
tDecoderInit(&coder, pDataCopy, nData);
|
||||
ret = metaDecodeEntry(&coder, &me);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
|
@ -272,7 +271,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
|
|||
}
|
||||
|
||||
taosMemoryFree(pDataCopy);
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&coder);
|
||||
tdbDbcClose(pTbDbc);
|
||||
|
||||
if (type == TSDB_CHILD_TABLE) {
|
||||
|
@ -309,7 +308,7 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
void *pVal = NULL;
|
||||
int kLen = 0;
|
||||
int vLen = 0;
|
||||
SCoder coder = {0};
|
||||
SEncoder coder = {0};
|
||||
|
||||
// set key and value
|
||||
tbDbKey.version = pME->version;
|
||||
|
@ -330,13 +329,13 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER);
|
||||
tEncoderInit(&coder, pVal, vLen);
|
||||
|
||||
if (metaEncodeEntry(&coder, pME) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
tCoderClear(&coder);
|
||||
tEncoderClear(&coder);
|
||||
|
||||
// write to table.db
|
||||
if (tdbDbInsert(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) {
|
||||
|
@ -393,7 +392,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
}
|
||||
|
||||
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCoder coder = {0};
|
||||
SEncoder coder = {0};
|
||||
void *pVal = NULL;
|
||||
int vLen = 0;
|
||||
int rcode = 0;
|
||||
|
@ -422,7 +421,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER);
|
||||
tEncoderInit(&coder, pVal, vLen);
|
||||
tEncodeSSchemaWrapper(&coder, pSW);
|
||||
|
||||
if (tdbDbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) {
|
||||
|
@ -432,7 +431,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
|
||||
_exit:
|
||||
taosMemoryFree(pVal);
|
||||
tCoderClear(&coder);
|
||||
tEncoderClear(&coder);
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_
|
|||
tqReadHandleSetMsg(pReader, pReq, 0);
|
||||
while (tqNextDataBlock(pReader)) {
|
||||
SSDataBlock block = {0};
|
||||
if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.rows,
|
||||
if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows,
|
||||
&block.info.numOfCols) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
tqReadHandleSetMsg(pReader, pCont, 0);
|
||||
while (tqNextDataBlock(pReader)) {
|
||||
SSDataBlock block = {0};
|
||||
if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.rows,
|
||||
if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows,
|
||||
&block.info.numOfCols) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -910,12 +910,12 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
if (pTask == NULL) {
|
||||
return -1;
|
||||
}
|
||||
SCoder decoder;
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, (uint8_t*)msg, msgLen, TD_DECODER);
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, (uint8_t*)msg, msgLen);
|
||||
if (tDecodeSStreamTask(&decoder, pTask) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
tCoderClear(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
// exec
|
||||
if (tqExpandTask(pTq, pTask, 4) < 0) {
|
||||
|
|
|
@ -84,10 +84,12 @@ bool tqNextDataBlock(STqReadHandle* pHandle) {
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* pGroupId, int32_t* pNumOfRows,
|
||||
int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* pGroupId, uint64_t* pUid, int32_t* pNumOfRows,
|
||||
int16_t* pNumOfCols) {
|
||||
/*int32_t sversion = pHandle->pBlock->sversion;*/
|
||||
// TODO set to real sversion
|
||||
*pUid = 0;
|
||||
|
||||
int32_t sversion = 0;
|
||||
if (pHandle->sver != sversion) {
|
||||
pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion);
|
||||
|
@ -169,7 +171,10 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
|||
tdSTSRowIterInit(&iter, pTschema);
|
||||
STSRow* row;
|
||||
int32_t curRow = 0;
|
||||
|
||||
tInitSubmitBlkIter(&pHandle->msgIter, pHandle->pBlock, &pHandle->blkIter);
|
||||
*pUid = pHandle->msgIter.uid; // set the uid of table for submit block
|
||||
|
||||
while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) {
|
||||
tdSTSRowIterReset(&iter, row);
|
||||
// get all wanted col of that block
|
||||
|
|
|
@ -943,16 +943,16 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
|
|||
&(pAggrBlkCol->numOfNull));
|
||||
|
||||
if (pAggrBlkCol->numOfNull == 0) {
|
||||
TD_SET_COL_ROWS_NORM(pBlockCol);
|
||||
pBlockCol->blen = 0;
|
||||
} else {
|
||||
TD_SET_COL_ROWS_MISC(pBlockCol);
|
||||
pBlockCol->blen = 1;
|
||||
}
|
||||
++nColsOfBlockSma;
|
||||
} else if (tdIsBitmapBlkNorm(pDataCol->pBitmap, rowsToWrite, pDataCols->bitmapMode)) {
|
||||
// check if all rows normal
|
||||
TD_SET_COL_ROWS_NORM(pBlockCol);
|
||||
pBlockCol->blen = 0;
|
||||
} else {
|
||||
TD_SET_COL_ROWS_MISC(pBlockCol);
|
||||
pBlockCol->blen = 1;
|
||||
}
|
||||
|
||||
++nColsNotAllNull;
|
||||
|
@ -985,7 +985,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
|
|||
#ifdef TD_SUPPORT_BITMAP
|
||||
int32_t tBitmaps = 0;
|
||||
int32_t tBitmapsLen = 0;
|
||||
if ((ncol != 0) && !TD_COL_ROWS_NORM(pBlockCol)) {
|
||||
if ((ncol != 0) && (pBlockCol->blen > 0)) {
|
||||
tBitmaps = isSuper ? sBitmaps : nBitmaps;
|
||||
}
|
||||
#endif
|
||||
|
@ -1330,13 +1330,15 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
TSKEY maxKey, int maxRows, int8_t update) {
|
||||
TSKEY key1 = INT64_MAX;
|
||||
TSKEY key2 = INT64_MAX;
|
||||
TSKEY lastKey = TSKEY_INITIAL_VAL;
|
||||
STSchema *pSchema = NULL;
|
||||
|
||||
ASSERT(maxRows > 0 && dataColsKeyLast(pDataCols) <= maxKey);
|
||||
tdResetDataCols(pTarget);
|
||||
|
||||
pTarget->bitmapMode = pDataCols->bitmapMode;
|
||||
|
||||
// TODO: filter Multi-Version
|
||||
// TODO: support delete function
|
||||
while (true) {
|
||||
key1 = (*iter >= pDataCols->numOfRows) ? INT64_MAX : dataColsKeyAt(pDataCols, *iter);
|
||||
STSRow *row = tsdbNextIterRow(pCommitIter->pIter);
|
||||
|
@ -1349,6 +1351,9 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
if (key1 == INT64_MAX && key2 == INT64_MAX) break;
|
||||
|
||||
if (key1 < key2) {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pTarget->numOfRows;
|
||||
}
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
// TODO: dataColAppendVal may fail
|
||||
SCellVal sVal = {0};
|
||||
|
@ -1356,10 +1361,10 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
TASSERT(0);
|
||||
}
|
||||
tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints,
|
||||
pTarget->bitmapMode);
|
||||
pTarget->bitmapMode, false);
|
||||
}
|
||||
|
||||
++pTarget->numOfRows;
|
||||
lastKey = key1;
|
||||
++(*iter);
|
||||
} else if (key1 > key2) {
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) {
|
||||
|
@ -1367,7 +1372,17 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget);
|
||||
if (key2 == lastKey) {
|
||||
if (TD_SUPPORT_UPDATE(update)) {
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget, true);
|
||||
}
|
||||
} else {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pTarget->numOfRows;
|
||||
}
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget, false);
|
||||
lastKey = key2;
|
||||
}
|
||||
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
} else {
|
||||
|
@ -1397,6 +1412,12 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
#endif
|
||||
|
||||
if(lastKey != key1) {
|
||||
lastKey = key1;
|
||||
++pTarget->numOfRows;
|
||||
}
|
||||
|
||||
// copy disk data
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
SCellVal sVal = {0};
|
||||
|
@ -1405,7 +1426,7 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
}
|
||||
// TODO: tdAppendValToDataCol may fail
|
||||
tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints,
|
||||
pTarget->bitmapMode);
|
||||
pTarget->bitmapMode, false);
|
||||
}
|
||||
|
||||
if (TD_SUPPORT_UPDATE(update)) {
|
||||
|
@ -1416,26 +1437,17 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
}
|
||||
|
||||
// TODO: merge with Multi-Version
|
||||
STSRow *curRow = row;
|
||||
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
STSRow *nextRow = tsdbNextIterRow(pCommitIter->pIter);
|
||||
|
||||
if (key2 < TD_ROW_KEY(nextRow)) {
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget);
|
||||
} else {
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget);
|
||||
}
|
||||
// TODO: merge with Multi-Version
|
||||
} else {
|
||||
++pTarget->numOfRows;
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget, true);
|
||||
}
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
}
|
||||
|
||||
if (pTarget->numOfRows >= maxRows) break;
|
||||
if (pTarget->numOfRows >= (maxRows - 1)) break;
|
||||
}
|
||||
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pTarget->numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ static void tsdbFreeTbData(STbData *pTbData);
|
|||
static char *tsdbGetTsTupleKey(const void *data);
|
||||
static int tsdbTbDataComp(const void *arg1, const void *arg2);
|
||||
static char *tsdbTbDataGetUid(const void *arg);
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row);
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, bool merge);
|
||||
|
||||
int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable) {
|
||||
STsdbMemTable *pMemTable;
|
||||
|
@ -82,14 +82,19 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) {
|
||||
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0);
|
||||
if (pIter == NULL) return 0;
|
||||
STSchema *pSchema = NULL;
|
||||
TSKEY rowKey = 0;
|
||||
TSKEY fKey = 0;
|
||||
STSchema *pSchema = NULL;
|
||||
TSKEY rowKey = 0;
|
||||
TSKEY fKey = 0;
|
||||
// only fetch lastKey from mem data as file data not used in this function actually
|
||||
TSKEY lastKey = TSKEY_INITIAL_VAL;
|
||||
bool isRowDel = false;
|
||||
int filterIter = 0;
|
||||
STSRow *row = NULL;
|
||||
SMergeInfo mInfo;
|
||||
|
||||
// TODO: support Multi-Version(the rows with the same TS keys in memory can't be merged if its version refered by
|
||||
// query handle)
|
||||
|
||||
if (pMergeInfo == NULL) pMergeInfo = &mInfo;
|
||||
|
||||
memset(pMergeInfo, 0, sizeof(*pMergeInfo));
|
||||
|
@ -111,7 +116,8 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
} else {
|
||||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
|
||||
// 1. fkey - no dup since merged up to maxVersion of each query handle by tsdbLoadBlockDataCols
|
||||
// 2. rowKey - would dup since Multi-Version supported
|
||||
while (true) {
|
||||
if (fKey == INT64_MAX && rowKey == INT64_MAX) break;
|
||||
|
||||
|
@ -125,12 +131,14 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
} else {
|
||||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
#if 0
|
||||
} else if (fKey > rowKey) {
|
||||
if (isRowDel) {
|
||||
pMergeInfo->rowsDeleteFailed++;
|
||||
} else {
|
||||
if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break;
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
|
||||
pMergeInfo->rowsInserted++;
|
||||
pMergeInfo->nOperations++;
|
||||
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey);
|
||||
|
@ -185,6 +193,96 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
} else if (fKey > rowKey) {
|
||||
if (isRowDel) {
|
||||
// TODO: support delete function
|
||||
pMergeInfo->rowsDeleteFailed++;
|
||||
} else {
|
||||
if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break;
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
|
||||
if (lastKey != rowKey) {
|
||||
pMergeInfo->rowsInserted++;
|
||||
pMergeInfo->nOperations++;
|
||||
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey);
|
||||
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey);
|
||||
if (pCols) {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pCols->numOfRows;
|
||||
}
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
}
|
||||
lastKey = rowKey;
|
||||
} else {
|
||||
if (keepDup) {
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, true);
|
||||
} else {
|
||||
// discard
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tSkipListIterNext(pIter);
|
||||
row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL || TD_ROW_KEY(row) > maxKey) {
|
||||
rowKey = INT64_MAX;
|
||||
isRowDel = false;
|
||||
} else {
|
||||
rowKey = TD_ROW_KEY(row);
|
||||
isRowDel = TD_ROW_IS_DELETED(row);
|
||||
}
|
||||
} else { // fkey == rowKey
|
||||
if (isRowDel) { // TODO: support delete function(How to stands for delete in file? rowVersion = -1?)
|
||||
ASSERT(!keepDup);
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
pMergeInfo->rowsDeleteSucceed++;
|
||||
pMergeInfo->nOperations++;
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
} else {
|
||||
if (keepDup) {
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
if (lastKey != rowKey) {
|
||||
pMergeInfo->rowsUpdated++;
|
||||
pMergeInfo->nOperations++;
|
||||
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey);
|
||||
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey);
|
||||
lastKey = rowKey;
|
||||
if (pCols) {
|
||||
++pCols->numOfRows;
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
}
|
||||
} else {
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, true);
|
||||
}
|
||||
} else {
|
||||
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey);
|
||||
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey);
|
||||
}
|
||||
}
|
||||
|
||||
tSkipListIterNext(pIter);
|
||||
row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL || TD_ROW_KEY(row) > maxKey) {
|
||||
rowKey = INT64_MAX;
|
||||
isRowDel = false;
|
||||
} else {
|
||||
rowKey = TD_ROW_KEY(row);
|
||||
isRowDel = TD_ROW_IS_DELETED(row);
|
||||
}
|
||||
|
||||
filterIter++;
|
||||
if (filterIter >= nFilterKeys) {
|
||||
fKey = INT64_MAX;
|
||||
} else {
|
||||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (pCols && (lastKey != TSKEY_INITIAL_VAL)) {
|
||||
++pCols->numOfRows;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -254,9 +352,12 @@ static STbData *tsdbNewTbData(tb_uid_t uid) {
|
|||
pTbData->keyMin = TSKEY_MAX;
|
||||
pTbData->keyMax = TSKEY_MIN;
|
||||
pTbData->nrows = 0;
|
||||
|
||||
#if 0
|
||||
pTbData->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), tkeyComparFn, SL_DISCARD_DUP_KEY,
|
||||
tsdbGetTsTupleKey);
|
||||
#endif
|
||||
pTbData->pData =
|
||||
tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), tkeyComparFn, SL_ALLOW_DUP_KEY, tsdbGetTsTupleKey);
|
||||
if (pTbData->pData == NULL) {
|
||||
taosMemoryFree(pTbData);
|
||||
return NULL;
|
||||
|
@ -291,7 +392,7 @@ static char *tsdbTbDataGetUid(const void *arg) {
|
|||
STbData *pTbData = (STbData *)arg;
|
||||
return (char *)(&(pTbData->uid));
|
||||
}
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row) {
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, bool merge) {
|
||||
if (pCols) {
|
||||
if (*ppSchema == NULL || schemaVersion(*ppSchema) != TD_ROW_SVER(row)) {
|
||||
*ppSchema = tsdbGetTableSchemaImpl(pTable, false, false, TD_ROW_SVER(row));
|
||||
|
@ -301,7 +402,7 @@ static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema *
|
|||
}
|
||||
}
|
||||
|
||||
tdAppendSTSRowToDataCol(row, *ppSchema, pCols);
|
||||
tdAppendSTSRowToDataCol(row, *ppSchema, pCols, merge);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
|
||||
#include "tsdb.h"
|
||||
|
||||
typedef struct SMemTable SMemTable;
|
||||
typedef struct SMemData SMemData;
|
||||
typedef struct SMemSkipList SMemSkipList;
|
||||
typedef struct SMemSkipListCfg SMemSkipListCfg;
|
||||
typedef struct SMemTable SMemTable;
|
||||
typedef struct SMemData SMemData;
|
||||
typedef struct SMemSkipList SMemSkipList;
|
||||
typedef struct SMemSkipListNode SMemSkipListNode;
|
||||
typedef struct SMemSkipListCurosr SMemSkipListCurosr;
|
||||
|
||||
struct SMemTable {
|
||||
STsdb *pTsdb;
|
||||
|
@ -32,15 +33,17 @@ struct SMemTable {
|
|||
SMemData **pBuckets;
|
||||
};
|
||||
|
||||
struct SMemSkipListCfg {
|
||||
int8_t maxLevel;
|
||||
int32_t nKey;
|
||||
int32_t nData;
|
||||
struct SMemSkipListNode {
|
||||
int8_t level;
|
||||
SMemSkipListNode *forwards[];
|
||||
};
|
||||
|
||||
struct SMemSkipList {
|
||||
int8_t level;
|
||||
uint32_t seed;
|
||||
uint32_t seed;
|
||||
int8_t maxLevel;
|
||||
int8_t level;
|
||||
int32_t size;
|
||||
SMemSkipListNode pHead[];
|
||||
};
|
||||
|
||||
struct SMemData {
|
||||
|
@ -55,6 +58,24 @@ struct SMemData {
|
|||
SMemSkipList sl;
|
||||
};
|
||||
|
||||
struct SMemSkipListCurosr {
|
||||
SMemSkipList *pSl;
|
||||
SMemSkipListNode *pNodeC;
|
||||
};
|
||||
|
||||
#define HASH_BUCKET(SUID, UID, NBUCKET) (TABS((SUID) + (UID)) % (NBUCKET))
|
||||
|
||||
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2)
|
||||
#define SL_NODE_HALF_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l))
|
||||
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
||||
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
||||
#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level))
|
||||
|
||||
#define SL_HEAD_NODE(sl) ((sl)->pHead)
|
||||
#define SL_TAIL_NODE(sl) ((SMemSkipListNode *)&SL_NODE_FORWARD(SL_HEAD_NODE(sl), (sl)->maxLevel))
|
||||
#define SL_HEAD_NODE_FORWARD(n, l) SL_NODE_FORWARD(n, l)
|
||||
#define SL_TAIL_NODE_BACKWARD(n, l) SL_NODE_FORWARD(n, l)
|
||||
|
||||
// SMemTable
|
||||
int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
||||
SMemTable *pMemTb = NULL;
|
||||
|
@ -76,6 +97,7 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
|||
pMemTb->pBuckets = taosMemoryCalloc(pMemTb->nBucket, sizeof(*pMemTb->pBuckets));
|
||||
if (pMemTb->pBuckets == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pMemTb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -83,11 +105,127 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbMemTableDestroy2(STsdb *pTsdb, SMemTable *pMT) {
|
||||
// TODO
|
||||
int32_t tsdbMemTableDestroy2(STsdb *pTsdb, SMemTable *pMemTb) {
|
||||
if (pMemTb) {
|
||||
// loop to destroy the contents (todo)
|
||||
taosMemoryFree(pMemTb->pBuckets);
|
||||
taosMemoryFree(pMemTb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// SMemData
|
||||
int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *pSubmitBlk) {
|
||||
SMemData *pMemData;
|
||||
STsdb *pTsdb = pMemTb->pTsdb;
|
||||
SVnode *pVnode = pTsdb->pVnode;
|
||||
SVBufPool *pPool = pVnode->inUse;
|
||||
tb_uid_t suid = pSubmitBlk->suid;
|
||||
tb_uid_t uid = pSubmitBlk->uid;
|
||||
int32_t iBucket;
|
||||
|
||||
// SMemSkipList
|
||||
// search SMemData by hash
|
||||
iBucket = HASH_BUCKET(suid, uid, pMemTb->nBucket);
|
||||
for (pMemData = pMemTb->pBuckets[iBucket]; pMemData; pMemData = pMemData->pHashNext) {
|
||||
if (pMemData->suid == suid && pMemData->uid == uid) break;
|
||||
}
|
||||
|
||||
// create pMemData if need
|
||||
if (pMemData == NULL) {
|
||||
int8_t maxLevel = pVnode->config.tsdbCfg.slLevel;
|
||||
int32_t tsize = sizeof(*pMemData) + SL_NODE_HALF_SIZE(maxLevel) * 2;
|
||||
SMemSkipListNode *pHead, *pTail;
|
||||
|
||||
pMemData = vnodeBufPoolMalloc(pPool, tsize);
|
||||
if (pMemData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMemData->pHashNext = NULL;
|
||||
pMemData->suid = suid;
|
||||
pMemData->uid = uid;
|
||||
pMemData->minKey = TSKEY_MAX;
|
||||
pMemData->maxKey = TSKEY_MIN;
|
||||
pMemData->minVer = -1;
|
||||
pMemData->maxVer = -1;
|
||||
pMemData->nRows = 0;
|
||||
pMemData->sl.seed = taosRand();
|
||||
pMemData->sl.maxLevel = maxLevel;
|
||||
pMemData->sl.level = 0;
|
||||
pMemData->sl.size = 0;
|
||||
pHead = SL_HEAD_NODE(&pMemData->sl);
|
||||
pTail = SL_TAIL_NODE(&pMemData->sl);
|
||||
pHead->level = maxLevel;
|
||||
pTail->level = maxLevel;
|
||||
for (int iLevel = 0; iLevel < maxLevel; iLevel++) {
|
||||
SL_HEAD_NODE_FORWARD(pHead, iLevel) = pTail;
|
||||
SL_TAIL_NODE_BACKWARD(pTail, iLevel) = pHead;
|
||||
}
|
||||
|
||||
// add to hash
|
||||
if (pMemTb->nHash >= pMemTb->nBucket) {
|
||||
// rehash (todo)
|
||||
}
|
||||
iBucket = HASH_BUCKET(suid, uid, pMemTb->nBucket);
|
||||
pMemData->pHashNext = pMemTb->pBuckets[iBucket];
|
||||
pMemTb->pBuckets[iBucket] = pMemData;
|
||||
pMemTb->nHash++;
|
||||
|
||||
// sort organize (todo)
|
||||
}
|
||||
|
||||
// do insert data to SMemData
|
||||
SMemSkipListCurosr slc = {0};
|
||||
const uint8_t *p = pSubmitBlk->pData;
|
||||
const uint8_t *pt;
|
||||
const STSRow *pRow;
|
||||
uint64_t szRow;
|
||||
SDecoder decoder = {0};
|
||||
|
||||
// tCoderInit(&coder, TD_LITTLE_ENDIAN, pSubmitBlk->pData, pSubmitBlk->nData, TD_DECODER);
|
||||
for (;;) {
|
||||
// if (tDecodeIsEnd(&coder)) break;
|
||||
|
||||
// if (tDecodeBinary(&coder, (const uint8_t **)&pRow, &szRow) < 0) {
|
||||
// terrno = TSDB_CODE_INVALID_MSG;
|
||||
// return -1;
|
||||
// }
|
||||
// check the row (todo)
|
||||
|
||||
// // move the cursor to position to write (todo)
|
||||
// int32_t c;
|
||||
// tsdbMemSkipListCursorMoveTo(&slc, pTSRow, version, &c);
|
||||
// ASSERT(c);
|
||||
|
||||
// // encode row
|
||||
// int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl);
|
||||
// int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (p - pt);
|
||||
// pSlNode = vnodeBufPoolMalloc(pPool, tsize);
|
||||
// pSlNode->level = level;
|
||||
|
||||
// uint8_t *pData = SL_NODE_DATA(pSlNode);
|
||||
// *(int64_t *)pData = version;
|
||||
// pData += sizeof(version);
|
||||
// memcpy(pData, pt, p - pt);
|
||||
|
||||
// // insert row
|
||||
// tsdbMemSkipListCursorPut(&slc, pSlNode);
|
||||
|
||||
// update status
|
||||
if (pRow->ts < pMemData->minKey) pMemData->minKey = pRow->ts;
|
||||
if (pRow->ts > pMemData->maxKey) pMemData->maxKey = pRow->ts;
|
||||
}
|
||||
// tCoderClear(&coder);
|
||||
// tsdbMemSkipListCursorClose(&slc);
|
||||
|
||||
// update status
|
||||
if (pMemData->minVer == -1) pMemData->minVer = version;
|
||||
if (pMemData->maxVer == -1 || pMemData->maxVer < version) pMemData->maxVer = version;
|
||||
|
||||
if (pMemTb->minKey < pMemData->minKey) pMemTb->minKey = pMemData->minKey;
|
||||
if (pMemTb->maxKey < pMemData->maxKey) pMemTb->maxKey = pMemData->maxKey;
|
||||
if (pMemTb->minVer == -1) pMemTb->minVer = version;
|
||||
if (pMemTb->maxVer == -1 || pMemTb->maxVer < version) pMemTb->maxVer = version;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -163,7 +163,7 @@ static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2);
|
|||
// static void* destroyTableCheckInfo(SArray* pTableCheckInfo);
|
||||
static bool tsdbGetExternalRow(tsdbReaderT pHandle);
|
||||
|
||||
static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* retentions);
|
||||
static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle, TSKEY winSKey, SRetention* retentions);
|
||||
|
||||
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
|
||||
pBlockLoadInfo->slot = -1;
|
||||
|
@ -351,36 +351,43 @@ static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableData
|
|||
pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
int nQUERY = 0;
|
||||
#if 1
|
||||
int nQUERY = 0;
|
||||
#endif
|
||||
static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* retentions) {
|
||||
static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle, TSKEY winSKey, SRetention* retentions) {
|
||||
if (vnodeIsRollup(pVnode)) {
|
||||
int level = 0;
|
||||
#if 1
|
||||
#if 0
|
||||
int64_t now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
|
||||
for (int i = 0; i < TSDB_RETENTION_MAX; ++i) {
|
||||
SRetention* pRetention = retentions + i;
|
||||
if (pRetention->keep <= 0 || (now - pRetention->keep) >= winSKey) {
|
||||
break;
|
||||
}
|
||||
++level;
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
++nQUERY;
|
||||
if(nQUERY%3 == 0) {
|
||||
level = 2;
|
||||
} else if(nQUERY%2 == 0) {
|
||||
level = 1;
|
||||
} else {
|
||||
level = 0;
|
||||
#if 1
|
||||
switch ((nQUERY++) % 3) {
|
||||
case 0:
|
||||
level = 0;
|
||||
break;
|
||||
case 1:
|
||||
level = 1;
|
||||
break;
|
||||
default:
|
||||
level = 2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (level == TSDB_RETENTION_L0) {
|
||||
tsdbDebug("%p rsma level %d is selected to query\n", pReadHandle, level);
|
||||
return VND_RSMA0(pVnode);
|
||||
} else if (level == TSDB_RETENTION_L1) {
|
||||
tsdbDebug("%p rsma level %d is selected to query\n", pReadHandle, level);
|
||||
return VND_RSMA1(pVnode);
|
||||
} else {
|
||||
tsdbDebug("%p rsma level %d is selected to query\n", pReadHandle, level);
|
||||
return VND_RSMA2(pVnode);
|
||||
}
|
||||
}
|
||||
|
@ -393,7 +400,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond*
|
|||
goto _end;
|
||||
}
|
||||
|
||||
STsdb* pTsdb = getTsdbByRetentions(pVnode, pCond->twindow.skey, pVnode->config.tsdbCfg.retentions);
|
||||
STsdb* pTsdb = getTsdbByRetentions(pVnode, pReadHandle, pCond->twindow.skey, pVnode->config.tsdbCfg.retentions);
|
||||
|
||||
pReadHandle->order = pCond->order;
|
||||
pReadHandle->pTsdb = pTsdb;
|
||||
|
@ -803,12 +810,16 @@ static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) {
|
|||
tSkipListDestroyIter(pCheckInfo->iiter);
|
||||
}
|
||||
|
||||
static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, int32_t update) {
|
||||
static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, TDRowVerT maxVer) {
|
||||
STSRow *rmem = NULL, *rimem = NULL;
|
||||
if (pCheckInfo->iter) {
|
||||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter);
|
||||
if (node != NULL) {
|
||||
rmem = (STSRow*)SL_GET_NODE_DATA(node);
|
||||
// TODO: filter max version
|
||||
// if (TD_ROW_VER(rmem) > maxVer) {
|
||||
// rmem = NULL;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -816,6 +827,10 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order,
|
|||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter);
|
||||
if (node != NULL) {
|
||||
rimem = (STSRow*)SL_GET_NODE_DATA(node);
|
||||
// TODO: filter max version
|
||||
// if (TD_ROW_VER(rimem) > maxVer) {
|
||||
// rimem = NULL;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -837,6 +852,7 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order,
|
|||
TSKEY r2 = TD_ROW_KEY(rimem);
|
||||
|
||||
if (r1 == r2) {
|
||||
#if 0
|
||||
if (update == TD_ROW_DISCARD_UPDATE) {
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM;
|
||||
tSkipListIterNext(pCheckInfo->iter);
|
||||
|
@ -846,6 +862,13 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order,
|
|||
} else {
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH;
|
||||
}
|
||||
#endif
|
||||
if (TD_SUPPORT_UPDATE(update)) {
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH;
|
||||
} else {
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM;
|
||||
tSkipListIterNext(pCheckInfo->iter);
|
||||
}
|
||||
return r1;
|
||||
} else if (r1 < r2 && ASCENDING_TRAVERSE(order)) {
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM;
|
||||
|
@ -856,12 +879,18 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order,
|
|||
}
|
||||
}
|
||||
|
||||
static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, STSRow** extraRow) {
|
||||
|
||||
static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, STSRow** extraRow, TDRowVerT maxVer) {
|
||||
STSRow *rmem = NULL, *rimem = NULL;
|
||||
if (pCheckInfo->iter) {
|
||||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter);
|
||||
if (node != NULL) {
|
||||
rmem = (STSRow*)SL_GET_NODE_DATA(node);
|
||||
#if 0 // TODO: skiplist refactor
|
||||
if (TD_ROW_VER(rmem) > maxVer) {
|
||||
rmem = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -869,6 +898,11 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int
|
|||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter);
|
||||
if (node != NULL) {
|
||||
rimem = (STSRow*)SL_GET_NODE_DATA(node);
|
||||
#if 0 // TODO: skiplist refactor
|
||||
if (TD_ROW_VER(rimem) > maxVer) {
|
||||
rimem = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -890,6 +924,7 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int
|
|||
TSKEY r2 = TD_ROW_KEY(rimem);
|
||||
|
||||
if (r1 == r2) {
|
||||
#if 0
|
||||
if (update == TD_ROW_DISCARD_UPDATE) {
|
||||
tSkipListIterNext(pCheckInfo->iter);
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM;
|
||||
|
@ -903,6 +938,16 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int
|
|||
*extraRow = rimem;
|
||||
return rmem;
|
||||
}
|
||||
#endif
|
||||
if (TD_SUPPORT_UPDATE(update)) {
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH;
|
||||
*extraRow = rimem;
|
||||
return rmem;
|
||||
} else {
|
||||
tSkipListIterNext(pCheckInfo->iter);
|
||||
pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM;
|
||||
return rimem;
|
||||
}
|
||||
} else {
|
||||
if (ASCENDING_TRAVERSE(order)) {
|
||||
if (r1 < r2) {
|
||||
|
@ -973,7 +1018,7 @@ static bool hasMoreDataInCache(STsdbReadHandle* pHandle) {
|
|||
initTableMemIterator(pHandle, pCheckInfo);
|
||||
}
|
||||
|
||||
STSRow* row = getSRowInTableMem(pCheckInfo, pHandle->order, pCfg->update, NULL);
|
||||
STSRow* row = getSRowInTableMem(pCheckInfo, pHandle->order, pCfg->update, NULL, TD_VER_MAX);
|
||||
if (row == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1250,7 +1295,7 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
|||
/*bool hasData = */ initTableMemIterator(pTsdbReadHandle, pCheckInfo);
|
||||
assert(cur->pos >= 0 && cur->pos <= binfo.rows);
|
||||
|
||||
key = extractFirstTraverseKey(pCheckInfo, pTsdbReadHandle->order, pCfg->update);
|
||||
key = extractFirstTraverseKey(pCheckInfo, pTsdbReadHandle->order, pCfg->update, TD_VER_MAX);
|
||||
|
||||
if (key != TSKEY_INITIAL_VAL) {
|
||||
tsdbDebug("%p key in mem:%" PRId64 ", %s", pTsdbReadHandle, key, pTsdbReadHandle->idStr);
|
||||
|
@ -1497,10 +1542,10 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
|||
TASSERT(0);
|
||||
}
|
||||
|
||||
if (sVal.valType == TD_VTYPE_NULL) {
|
||||
colDataAppendNULL(pColInfo, rowIndex);
|
||||
} else {
|
||||
if (sVal.valType == TD_VTYPE_NORM) {
|
||||
colDataAppend(pColInfo, rowIndex, sVal.val, false);
|
||||
} else {
|
||||
colDataAppendNULL(pColInfo, rowIndex);
|
||||
}
|
||||
}
|
||||
} else { // handle the var-string
|
||||
|
@ -1513,10 +1558,10 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
|||
TASSERT(0);
|
||||
}
|
||||
|
||||
if (sVal.valType == TD_VTYPE_NULL) {
|
||||
colDataAppendNULL(pColInfo, rowIndex);
|
||||
} else {
|
||||
if (sVal.valType == TD_VTYPE_NORM) {
|
||||
colDataAppend(pColInfo, rowIndex, sVal.val, false);
|
||||
} else {
|
||||
colDataAppendNULL(pColInfo, rowIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1541,11 +1586,26 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
|||
return numOfRows + num;
|
||||
}
|
||||
|
||||
// TODO fix bug for reverse copy data problem
|
||||
// Note: row1 always has high priority
|
||||
static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, STSRow* row1,
|
||||
STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2,
|
||||
bool forceSetNull) {
|
||||
/**
|
||||
* @brief // TODO fix bug for reverse copy data problem
|
||||
* Note: row1 always has high priority
|
||||
*
|
||||
* @param pTsdbReadHandle
|
||||
* @param capacity
|
||||
* @param curRow
|
||||
* @param row1
|
||||
* @param row2
|
||||
* @param numOfCols
|
||||
* @param uid
|
||||
* @param pSchema1
|
||||
* @param pSchema2
|
||||
* @param update
|
||||
* @param lastRowKey
|
||||
* @return int32_t The quantity of rows appended
|
||||
*/
|
||||
static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t* curRow, STSRow* row1,
|
||||
STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2,
|
||||
bool update, TSKEY* lastRowKey) {
|
||||
#if 1
|
||||
STSchema* pSchema;
|
||||
STSRow* row;
|
||||
|
@ -1557,12 +1617,17 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
bool isChosenRowDataRow;
|
||||
int32_t chosen_itr;
|
||||
SCellVal sVal = {0};
|
||||
TSKEY rowKey = TSKEY_INITIAL_VAL;
|
||||
int32_t nResult = 0;
|
||||
int32_t mergeOption = 0; // 0 discard 1 overwrite 2 merge
|
||||
|
||||
// the schema version info is embeded in STSRow
|
||||
int32_t numOfColsOfRow1 = 0;
|
||||
|
||||
if (pSchema1 == NULL) {
|
||||
pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row1));
|
||||
// pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row1));
|
||||
// TODO: use the real schemaVersion
|
||||
pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, 0);
|
||||
}
|
||||
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
|
@ -1579,7 +1644,9 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
if (row2) {
|
||||
isRow2DataRow = TD_IS_TP_ROW(row2);
|
||||
if (pSchema2 == NULL) {
|
||||
pSchema2 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row2));
|
||||
// pSchema2 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row2));
|
||||
// TODO: use the real schemaVersion
|
||||
pSchema2 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, 0);
|
||||
}
|
||||
if (isRow2DataRow) {
|
||||
numOfColsOfRow2 = schemaNCols(pSchema2);
|
||||
|
@ -1610,19 +1677,19 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
colIdOfRow2 = tdKvRowColIdAt(row2, k);
|
||||
}
|
||||
|
||||
if (colIdOfRow1 == colIdOfRow2) {
|
||||
if (colIdOfRow1 < colIdOfRow2) { // the most probability
|
||||
if (colIdOfRow1 < pColInfo->info.colId) {
|
||||
j++;
|
||||
k++;
|
||||
++j;
|
||||
continue;
|
||||
}
|
||||
row = row1;
|
||||
pSchema = pSchema1;
|
||||
isChosenRowDataRow = isRow1DataRow;
|
||||
chosen_itr = j;
|
||||
} else if (colIdOfRow1 < colIdOfRow2) {
|
||||
} else if (colIdOfRow1 == colIdOfRow2) {
|
||||
if (colIdOfRow1 < pColInfo->info.colId) {
|
||||
j++;
|
||||
++j;
|
||||
++k;
|
||||
continue;
|
||||
}
|
||||
row = row1;
|
||||
|
@ -1631,7 +1698,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
chosen_itr = j;
|
||||
} else {
|
||||
if (colIdOfRow2 < pColInfo->info.colId) {
|
||||
k++;
|
||||
++k;
|
||||
continue;
|
||||
}
|
||||
row = row2;
|
||||
|
@ -1639,16 +1706,48 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
chosen_itr = k;
|
||||
isChosenRowDataRow = isRow2DataRow;
|
||||
}
|
||||
|
||||
if (isChosenRowDataRow) {
|
||||
colId = pSchema->columns[chosen_itr].colId;
|
||||
offset = pSchema->columns[chosen_itr].offset;
|
||||
// TODO: use STSRowIter
|
||||
tdSTpRowGetVal(row, colId, pSchema->columns[chosen_itr].type, pSchema->flen, offset, chosen_itr - 1, &sVal);
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
rowKey = *(TSKEY*)sVal.val;
|
||||
if (rowKey != *lastRowKey) {
|
||||
mergeOption = 1;
|
||||
if (*lastRowKey != TSKEY_INITIAL_VAL) {
|
||||
++(*curRow);
|
||||
}
|
||||
++nResult;
|
||||
} else if (update){
|
||||
mergeOption = 2;
|
||||
} else {
|
||||
mergeOption = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
*lastRowKey = rowKey;
|
||||
}
|
||||
} else {
|
||||
// TODO: use STSRowIter
|
||||
if (chosen_itr == 0) {
|
||||
colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
tdSKvRowGetVal(row, PRIMARYKEY_TIMESTAMP_COL_ID, -1, -1, &sVal);
|
||||
rowKey = *(TSKEY*)sVal.val;
|
||||
if (rowKey != *lastRowKey) {
|
||||
mergeOption = 1;
|
||||
if (*lastRowKey != TSKEY_INITIAL_VAL) {
|
||||
++(*curRow);
|
||||
}
|
||||
++nResult;
|
||||
} else if(update) {
|
||||
mergeOption = 2;
|
||||
} else {
|
||||
mergeOption = 0;
|
||||
break;
|
||||
}
|
||||
*lastRowKey = rowKey;
|
||||
} else {
|
||||
SKvRowIdx* pColIdx = tdKvRowColIdxAt(row, chosen_itr - 1);
|
||||
colId = pColIdx->colId;
|
||||
|
@ -1657,35 +1756,46 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT(rowKey != TSKEY_INITIAL_VAL);
|
||||
|
||||
if (colId == pColInfo->info.colId) {
|
||||
if (tdValTypeIsNorm(sVal.valType)) {
|
||||
colDataAppend(pColInfo, numOfRows, sVal.val, false);
|
||||
} else if (forceSetNull) {
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
colDataAppend(pColInfo, *curRow, sVal.val, false);
|
||||
} else if (tdValTypeIsNull(sVal.valType)) {
|
||||
colDataAppend(pColInfo, *curRow, NULL, true);
|
||||
} else if (tdValTypeIsNone(sVal.valType)) {
|
||||
// TODO: Set null if nothing append for this row
|
||||
if (mergeOption == 1) {
|
||||
colDataAppend(pColInfo, *curRow, NULL, true);
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
i++;
|
||||
++i;
|
||||
|
||||
if (row == row1) {
|
||||
j++;
|
||||
++j;
|
||||
} else {
|
||||
k++;
|
||||
++k;
|
||||
}
|
||||
} else {
|
||||
if (forceSetNull) {
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
if (mergeOption == 1) {
|
||||
colDataAppend(pColInfo, *curRow, NULL, true);
|
||||
}
|
||||
i++;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
if (forceSetNull) {
|
||||
if (mergeOption == 1) {
|
||||
while (i < numOfCols) { // the remain columns are all null data
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
i++;
|
||||
colDataAppend(pColInfo, *curRow, NULL, true);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
return nResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1859,6 +1969,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
|
||||
// compared with the data from in-memory buffer, to generate the correct timestamp array list
|
||||
int32_t numOfRows = 0;
|
||||
int32_t curRow = 0;
|
||||
|
||||
int16_t rv1 = -1;
|
||||
int16_t rv2 = -1;
|
||||
|
@ -1874,9 +1985,11 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
return;
|
||||
} else if (pCheckInfo->iter != NULL || pCheckInfo->iiter != NULL) {
|
||||
SSkipListNode* node = NULL;
|
||||
TSKEY lastRowKey = TSKEY_INITIAL_VAL;
|
||||
|
||||
do {
|
||||
STSRow* row2 = NULL;
|
||||
STSRow* row1 = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, &row2);
|
||||
STSRow* row1 = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, &row2, TD_VER_MAX);
|
||||
if (row1 == NULL) {
|
||||
break;
|
||||
}
|
||||
|
@ -1905,9 +2018,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
rv2 = TD_ROW_SVER(row2);
|
||||
}
|
||||
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, true);
|
||||
numOfRows += 1;
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastRowKey);
|
||||
// numOfRows += 1;
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = key;
|
||||
}
|
||||
|
@ -1918,6 +2031,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
} else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it
|
||||
#if 0
|
||||
if (pCfg->update) {
|
||||
if (pCfg->update == TD_ROW_PARTIAL_UPDATE) {
|
||||
doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, pos, pos);
|
||||
|
@ -1933,7 +2047,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
|
||||
bool forceSetNull = pCfg->update != TD_ROW_PARTIAL_UPDATE;
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull);
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull, &lastRowKey);
|
||||
numOfRows += 1;
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = key;
|
||||
|
@ -1943,6 +2057,35 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
cur->lastKey = key + step;
|
||||
cur->mixBlock = true;
|
||||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
pos += step;
|
||||
} else {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
}
|
||||
#endif
|
||||
if (TD_SUPPORT_UPDATE(pCfg->update)) {
|
||||
doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos);
|
||||
|
||||
if (rv1 != TD_ROW_SVER(row1)) {
|
||||
// pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1));
|
||||
rv1 = TD_ROW_SVER(row1);
|
||||
}
|
||||
if (row2 && rv2 != TD_ROW_SVER(row2)) {
|
||||
// pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2));
|
||||
rv2 = TD_ROW_SVER(row2);
|
||||
}
|
||||
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastRowKey);
|
||||
// ++numOfRows;
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = key;
|
||||
}
|
||||
|
||||
cur->win.ekey = key;
|
||||
cur->lastKey = key + step;
|
||||
cur->mixBlock = true;
|
||||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
pos += step;
|
||||
} else {
|
||||
|
@ -1958,11 +2101,18 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
assert(end != -1);
|
||||
|
||||
if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it
|
||||
#if 0
|
||||
if (pCfg->update == TD_ROW_DISCARD_UPDATE) {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
} else {
|
||||
end -= step;
|
||||
}
|
||||
#endif
|
||||
if (!TD_SUPPORT_UPDATE(pCfg->update)) {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
} else {
|
||||
end -= step;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t qstart = 0, qend = 0;
|
||||
|
@ -2572,6 +2722,7 @@ static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) {
|
|||
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win,
|
||||
STsdbReadHandle* pTsdbReadHandle) {
|
||||
int numOfRows = 0;
|
||||
int curRows = 0;
|
||||
int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns);
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
win->skey = TSKEY_INITIAL_VAL;
|
||||
|
@ -2579,9 +2730,11 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
int64_t st = taosGetTimestampUs();
|
||||
int16_t rv = -1;
|
||||
STSchema* pSchema = NULL;
|
||||
TSKEY lastRowKey = TSKEY_INITIAL_VAL;
|
||||
|
||||
|
||||
do {
|
||||
STSRow* row = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, NULL);
|
||||
STSRow* row = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, NULL, TD_VER_MAX);
|
||||
if (row == NULL) {
|
||||
break;
|
||||
}
|
||||
|
@ -2604,16 +2757,18 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0);
|
||||
rv = TD_ROW_SVER(row);
|
||||
}
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, numOfRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema,
|
||||
NULL, true);
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, &curRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema,
|
||||
NULL, pCfg->update, &lastRowKey);
|
||||
|
||||
if (++numOfRows >= maxRowsToRead) {
|
||||
if (numOfRows >= maxRowsToRead) {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
} while (moveToNextRowInMem(pCheckInfo));
|
||||
|
||||
taosMemoryFreeClear(pSchema); // free the STSChema
|
||||
|
||||
assert(numOfRows <= maxRowsToRead);
|
||||
|
||||
// if the buffer is not full in case of descending order query, move the data in the front of the buffer
|
||||
|
@ -2731,6 +2886,8 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) {
|
|||
STSRow* pRow = NULL;
|
||||
TSKEY key = TSKEY_INITIAL_VAL;
|
||||
int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1;
|
||||
TSKEY lastRowKey = TSKEY_INITIAL_VAL;
|
||||
int32_t curRow = 0;
|
||||
|
||||
if (++pTsdbReadHandle->activeIndex < numOfTables) {
|
||||
STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex);
|
||||
|
@ -2738,8 +2895,8 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) {
|
|||
// if (ret != TSDB_CODE_SUCCESS) {
|
||||
// return false;
|
||||
// }
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, pRow, NULL, numOfCols, pCheckInfo->tableId,
|
||||
NULL, NULL, true);
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, pRow, NULL, numOfCols, pCheckInfo->tableId,
|
||||
NULL, NULL, true, &lastRowKey);
|
||||
taosMemoryFreeClear(pRow);
|
||||
|
||||
// update the last key value
|
||||
|
|
|
@ -246,6 +246,12 @@ int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tsdbSwapDataCols(SDataCols *pDest, SDataCols *pSrc) {
|
||||
SDataCol *pCols = pDest->cols;
|
||||
memcpy(pDest, pSrc, sizeof(SDataCols));
|
||||
pSrc->cols = pCols;
|
||||
}
|
||||
|
||||
int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) {
|
||||
ASSERT(pBlock->numOfSubBlocks > 0);
|
||||
STsdbCfg *pCfg = REPO_CFG(pReadh->pRepo);
|
||||
|
@ -266,17 +272,29 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) {
|
|||
if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1]) < 0) return -1;
|
||||
// TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version
|
||||
if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL,
|
||||
update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0)
|
||||
TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0)
|
||||
return -1;
|
||||
}
|
||||
// if ((pBlock->numOfSubBlocks == 1) && (iBlock->hasDupKey)) { // TODO: use this line
|
||||
if (pBlock->numOfSubBlocks == 1) {
|
||||
tdResetDataCols(pReadh->pDCols[1]);
|
||||
pReadh->pDCols[1]->bitmapMode = pReadh->pDCols[0]->bitmapMode;
|
||||
if (tdMergeDataCols(pReadh->pDCols[1], pReadh->pDCols[0], pReadh->pDCols[0]->numOfRows, NULL,
|
||||
TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0) {
|
||||
return -1;
|
||||
}
|
||||
tsdbSwapDataCols(pReadh->pDCols[0], pReadh->pDCols[1]);
|
||||
ASSERT(pReadh->pDCols[0]->bitmapMode != 0);
|
||||
}
|
||||
|
||||
ASSERT(pReadh->pDCols[0]->numOfRows == pBlock->numOfRows);
|
||||
ASSERT(pReadh->pDCols[0]->numOfRows <= pBlock->numOfRows);
|
||||
ASSERT(dataColsKeyFirst(pReadh->pDCols[0]) == pBlock->keyFirst);
|
||||
ASSERT(dataColsKeyLast(pReadh->pDCols[0]) == pBlock->keyLast);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: filter by Multi-Version
|
||||
int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds,
|
||||
bool mergeBitmap) {
|
||||
ASSERT(pBlock->numOfSubBlocks > 0);
|
||||
|
@ -297,9 +315,21 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
|||
if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds) < 0) return -1;
|
||||
// TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version
|
||||
if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL,
|
||||
update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0)
|
||||
TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0)
|
||||
return -1;
|
||||
}
|
||||
// if ((pBlock->numOfSubBlocks == 1) && (iBlock->hasDupKey)) { // TODO: use this line
|
||||
if (pBlock->numOfSubBlocks == 1) {
|
||||
tdResetDataCols(pReadh->pDCols[1]);
|
||||
pReadh->pDCols[1]->bitmapMode = pReadh->pDCols[0]->bitmapMode;
|
||||
if (tdMergeDataCols(pReadh->pDCols[1], pReadh->pDCols[0], pReadh->pDCols[0]->numOfRows, NULL,
|
||||
TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0) {
|
||||
return -1;
|
||||
}
|
||||
tsdbSwapDataCols(pReadh->pDCols[0], pReadh->pDCols[1]);
|
||||
ASSERT(pReadh->pDCols[0]->bitmapMode != 0);
|
||||
}
|
||||
|
||||
|
||||
if (mergeBitmap && !tdDataColsIsBitmapI(pReadh->pDCols[0])) {
|
||||
for (int i = 0; i < numOfColsIds; ++i) {
|
||||
|
@ -312,7 +342,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT(pReadh->pDCols[0]->numOfRows == pBlock->numOfRows);
|
||||
ASSERT(pReadh->pDCols[0]->numOfRows <= pBlock->numOfRows);
|
||||
ASSERT(dataColsKeyFirst(pReadh->pDCols[0]) == pBlock->keyFirst);
|
||||
ASSERT(dataColsKeyLast(pReadh->pDCols[0]) == pBlock->keyLast);
|
||||
|
||||
|
@ -586,7 +616,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
|||
tcolId = pBlockCol->colId;
|
||||
toffset = tsdbGetBlockColOffset(pBlockCol);
|
||||
tlen = pBlockCol->len;
|
||||
pDataCol->bitmap = pBlockCol->bitmap;
|
||||
pDataCol->bitmap = pBlockCol->blen > 0 ? 1 : 0;
|
||||
} else {
|
||||
ASSERT(pDataCol->colId == tcolId);
|
||||
TD_SET_COL_ROWS_NORM(pDataCol);
|
||||
|
@ -594,17 +624,8 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
|||
|
||||
// int32_t tBitmaps = 0;
|
||||
int32_t tLenBitmap = 0;
|
||||
if ((dcol != 0) && !TD_COL_ROWS_NORM(pBlockCol)) {
|
||||
if ((dcol != 0) && (pBlockCol->blen > 0)) {
|
||||
tLenBitmap = nBitmaps;
|
||||
#if 0
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
tBitmaps = nBitmaps;
|
||||
tLenBitmap = tBitmaps;
|
||||
} else {
|
||||
tBitmaps = (int32_t)ceil((double)nBitmaps / TYPE_BYTES[pDataCol->type]);
|
||||
tLenBitmap = tBitmaps * TYPE_BYTES[pDataCol->type];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (tcolId == pDataCol->colId) {
|
||||
|
@ -623,15 +644,15 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
|||
}
|
||||
|
||||
if (dcol != 0) {
|
||||
ccol++;
|
||||
++ccol;
|
||||
}
|
||||
dcol++;
|
||||
++dcol;
|
||||
} else if (tcolId < pDataCol->colId) {
|
||||
ccol++;
|
||||
++ccol;
|
||||
} else {
|
||||
// Set current column as NULL and forward
|
||||
dataColReset(pDataCol);
|
||||
dcol++;
|
||||
++dcol;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -754,8 +775,7 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *
|
|||
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { // load the key row
|
||||
blockCol.colId = colId;
|
||||
TD_SET_COL_ROWS_NORM(&blockCol); // default is NORM for the primary key column
|
||||
blockCol.blen = 0;
|
||||
blockCol.blen = 0; // default is NORM for the primary key column
|
||||
blockCol.len = pBlock->keyLen;
|
||||
blockCol.type = pDataCol->type;
|
||||
blockCol.offset = TSDB_KEY_COL_OFFSET;
|
||||
|
@ -785,7 +805,7 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *
|
|||
ASSERT(pBlockCol->colId == pDataCol->colId);
|
||||
}
|
||||
// set the bitmap
|
||||
pDataCol->bitmap = pBlockCol->bitmap;
|
||||
pDataCol->bitmap = pBlockCol->blen > 0 ? 1 : 0;
|
||||
|
||||
if (tsdbLoadColData(pReadh, pDFile, pBlock, pBlockCol, pDataCol) < 0) return -1;
|
||||
}
|
||||
|
@ -803,17 +823,8 @@ static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBloc
|
|||
// int32_t tBitmaps = 0;
|
||||
int32_t tLenBitmap = 0;
|
||||
|
||||
if (!TD_COL_ROWS_NORM(pBlockCol)) {
|
||||
if (pBlockCol->blen) {
|
||||
tLenBitmap = nBitmaps;
|
||||
#if 0
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
tBitmaps = nBitmaps;
|
||||
tLenBitmap = tBitmaps;
|
||||
} else {
|
||||
tBitmaps = (int32_t)ceil((double)nBitmaps / TYPE_BYTES[pDataCol->type]);
|
||||
tLenBitmap = tBitmaps * TYPE_BYTES[pDataCol->type];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int tsize = pDataCol->bytes * pBlock->numOfRows + tLenBitmap + 2 * COMP_OVERFLOW_BYTES;
|
||||
|
|
|
@ -1635,17 +1635,20 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
|||
SSmaCfg vCreateSmaReq = {0};
|
||||
if (!tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
||||
tsdbWarn("vgId:%d tsma create msg received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
||||
return -1;
|
||||
}
|
||||
tsdbDebug("vgId:%d TDMT_VND_CREATE_SMA msg received for %s:%" PRIi64, REPO_ID(pTsdb), vCreateSmaReq.tSma.indexName,
|
||||
vCreateSmaReq.tSma.indexUid);
|
||||
|
||||
tsdbDebug("vgId:%d tsma create msg %s:%" PRIi64 " for table %" PRIi64 " received", REPO_ID(pTsdb),
|
||||
vCreateSmaReq.tSma.indexName, vCreateSmaReq.tSma.indexUid, vCreateSmaReq.tSma.tableUid);
|
||||
|
||||
// record current timezone of server side
|
||||
vCreateSmaReq.tSma.timezoneInt = tsTimezone;
|
||||
|
||||
if (metaCreateTSma(REPO_META(pTsdb), &vCreateSmaReq) < 0) {
|
||||
// TODO: handle error
|
||||
tsdbWarn("vgId:%d tsma %s:%" PRIi64 " create failed for table %" PRIi64 " since %s", REPO_ID(pTsdb),
|
||||
vCreateSmaReq.tSma.indexName, vCreateSmaReq.tSma.indexUid, vCreateSmaReq.tSma.tableUid, terrstr(terrno));
|
||||
tdDestroyTSma(&vCreateSmaReq.tSma);
|
||||
return -1;
|
||||
}
|
||||
|
@ -2003,6 +2006,12 @@ static FORCE_INLINE int32_t tsdbExecuteRSmaImpl(STsdb *pTsdb, const void *pMsg,
|
|||
qTaskInfo_t *taskInfo, STSchema *pTSchema, tb_uid_t suid, tb_uid_t uid,
|
||||
int8_t level) {
|
||||
SArray *pResult = NULL;
|
||||
|
||||
if (!taskInfo) {
|
||||
tsdbDebug("vgId:%d no qTaskInfo to execute rsma %" PRIi8 " task for suid:%" PRIu64, REPO_ID(pTsdb), level, suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
tsdbDebug("vgId:%d execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, REPO_ID(pTsdb), level, taskInfo,
|
||||
suid);
|
||||
|
||||
|
@ -2068,10 +2077,18 @@ static int32_t tsdbExecuteRSma(STsdb *pTsdb, const void *pMsg, int32_t inputType
|
|||
tsdbDebug("vgId:%d no rsma info for suid:%" PRIu64, REPO_ID(pTsdb), suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (!pRSmaInfo->taskInfo[0]) {
|
||||
tsdbDebug("vgId:%d no rsma qTaskInfo for suid:%" PRIu64, REPO_ID(pTsdb), suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||
// TODO: use the proper schema instead of 0, and cache STSchema in cache
|
||||
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, suid, 0);
|
||||
if (!pTSchema) {
|
||||
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
tsdbExecuteRSmaImpl(pTsdb, pMsg, inputType, pRSmaInfo->taskInfo[0], pTSchema, suid, uid, TSDB_RETENTION_L1);
|
||||
tsdbExecuteRSmaImpl(pTsdb, pMsg, inputType, pRSmaInfo->taskInfo[1], pTSchema, suid, uid, TSDB_RETENTION_L2);
|
||||
taosMemoryFree(pTSchema);
|
||||
|
|
|
@ -25,7 +25,7 @@ const SVnodeCfg vnodeCfgDefault = {
|
|||
.isHeap = false,
|
||||
.isWeak = 0,
|
||||
.tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI,
|
||||
.update = 0,
|
||||
.update = 1,
|
||||
.compression = 2,
|
||||
.slLevel = 5,
|
||||
.days = 10,
|
||||
|
|
|
@ -286,7 +286,7 @@ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
|
||||
static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int len, SRpcMsg *pRsp) {
|
||||
SVCreateStbReq req = {0};
|
||||
SCoder coder;
|
||||
SDecoder coder;
|
||||
|
||||
pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
|
@ -294,7 +294,7 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
pRsp->contLen = 0;
|
||||
|
||||
// decode and process req
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER);
|
||||
tDecoderInit(&coder, pReq, len);
|
||||
|
||||
if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
pRsp->code = terrno;
|
||||
|
@ -308,16 +308,16 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
|
||||
tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &req);
|
||||
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&coder);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&coder);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq, int len, SRpcMsg *pRsp) {
|
||||
SCoder coder = {0};
|
||||
SDecoder decoder = {0};
|
||||
int rcode = 0;
|
||||
SVCreateTbBatchReq req = {0};
|
||||
SVCreateTbReq *pCreateReq;
|
||||
|
@ -332,14 +332,14 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
pRsp->contLen = 0;
|
||||
|
||||
// decode
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER);
|
||||
if (tDecodeSVCreateTbBatchReq(&coder, &req) < 0) {
|
||||
tDecoderInit(&decoder, pReq, len);
|
||||
if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
|
||||
rcode = -1;
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
rsp.pArray = taosArrayInit(sizeof(cRsp), req.nReqs);
|
||||
rsp.pArray = taosArrayInit(req.nReqs, sizeof(cRsp));
|
||||
if (rsp.pArray == NULL) {
|
||||
rcode = -1;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -360,7 +360,11 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
|
||||
// do create table
|
||||
if (metaCreateTable(pVnode->pMeta, version, pCreateReq) < 0) {
|
||||
cRsp.code = terrno;
|
||||
if (pCreateReq->flags & TD_CREATE_IF_NOT_EXISTS && terrno == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||
cRsp.code = TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
cRsp.code = terrno;
|
||||
}
|
||||
} else {
|
||||
cRsp.code = TSDB_CODE_SUCCESS;
|
||||
tsdbFetchTbUidList(pVnode->pTsdb, &pStore, pCreateReq->ctb.suid, pCreateReq->uid);
|
||||
|
@ -369,13 +373,14 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
taosArrayPush(rsp.pArray, &cRsp);
|
||||
}
|
||||
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
tsdbUpdateTbUidList(pVnode->pTsdb, pStore);
|
||||
tsdbUidStoreFree(pStore);
|
||||
|
||||
// prepare rsp
|
||||
int32_t ret = 0;
|
||||
SEncoder encoder = {0};
|
||||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret);
|
||||
pRsp->pCont = rpcMallocCont(pRsp->contLen);
|
||||
if (pRsp->pCont == NULL) {
|
||||
|
@ -383,12 +388,14 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pRsp->pCont, pRsp->contLen, TD_ENCODER);
|
||||
tEncodeSVCreateTbBatchRsp(&coder, &rsp);
|
||||
tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen);
|
||||
tEncodeSVCreateTbBatchRsp(&encoder, &rsp);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
_exit:
|
||||
taosArrayClear(rsp.pArray);
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&decoder);
|
||||
tEncoderClear(&encoder);
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
@ -412,15 +419,15 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpc
|
|||
static int vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVDropStbReq req = {0};
|
||||
int rcode = TSDB_CODE_SUCCESS;
|
||||
SCoder coder = {0};
|
||||
SDecoder decoder = {0};
|
||||
|
||||
pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
|
||||
// decode request
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER);
|
||||
if (tDecodeSVDropStbReq(&coder, &req) < 0) {
|
||||
tDecoderInit(&decoder, pReq, len);
|
||||
if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
|
||||
rcode = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
@ -434,7 +441,7 @@ static int vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pReq, i
|
|||
// return rsp
|
||||
_exit:
|
||||
pRsp->code = rcode;
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -447,7 +454,7 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcM
|
|||
static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVDropTbBatchReq req = {0};
|
||||
SVDropTbBatchRsp rsp = {0};
|
||||
SCoder coder = {0};
|
||||
SDecoder decoder = {0};
|
||||
int ret;
|
||||
|
||||
pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
|
||||
|
@ -456,8 +463,8 @@ static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// decode req
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER);
|
||||
ret = tDecodeSVDropTbBatchReq(&coder, &req);
|
||||
tDecoderInit(&decoder, pReq, len);
|
||||
ret = tDecodeSVDropTbBatchReq(&decoder, &req);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
pRsp->code = terrno;
|
||||
|
@ -486,7 +493,7 @@ static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
}
|
||||
|
||||
_exit:
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&decoder);
|
||||
// encode rsp (TODO)
|
||||
return 0;
|
||||
}
|
||||
|
@ -497,7 +504,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
SSubmitBlk *pBlock;
|
||||
SSubmitRsp rsp = {0};
|
||||
SVCreateTbReq createTbReq = {0};
|
||||
SCoder coder = {0};
|
||||
SDecoder decoder = {0};
|
||||
int32_t nRows;
|
||||
|
||||
pRsp->code = 0;
|
||||
|
@ -514,22 +521,29 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
|
||||
// create table for auto create table mode
|
||||
if (msgIter.schemaLen > 0) {
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBlock->data, msgIter.schemaLen, TD_DECODER);
|
||||
if (tDecodeSVCreateTbReq(&coder, &createTbReq) < 0) {
|
||||
tDecoderInit(&decoder, pBlock->data, msgIter.schemaLen);
|
||||
if (tDecodeSVCreateTbReq(&decoder, &createTbReq) < 0) {
|
||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&decoder);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (metaCreateTable(pVnode->pMeta, version, &createTbReq) < 0) {
|
||||
if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||
pRsp->code = terrno;
|
||||
tCoderClear(&coder);
|
||||
tDecoderClear(&decoder);
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
tCoderClear(&coder);
|
||||
msgIter.uid = createTbReq.uid;
|
||||
if (createTbReq.type == TSDB_CHILD_TABLE) {
|
||||
msgIter.suid = createTbReq.ctb.suid;
|
||||
} else {
|
||||
msgIter.suid = 0;
|
||||
}
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
}
|
||||
|
||||
if (tsdbInsertTableData(pVnode->pTsdb, &msgIter, pBlock, &nRows) < 0) {
|
||||
|
|
|
@ -17,4 +17,4 @@ add_subdirectory(tfs)
|
|||
add_subdirectory(monitor)
|
||||
add_subdirectory(nodes)
|
||||
add_subdirectory(scalar)
|
||||
add_subdirectory(command)
|
||||
add_subdirectory(command)
|
|
@ -17,6 +17,6 @@ target_include_directories(
|
|||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
#if(${BUILD_TEST})
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
#endif(${BUILD_TEST})
|
||||
endif(${BUILD_TEST})
|
||||
|
|
|
@ -38,6 +38,7 @@ extern "C" {
|
|||
#include "tlockfree.h"
|
||||
#include "tmsg.h"
|
||||
#include "tpagedbuf.h"
|
||||
#include "tstreamUpdate.h"
|
||||
|
||||
#include "vnode.h"
|
||||
#include "executorInt.h"
|
||||
|
@ -87,9 +88,7 @@ typedef struct SResultInfo { // TODO refactor
|
|||
typedef struct STableQueryInfo {
|
||||
TSKEY lastKey; // last check ts, todo remove it later
|
||||
SResultRowPosition pos; // current active time window
|
||||
// int32_t groupIndex; // group id in table list
|
||||
// SVariant tag;
|
||||
// SResultRowInfo resInfo; // result info
|
||||
} STableQueryInfo;
|
||||
|
||||
typedef enum {
|
||||
|
@ -327,10 +326,15 @@ typedef struct SExchangeInfo {
|
|||
SLoadRemoteDataInfo loadInfo;
|
||||
} SExchangeInfo;
|
||||
|
||||
#define COL_MATCH_FROM_COL_ID 0x1
|
||||
#define COL_MATCH_FROM_SLOT_ID 0x2
|
||||
|
||||
typedef struct SColMatchInfo {
|
||||
int32_t srcSlotId; // source slot id
|
||||
int32_t colId;
|
||||
int32_t targetSlotId;
|
||||
bool output;
|
||||
int32_t matchType; // determinate the source according to col id or slot id
|
||||
} SColMatchInfo;
|
||||
|
||||
typedef struct SScanInfo {
|
||||
|
@ -363,11 +367,12 @@ typedef struct STableScanInfo {
|
|||
} STableScanInfo;
|
||||
|
||||
typedef struct STagScanInfo {
|
||||
SColumnInfo *pCols;
|
||||
SSDataBlock *pRes;
|
||||
int32_t totalTables;
|
||||
int32_t curPos;
|
||||
void *pReader;
|
||||
SColumnInfo *pCols;
|
||||
SSDataBlock *pRes;
|
||||
SArray *pColMatchInfo;
|
||||
int32_t curPos;
|
||||
SReadHandle readHandle;
|
||||
STableGroupInfo *pTableGroups;
|
||||
} STagScanInfo;
|
||||
|
||||
typedef struct SStreamBlockScanInfo {
|
||||
|
@ -381,6 +386,9 @@ typedef struct SStreamBlockScanInfo {
|
|||
void* readerHandle; // stream block reader handle
|
||||
SArray* pColMatchInfo; //
|
||||
SNode* pCondition;
|
||||
SArray* tsArray;
|
||||
SUpdateInfo* pUpdateInfo;
|
||||
int32_t primaryTsIndex; // primary time stamp slot id
|
||||
} SStreamBlockScanInfo;
|
||||
|
||||
typedef struct SSysTableScanInfo {
|
||||
|
@ -441,6 +449,7 @@ typedef struct SIntervalAggOperatorInfo {
|
|||
SArray* pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
|
||||
STimeWindowAggSupp twAggSup;
|
||||
struct SFillInfo* pFillInfo; // fill info
|
||||
bool invertible;
|
||||
} SIntervalAggOperatorInfo;
|
||||
|
||||
typedef struct SAggOperatorInfo {
|
||||
|
@ -579,9 +588,8 @@ typedef struct SSortOperatorInfo {
|
|||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* inputSlotMap; // for index map from table scan output
|
||||
SArray* pColMatchInfo; // for index map from table scan output
|
||||
int32_t bufPageSize;
|
||||
// int32_t numOfRowsInRes;
|
||||
|
||||
// TODO extact struct
|
||||
int64_t startTs; // sort start time
|
||||
|
@ -646,7 +654,7 @@ void cleanupAggSup(SAggSupporter* pAggSup);
|
|||
void destroyBasicOperatorInfo(void* param, int32_t numOfOutput);
|
||||
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
|
||||
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity);
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo);
|
||||
SSDataBlock* loadNextDataBlock(void* param);
|
||||
|
||||
void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset);
|
||||
|
@ -704,7 +712,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTagScanOperatorInfo(void* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, SExprInfo* pExpr, int32_t numOfOutput, SSDataBlock* pResBlock, SArray* pColMatchInfo, STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
#if 0
|
||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
||||
|
@ -717,7 +725,6 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
|
|||
|
||||
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, bool createDummyCol);
|
||||
|
||||
void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
||||
STableQueryInfo* createTableQueryInfo(void* buf, STimeWindow win);
|
||||
|
|
|
@ -117,18 +117,25 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle);
|
|||
/**
|
||||
*
|
||||
* @param pHandle
|
||||
* @param colIndex
|
||||
* @param colId
|
||||
* @return
|
||||
*/
|
||||
bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colIndex);
|
||||
bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pHandle
|
||||
* @param colIndex
|
||||
* @param colId
|
||||
* @return
|
||||
*/
|
||||
void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex);
|
||||
void* tsortGetValue(STupleHandle* pVHandle, int32_t colId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pSortHandle
|
||||
* @return
|
||||
*/
|
||||
SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -60,4 +60,5 @@ void dsScheduleProcess(void* ahandle, void* pItem) {
|
|||
void dsDestroyDataSinker(DataSinkHandle handle) {
|
||||
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
||||
pHandleImpl->fDestroy(pHandleImpl);
|
||||
taosMemoryFree(pHandleImpl);
|
||||
}
|
||||
|
|
|
@ -36,21 +36,6 @@ typedef struct STaskMgmt {
|
|||
bool closed;
|
||||
} STaskMgmt;
|
||||
|
||||
static void taskMgmtKillTaskFn(void* handle, void* param1) {
|
||||
void** fp = (void**)handle;
|
||||
qKillTask(*fp);
|
||||
}
|
||||
|
||||
static void freeqinfoFn(void *qhandle) {
|
||||
void** handle = qhandle;
|
||||
if (handle == NULL || *handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
qKillTask(*handle);
|
||||
qDestroyTask(*handle);
|
||||
}
|
||||
|
||||
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan,
|
||||
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, EOPTR_EXEC_MODEL model) {
|
||||
assert(readHandle != NULL && pSubplan != NULL);
|
||||
|
|
|
@ -198,6 +198,7 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) {
|
|||
|
||||
pBlock->info.blockId = pNode->dataBlockId;
|
||||
pBlock->info.rowSize = pNode->totalRowSize; // todo ??
|
||||
pBlock->info.type = STREAM_INVALID;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData idata = {{0}};
|
||||
|
@ -1225,6 +1226,8 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
|||
|
||||
taosVariantDestroy(&pCtx[i].tag);
|
||||
taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
|
||||
taosMemoryFree(pCtx[i].input.pData);
|
||||
taosMemoryFree(pCtx[i].input.pColumnDataAgg);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pCtx);
|
||||
|
@ -2840,9 +2843,9 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray
|
|||
int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData,
|
||||
int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total,
|
||||
SArray* pColList) {
|
||||
blockDataEnsureCapacity(pRes, numOfRows);
|
||||
|
||||
if (pColList == NULL) { // data from other sources
|
||||
blockDataEnsureCapacity(pRes, numOfRows);
|
||||
|
||||
int32_t dataLen = *(int32_t*)pData;
|
||||
pData += sizeof(int32_t);
|
||||
|
||||
|
@ -2898,20 +2901,23 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
|||
pStart += sizeof(SSysTableSchema);
|
||||
}
|
||||
|
||||
SSDataBlock block = {.pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)), .info.numOfCols = numOfCols};
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
pBlock->info.numOfCols = numOfCols;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData idata = {0};
|
||||
idata.info.type = pSchema[i].type;
|
||||
idata.info.bytes = pSchema[i].bytes;
|
||||
idata.info.colId = pSchema[i].colId;
|
||||
|
||||
taosArrayPush(block.pDataBlock, &idata);
|
||||
taosArrayPush(pBlock->pDataBlock, &idata);
|
||||
if (IS_VAR_DATA_TYPE(idata.info.type)) {
|
||||
block.info.hasVarCol = true;
|
||||
pBlock->info.hasVarCol = true;
|
||||
}
|
||||
}
|
||||
|
||||
blockDataEnsureCapacity(&block, numOfRows);
|
||||
blockDataEnsureCapacity(pBlock, numOfRows);
|
||||
|
||||
int32_t dataLen = *(int32_t*)pStart;
|
||||
uint64_t groupId = *(uint64_t*)(pStart + sizeof(int32_t));
|
||||
|
@ -2924,7 +2930,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
|||
colLen[i] = htonl(colLen[i]);
|
||||
ASSERT(colLen[i] >= 0);
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(block.pDataBlock, i);
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
pColInfoData->varmeta.length = colLen[i];
|
||||
pColInfoData->varmeta.allocLen = colLen[i];
|
||||
|
@ -2943,7 +2949,10 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
|||
}
|
||||
|
||||
// data from mnode
|
||||
relocateColumnData(pRes, pColList, block.pDataBlock);
|
||||
relocateColumnData(pRes, pColList, pBlock->pDataBlock);
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
taosMemoryFree(pBlock);
|
||||
// blockDataDestroy(pBlock);
|
||||
}
|
||||
|
||||
pRes->info.rows = numOfRows;
|
||||
|
@ -3520,7 +3529,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator) {
|
|||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SSortedMergeOperatorInfo* pInfo = pOperator->info;
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, NULL);
|
||||
}
|
||||
|
||||
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
|
@ -4184,6 +4193,18 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
|||
pOperator->numOfDownstream = 0;
|
||||
}
|
||||
|
||||
if (pOperator->pExpr != NULL) {
|
||||
for (int32_t i = 0; i < pOperator->numOfExprs; ++i) {
|
||||
SExprInfo* pExprInfo = &pOperator->pExpr[i];
|
||||
if (pExprInfo->pExpr->nodeType == QUERY_NODE_COLUMN) {
|
||||
taosMemoryFree(pExprInfo->base.pParam[0].pCol);
|
||||
}
|
||||
taosMemoryFree(pExprInfo->base.pParam);
|
||||
taosMemoryFree(pExprInfo->pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(pOperator->pExpr);
|
||||
taosMemoryFreeClear(pOperator->info);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
}
|
||||
|
@ -4195,8 +4216,6 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n
|
|||
pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
|
||||
pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
|
||||
pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK);
|
||||
// pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK);
|
||||
// pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell));
|
||||
|
||||
if (pAggSup->keyBuf == NULL /*|| pAggSup->pResultRowArrayList == NULL || pAggSup->pResultRowListSet == NULL*/ ||
|
||||
pAggSup->pResultRowHashTable == NULL) {
|
||||
|
@ -4358,6 +4377,8 @@ void destroySFillOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SProjectOperatorInfo* pInfo = (SProjectOperatorInfo*)param;
|
||||
doDestroyBasicInfo(&pInfo->binfo, numOfOutput);
|
||||
cleanupAggSup(&pInfo->aggSup);
|
||||
taosArrayDestroy(pInfo->pPseudoColInfo);
|
||||
}
|
||||
|
||||
void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
|
@ -4687,7 +4708,7 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
|
|||
|
||||
char* p = taosMemoryCalloc(1, 128);
|
||||
snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId);
|
||||
pTaskInfo->id.str = strdup(p);
|
||||
pTaskInfo->id.str = p;
|
||||
|
||||
return pTaskInfo;
|
||||
}
|
||||
|
@ -4699,10 +4720,9 @@ static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t
|
|||
uint64_t queryId, uint64_t taskId);
|
||||
static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo);
|
||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||
static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols);
|
||||
static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type);
|
||||
|
||||
static SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget);
|
||||
static SArray* createIndexMap(SNodeList* pNodeList);
|
||||
static SArray* createSortInfo(SNodeList* pNodeList);
|
||||
static SArray* extractPartitionColInfo(SNodeList* pNodeList);
|
||||
static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode);
|
||||
static void setJoinColumnInfo(SColumnInfo* pInfo, const SColumnNode* pLeftNode);
|
||||
|
@ -4734,12 +4754,12 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SArray* pColList =
|
||||
extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols);
|
||||
SSDataBlock* pResBlock = createResDataBlock(pScanPhyNode->node.pOutputDataBlockDesc);
|
||||
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
||||
|
||||
SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
SQueryTableDataCond cond = {0};
|
||||
|
||||
int32_t code = initQueryTableDataCond(&cond, pTableScanNode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
|
@ -4762,10 +4782,11 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId);
|
||||
SArray* tableIdList = extractTableIdList(pTableGroupInfo);
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pScanPhyNode->node.pOutputDataBlockDesc);
|
||||
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
SArray* pCols = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols);
|
||||
SArray* pCols = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, pCols, tableIdList, pTaskInfo,
|
||||
pScanPhyNode->node.pConditions);
|
||||
taosArrayDestroy(tableIdList);
|
||||
|
@ -4774,15 +4795,37 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
|
||||
SScanPhysiNode* pScanNode = &pSysScanPhyNode->scan;
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pScanNode->node.pOutputDataBlockDesc);
|
||||
SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc;
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* colList =
|
||||
extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfOutputCols);
|
||||
SArray* colList = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &numOfOutputCols, COL_MATCH_FROM_COL_ID);
|
||||
SOperatorInfo* pOperator = createSysTableScanOperatorInfo(
|
||||
pHandle, pResBlock, &pScanNode->tableName, pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, colList,
|
||||
pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId);
|
||||
return pOperator;
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
|
||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*) pPhyNode;
|
||||
|
||||
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t code =
|
||||
doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t num = 0;
|
||||
SExprInfo* pExprInfo = createExprInfo(pScanPhyNode->pScanPseudoCols, NULL, &num);
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* colList = extractColMatchInfo(pScanPhyNode->pScanPseudoCols, pDescNode, &numOfOutputCols, COL_MATCH_FROM_COL_ID);
|
||||
|
||||
SOperatorInfo* pOperator = createTagScanOperatorInfo(pHandle, pExprInfo, num, pResBlock, colList, pTableGroupInfo, pTaskInfo);
|
||||
return pOperator;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -4851,17 +4894,18 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
} else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
|
||||
SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode;
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||
SArray* info = createSortInfo(pSortPhyNode->pSortKeys, pSortPhyNode->pTargets);
|
||||
SArray* slotMap = createIndexMap(pSortPhyNode->pTargets);
|
||||
SDataBlockDescNode* pDescNode = pPhyNode->pOutputDataBlockDesc;
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
SArray* info = createSortInfo(pSortPhyNode->pSortKeys);
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
SExprInfo* pExprInfo = NULL;
|
||||
if (pSortPhyNode->pExprs != NULL) {
|
||||
pExprInfo = createExprInfo(pSortPhyNode->pExprs, NULL, &numOfCols);
|
||||
}
|
||||
SExprInfo* pExprInfo = createExprInfo(pSortPhyNode->pExprs, NULL, &numOfCols);
|
||||
|
||||
pOptr = createSortOperatorInfo(ops[0], pResBlock, info, pExprInfo, numOfCols, slotMap, pTaskInfo);
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColList = extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
pOptr = createSortOperatorInfo(ops[0], pResBlock, info, pExprInfo, numOfCols, pColList, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == type) {
|
||||
SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
|
||||
|
||||
|
@ -5019,7 +5063,7 @@ SArray* extractPartitionColInfo(SNodeList* pNodeList) {
|
|||
return pList;
|
||||
}
|
||||
|
||||
SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget) {
|
||||
SArray* createSortInfo(SNodeList* pNodeList) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SBlockOrderInfo));
|
||||
if (pList == NULL) {
|
||||
|
@ -5034,47 +5078,14 @@ SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget) {
|
|||
bi.nullFirst = (pSortKey->nullOrder == NULL_ORDER_FIRST);
|
||||
|
||||
SColumnNode* pColNode = (SColumnNode*)pSortKey->pExpr;
|
||||
|
||||
bool found = false;
|
||||
for (int32_t j = 0; j < LIST_LENGTH(pNodeListTarget); ++j) {
|
||||
STargetNode* pTarget = (STargetNode*)nodesListGetNode(pNodeListTarget, j);
|
||||
|
||||
SColumnNode* pColNodeT = (SColumnNode*)pTarget->pExpr;
|
||||
if (pColNode->slotId == pColNodeT->slotId) { // to find slotId in PhysiSort OutputDataBlockDesc
|
||||
bi.slotId = pTarget->slotId;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
qError("sort slot id does not found");
|
||||
}
|
||||
bi.slotId = pColNode->slotId;
|
||||
taosArrayPush(pList, &bi);
|
||||
}
|
||||
|
||||
return pList;
|
||||
}
|
||||
|
||||
SArray* createIndexMap(SNodeList* pNodeList) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(int32_t));
|
||||
if (pList == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return pList;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
STargetNode* pTarget = (STargetNode*)nodesListGetNode(pNodeList, i);
|
||||
|
||||
SColumnNode* pColNode = (SColumnNode*)pTarget->pExpr;
|
||||
taosArrayPush(pList, &pColNode->slotId);
|
||||
}
|
||||
|
||||
return pList;
|
||||
}
|
||||
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols) {
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo));
|
||||
if (pList == NULL) {
|
||||
|
@ -5087,8 +5098,10 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
||||
|
||||
SColMatchInfo c = {0};
|
||||
c.output = true;
|
||||
c.colId = pColNode->colId;
|
||||
c.output = true;
|
||||
c.colId = pColNode->colId;
|
||||
c.srcSlotId = pColNode->slotId;
|
||||
c.matchType = type;
|
||||
c.targetSlotId = pNode->slotId;
|
||||
taosArrayPush(pList, &c);
|
||||
}
|
||||
|
@ -5166,9 +5179,7 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle*
|
|||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
#if 0
|
||||
return tsdbQueryTables(pHandle->reader, &cond, pTableGroupInfo, queryId, taskId);
|
||||
#endif
|
||||
|
||||
return tsdbQueryTables(pHandle->vnode, &cond, pTableGroupInfo, queryId, taskId);
|
||||
|
||||
_error:
|
||||
|
@ -5297,6 +5308,7 @@ void doDestroyTask(SExecTaskInfo* pTaskInfo) {
|
|||
qDebug("%s execTask is freed", GET_TASKID(pTaskInfo));
|
||||
|
||||
doDestroyTableQueryInfo(&pTaskInfo->tableqinfoGroupInfo);
|
||||
destroyOperatorInfo(pTaskInfo->pRoot);
|
||||
// taosArrayDestroy(pTaskInfo->summary.queryProfEvents);
|
||||
// taosHashCleanup(pTaskInfo->summary.operatorProfResults);
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData
|
|||
char* val = colDataGetData(pColInfoData, rowIndex);
|
||||
if (IS_VAR_DATA_TYPE(pkey->type)) {
|
||||
memcpy(pkey->pData, val, varDataTLen(val));
|
||||
ASSERT(varDataTLen(val) <= pkey->bytes);
|
||||
} else {
|
||||
memcpy(pkey->pData, val, pkey->bytes);
|
||||
}
|
||||
|
|
|
@ -252,8 +252,8 @@ static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *outpu
|
|||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
|
||||
SIndexTerm *tm = indexTermCreate(left->suid, DEFAULT, operType, left->colValType, left->colName,
|
||||
strlen(left->colName), right->condValue, strlen(right->condValue));
|
||||
SIndexTerm *tm = indexTermCreate(left->suid, DEFAULT, left->colValType, left->colName, strlen(left->colName),
|
||||
right->condValue, strlen(right->condValue));
|
||||
if (tm == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -13,15 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ttime.h"
|
||||
#include <libs/function/function.h>
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
#include "os.h"
|
||||
#include "querynodes.h"
|
||||
#include "systable.h"
|
||||
#include "tglobal.h"
|
||||
#include "tname.h"
|
||||
#include "systable.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#include "tdatablock.h"
|
||||
#include "tmsg.h"
|
||||
|
@ -511,6 +512,25 @@ static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) {
|
|||
taosArrayClear(pInfo->pBlockLists);
|
||||
}
|
||||
|
||||
static SSDataBlock* getUpdateDataBlock(SStreamBlockScanInfo* pInfo) {
|
||||
SColumnInfoData* pColDataInfo = taosArrayGet(pInfo->pRes->pDataBlock, pInfo->primaryTsIndex);
|
||||
TSKEY* ts = (TSKEY*)pColDataInfo->pData;
|
||||
for (int32_t i = 0; i < pInfo->pRes->info.rows; i++) {
|
||||
if (updateInfoIsUpdated(pInfo->pUpdateInfo, pInfo->pRes->info.uid, ts[i])) {
|
||||
taosArrayPush(pInfo->tsArray, ts+i);
|
||||
}
|
||||
}
|
||||
if (taosArrayGetSize(pInfo->tsArray) > 0) {
|
||||
//TODO(liuyao) get from tsdb
|
||||
// SSDataBlock* p = createOneDataBlock(pInfo->pRes, true);
|
||||
// p->info.type = STREAM_INVERT;
|
||||
// taosArrayClear(pInfo->tsArray);
|
||||
// return p;
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
||||
// NOTE: this operator does never check if current status is done or not
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -522,8 +542,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
size_t total = taosArrayGetSize(pInfo->pBlockLists);
|
||||
if (pInfo->blockType == STREAM_DATA_TYPE_SSDATA_BLOCK) {
|
||||
size_t total = taosArrayGetSize(pInfo->pBlockLists);
|
||||
if (pInfo->validBlockIndex >= total) {
|
||||
doClearBufferedBlocks(pInfo);
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
|
@ -533,15 +553,25 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
|||
int32_t current = pInfo->validBlockIndex++;
|
||||
return taosArrayGetP(pInfo->pBlockLists, current);
|
||||
} else {
|
||||
if (total > 0) {
|
||||
ASSERT(total == 2);
|
||||
SSDataBlock* pRes = taosArrayGetP(pInfo->pBlockLists, 0);
|
||||
SSDataBlock* pUpRes = taosArrayGetP(pInfo->pBlockLists, 1);
|
||||
blockDataDestroy(pUpRes);
|
||||
taosArrayClear(pInfo->pBlockLists);
|
||||
return pRes;
|
||||
}
|
||||
SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
|
||||
while (tqNextDataBlock(pInfo->readerHandle)) {
|
||||
SArray* pCols = NULL;
|
||||
uint64_t groupId;
|
||||
int32_t numOfRows;
|
||||
int16_t outputCol;
|
||||
int32_t code = tqRetrieveDataBlock(&pCols, pInfo->readerHandle, &groupId, &numOfRows, &outputCol);
|
||||
uint64_t groupId = 0;
|
||||
uint64_t uid = 0;
|
||||
int32_t numOfRows = 0;
|
||||
int16_t outputCol = 0;
|
||||
|
||||
int32_t code = tqRetrieveDataBlock(&pCols, pInfo->readerHandle, &groupId, &uid, &numOfRows, &outputCol);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS || numOfRows == 0) {
|
||||
pTaskInfo->code = code;
|
||||
|
@ -550,6 +580,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
|||
|
||||
pInfo->pRes->info.groupId = groupId;
|
||||
pInfo->pRes->info.rows = numOfRows;
|
||||
pInfo->pRes->info.uid = uid;
|
||||
pInfo->pRes->info.type = STREAM_NORMAL;
|
||||
|
||||
int32_t numOfCols = pInfo->pRes->info.numOfCols;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
|
@ -594,6 +626,13 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
|||
|
||||
if (rows == 0) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
} else {
|
||||
SSDataBlock* upRes = getUpdateDataBlock(pInfo);
|
||||
if (upRes) {
|
||||
taosArrayPush(pInfo->pBlockLists, &(pInfo->pRes));
|
||||
taosArrayPush(pInfo->pBlockLists, &upRes);
|
||||
return upRes;
|
||||
}
|
||||
}
|
||||
|
||||
return (rows == 0) ? NULL : pInfo->pRes;
|
||||
|
@ -605,10 +644,8 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
taosMemoryFreeClear(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
int32_t numOfOutput = taosArrayGetSize(pColList);
|
||||
|
@ -625,13 +662,25 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
tqReadHandleSetColIdList((STqReadHandle*)streamReadHandle, pColIds);
|
||||
int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList);
|
||||
if (code != 0) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES);
|
||||
if (pInfo->pBlockLists == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->tsArray = taosArrayInit(4, sizeof(TSKEY));
|
||||
if (pInfo->tsArray == NULL) {
|
||||
taosMemoryFreeClear(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES);
|
||||
if (pInfo->pBlockLists == NULL) {
|
||||
pInfo->primaryTsIndex = 0; //TODO(liuyao) get it from physical plan
|
||||
pInfo->pUpdateInfo = updateInfoInit(60000, 0, 100); //TODO(liuyao) get it from physical plan
|
||||
if (pInfo->pUpdateInfo == NULL) {
|
||||
taosMemoryFreeClear(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
return NULL;
|
||||
|
@ -646,7 +695,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfExprs = pResBlock->info.numOfCols;
|
||||
pOperator->numOfExprs = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet._openFn = operatorDummyOpenFn;
|
||||
pOperator->fpSet.getNextFn = doStreamBlockScan;
|
||||
pOperator->fpSet.closeFn = operatorDummyCloseFn;
|
||||
|
@ -655,6 +704,11 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamBlockScan, NULL, NULL, operatorDummyCloseFn, NULL, NULL, NULL);
|
||||
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
taosMemoryFreeClear(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void destroySysScanOperator(void* param, int32_t numOfOutput) {
|
||||
|
@ -666,6 +720,8 @@ static void destroySysScanOperator(void* param, int32_t numOfOutput) {
|
|||
if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
metaCloseTbCursor(pInfo->pCur);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pInfo->scanCols);
|
||||
}
|
||||
|
||||
EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
|
||||
|
@ -1150,7 +1206,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfExprs = pResBlock->info.numOfCols;
|
||||
pOperator->numOfExprs = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator,
|
||||
NULL, NULL, NULL);
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
@ -1159,16 +1215,17 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
}
|
||||
|
||||
static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
||||
#if 0
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
#if 0
|
||||
int32_t maxNumOfTables = (int32_t)pResultInfo->capacity;
|
||||
|
||||
STagScanInfo *pInfo = pOperator->info;
|
||||
SSDataBlock *pRes = pInfo->pRes;
|
||||
*newgroup = false;
|
||||
|
||||
int32_t count = 0;
|
||||
SArray* pa = GET_TABLEGROUP(pRuntimeEnv, 0);
|
||||
|
@ -1237,55 +1294,59 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
|||
pOperator->status = OP_EXEC_DONE;
|
||||
//qDebug("QInfo:0x%"PRIx64" create count(tbname) query, res:%d rows:1", GET_TASKID(pRuntimeEnv), count);
|
||||
} else { // return only the tags|table name etc.
|
||||
SExprInfo* pExprInfo = &pOperator->pExpr[0]; // todo use the column list instead of exprinfo
|
||||
#endif
|
||||
|
||||
count = 0;
|
||||
while(pInfo->curPos < pInfo->totalTables && count < maxNumOfTables) {
|
||||
int32_t i = pInfo->curPos++;
|
||||
STagScanInfo* pInfo = pOperator->info;
|
||||
SExprInfo* pExprInfo = &pOperator->pExpr[0];
|
||||
SSDataBlock* pRes = pInfo->pRes;
|
||||
|
||||
STableQueryInfo* item = taosArrayGetP(pa, i);
|
||||
if (taosArrayGetSize(pInfo->pTableGroups->pGroupList) == 0) {
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *data = NULL, *dst = NULL;
|
||||
int16_t type = 0, bytes = 0;
|
||||
for(int32_t j = 0; j < pOperator->numOfExprs; ++j) {
|
||||
// not assign value in case of user defined constant output column
|
||||
if (TSDB_COL_IS_UD_COL(pExprInfo[j].base.pColumns->flag)) {
|
||||
continue;
|
||||
}
|
||||
SArray* pa = taosArrayGetP(pInfo->pTableGroups->pGroupList, 0);
|
||||
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pRes->pDataBlock, j);
|
||||
type = pExprInfo[j].base.resSchema.type;
|
||||
bytes = pExprInfo[j].base.resSchema.bytes;
|
||||
char str[512] = {0};
|
||||
int32_t count = 0;
|
||||
SMetaReader mr = {0};
|
||||
|
||||
if (pExprInfo[j].base.pColumns->info.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
data = tsdbGetTableName(item->pTable);
|
||||
} else {
|
||||
data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.pColumns->info.colId, type, bytes);
|
||||
}
|
||||
while (pInfo->curPos < pInfo->pTableGroups->numOfTables && count < pOperator->resultInfo.capacity) {
|
||||
STableKeyInfo* item = taosArrayGet(pa, pInfo->curPos);
|
||||
|
||||
dst = pColInfo->pData + count * pExprInfo[j].base.resSchema.bytes;
|
||||
doSetTagValueToResultBuf(dst, data, type, bytes);
|
||||
for (int32_t j = 0; j < pOperator->numOfExprs; ++j) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pRes->pDataBlock, pExprInfo[j].base.resSchema.slotId);
|
||||
|
||||
// refactor later
|
||||
if (fmIsScanPseudoColumnFunc(pExprInfo[j].pExpr->_function.functionId)) {
|
||||
metaReaderInit(&mr, pInfo->readHandle.meta, 0);
|
||||
metaGetTableEntryByUid(&mr, item->uid);
|
||||
|
||||
STR_TO_VARSTR(str, mr.me.name);
|
||||
metaReaderClear(&mr);
|
||||
|
||||
colDataAppend(pDst, count, str, false);
|
||||
|
||||
// data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.pColumns->info.colId, type, bytes);
|
||||
// dst = pColInfo->pData + count * pExprInfo[j].base.resSchema.bytes;
|
||||
// doSetTagValueToResultBuf(dst, data, type, bytes);
|
||||
}
|
||||
|
||||
count += 1;
|
||||
}
|
||||
|
||||
if (pInfo->curPos >= pInfo->totalTables) {
|
||||
if (++pInfo->curPos >= pInfo->pTableGroups->numOfTables) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
|
||||
//qDebug("QInfo:0x%"PRIx64" create tag values results completed, rows:%d", GET_TASKID(pRuntimeEnv), count);
|
||||
}
|
||||
|
||||
// qDebug("QInfo:0x%"PRIx64" create tag values results completed, rows:%d", GET_TASKID(pRuntimeEnv), count);
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
setTaskStatus(pOperator->pRuntimeEnv, TASK_COMPLETED);
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
}
|
||||
|
||||
pRes->info.rows = count;
|
||||
return (pRes->info.rows == 0)? NULL:pInfo->pRes;
|
||||
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return (pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
}
|
||||
|
||||
static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
|
@ -1293,14 +1354,18 @@ static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||
}
|
||||
|
||||
SOperatorInfo* createTagScanOperatorInfo(void* readHandle, SExprInfo* pExpr, int32_t numOfOutput, SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, SExprInfo* pExpr, int32_t numOfOutput,
|
||||
SSDataBlock* pResBlock, SArray* pColMatchInfo, STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) {
|
||||
STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->pReader = readHandle;
|
||||
pInfo->pTableGroups = pTableGroupInfo;
|
||||
pInfo->pColMatchInfo = pColMatchInfo;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->readHandle = *pReadHandle;
|
||||
pInfo->curPos = 0;
|
||||
pOperator->name = "TagScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN;
|
||||
|
@ -1308,9 +1373,12 @@ SOperatorInfo* createTagScanOperatorInfo(void* readHandle, SExprInfo* pExpr, int
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfExprs = numOfOutput;
|
||||
pOperator->numOfExprs = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
initResultSizeInfo(pOperator, 4096);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL, NULL, NULL);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator);
|
|||
static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
||||
SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SArray* pIndexMap, SExecTaskInfo* pTaskInfo) {
|
||||
SArray* pColMatchColInfo, SExecTaskInfo* pTaskInfo) {
|
||||
SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
int32_t rowSize = pResBlock->info.rowSize;
|
||||
|
@ -20,17 +20,19 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR
|
|||
pInfo->binfo.pRes = pResBlock;
|
||||
|
||||
initResultSizeInfo(pOperator, 1024);
|
||||
pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + header
|
||||
|
||||
pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer
|
||||
pInfo->pSortInfo = pSortInfo;
|
||||
pInfo->inputSlotMap = pIndexMap;
|
||||
pInfo->pColMatchInfo= pColMatchColInfo;
|
||||
pOperator->name = "SortOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT;
|
||||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
// lazy evaluation for the following parameter since the input datablock is not known till now.
|
||||
// pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + header
|
||||
// pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, NULL);
|
||||
|
@ -45,14 +47,12 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// TODO merge aggregate super table
|
||||
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) {
|
||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
||||
bool isNull = tsortIsNullVal(pTupleHandle, i);
|
||||
if (isNull) {
|
||||
colDataAppend(pColInfo, pBlock->info.rows, NULL, true);
|
||||
colDataAppendNULL(pColInfo, pBlock->info.rows);
|
||||
} else {
|
||||
char* pData = tsortGetValue(pTupleHandle, i);
|
||||
colDataAppend(pColInfo, pBlock->info.rows, pData, false);
|
||||
|
@ -62,11 +62,16 @@ void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) {
|
|||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity) {
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo) {
|
||||
blockDataCleanup(pDataBlock);
|
||||
blockDataEnsureCapacity(pDataBlock, capacity);
|
||||
ASSERT(taosArrayGetSize(pColMatchInfo) == pDataBlock->info.numOfCols);
|
||||
|
||||
blockDataEnsureCapacity(pDataBlock, capacity);
|
||||
SSDataBlock* p = tsortGetSortedDataBlock(pHandle);
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
blockDataEnsureCapacity(p, capacity);
|
||||
|
||||
while (1) {
|
||||
STupleHandle* pTupleHandle = tsortNextTuple(pHandle);
|
||||
|
@ -74,12 +79,28 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i
|
|||
break;
|
||||
}
|
||||
|
||||
appendOneRowToDataBlock(pDataBlock, pTupleHandle);
|
||||
if (pDataBlock->info.rows >= capacity) {
|
||||
appendOneRowToDataBlock(p, pTupleHandle);
|
||||
if (p->info.rows >= capacity) {
|
||||
return pDataBlock;
|
||||
}
|
||||
}
|
||||
|
||||
if (p->info.rows > 0) {
|
||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId);
|
||||
colDataAssign(pDst, pSrc, p->info.rows);
|
||||
}
|
||||
|
||||
pDataBlock->info.rows = p->info.rows;
|
||||
pDataBlock->info.capacity = p->info.rows;
|
||||
}
|
||||
|
||||
blockDataDestroy(p);
|
||||
return (pDataBlock->info.rows > 0) ? pDataBlock : NULL;
|
||||
}
|
||||
|
||||
|
@ -106,16 +127,16 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
|||
SSortOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
}
|
||||
|
||||
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->inputSlotMap, SORT_SINGLESOURCE_SORT,
|
||||
pInfo->bufPageSize, numOfBufPage, pInfo->binfo.pRes, pTaskInfo->id.str);
|
||||
// pInfo->binfo.pRes is not equalled to the input datablock.
|
||||
// int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT,
|
||||
-1, -1, NULL, pTaskInfo->id.str);
|
||||
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator);
|
||||
|
||||
|
||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||
ps->param = pOperator->pDownstream[0];
|
||||
tsortAddSource(pInfo->pSortHandle, ps);
|
||||
|
@ -127,7 +148,7 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
}
|
||||
|
||||
void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
|
@ -135,5 +156,5 @@ void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes);
|
||||
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->inputSlotMap);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ttime.h"
|
||||
#include "tdatablock.h"
|
||||
#include "executorimpl.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
typedef enum SResultTsInterpType {
|
||||
RESULT_ROW_START_INTERP = 1,
|
||||
|
@ -979,6 +980,15 @@ static void finalizeUpdatedResult(int32_t numOfOutput, SDiskbasedBuf* pBuf, SArr
|
|||
releaseBufPage(pBuf, bufPage);
|
||||
}
|
||||
}
|
||||
static void setInverFunction(SqlFunctionCtx* pCtx, int32_t num, EStreamType type) {
|
||||
for ( int i = 0; i < num; i++) {
|
||||
if (type == STREAM_INVERT) {
|
||||
fmSetInvertFunc(pCtx[i].functionId, &(pCtx[i].fpSet));
|
||||
} else if (type == STREAM_NORMAL){
|
||||
fmSetNormalFunc(pCtx[i].functionId, &(pCtx[i].fpSet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
||||
SIntervalAggOperatorInfo* pInfo = pOperator->info;
|
||||
|
@ -1016,6 +1026,9 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfExprs);
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order, true);
|
||||
if (pInfo->invertible) {
|
||||
setInverFunction(pInfo->binfo.pCtx, pOperator->numOfExprs, pBlock->info.type);
|
||||
}
|
||||
pUpdated = hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0);
|
||||
}
|
||||
|
||||
|
@ -1043,6 +1056,15 @@ void destroyIntervalOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
cleanupAggSup(&pInfo->aggSup);
|
||||
}
|
||||
|
||||
bool allInvertible(SqlFunctionCtx* pFCtx, int32_t numOfCols) {
|
||||
for (int32_t i = 0; i < numOfCols; i++) {
|
||||
if (!fmIsInvertible(pFCtx[i].functionId)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId,
|
||||
STimeWindowAggSupp* pTwAggSupp, const STableGroupInfo* pTableGroupInfo,
|
||||
|
@ -1068,6 +1090,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, pResBlock, keyBufSize, pTaskInfo->id.str);
|
||||
|
||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->win);
|
||||
pInfo->invertible = allInvertible(pInfo->binfo.pCtx, numOfCols);
|
||||
|
||||
// pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo);
|
||||
if (code != TSDB_CODE_SUCCESS /* || pInfo->pTableQueryInfo == NULL*/) {
|
||||
|
|
|
@ -64,25 +64,8 @@ struct SSortHandle {
|
|||
|
||||
static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param);
|
||||
|
||||
static SSDataBlock* createDataBlock_rv(SSchema* pSchema, int32_t numOfCols) {
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
pBlock->info.numOfCols = numOfCols;
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
|
||||
colInfo.info.type = pSchema[i].type;
|
||||
colInfo.info.bytes = pSchema[i].bytes;
|
||||
colInfo.info.colId = pSchema[i].colId;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfo);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(colInfo.info.type)) {
|
||||
pBlock->info.hasVarCol = true;
|
||||
}
|
||||
}
|
||||
|
||||
return pBlock;
|
||||
SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle) {
|
||||
return createOneDataBlock(pSortHandle->pDataBlock, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +81,10 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, SArray* pIndexMap, int32_t
|
|||
pSortHandle->numOfPages = numOfPages;
|
||||
pSortHandle->pSortInfo = pSortInfo;
|
||||
pSortHandle->pIndexMap = pIndexMap;
|
||||
pSortHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
|
||||
if (pBlock != NULL) {
|
||||
pSortHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
}
|
||||
|
||||
pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES);
|
||||
pSortHandle->cmpParam.orderInfo = pSortInfo;
|
||||
|
@ -530,6 +516,17 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
|
||||
if (pHandle->pDataBlock == NULL) {
|
||||
pHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
|
||||
// calculate the buffer pages according to the total available buffers.
|
||||
int32_t rowSize = blockDataGetRowSize(pBlock);
|
||||
if (rowSize * 4 > 4096) {
|
||||
pHandle->pageSize = rowSize * 4;
|
||||
} else {
|
||||
pHandle->pageSize = 4096;
|
||||
}
|
||||
// todo!!
|
||||
pHandle->numOfPages = 1024;
|
||||
sortBufSize = pHandle->numOfPages * pHandle->pageSize;
|
||||
}
|
||||
|
||||
// perform the scalar function calculation before apply the sort
|
||||
|
@ -538,7 +535,6 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
}
|
||||
|
||||
// todo relocate the columns
|
||||
|
||||
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
|
@ -557,7 +553,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pHandle->pDataBlock->info.rows > 0) {
|
||||
if (pHandle->pDataBlock != NULL && pHandle->pDataBlock->info.rows > 0) {
|
||||
size_t size = blockDataGetSize(pHandle->pDataBlock);
|
||||
|
||||
// Perform the in-memory sort and then flush data in the buffer into disk.
|
||||
|
@ -689,7 +685,7 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) {
|
|||
|
||||
bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colIndex) {
|
||||
SColumnInfoData* pColInfoSrc = taosArrayGet(pVHandle->pBlock->pDataBlock, colIndex);
|
||||
return colDataIsNull(pColInfoSrc, 0, pVHandle->rowIndex, NULL);
|
||||
return colDataIsNull_s(pColInfoSrc, pVHandle->rowIndex);
|
||||
}
|
||||
|
||||
void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) {
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef struct SBuiltinFuncDefinition {
|
|||
FExecProcess processFunc;
|
||||
FScalarExecProcess sprocessFunc;
|
||||
FExecFinalize finalizeFunc;
|
||||
FExecProcess invertFunc;
|
||||
} SBuiltinFuncDefinition;
|
||||
|
||||
extern const SBuiltinFuncDefinition funcMgtBuiltins[];
|
||||
|
|
|
@ -30,10 +30,12 @@ int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock,
|
|||
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t countFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t countInvertFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t sumFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t sumInvertFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
|
@ -45,11 +47,13 @@ bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
|||
bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t avgFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
int32_t avgInvertFunction(SqlFunctionCtx* pCtx);
|
||||
|
||||
bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t stddevFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
int32_t stddevInvertFunction(SqlFunctionCtx* pCtx);
|
||||
|
||||
bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
|
@ -73,6 +77,11 @@ bool spreadFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo)
|
|||
int32_t spreadFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t histogramFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -225,6 +225,26 @@ static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (4 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
if (((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type != TSDB_DATA_TYPE_BINARY ||
|
||||
((SExprNode*)nodesListGetNode(pFunc->pParameterList, 2))->resType.type != TSDB_DATA_TYPE_BINARY ||
|
||||
((SExprNode*)nodesListGetNode(pFunc->pParameterList, 3))->resType.type != TSDB_DATA_TYPE_BIGINT) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = 512, .type = TSDB_DATA_TYPE_BINARY };
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateLastRow(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// todo
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -242,8 +262,7 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
"The parameters of first/last can only be columns");
|
||||
}
|
||||
|
||||
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[paraType].bytes, .type = paraType};
|
||||
pFunc->node.resType = ((SExprNode*)pPara)->resType;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -454,7 +473,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getCountFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = countFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
.finalizeFunc = functionFinalize,
|
||||
.invertFunc = countInvertFunction
|
||||
},
|
||||
{
|
||||
.name = "sum",
|
||||
|
@ -465,7 +485,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getSumFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = sumFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
.finalizeFunc = functionFinalize,
|
||||
.invertFunc = sumInvertFunction
|
||||
},
|
||||
{
|
||||
.name = "min",
|
||||
|
@ -497,7 +518,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getStddevFuncEnv,
|
||||
.initFunc = stddevFunctionSetup,
|
||||
.processFunc = stddevFunction,
|
||||
.finalizeFunc = stddevFinalize
|
||||
.finalizeFunc = stddevFinalize,
|
||||
.invertFunc = stddevInvertFunction
|
||||
},
|
||||
{
|
||||
.name = "avg",
|
||||
|
@ -507,7 +529,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getAvgFuncEnv,
|
||||
.initFunc = avgFunctionSetup,
|
||||
.processFunc = avgFunction,
|
||||
.finalizeFunc = avgFinalize
|
||||
.finalizeFunc = avgFinalize,
|
||||
.invertFunc = avgInvertFunction
|
||||
},
|
||||
{
|
||||
.name = "percentile",
|
||||
|
@ -600,6 +623,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.processFunc = diffFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "histogram",
|
||||
.type = FUNCTION_TYPE_HISTOGRAM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateHistogram,
|
||||
.getEnvFunc = getHistogramFuncEnv,
|
||||
.initFunc = histogramFunctionSetup,
|
||||
.processFunc = histogramFunction,
|
||||
.finalizeFunc = histogramFinalize
|
||||
},
|
||||
{
|
||||
.name = "abs",
|
||||
.type = FUNCTION_TYPE_ABS,
|
||||
|
@ -917,7 +950,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.translateFunc = translateTbnameColumn,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
.sprocessFunc = qTbnameFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
*/
|
||||
|
||||
#include "builtinsimpl.h"
|
||||
#include "cJSON.h"
|
||||
#include "function.h"
|
||||
#include "querynodes.h"
|
||||
#include "taggfunction.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tpercentile.h"
|
||||
|
||||
#define HISTOGRAM_MAX_BINS_NUM 100
|
||||
|
||||
typedef struct SSumRes {
|
||||
union {
|
||||
int64_t isum;
|
||||
|
@ -89,6 +92,29 @@ typedef struct SSpreadInfo {
|
|||
double max;
|
||||
} SSpreadInfo;
|
||||
|
||||
typedef struct SHistoFuncBin {
|
||||
double lower;
|
||||
double upper;
|
||||
union {
|
||||
int64_t count;
|
||||
double percentage;
|
||||
};
|
||||
} SHistoFuncBin;
|
||||
|
||||
typedef struct SHistoFuncInfo {
|
||||
int32_t numOfBins;
|
||||
bool normalized;
|
||||
SHistoFuncBin bins[];
|
||||
} SHistoFuncInfo;
|
||||
|
||||
typedef enum {
|
||||
UNKNOWN_BIN = 0,
|
||||
USER_INPUT_BIN,
|
||||
LINEAR_BIN,
|
||||
LOG_BIN
|
||||
} EHistoBinType;
|
||||
|
||||
|
||||
#define SET_VAL(_info, numOfElem, res) \
|
||||
do { \
|
||||
if ((numOfElem) <= 0) { \
|
||||
|
@ -183,11 +209,7 @@ bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
||||
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
||||
*/
|
||||
int32_t countFunction(SqlFunctionCtx* pCtx) {
|
||||
static FORCE_INLINE int32_t getNumofElem(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
/*
|
||||
|
@ -214,7 +236,14 @@ int32_t countFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElem = pInput->numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
return numOfElem;
|
||||
}
|
||||
/*
|
||||
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
||||
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
||||
*/
|
||||
int32_t countFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = getNumofElem(pCtx);
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
*((int64_t*)buf) += numOfElem;
|
||||
|
@ -223,6 +252,17 @@ int32_t countFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t countInvertFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = getNumofElem(pCtx);
|
||||
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
*((int64_t*)buf) -= numOfElem;
|
||||
|
||||
SET_VAL(pResInfo, *((int64_t*)buf), 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \
|
||||
do { \
|
||||
_t* d = (_t*)(_col->pData); \
|
||||
|
@ -235,6 +275,18 @@ int32_t countFunction(SqlFunctionCtx* pCtx) {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define LIST_SUB_N(_res, _col, _start, _rows, _t, numOfElem) \
|
||||
do { \
|
||||
_t* d = (_t*)(_col->pData); \
|
||||
for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \
|
||||
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
|
||||
continue; \
|
||||
}; \
|
||||
(_res) -= (d)[i]; \
|
||||
(numOfElem)++; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t sumFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
|
@ -294,6 +346,65 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t sumInvertFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
// Only the pre-computing information loaded and actual data does not loaded
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0];
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
SSumRes* pSumRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
if (pInput->colDataAggIsSet) {
|
||||
numOfElem = pInput->numOfRows - pAgg->numOfNull;
|
||||
ASSERT(numOfElem >= 0);
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
pSumRes->isum -= pAgg->sum;
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
pSumRes->usum -= pAgg->sum;
|
||||
} else if (IS_FLOAT_TYPE(type)) {
|
||||
pSumRes->dsum -= GET_DOUBLE_VAL((const char*)&(pAgg->sum));
|
||||
}
|
||||
} else { // computing based on the true data block
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) {
|
||||
LIST_SUB_N(pSumRes->isum, pCol, start, numOfRows, int8_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
|
||||
LIST_SUB_N(pSumRes->isum, pCol, start, numOfRows, int16_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_INT) {
|
||||
LIST_SUB_N(pSumRes->isum, pCol, start, numOfRows, int32_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||
LIST_SUB_N(pSumRes->isum, pCol, start, numOfRows, int64_t, numOfElem);
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_UTINYINT) {
|
||||
LIST_SUB_N(pSumRes->usum, pCol, start, numOfRows, uint8_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_USMALLINT) {
|
||||
LIST_SUB_N(pSumRes->usum, pCol, start, numOfRows, uint16_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_UINT) {
|
||||
LIST_SUB_N(pSumRes->usum, pCol, start, numOfRows, uint32_t, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_UBIGINT) {
|
||||
LIST_SUB_N(pSumRes->usum, pCol, start, numOfRows, uint64_t, numOfElem);
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
LIST_SUB_N(pSumRes->dsum, pCol, start, numOfRows, double, numOfElem);
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
LIST_SUB_N(pSumRes->dsum, pCol, start, numOfRows, float, numOfElem);
|
||||
}
|
||||
}
|
||||
|
||||
// data in the check operation are all null, not output
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool getSumFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SSumRes);
|
||||
return true;
|
||||
|
@ -425,6 +536,69 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#define LIST_AVG_N(sumT, T) \
|
||||
do { \
|
||||
T* plist = (T*)pCol->pData; \
|
||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { \
|
||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { \
|
||||
continue; \
|
||||
} \
|
||||
\
|
||||
numOfElem += 1; \
|
||||
pAvgRes->count -= 1; \
|
||||
sumT -= plist[i]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t avgInvertFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
// Only the pre-computing information loaded and actual data does not loaded
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
// computing based on the true data block
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
LIST_AVG_N(pAvgRes->sum.isum, int8_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
LIST_AVG_N(pAvgRes->sum.isum, int16_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
LIST_AVG_N(pAvgRes->sum.isum, int32_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
LIST_AVG_N(pAvgRes->sum.isum, int64_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
LIST_AVG_N(pAvgRes->sum.dsum, float);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
LIST_AVG_N(pAvgRes->sum.dsum, double);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// data in the check operation are all null, not output
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
@ -859,6 +1033,69 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#define LIST_STDDEV_SUB_N(sumT, T) \
|
||||
do { \
|
||||
T* plist = (T*)pCol->pData; \
|
||||
for (int32_t i = start; i < numOfRows + start; ++i) { \
|
||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { \
|
||||
continue; \
|
||||
} \
|
||||
numOfElem += 1; \
|
||||
pStddevRes->count -= 1; \
|
||||
sumT -= plist[i]; \
|
||||
pStddevRes->quadraticISum -= plist[i] * plist[i]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElem = 0;
|
||||
|
||||
// Only the pre-computing information loaded and actual data does not loaded
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
// computing based on the true data block
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
LIST_STDDEV_SUB_N(pStddevRes->isum, int8_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
LIST_STDDEV_SUB_N(pStddevRes->isum, int16_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
LIST_STDDEV_SUB_N(pStddevRes->isum, int32_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
LIST_STDDEV_SUB_N(pStddevRes->isum, int64_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
LIST_STDDEV_SUB_N(pStddevRes->dsum, float);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
LIST_STDDEV_SUB_N(pStddevRes->dsum, double);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// data in the check operation are all null, not output
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
@ -1420,11 +1657,6 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
// initial value is not set yet
|
||||
if (numOfElems <= 0) {
|
||||
/*
|
||||
* 1. current block and blocks before are full of null
|
||||
* 2. current block may be null value
|
||||
*/
|
||||
assert(pCtx->hasNull);
|
||||
return 0;
|
||||
} else {
|
||||
return (isFirstBlock) ? numOfElems - 1 : numOfElems;
|
||||
|
@ -1777,3 +2009,247 @@ int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
}
|
||||
return functionFinalize(pCtx, pBlock);
|
||||
}
|
||||
|
||||
bool getHistogramFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SHistoFuncInfo) + HISTOGRAM_MAX_BINS_NUM * sizeof(SHistoFuncBin);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int8_t getHistogramBinType(char *binTypeStr) {
|
||||
int8_t binType;
|
||||
if (strcasecmp(binTypeStr, "user_input") == 0) {
|
||||
binType = USER_INPUT_BIN;
|
||||
} else if (strcasecmp(binTypeStr, "linear_bin") == 0) {
|
||||
binType = LINEAR_BIN;
|
||||
} else if (strcasecmp(binTypeStr, "log_bin") == 0) {
|
||||
binType = LOG_BIN;
|
||||
} else {
|
||||
binType = UNKNOWN_BIN;
|
||||
}
|
||||
|
||||
return binType;
|
||||
}
|
||||
|
||||
static bool getHistogramBinDesc(SHistoFuncInfo *pInfo, char *binDescStr, int8_t binType, bool normalized) {
|
||||
cJSON* binDesc = cJSON_Parse(binDescStr);
|
||||
int32_t numOfBins;
|
||||
double* intervals;
|
||||
if (cJSON_IsObject(binDesc)) { /* linaer/log bins */
|
||||
int32_t numOfParams = cJSON_GetArraySize(binDesc);
|
||||
int32_t startIndex;
|
||||
if (numOfParams != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON* start = cJSON_GetObjectItem(binDesc, "start");
|
||||
cJSON* factor = cJSON_GetObjectItem(binDesc, "factor");
|
||||
cJSON* width = cJSON_GetObjectItem(binDesc, "width");
|
||||
cJSON* count = cJSON_GetObjectItem(binDesc, "count");
|
||||
cJSON* infinity = cJSON_GetObjectItem(binDesc, "infinity");
|
||||
|
||||
if (!cJSON_IsNumber(start) || !cJSON_IsNumber(count) || !cJSON_IsBool(infinity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count->valueint <= 0 || count->valueint > 1000) { // limit count to 1000
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isinf(start->valuedouble) || (width != NULL && isinf(width->valuedouble)) ||
|
||||
(factor != NULL && isinf(factor->valuedouble)) || (count != NULL && isinf(count->valuedouble))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t counter = (int32_t)count->valueint;
|
||||
if (infinity->valueint == false) {
|
||||
startIndex = 0;
|
||||
numOfBins = counter + 1;
|
||||
} else {
|
||||
startIndex = 1;
|
||||
numOfBins = counter + 3;
|
||||
}
|
||||
|
||||
intervals = taosMemoryCalloc(numOfBins, sizeof(double));
|
||||
if (cJSON_IsNumber(width) && factor == NULL && binType == LINEAR_BIN) {
|
||||
// linear bin process
|
||||
if (width->valuedouble == 0) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < counter + 1; ++i) {
|
||||
intervals[startIndex] = start->valuedouble + i * width->valuedouble;
|
||||
if (isinf(intervals[startIndex])) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
startIndex++;
|
||||
}
|
||||
} else if (cJSON_IsNumber(factor) && width == NULL && binType == LOG_BIN) {
|
||||
// log bin process
|
||||
if (start->valuedouble == 0) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
if (factor->valuedouble < 0 || factor->valuedouble == 0 || factor->valuedouble == 1) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < counter + 1; ++i) {
|
||||
intervals[startIndex] = start->valuedouble * pow(factor->valuedouble, i * 1.0);
|
||||
if (isinf(intervals[startIndex])) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
startIndex++;
|
||||
}
|
||||
} else {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (infinity->valueint == true) {
|
||||
intervals[0] = -INFINITY;
|
||||
intervals[numOfBins - 1] = INFINITY;
|
||||
// in case of desc bin orders, -inf/inf should be swapped
|
||||
ASSERT(numOfBins >= 4);
|
||||
if (intervals[1] > intervals[numOfBins - 2]) {
|
||||
TSWAP(intervals[0], intervals[numOfBins - 1]);
|
||||
}
|
||||
}
|
||||
} else if (cJSON_IsArray(binDesc)) { /* user input bins */
|
||||
if (binType != USER_INPUT_BIN) {
|
||||
return false;
|
||||
}
|
||||
numOfBins = cJSON_GetArraySize(binDesc);
|
||||
intervals = taosMemoryCalloc(numOfBins, sizeof(double));
|
||||
cJSON* bin = binDesc->child;
|
||||
if (bin == NULL) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
int i = 0;
|
||||
while (bin) {
|
||||
intervals[i] = bin->valuedouble;
|
||||
if (!cJSON_IsNumber(bin)) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
if (i != 0 && intervals[i] <= intervals[i - 1]) {
|
||||
taosMemoryFree(intervals);
|
||||
return false;
|
||||
}
|
||||
bin = bin->next;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
pInfo->numOfBins = numOfBins - 1;
|
||||
pInfo->normalized = normalized;
|
||||
for (int32_t i = 0; i < pInfo->numOfBins; ++i) {
|
||||
pInfo->bins[i].lower = intervals[i] < intervals[i + 1] ? intervals[i] : intervals[i + 1];
|
||||
pInfo->bins[i].upper = intervals[i + 1] > intervals[i] ? intervals[i + 1] : intervals[i];
|
||||
pInfo->bins[i].count = 0;
|
||||
}
|
||||
|
||||
taosMemoryFree(intervals);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo *pResultInfo) {
|
||||
if (!functionSetup(pCtx, pResultInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SHistoFuncInfo *pInfo = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
|
||||
int8_t binType = getHistogramBinType(varDataVal(pCtx->param[1].param.pz));
|
||||
if (binType == UNKNOWN_BIN) {
|
||||
return false;
|
||||
}
|
||||
char* binDesc = varDataVal(pCtx->param[2].param.pz);
|
||||
int64_t normalized = pCtx->param[3].param.i;
|
||||
if (normalized != 0 && normalized != 1) {
|
||||
return false;
|
||||
}
|
||||
if (!getHistogramBinDesc(pInfo, binDesc, binType, (bool)normalized)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t histogramFunction(SqlFunctionCtx *pCtx) {
|
||||
SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
int32_t numOfElems = 0;
|
||||
int32_t totalElems = 0;
|
||||
for (int32_t i = start; i < numOfRows + start; ++i) {
|
||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
|
||||
char* data = colDataGetData(pCol, i);
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, type, data);
|
||||
|
||||
for (int32_t k = 0; k < pInfo->numOfBins; ++k) {
|
||||
if (v > pInfo->bins[k].lower && v <= pInfo->bins[k].upper) {
|
||||
pInfo->bins[k].count++;
|
||||
totalElems++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (pInfo->normalized) {
|
||||
for (int32_t k = 0; k < pInfo->numOfBins; ++k) {
|
||||
if(totalElems != 0) {
|
||||
pInfo->bins[k].percentage = pInfo->bins[k].count / (double)totalElems;
|
||||
} else {
|
||||
pInfo->bins[k].percentage = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SET_VAL(GET_RES_INFO(pCtx), numOfElems, pInfo->numOfBins);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
int32_t currentRow = pBlock->info.rows;
|
||||
|
||||
for (int32_t i = 0; i < pResInfo->numOfRes; ++i) {
|
||||
int32_t len;
|
||||
char buf[512] = {0};
|
||||
if (!pInfo->normalized) {
|
||||
len = sprintf(buf + VARSTR_HEADER_SIZE, "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%"PRId64"}",
|
||||
pInfo->bins[i].lower, pInfo->bins[i].upper, pInfo->bins[i].count);
|
||||
} else {
|
||||
len = sprintf(buf + VARSTR_HEADER_SIZE, "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}",
|
||||
pInfo->bins[i].lower, pInfo->bins[i].upper, pInfo->bins[i].percentage);
|
||||
}
|
||||
varDataSetLen(buf, len);
|
||||
colDataAppend(pCol, currentRow, buf, false);
|
||||
currentRow++;
|
||||
}
|
||||
|
||||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
|
|
@ -177,3 +177,35 @@ void fmFuncMgtDestroy() {
|
|||
taosHashCleanup(m);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
||||
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
pFpSet->process = funcMgtBuiltins[funcId].invertFunc;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
||||
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
pFpSet->process = funcMgtBuiltins[funcId].processFunc;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool fmIsInvertible(int32_t funcId) {
|
||||
bool res = false;
|
||||
switch (funcMgtBuiltins[funcId].type) {
|
||||
case FUNCTION_TYPE_COUNT:
|
||||
case FUNCTION_TYPE_SUM:
|
||||
case FUNCTION_TYPE_STDDEV:
|
||||
case FUNCTION_TYPE_AVG:
|
||||
res = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -594,7 +594,9 @@ int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SS
|
|||
|
||||
//TODO: free the array output->pDataBlock
|
||||
output->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
taosArrayPush(output->pDataBlock, input->columnData);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
taosArrayPush(output->pDataBlock, (input + i)->columnData);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,9 @@ typedef struct SUdf {
|
|||
TUdfAggStartFunc aggStartFunc;
|
||||
TUdfAggProcessFunc aggProcFunc;
|
||||
TUdfAggFinishFunc aggFinishFunc;
|
||||
|
||||
TUdfInitFunc initFunc;
|
||||
TUdfDestroyFunc destroyFunc;
|
||||
} SUdf;
|
||||
|
||||
// TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix
|
||||
|
@ -101,7 +104,19 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
|||
fnError("can not load library %s. error: %s", udf->path, uv_strerror(err));
|
||||
return UDFC_CODE_LOAD_UDF_FAILURE;
|
||||
}
|
||||
//TODO: init and destroy function
|
||||
|
||||
char initFuncName[TSDB_FUNC_NAME_LEN+5] = {0};
|
||||
char *initSuffix = "_init";
|
||||
strcpy(initFuncName, udfName);
|
||||
strncat(initFuncName, initSuffix, strlen(initSuffix));
|
||||
uv_dlsym(&udf->lib, initFuncName, (void**)(&udf->initFunc));
|
||||
|
||||
char destroyFuncName[TSDB_FUNC_NAME_LEN+5] = {0};
|
||||
char *destroySuffix = "_destroy";
|
||||
strcpy(destroyFuncName, udfName);
|
||||
strncat(destroyFuncName, destroySuffix, strlen(destroySuffix));
|
||||
uv_dlsym(&udf->lib, destroyFuncName, (void**)(&udf->destroyFunc));
|
||||
|
||||
if (udf->funcType == TSDB_FUNC_TYPE_SCALAR) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
|
@ -159,6 +174,9 @@ void udfdProcessRequest(uv_work_t *req) {
|
|||
if (udf->state == UDF_STATE_INIT) {
|
||||
udf->state = UDF_STATE_LOADING;
|
||||
udfdLoadUdf(setup->udfName, udf);
|
||||
if (udf->initFunc) {
|
||||
udf->initFunc();
|
||||
}
|
||||
udf->state = UDF_STATE_READY;
|
||||
uv_cond_broadcast(&udf->condReady);
|
||||
uv_mutex_unlock(&udf->lock);
|
||||
|
@ -170,7 +188,6 @@ void udfdProcessRequest(uv_work_t *req) {
|
|||
}
|
||||
SUdfcFuncHandle *handle = taosMemoryMalloc(sizeof(SUdfcFuncHandle));
|
||||
handle->udf = udf;
|
||||
// TODO: allocate private structure and call init function and set it to handle
|
||||
SUdfResponse rsp;
|
||||
rsp.seqNum = request.seqNum;
|
||||
rsp.type = request.type;
|
||||
|
@ -275,10 +292,12 @@ void udfdProcessRequest(uv_work_t *req) {
|
|||
if (unloadUdf) {
|
||||
uv_cond_destroy(&udf->condReady);
|
||||
uv_mutex_destroy(&udf->lock);
|
||||
if (udf->destroyFunc) {
|
||||
(udf->destroyFunc)();
|
||||
}
|
||||
uv_dlclose(&udf->lib);
|
||||
taosMemoryFree(udf);
|
||||
}
|
||||
// TODO: call destroy and free udf private
|
||||
taosMemoryFree(handle);
|
||||
|
||||
SUdfResponse response;
|
||||
|
|
|
@ -31,6 +31,7 @@ extern "C" {
|
|||
typedef struct MemTable {
|
||||
T_REF_DECLARE()
|
||||
SSkipList* mem;
|
||||
void* pCache;
|
||||
} MemTable;
|
||||
typedef struct IndexCache {
|
||||
T_REF_DECLARE()
|
||||
|
@ -47,6 +48,7 @@ typedef struct IndexCache {
|
|||
} IndexCache;
|
||||
|
||||
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
|
||||
|
||||
typedef struct CacheTerm {
|
||||
// key
|
||||
char* colVal;
|
||||
|
|
|
@ -24,7 +24,7 @@ extern char JSON_COLUMN[];
|
|||
extern char JSON_VALUE_DELIM;
|
||||
|
||||
char* indexPackJsonData(SIndexTerm* itm);
|
||||
|
||||
char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -166,7 +166,9 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf);
|
|||
} while (0)
|
||||
|
||||
#define INDEX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
|
||||
#define INDEX_TYPE_GET_TYPE(ty) (ty & 0x0F)
|
||||
|
||||
#define INDEX_TYPE_GET_TYPE(ty) (ty & 0x0F)
|
||||
|
||||
#define INDEX_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
|
||||
do { \
|
||||
uint8_t oldTy = ty; \
|
||||
|
|
|
@ -244,8 +244,8 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde
|
|||
return 0;
|
||||
}
|
||||
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, int8_t queryType, uint8_t colType,
|
||||
const char* colName, int32_t nColName, const char* colVal, int32_t nColVal) {
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName,
|
||||
int32_t nColName, const char* colVal, int32_t nColVal) {
|
||||
SIndexTerm* tm = (SIndexTerm*)taosMemoryCalloc(1, (sizeof(SIndexTerm)));
|
||||
if (tm == NULL) {
|
||||
return NULL;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue