Merge branch '3.0' into feat/TD-30053-3.0
This commit is contained in:
commit
ee9ccdea86
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -80,7 +80,7 @@ If a stream is created with PARTITION BY clause and SUBTABLE clause, the name of
|
|||
CREATE STREAM avg_vol_s INTO avg_vol SUBTABLE(CONCAT('new-', tname)) AS SELECT _wstart, count(*), avg(voltage) FROM meters PARTITION BY tbname tname INTERVAL(1m);
|
||||
```
|
||||
|
||||
IN PARTITION clause, 'tbname', representing each subtable name of source supertable, is given alias 'tname'. And 'tname' is used in SUBTABLE clause. In SUBTABLE clause, each auto created subtable will concat 'new-' and source subtable name as their name(Starting from 3.2.3.0, in order to avoid the expression in subtable being unable to distinguish between different subtables, add '_groupId' to the end of subtable name).
|
||||
IN PARTITION clause, 'tbname', representing each subtable name of source supertable, is given alias 'tname'. And 'tname' is used in SUBTABLE clause. In SUBTABLE clause, each auto created subtable will concat 'new-' and source subtable name as their name(Starting from 3.2.3.0, in order to avoid the expression in subtable being unable to distinguish between different subtables, add '_stableName_groupId' to the end of subtable name).
|
||||
|
||||
If the output length exceeds the limitation of TDengine(192), the name will be truncated. If the generated name is occupied by some other table, the creation and writing of the new subtable will be failed.
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ SELECT _wstart, count(*), avg(voltage) from meters PARTITION BY tbname COUNT_WIN
|
|||
CREATE STREAM avg_vol_s INTO avg_vol SUBTABLE(CONCAT('new-', tname)) AS SELECT _wstart, count(*), avg(voltage) FROM meters PARTITION BY tbname tname INTERVAL(1m);
|
||||
```
|
||||
|
||||
PARTITION 子句中,为 tbname 定义了一个别名 tname, 在PARTITION 子句中的别名可以用于 SUBTABLE 子句中的表达式计算,在上述示例中,流新创建的子表将以前缀 'new-' 连接原表名作为表名(从3.2.3.0开始,为了避免 sutable 中的表达式无法区分各个子表,即误将多个相同时间线写入一个子表,在指定的子表名后面加上 _groupId)。
|
||||
PARTITION 子句中,为 tbname 定义了一个别名 tname, 在PARTITION 子句中的别名可以用于 SUBTABLE 子句中的表达式计算,在上述示例中,流新创建的子表将以前缀 'new-' 连接原表名作为表名(从3.2.3.0开始,为了避免 sutable 中的表达式无法区分各个子表,即误将多个相同时间线写入一个子表,在指定的子表名后面加上 __stableName_groupId)。
|
||||
|
||||
注意,子表名的长度若超过 TDengine 的限制,将被截断。若要生成的子表名已经存在于另一超级表,由于 TDengine 的子表名是唯一的,因此对应新子表的创建以及数据的写入将会失败。
|
||||
|
||||
|
@ -190,7 +190,7 @@ T3 时刻,最新事件到达,T 向后推移超过了第二个窗口关闭的
|
|||
|
||||
TDengine 对于过期数据提供两种处理方式,由 IGNORE EXPIRED 选项指定:
|
||||
|
||||
1. 重新计算,即 IGNORE EXPIRED 0:从 TSDB 中重新查找对应窗口的所有数据并重新计算得到最新结果
|
||||
1. 增量计算,即 IGNORE EXPIRED 0。
|
||||
|
||||
2. 直接丢弃,即 IGNORE EXPIRED 1:默认配置,忽略过期数据
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ typedef enum tmq_res_t {
|
|||
TMQ_RES_INVALID = -1,
|
||||
TMQ_RES_DATA = 1,
|
||||
TMQ_RES_TABLE_META = 2,
|
||||
TMQ_RES_METADATA = 3,
|
||||
TMQ_RES_METADATA = 3
|
||||
} tmq_res_t;
|
||||
|
||||
typedef struct tmq_topic_assignment {
|
||||
|
|
|
@ -144,6 +144,7 @@ enum {
|
|||
TMQ_MSG_TYPE__EP_RSP,
|
||||
TMQ_MSG_TYPE__POLL_DATA_META_RSP,
|
||||
TMQ_MSG_TYPE__WALINFO_RSP,
|
||||
TMQ_MSG_TYPE__POLL_BATCH_META_RSP,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
|
@ -171,6 +171,7 @@ typedef enum _mgmt_table {
|
|||
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX 11
|
||||
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX 12
|
||||
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS 13
|
||||
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
|
||||
|
||||
#define TSDB_FILL_NONE 0
|
||||
#define TSDB_FILL_NULL 1
|
||||
|
@ -2360,12 +2361,19 @@ typedef struct {
|
|||
char* token;
|
||||
} SMArbUpdateGroupMember;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char* token;
|
||||
int8_t acked;
|
||||
} SMArbUpdateGroupAssigned;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t dbUid;
|
||||
SMArbUpdateGroupMember members[2];
|
||||
int8_t isSync;
|
||||
SMArbUpdateGroupMember assignedLeader;
|
||||
int8_t assignedAcked;
|
||||
SMArbUpdateGroupAssigned assignedLeader;
|
||||
int64_t version;
|
||||
} SMArbUpdateGroup;
|
||||
|
||||
|
@ -2748,6 +2756,7 @@ typedef struct {
|
|||
int32_t autoCommitInterval;
|
||||
int8_t resetOffsetCfg;
|
||||
int8_t enableReplay;
|
||||
int8_t enableBatchMeta;
|
||||
} SCMSubscribeReq;
|
||||
|
||||
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
|
||||
|
@ -2768,6 +2777,7 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc
|
|||
tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
@ -2792,6 +2802,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
|
|||
buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -2980,6 +2991,7 @@ typedef struct {
|
|||
|
||||
int tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
|
||||
int tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
|
||||
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
|
@ -3569,7 +3581,7 @@ static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t u
|
|||
pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
|
||||
pOffsetVal->uid = uid;
|
||||
pOffsetVal->ts = ts;
|
||||
if(IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)){
|
||||
if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
|
||||
taosMemoryFree(pOffsetVal->primaryKey.pData);
|
||||
}
|
||||
pOffsetVal->primaryKey = primaryKey;
|
||||
|
@ -3897,11 +3909,12 @@ typedef struct {
|
|||
STqOffsetVal reqOffset;
|
||||
int8_t enableReplay;
|
||||
int8_t sourceExcluded;
|
||||
int8_t enableBatchMeta;
|
||||
} SMqPollReq;
|
||||
|
||||
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
|
||||
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
|
||||
void tDestroySMqPollReq(SMqPollReq *pReq);
|
||||
void tDestroySMqPollReq(SMqPollReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
|
@ -3945,7 +3958,7 @@ typedef struct {
|
|||
|
||||
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
|
||||
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
|
||||
void tDeleteMqMetaRsp(SMqMetaRsp *pRsp);
|
||||
void tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
|
||||
|
||||
#define MQ_DATA_RSP_VERSION 100
|
||||
|
||||
|
@ -3982,6 +3995,20 @@ int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const void* pRsp);
|
|||
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, void* pRsp);
|
||||
void tDeleteSTaosxRsp(void* pRsp);
|
||||
|
||||
typedef struct SMqBatchMetaRsp {
|
||||
SMqRspHead head; // not serialize
|
||||
STqOffsetVal rspOffset;
|
||||
SArray* batchMetaLen;
|
||||
SArray* batchMetaReq;
|
||||
void* pMetaBuff; // not serialize
|
||||
uint32_t metaBuffLen; // not serialize
|
||||
} SMqBatchMetaRsp;
|
||||
|
||||
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
|
||||
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
|
||||
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
|
||||
void tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
SMqRspHead head;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
|
@ -4294,7 +4321,7 @@ void tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
|
|||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN]; // table name or tsma name
|
||||
bool fetchingWithTsmaName; // if we are fetching with tsma name
|
||||
}STableTSMAInfoReq;
|
||||
} STableTSMAInfoReq;
|
||||
|
||||
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
|
||||
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
|
||||
|
|
|
@ -44,6 +44,11 @@ int32_t dmRun();
|
|||
*/
|
||||
void dmStop();
|
||||
|
||||
/**
|
||||
* for tests
|
||||
*/
|
||||
bool dmReadyForTest();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -101,6 +101,8 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
*/
|
||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
||||
|
||||
int64_t mndGetRoleTimeMs(SMnode *pMnode);
|
||||
|
||||
/**
|
||||
* @brief Process the rpc, sync request.
|
||||
*
|
||||
|
|
|
@ -201,7 +201,7 @@ void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded);
|
|||
|
||||
void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
|
||||
|
||||
SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
|
||||
SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
|
||||
|
||||
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
|
||||
|
||||
|
|
|
@ -104,6 +104,8 @@ typedef struct SNodeAllocator SNodeAllocator;
|
|||
int32_t nodesInitAllocatorSet();
|
||||
void nodesDestroyAllocatorSet();
|
||||
int32_t nodesCreateAllocator(int64_t queryId, int32_t chunkSize, int64_t* pAllocatorId);
|
||||
int32_t nodesSimAcquireAllocator(int64_t allocatorId);
|
||||
int32_t nodesSimReleaseAllocator(int64_t allocatorId);
|
||||
int32_t nodesAcquireAllocator(int64_t allocatorId);
|
||||
int32_t nodesReleaseAllocator(int64_t allocatorId);
|
||||
int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId);
|
||||
|
|
|
@ -183,6 +183,7 @@ typedef struct SProjectLogicNode {
|
|||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreGroupId;
|
||||
bool inputIgnoreGroup;
|
||||
bool isSetOpProj;
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SIndefRowsFuncLogicNode {
|
||||
|
|
|
@ -415,6 +415,7 @@ typedef struct SSelectStmt {
|
|||
int32_t returnRows; // EFuncReturnRows
|
||||
ETimeLineMode timeLineCurMode;
|
||||
ETimeLineMode timeLineResMode;
|
||||
bool timeLineFromOrderBy;
|
||||
bool isEmptyResult;
|
||||
bool isSubquery;
|
||||
bool hasAggFuncs;
|
||||
|
@ -453,6 +454,7 @@ typedef struct SSetOperator {
|
|||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
ETimeLineMode timeLineResMode;
|
||||
bool timeLineFromOrderBy;
|
||||
bool joinContains;
|
||||
} SSetOperator;
|
||||
|
||||
|
|
|
@ -114,6 +114,12 @@ int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val);
|
|||
int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val);
|
||||
void *atomic_fetch_xor_ptr(void *ptr, void *val);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define tmemory_barrier(order) MemoryBarrier()
|
||||
#else
|
||||
#define tmemory_barrier(order) __sync_synchronize()
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -177,7 +177,7 @@ static int32_t tBufferReaderInit(SBufferReader *reader, uint32_t offset, SBuffer
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferGet(SBufferReader *reader, uint32_t size, void *data) {
|
||||
if (reader->offset < 0 || reader->offset + size > reader->buffer->size) {
|
||||
if (reader->offset + size > reader->buffer->size) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
if (data) {
|
||||
|
|
|
@ -77,6 +77,7 @@ typedef struct {
|
|||
#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))
|
||||
#define TD_CODER_REMAIN_CAPACITY(CODER) ((CODER)->size - (CODER)->pos)
|
||||
|
||||
#define tEncodeSize(E, S, SIZE, RET) \
|
||||
do { \
|
||||
|
|
|
@ -119,7 +119,7 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
|
||||
#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \
|
||||
do { \
|
||||
if ((CODE)) { \
|
||||
if (TSDB_CODE_SUCCESS != (CODE)) { \
|
||||
LINO = __LINE__; \
|
||||
goto LABEL; \
|
||||
} \
|
||||
|
|
|
@ -44,6 +44,7 @@ enum {
|
|||
RES_TYPE__TMQ,
|
||||
RES_TYPE__TMQ_META,
|
||||
RES_TYPE__TMQ_METADATA,
|
||||
RES_TYPE__TMQ_BATCH_META,
|
||||
};
|
||||
|
||||
#define SHOW_VARIABLES_RESULT_COLS 3
|
||||
|
@ -55,6 +56,7 @@ enum {
|
|||
#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
|
||||
#define TD_RES_TMQ_META(res) (*(int8_t*)res == RES_TYPE__TMQ_META)
|
||||
#define TD_RES_TMQ_METADATA(res) (*(int8_t*)res == RES_TYPE__TMQ_METADATA)
|
||||
#define TD_RES_TMQ_BATCH_META(res) (*(int8_t*)res == RES_TYPE__TMQ_BATCH_META)
|
||||
|
||||
typedef struct SAppInstInfo SAppInstInfo;
|
||||
|
||||
|
@ -241,6 +243,11 @@ typedef struct {
|
|||
STaosxRsp rsp;
|
||||
} SMqTaosxRspObj;
|
||||
|
||||
typedef struct {
|
||||
SMqRspObjCommon common;
|
||||
SMqBatchMetaRsp rsp;
|
||||
} SMqBatchMetaRspObj;
|
||||
|
||||
typedef struct SReqRelInfo {
|
||||
uint64_t userRefId;
|
||||
uint64_t prevRefId;
|
||||
|
|
|
@ -89,6 +89,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
"current:%d, app current:%d",
|
||||
pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000.0, num, currentInst);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == nodesSimAcquireAllocator(pRequest->allocatorRefId)) {
|
||||
if (pRequest->pQuery && pRequest->pQuery->pRoot) {
|
||||
if (QUERY_NODE_VNODE_MODIFY_STMT == pRequest->pQuery->pRoot->type &&
|
||||
(0 == ((SVnodeModifyOpStmt *)pRequest->pQuery->pRoot)->sqlNodeType)) {
|
||||
|
@ -109,6 +110,9 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
}
|
||||
}
|
||||
|
||||
nodesSimReleaseAllocator(pRequest->allocatorRefId);
|
||||
}
|
||||
|
||||
if (QUERY_NODE_VNODE_MODIFY_STMT == pRequest->stmtType || QUERY_NODE_INSERT_STMT == pRequest->stmtType) {
|
||||
sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPEINSERT);
|
||||
} else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
|
||||
|
@ -491,7 +495,10 @@ void doDestroyRequest(void *p) {
|
|||
}
|
||||
taosMemoryFree(pRequest->body.interParam);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == nodesSimAcquireAllocator(pRequest->allocatorRefId)) {
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
nodesSimReleaseAllocator(pRequest->allocatorRefId);
|
||||
}
|
||||
nodesDestroyAllocator(pRequest->allocatorRefId);
|
||||
|
||||
taosMemoryFreeClear(pRequest->effectiveUser);
|
||||
|
|
|
@ -301,7 +301,7 @@ void taos_close(TAOS *taos) {
|
|||
}
|
||||
|
||||
int taos_errno(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ int taos_errno(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
const char *taos_errstr(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return (const char *)tstrerror(terrno);
|
||||
}
|
||||
|
||||
|
@ -354,6 +354,10 @@ void taos_free_result(TAOS_RES *res) {
|
|||
SMqMetaRspObj *pRspObj = (SMqMetaRspObj *)res;
|
||||
tDeleteMqMetaRsp(&pRspObj->metaRsp);
|
||||
taosMemoryFree(pRspObj);
|
||||
} else if (TD_RES_TMQ_BATCH_META(res)) {
|
||||
SMqBatchMetaRspObj *pBtRspObj = (SMqBatchMetaRspObj *)res;
|
||||
tDeleteMqBatchMetaRsp(&pBtRspObj->rsp);
|
||||
taosMemoryFree(pBtRspObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,7 +375,7 @@ void taos_kill_query(TAOS *taos) {
|
|||
}
|
||||
|
||||
int taos_field_count(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -382,7 +386,7 @@ int taos_field_count(TAOS_RES *res) {
|
|||
int taos_num_fields(TAOS_RES *res) { return taos_field_count(res); }
|
||||
|
||||
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
||||
if (taos_num_fields(res) == 0 || TD_RES_TMQ_META(res)) {
|
||||
if (taos_num_fields(res) == 0 || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -437,7 +441,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
pResultInfo->current += 1;
|
||||
return pResultInfo->row;
|
||||
}
|
||||
} else if (TD_RES_TMQ_META(res)) {
|
||||
} else if (TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return NULL;
|
||||
} else {
|
||||
// assert to avoid un-initialization error
|
||||
|
@ -548,7 +552,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
}
|
||||
|
||||
int *taos_fetch_lengths(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -557,7 +561,7 @@ int *taos_fetch_lengths(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
TAOS_ROW *taos_result_block(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -625,7 +629,7 @@ const char *taos_get_client_info() { return version; }
|
|||
|
||||
// return int32_t
|
||||
int taos_affected_rows(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -636,7 +640,7 @@ int taos_affected_rows(TAOS_RES *res) {
|
|||
|
||||
// return int64_t
|
||||
int64_t taos_affected_rows64(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -646,7 +650,7 @@ int64_t taos_affected_rows64(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
int taos_result_precision(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return TSDB_TIME_PRECISION_MILLI;
|
||||
}
|
||||
|
||||
|
@ -686,7 +690,7 @@ int taos_select_db(TAOS *taos, const char *db) {
|
|||
}
|
||||
|
||||
void taos_stop_query(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -694,7 +698,7 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return true;
|
||||
}
|
||||
SReqResultInfo *pResultInfo = tscGetCurResInfo(res);
|
||||
|
@ -719,7 +723,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
}
|
||||
|
||||
int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -761,7 +765,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
*numOfRows = 0;
|
||||
*pData = NULL;
|
||||
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -797,7 +801,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
}
|
||||
|
||||
int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,13 @@
|
|||
#define LOG_ID_TAG "connId:0x%" PRIx64 ",reqId:0x%" PRIx64
|
||||
#define LOG_ID_VALUE *(int64_t*)taos, pRequest->requestId
|
||||
|
||||
#define TMQ_META_VERSION "1.0"
|
||||
|
||||
static int32_t tmqWriteBatchMetaDataImpl(TAOS* taos, void* meta, int32_t metaLen);
|
||||
|
||||
static tb_uid_t processSuid(tb_uid_t suid, char* db) { return suid + MurmurHash3_32(db, strlen(db)); }
|
||||
|
||||
static char* buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* schemaTag, char* name, int64_t id,
|
||||
static cJSON* buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* schemaTag, char* name, int64_t id,
|
||||
int8_t t, SColCmprWrapper* pColCmprRow) {
|
||||
int8_t buildDefaultCompress = 0;
|
||||
if (pColCmprRow->nCols <= 0) {
|
||||
|
@ -122,9 +126,7 @@ static char* buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* sch
|
|||
}
|
||||
cJSON_AddItemToObject(json, "tags", tags);
|
||||
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
cJSON_Delete(json);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
|
||||
static int32_t setCompressOption(cJSON* json, uint32_t para) {
|
||||
|
@ -151,7 +153,7 @@ static int32_t setCompressOption(cJSON* json, uint32_t para) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
static char* buildAlterSTableJson(void* alterData, int32_t alterDataLen) {
|
||||
static cJSON* buildAlterSTableJson(void* alterData, int32_t alterDataLen) {
|
||||
SMAlterStbReq req = {0};
|
||||
cJSON* json = NULL;
|
||||
char* string = NULL;
|
||||
|
@ -199,6 +201,26 @@ static char* buildAlterSTableJson(void* alterData, int32_t alterDataLen) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: {
|
||||
SFieldWithOptions* field = taosArrayGet(req.pFields, 0);
|
||||
cJSON* colName = cJSON_CreateString(field->name);
|
||||
cJSON_AddItemToObject(json, "colName", colName);
|
||||
cJSON* colType = cJSON_CreateNumber(field->type);
|
||||
cJSON_AddItemToObject(json, "colType", colType);
|
||||
|
||||
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
|
||||
field->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
int32_t length = field->bytes - VARSTR_HEADER_SIZE;
|
||||
cJSON* cbytes = cJSON_CreateNumber(length);
|
||||
cJSON_AddItemToObject(json, "colLength", cbytes);
|
||||
} else if (field->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||
cJSON* cbytes = cJSON_CreateNumber(length);
|
||||
cJSON_AddItemToObject(json, "colLength", cbytes);
|
||||
}
|
||||
setCompressOption(json, field->compress);
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_DROP_TAG:
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN: {
|
||||
TAOS_FIELD* field = taosArrayGet(req.pFields, 0);
|
||||
|
@ -245,18 +267,16 @@ static char* buildAlterSTableJson(void* alterData, int32_t alterDataLen) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
|
||||
end:
|
||||
cJSON_Delete(json);
|
||||
tFreeSMAltertbReq(&req);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
|
||||
static char* processCreateStb(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processCreateStb(SMqMetaRsp* metaRsp) {
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder coder;
|
||||
char* string = NULL;
|
||||
cJSON* pJson = NULL;
|
||||
|
||||
uDebug("create stable data:%p", metaRsp);
|
||||
// decode and process req
|
||||
|
@ -267,17 +287,17 @@ static char* processCreateStb(SMqMetaRsp* metaRsp) {
|
|||
if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
string = buildCreateTableJson(&req.schemaRow, &req.schemaTag, req.name, req.suid, TSDB_SUPER_TABLE, &req.colCmpr);
|
||||
pJson = buildCreateTableJson(&req.schemaRow, &req.schemaTag, req.name, req.suid, TSDB_SUPER_TABLE, &req.colCmpr);
|
||||
_err:
|
||||
uDebug("create stable return, sql json:%s", string);
|
||||
uDebug("create stable return, sql json:%s", cJSON_PrintUnformatted(pJson));
|
||||
tDecoderClear(&coder);
|
||||
return string;
|
||||
return pJson;
|
||||
}
|
||||
|
||||
static char* processAlterStb(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processAlterStb(SMqMetaRsp* metaRsp) {
|
||||
SVCreateStbReq req = {0};
|
||||
SDecoder coder;
|
||||
char* string = NULL;
|
||||
cJSON* pJson = NULL;
|
||||
uDebug("alter stable data:%p", metaRsp);
|
||||
|
||||
// decode and process req
|
||||
|
@ -288,11 +308,11 @@ static char* processAlterStb(SMqMetaRsp* metaRsp) {
|
|||
if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
string = buildAlterSTableJson(req.alterOriData, req.alterOriDataLen);
|
||||
pJson = buildAlterSTableJson(req.alterOriData, req.alterOriDataLen);
|
||||
_err:
|
||||
uDebug("alter stable return, sql json:%s", string);
|
||||
uDebug("alter stable return, sql json:%s", cJSON_PrintUnformatted(pJson));
|
||||
tDecoderClear(&coder);
|
||||
return string;
|
||||
return pJson;
|
||||
}
|
||||
|
||||
static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
|
||||
|
@ -385,7 +405,7 @@ end:
|
|||
taosArrayDestroy(pTagVals);
|
||||
}
|
||||
|
||||
static char* buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs) {
|
||||
static cJSON* buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs) {
|
||||
char* string = NULL;
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
if (json == NULL) {
|
||||
|
@ -410,16 +430,14 @@ static char* buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs) {
|
|||
cJSON_AddItemToArray(createList, create);
|
||||
}
|
||||
cJSON_AddItemToObject(json, "createList", createList);
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
cJSON_Delete(json);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
|
||||
static char* processCreateTable(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processCreateTable(SMqMetaRsp* metaRsp) {
|
||||
SDecoder decoder = {0};
|
||||
SVCreateTbBatchReq req = {0};
|
||||
SVCreateTbReq* pCreateReq;
|
||||
char* string = NULL;
|
||||
cJSON* pJson = NULL;
|
||||
// decode
|
||||
uDebug("create table data:%p", metaRsp);
|
||||
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
|
||||
|
@ -433,25 +451,18 @@ static char* processCreateTable(SMqMetaRsp* metaRsp) {
|
|||
if (req.nReqs > 0) {
|
||||
pCreateReq = req.pReqs;
|
||||
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
||||
string = buildCreateCTableJson(req.pReqs, req.nReqs);
|
||||
pJson = buildCreateCTableJson(req.pReqs, req.nReqs);
|
||||
} else if (pCreateReq->type == TSDB_NORMAL_TABLE) {
|
||||
string = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid,
|
||||
pJson = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid,
|
||||
TSDB_NORMAL_TABLE, &pCreateReq->colCmpr);
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
uDebug("create table return, sql json:%s", string);
|
||||
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
||||
pCreateReq = req.pReqs + iReq;
|
||||
taosMemoryFreeClear(pCreateReq->comment);
|
||||
taosMemoryFreeClear(pCreateReq->sql);
|
||||
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
||||
taosArrayDestroy(pCreateReq->ctb.tagName);
|
||||
}
|
||||
}
|
||||
uDebug("create table return, sql json:%s", cJSON_PrintUnformatted(pJson));
|
||||
tDeleteSVCreateTbBatchReq(&req);
|
||||
tDecoderClear(&decoder);
|
||||
return string;
|
||||
return pJson;
|
||||
}
|
||||
|
||||
static char* processAutoCreateTable(STaosxRsp* rsp) {
|
||||
|
@ -480,7 +491,9 @@ static char* processAutoCreateTable(STaosxRsp* rsp) {
|
|||
goto _exit;
|
||||
}
|
||||
}
|
||||
string = buildCreateCTableJson(pCreateReq, rsp->createTableNum);
|
||||
cJSON* pJson = buildCreateCTableJson(pCreateReq, rsp->createTableNum);
|
||||
string = cJSON_PrintUnformatted(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
_exit:
|
||||
uDebug("auto created table return, sql json:%s", string);
|
||||
for (int i = 0; i < rsp->createTableNum; i++) {
|
||||
|
@ -495,7 +508,7 @@ _exit:
|
|||
return string;
|
||||
}
|
||||
|
||||
static char* processAlterTable(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processAlterTable(SMqMetaRsp* metaRsp) {
|
||||
SDecoder decoder = {0};
|
||||
SVAlterTbReq vAlterTbReq = {0};
|
||||
char* string = NULL;
|
||||
|
@ -546,6 +559,25 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: {
|
||||
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
|
||||
cJSON_AddItemToObject(json, "colName", colName);
|
||||
cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type);
|
||||
cJSON_AddItemToObject(json, "colType", colType);
|
||||
|
||||
if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY ||
|
||||
vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE;
|
||||
cJSON* cbytes = cJSON_CreateNumber(length);
|
||||
cJSON_AddItemToObject(json, "colLength", cbytes);
|
||||
} else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||
cJSON* cbytes = cJSON_CreateNumber(length);
|
||||
cJSON_AddItemToObject(json, "colLength", cbytes);
|
||||
}
|
||||
setCompressOption(json, vAlterTbReq.compress);
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN: {
|
||||
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
|
||||
cJSON_AddItemToObject(json, "colName", colName);
|
||||
|
@ -620,19 +652,16 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
|
||||
_exit:
|
||||
uDebug("alter table return, sql json:%s", string);
|
||||
cJSON_Delete(json);
|
||||
uDebug("alter table return, sql json:%s", cJSON_PrintUnformatted(json));
|
||||
tDecoderClear(&decoder);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
|
||||
static char* processDropSTable(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processDropSTable(SMqMetaRsp* metaRsp) {
|
||||
SDecoder decoder = {0};
|
||||
SVDropStbReq req = {0};
|
||||
char* string = NULL;
|
||||
cJSON* json = NULL;
|
||||
uDebug("processDropSTable data:%p", metaRsp);
|
||||
|
||||
|
@ -657,18 +686,15 @@ static char* processDropSTable(SMqMetaRsp* metaRsp) {
|
|||
cJSON* tableName = cJSON_CreateString(req.name);
|
||||
cJSON_AddItemToObject(json, "tableName", tableName);
|
||||
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
_exit:
|
||||
uDebug("processDropSTable return, sql json:%s", string);
|
||||
cJSON_Delete(json);
|
||||
uDebug("processDropSTable return, sql json:%s", cJSON_PrintUnformatted(json));
|
||||
tDecoderClear(&decoder);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
static char* processDeleteTable(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processDeleteTable(SMqMetaRsp* metaRsp) {
|
||||
SDeleteRes req = {0};
|
||||
SDecoder coder = {0};
|
||||
cJSON* json = NULL;
|
||||
char* string = NULL;
|
||||
|
||||
uDebug("processDeleteTable data:%p", metaRsp);
|
||||
// decode and process req
|
||||
|
@ -696,18 +722,15 @@ static char* processDeleteTable(SMqMetaRsp* metaRsp) {
|
|||
cJSON* sqlJson = cJSON_CreateString(sql);
|
||||
cJSON_AddItemToObject(json, "sql", sqlJson);
|
||||
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
_exit:
|
||||
uDebug("processDeleteTable return, sql json:%s", string);
|
||||
cJSON_Delete(json);
|
||||
uDebug("processDeleteTable return, sql json:%s", cJSON_PrintUnformatted(json));
|
||||
tDecoderClear(&coder);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
|
||||
static char* processDropTable(SMqMetaRsp* metaRsp) {
|
||||
static cJSON* processDropTable(SMqMetaRsp* metaRsp) {
|
||||
SDecoder decoder = {0};
|
||||
SVDropTbBatchReq req = {0};
|
||||
char* string = NULL;
|
||||
cJSON* json = NULL;
|
||||
|
||||
uDebug("processDropTable data:%p", metaRsp);
|
||||
|
@ -741,12 +764,10 @@ static char* processDropTable(SMqMetaRsp* metaRsp) {
|
|||
}
|
||||
cJSON_AddItemToObject(json, "tableNameList", tableNameList);
|
||||
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
_exit:
|
||||
uDebug("processDropTable return, json sql:%s", string);
|
||||
cJSON_Delete(json);
|
||||
uDebug("processDropTable return, json sql:%s", cJSON_PrintUnformatted(json));
|
||||
tDecoderClear(&decoder);
|
||||
return string;
|
||||
return json;
|
||||
}
|
||||
|
||||
static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) {
|
||||
|
@ -1121,13 +1142,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
|
||||
end:
|
||||
uDebug(LOG_ID_TAG " create table return, msg:%s", LOG_ID_VALUE, tstrerror(code));
|
||||
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
||||
pCreateReq = req.pReqs + iReq;
|
||||
taosMemoryFreeClear(pCreateReq->comment);
|
||||
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
||||
taosArrayDestroy(pCreateReq->ctb.tagName);
|
||||
}
|
||||
}
|
||||
tDeleteSVCreateTbBatchReq(&req);
|
||||
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
destroyRequest(pRequest);
|
||||
|
@ -1803,6 +1818,7 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
char err[ERR_MSG_LEN] = {0};
|
||||
code = rawBlockBindData(pQuery, pTableMeta, rawData, NULL, fields, pSW->nCols, true, err, ERR_MSG_LEN);
|
||||
taosMemoryFree(fields);
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SET_ERROR_MSG("table:%s, err:%s", tbName, err);
|
||||
goto end;
|
||||
|
@ -1995,6 +2011,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
char err[ERR_MSG_LEN] = {0};
|
||||
code = rawBlockBindData(pQuery, pTableMeta, rawData, &pCreateReqDst, fields, pSW->nCols, true, err, ERR_MSG_LEN);
|
||||
taosMemoryFree(fields);
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SET_ERROR_MSG("table:%s, err:%s", tbName, err);
|
||||
goto end;
|
||||
|
@ -2025,38 +2042,85 @@ end:
|
|||
return code;
|
||||
}
|
||||
|
||||
static cJSON* processSimpleMeta(SMqMetaRsp* pMetaRsp) {
|
||||
if (pMetaRsp->resMsgType == TDMT_VND_CREATE_STB) {
|
||||
return processCreateStb(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_ALTER_STB) {
|
||||
return processAlterStb(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_DROP_STB) {
|
||||
return processDropSTable(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_CREATE_TABLE) {
|
||||
return processCreateTable(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_ALTER_TABLE) {
|
||||
return processAlterTable(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_DROP_TABLE) {
|
||||
return processDropTable(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_DROP_TABLE) {
|
||||
return processDropTable(pMetaRsp);
|
||||
} else if (pMetaRsp->resMsgType == TDMT_VND_DELETE) {
|
||||
return processDeleteTable(pMetaRsp);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static char* processBatchMetaToJson(SMqBatchMetaRsp* pMsgRsp) {
|
||||
SDecoder coder;
|
||||
SMqBatchMetaRsp rsp = {0};
|
||||
tDecoderInit(&coder, pMsgRsp->pMetaBuff, pMsgRsp->metaBuffLen);
|
||||
if (tDecodeMqBatchMetaRsp(&coder, &rsp) < 0) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(pJson, "tmq_meta_version", TMQ_META_VERSION);
|
||||
cJSON* pMetaArr = cJSON_CreateArray();
|
||||
int32_t num = taosArrayGetSize(rsp.batchMetaReq);
|
||||
for (int32_t i = 0; i < num; i++) {
|
||||
int32_t len = *(int32_t*)taosArrayGet(rsp.batchMetaLen, i);
|
||||
void* tmpBuf = taosArrayGetP(rsp.batchMetaReq, i);
|
||||
SDecoder metaCoder = {0};
|
||||
SMqMetaRsp metaRsp = {0};
|
||||
tDecoderInit(&metaCoder, POINTER_SHIFT(tmpBuf, sizeof(SMqRspHead)), len - sizeof(SMqRspHead));
|
||||
if(tDecodeMqMetaRsp(&metaCoder, &metaRsp) < 0 ) {
|
||||
goto _end;
|
||||
}
|
||||
cJSON* pItem = processSimpleMeta(&metaRsp);
|
||||
tDeleteMqMetaRsp(&metaRsp);
|
||||
cJSON_AddItemToArray(pMetaArr, pItem);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(pJson, "metas", pMetaArr);
|
||||
tDeleteMqBatchMetaRsp(&rsp);
|
||||
char* fullStr = cJSON_PrintUnformatted(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return fullStr;
|
||||
|
||||
_end:
|
||||
cJSON_Delete(pJson);
|
||||
tDeleteMqBatchMetaRsp(&rsp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* tmq_get_json_meta(TAOS_RES* res) {
|
||||
if (res == NULL) return NULL;
|
||||
uDebug("tmq_get_json_meta res:%p", res);
|
||||
if (!TD_RES_TMQ_META(res) && !TD_RES_TMQ_METADATA(res)) {
|
||||
if (!TD_RES_TMQ_META(res) && !TD_RES_TMQ_METADATA(res) && !TD_RES_TMQ_BATCH_META(res)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (TD_RES_TMQ_METADATA(res)) {
|
||||
SMqTaosxRspObj* pMetaDataRspObj = (SMqTaosxRspObj*)res;
|
||||
return processAutoCreateTable(&pMetaDataRspObj->rsp);
|
||||
} else if (TD_RES_TMQ_BATCH_META(res)) {
|
||||
SMqBatchMetaRspObj* pBatchMetaRspObj = (SMqBatchMetaRspObj*)res;
|
||||
return processBatchMetaToJson(&pBatchMetaRspObj->rsp);
|
||||
}
|
||||
|
||||
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
|
||||
if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_STB) {
|
||||
return processCreateStb(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_ALTER_STB) {
|
||||
return processAlterStb(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_STB) {
|
||||
return processDropSTable(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_TABLE) {
|
||||
return processCreateTable(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_ALTER_TABLE) {
|
||||
return processAlterTable(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_TABLE) {
|
||||
return processDropTable(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_TABLE) {
|
||||
return processDropTable(&pMetaRspObj->metaRsp);
|
||||
} else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DELETE) {
|
||||
return processDeleteTable(&pMetaRspObj->metaRsp);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
cJSON* pJson = processSimpleMeta(&pMetaRspObj->metaRsp);
|
||||
char* string = cJSON_PrintUnformatted(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return string;
|
||||
}
|
||||
|
||||
void tmq_free_json_meta(char* jsonMeta) { taosMemoryFreeClear(jsonMeta); }
|
||||
|
@ -2147,6 +2211,12 @@ int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
|
|||
}
|
||||
raw->raw_type = RES_TYPE__TMQ_METADATA;
|
||||
uDebug("tmq get raw type metadata:%p", raw);
|
||||
} else if (TD_RES_TMQ_BATCH_META(res)) {
|
||||
SMqBatchMetaRspObj* pBtMetaRspObj = (SMqBatchMetaRspObj*)res;
|
||||
raw->raw = pBtMetaRspObj->rsp.pMetaBuff;
|
||||
raw->raw_len = pBtMetaRspObj->rsp.metaBuffLen;
|
||||
raw->raw_type = RES_TYPE__TMQ_BATCH_META;
|
||||
uDebug("tmq get raw batch meta:%p", raw);
|
||||
} else {
|
||||
uError("tmq get raw error type:%d", *(int8_t*)res);
|
||||
terrno = TSDB_CODE_TMQ_INVALID_MSG;
|
||||
|
@ -2163,32 +2233,74 @@ void tmq_free_raw(tmq_raw_data raw) {
|
|||
memset(terrMsg, 0, ERR_MSG_LEN);
|
||||
}
|
||||
|
||||
static int32_t writeRawImpl(TAOS* taos, void* buf, uint32_t len, uint16_t type) {
|
||||
if (type == TDMT_VND_CREATE_STB) {
|
||||
return taosCreateStb(taos, buf, len);
|
||||
} else if (type == TDMT_VND_ALTER_STB) {
|
||||
return taosCreateStb(taos, buf, len);
|
||||
} else if (type == TDMT_VND_DROP_STB) {
|
||||
return taosDropStb(taos, buf, len);
|
||||
} else if (type == TDMT_VND_CREATE_TABLE) {
|
||||
return taosCreateTable(taos, buf, len);
|
||||
} else if (type == TDMT_VND_ALTER_TABLE) {
|
||||
return taosAlterTable(taos, buf, len);
|
||||
} else if (type == TDMT_VND_DROP_TABLE) {
|
||||
return taosDropTable(taos, buf, len);
|
||||
} else if (type == TDMT_VND_DELETE) {
|
||||
return taosDeleteData(taos, buf, len);
|
||||
} else if (type == RES_TYPE__TMQ) {
|
||||
return tmqWriteRawDataImpl(taos, buf, len);
|
||||
} else if (type == RES_TYPE__TMQ_METADATA) {
|
||||
return tmqWriteRawMetaDataImpl(taos, buf, len);
|
||||
} else if (type == RES_TYPE__TMQ_BATCH_META) {
|
||||
return tmqWriteBatchMetaDataImpl(taos, buf, len);
|
||||
}
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t tmq_write_raw(TAOS* taos, tmq_raw_data raw) {
|
||||
if (!taos) {
|
||||
goto end;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
if (raw.raw_type == TDMT_VND_CREATE_STB) {
|
||||
return taosCreateStb(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == TDMT_VND_ALTER_STB) {
|
||||
return taosCreateStb(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == TDMT_VND_DROP_STB) {
|
||||
return taosDropStb(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == TDMT_VND_CREATE_TABLE) {
|
||||
return taosCreateTable(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == TDMT_VND_ALTER_TABLE) {
|
||||
return taosAlterTable(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == TDMT_VND_DROP_TABLE) {
|
||||
return taosDropTable(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == TDMT_VND_DELETE) {
|
||||
return taosDeleteData(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == RES_TYPE__TMQ) {
|
||||
return tmqWriteRawDataImpl(taos, raw.raw, raw.raw_len);
|
||||
} else if (raw.raw_type == RES_TYPE__TMQ_METADATA) {
|
||||
return tmqWriteRawMetaDataImpl(taos, raw.raw, raw.raw_len);
|
||||
}
|
||||
return writeRawImpl(taos, raw.raw, raw.raw_len, raw.raw_type);
|
||||
}
|
||||
|
||||
end:
|
||||
static int32_t tmqWriteBatchMetaDataImpl(TAOS* taos, void* meta, int32_t metaLen) {
|
||||
if (taos == NULL || meta == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
SMqBatchMetaRsp rsp = {0};
|
||||
SDecoder coder;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// decode and process req
|
||||
tDecoderInit(&coder, meta, metaLen);
|
||||
if (tDecodeMqBatchMetaRsp(&coder, &rsp) < 0) {
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
goto _end;
|
||||
}
|
||||
int32_t num = taosArrayGetSize(rsp.batchMetaReq);
|
||||
for (int32_t i = 0; i < num; i++) {
|
||||
int32_t len = *(int32_t*)taosArrayGet(rsp.batchMetaLen, i);
|
||||
void* tmpBuf = taosArrayGetP(rsp.batchMetaReq, i);
|
||||
SDecoder metaCoder = {0};
|
||||
SMqMetaRsp metaRsp = {0};
|
||||
tDecoderInit(&metaCoder, POINTER_SHIFT(tmpBuf, sizeof(SMqRspHead)), len - sizeof(SMqRspHead));
|
||||
if (tDecodeMqMetaRsp(&metaCoder, &metaRsp) < 0) {
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
goto _end;
|
||||
}
|
||||
code = writeRawImpl(taos, metaRsp.metaRsp, metaRsp.metaRspLen, metaRsp.resMsgType);
|
||||
tDeleteMqMetaRsp(&metaRsp);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
_end:
|
||||
tDeleteMqBatchMetaRsp(&rsp);
|
||||
errno = code;
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -939,7 +939,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns,
|
|||
pReq.pColumns = taosArrayInit(pReq.numOfColumns, sizeof(SFieldWithOptions));
|
||||
for (int32_t i = 0; i < pReq.numOfColumns; ++i) {
|
||||
SField *pField = taosArrayGet(pColumns, i);
|
||||
SFieldWithOptions fieldWithOption;
|
||||
SFieldWithOptions fieldWithOption = {0};
|
||||
setFieldWithOptions(&fieldWithOption, pField);
|
||||
setDefaultOptionsForField(&fieldWithOption);
|
||||
taosArrayPush(pReq.pColumns, &fieldWithOption);
|
||||
|
|
|
@ -233,7 +233,7 @@ int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
|
|||
|
||||
SSmlKv kvTs = {0};
|
||||
smlBuildTsKv(&kvTs, ts);
|
||||
if (needConverTime) {
|
||||
if (needConverTime && info->currSTableMeta != NULL) {
|
||||
kvTs.i = convertTimePrecision(kvTs.i, TSDB_TIME_PRECISION_NANO, info->currSTableMeta->tableInfo.precision);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ struct tmq_conf_t {
|
|||
char* pass;
|
||||
tmq_commit_cb* commitCb;
|
||||
void* commitCbUserParam;
|
||||
int8_t enableBatchMeta;
|
||||
};
|
||||
|
||||
struct tmq_t {
|
||||
|
@ -87,6 +88,7 @@ struct tmq_t {
|
|||
uint64_t consumerId;
|
||||
tmq_commit_cb* commitCb;
|
||||
void* commitCbUserParam;
|
||||
int8_t enableBatchMeta;
|
||||
|
||||
// status
|
||||
SRWLatch lock;
|
||||
|
@ -174,6 +176,7 @@ typedef struct {
|
|||
SMqDataRsp dataRsp;
|
||||
SMqMetaRsp metaRsp;
|
||||
STaosxRsp taosxRsp;
|
||||
SMqBatchMetaRsp batchMetaRsp;
|
||||
};
|
||||
} SMqPollRspWrapper;
|
||||
|
||||
|
@ -268,6 +271,7 @@ tmq_conf_t* tmq_conf_new() {
|
|||
conf->autoCommit = true;
|
||||
conf->autoCommitInterval = DEFAULT_AUTO_COMMIT_INTERVAL;
|
||||
conf->resetOffset = TMQ_OFFSET__RESET_LATEST;
|
||||
conf->enableBatchMeta = false;
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
@ -397,6 +401,11 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
if (strcasecmp(key, "msg.enable.batchmeta") == 0) {
|
||||
conf->enableBatchMeta = (taosStr2int64(value) != 0) ? true : false;
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
return TMQ_CONF_UNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -635,6 +644,11 @@ static void asyncCommitFromResult(tmq_t* tmq, const TAOS_RES* pRes, tmq_commit_c
|
|||
pTopicName = pRspObj->common.topic;
|
||||
vgId = pRspObj->common.vgId;
|
||||
offsetVal = pRspObj->rsp.common.rspOffset;
|
||||
} else if (TD_RES_TMQ_BATCH_META(pRes)) {
|
||||
SMqBatchMetaRspObj* pBtRspObj = (SMqBatchMetaRspObj*)pRes;
|
||||
pTopicName = pBtRspObj->common.topic;
|
||||
vgId = pBtRspObj->common.vgId;
|
||||
offsetVal = pBtRspObj->rsp.rspOffset;
|
||||
} else {
|
||||
code = TSDB_CODE_TMQ_INVALID_MSG;
|
||||
goto end;
|
||||
|
@ -858,7 +872,10 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
|||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
int32_t code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
if (code != 0) {
|
||||
tscError("tmqSendHbReq asyncSendMsgToServer failed");
|
||||
}
|
||||
|
||||
OVER:
|
||||
tDestroySMqHbReq(&req);
|
||||
|
@ -934,6 +951,10 @@ static void tmqFreeRspWrapper(SMqRspWrapper* rspWrapper) {
|
|||
SMqPollRspWrapper* pRsp = (SMqPollRspWrapper*)rspWrapper;
|
||||
taosMemoryFreeClear(pRsp->pEpset);
|
||||
tDeleteSTaosxRsp(&pRsp->taosxRsp);
|
||||
} else if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_BATCH_META_RSP) {
|
||||
SMqPollRspWrapper* pRsp = (SMqPollRspWrapper*)rspWrapper;
|
||||
taosMemoryFreeClear(pRsp->pEpset);
|
||||
tDeleteMqBatchMetaRsp(&pRsp->batchMetaRsp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1112,6 +1133,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
pTmq->replayEnable = conf->replayEnable;
|
||||
pTmq->sourceExcluded = conf->sourceExcluded;
|
||||
pTmq->enableBatchMeta = conf->enableBatchMeta;
|
||||
if (conf->replayEnable) {
|
||||
pTmq->autoCommit = false;
|
||||
}
|
||||
|
@ -1189,6 +1211,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
req.autoCommitInterval = tmq->autoCommitInterval;
|
||||
req.resetOffsetCfg = tmq->resetOffsetCfg;
|
||||
req.enableReplay = tmq->replayEnable;
|
||||
req.enableBatchMeta = tmq->enableBatchMeta;
|
||||
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char* topic = taosArrayGetP(container, i);
|
||||
|
@ -1220,12 +1243,15 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(buf);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
SMqSubscribeCbParam param = {.rspErr = 0};
|
||||
if (tsem_init(¶m.rspSem, 0, 0) != 0) {
|
||||
code = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
taosMemoryFree(buf);
|
||||
taosMemoryFree(sendInfo);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -1245,10 +1271,6 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
goto FAIL;
|
||||
}
|
||||
|
||||
// avoid double free if msg is sent
|
||||
buf = NULL;
|
||||
sendInfo = NULL;
|
||||
|
||||
tsem_wait(¶m.rspSem);
|
||||
tsem_destroy(¶m.rspSem);
|
||||
|
||||
|
@ -1260,7 +1282,10 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
int32_t retryCnt = 0;
|
||||
while ((code = syncAskEp(tmq)) != 0) {
|
||||
if (retryCnt++ > MAX_RETRY_COUNT || code == TSDB_CODE_MND_CONSUMER_NOT_EXIST) {
|
||||
tscError("consumer:0x%" PRIx64 ", mnd not ready for subscribe, retry more than 2 minutes", tmq->consumerId);
|
||||
tscError("consumer:0x%" PRIx64 ", mnd not ready for subscribe, retry more than 2 minutes, code:%s", tmq->consumerId, strerror(code));
|
||||
if(code == TSDB_CODE_MND_CONSUMER_NOT_EXIST) {
|
||||
code = 0;
|
||||
}
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -1284,8 +1309,6 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
|
||||
FAIL:
|
||||
taosArrayDestroyP(req.topicNames, taosMemoryFree);
|
||||
taosMemoryFree(buf);
|
||||
taosMemoryFree(sendInfo);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1358,7 +1381,8 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
if(pMsg->pData == NULL){
|
||||
tscError("consumer:0x%" PRIx64 " msg discard from vgId:%d, since msg is NULL", tmq->consumerId, vgId);
|
||||
goto FAIL;
|
||||
code = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
goto END;
|
||||
}
|
||||
|
||||
int32_t msgEpoch = ((SMqRspHead*)pMsg->pData)->epoch;
|
||||
|
@ -1387,7 +1411,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
tDecoderClear(&decoder);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
goto END;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
|
@ -1403,7 +1427,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
tDecoderClear(&decoder);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
goto END;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
memcpy(&pRspWrapper->metaRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
|
@ -1414,10 +1438,23 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
tDecoderClear(&decoder);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
goto END;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
memcpy(&pRspWrapper->taosxRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
} else if (rspType == TMQ_MSG_TYPE__POLL_BATCH_META_RSP) {
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pMsg->len - sizeof(SMqRspHead));
|
||||
if(tSemiDecodeMqBatchMetaRsp(&decoder, &pRspWrapper->batchMetaRsp) < 0){
|
||||
tDecoderClear(&decoder);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
memcpy(&pRspWrapper->batchMetaRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
tscDebug("consumer:0x%" PRIx64 " recv poll batchmeta rsp, vgId:%d, reqId:0x%" PRIx64, tmq->consumerId, vgId,
|
||||
requestId);
|
||||
} else { // invalid rspType
|
||||
tscError("consumer:0x%" PRIx64 " invalid rsp msg received, type:%d ignored", tmq->consumerId, rspType);
|
||||
}
|
||||
|
@ -1600,6 +1637,7 @@ void tmqBuildConsumeReqImpl(SMqPollReq* pReq, tmq_t* tmq, int64_t timeout, SMqCl
|
|||
pReq->reqId = generateRequestId();
|
||||
pReq->enableReplay = tmq->replayEnable;
|
||||
pReq->sourceExcluded = tmq->sourceExcluded;
|
||||
pReq->enableBatchMeta = tmq->enableBatchMeta;
|
||||
}
|
||||
|
||||
SMqMetaRspObj* tmqBuildMetaRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
||||
|
@ -1616,6 +1654,20 @@ SMqMetaRspObj* tmqBuildMetaRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
|||
return pRspObj;
|
||||
}
|
||||
|
||||
SMqBatchMetaRspObj* tmqBuildBatchMetaRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
||||
SMqBatchMetaRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqBatchMetaRspObj));
|
||||
if(pRspObj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pRspObj->common.resType = RES_TYPE__TMQ_BATCH_META;
|
||||
tstrncpy(pRspObj->common.topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN);
|
||||
tstrncpy(pRspObj->common.db, pWrapper->topicHandle->db, TSDB_DB_FNAME_LEN);
|
||||
pRspObj->common.vgId = pWrapper->vgHandle->vgId;
|
||||
|
||||
memcpy(&pRspObj->rsp, &pWrapper->batchMetaRsp, sizeof(SMqBatchMetaRsp));
|
||||
tscDebug("build batchmeta Rsp from wrapper");
|
||||
return pRspObj;
|
||||
}
|
||||
|
||||
void changeByteEndian(char* pData){
|
||||
char* p = pData;
|
||||
|
@ -1744,6 +1796,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p
|
|||
pParam = taosMemoryMalloc(sizeof(SMqPollCbParam));
|
||||
if (pParam == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFreeClear(msg);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -1755,6 +1808,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p
|
|||
sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFreeClear(msg);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -1781,7 +1835,6 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p
|
|||
|
||||
return 0;
|
||||
FAIL:
|
||||
taosMemoryFreeClear(msg);
|
||||
return tmqPollCb(pParam, NULL, code);
|
||||
}
|
||||
|
||||
|
@ -1887,8 +1940,6 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) {
|
|||
terrno = pRspWrapper->code;
|
||||
tscError("consumer:0x%" PRIx64 " unexpected rsp from poll, code:%s", tmq->consumerId,
|
||||
tstrerror(pRspWrapper->code));
|
||||
taosFreeQitem(pRspWrapper);
|
||||
return NULL;
|
||||
} else {
|
||||
if (pRspWrapper->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { // for vnode transform
|
||||
askEp(tmq, NULL, false, true);
|
||||
|
@ -2006,6 +2057,42 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) {
|
|||
tmqFreeRspWrapper(pRspWrapper);
|
||||
taosFreeQitem(pRspWrapper);
|
||||
}
|
||||
} else if (pRspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_BATCH_META_RSP) {
|
||||
SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)pRspWrapper;
|
||||
int32_t consumerEpoch = atomic_load_32(&tmq->epoch);
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " process meta rsp", tmq->consumerId);
|
||||
|
||||
if (pollRspWrapper->batchMetaRsp.head.epoch == consumerEpoch) {
|
||||
taosWLockLatch(&tmq->lock);
|
||||
SMqClientVg* pVg = getVgInfo(tmq, pollRspWrapper->topicName, pollRspWrapper->vgId);
|
||||
pollRspWrapper->vgHandle = pVg;
|
||||
pollRspWrapper->topicHandle = getTopicInfo(tmq, pollRspWrapper->topicName);
|
||||
if (pollRspWrapper->vgHandle == NULL || pollRspWrapper->topicHandle == NULL) {
|
||||
tscError("consumer:0x%" PRIx64 " get vg or topic error, topic:%s vgId:%d", tmq->consumerId,
|
||||
pollRspWrapper->topicName, pollRspWrapper->vgId);
|
||||
tmqFreeRspWrapper(pRspWrapper);
|
||||
taosFreeQitem(pRspWrapper);
|
||||
taosWUnLockLatch(&tmq->lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// build rsp
|
||||
void* pRsp = NULL;
|
||||
updateVgInfo(pVg, &pollRspWrapper->batchMetaRsp.rspOffset, &pollRspWrapper->batchMetaRsp.rspOffset,
|
||||
pollRspWrapper->batchMetaRsp.head.walsver, pollRspWrapper->batchMetaRsp.head.walever,
|
||||
tmq->consumerId, true);
|
||||
pRsp = tmqBuildBatchMetaRspFromWrapper(pollRspWrapper);
|
||||
taosFreeQitem(pRspWrapper);
|
||||
taosWUnLockLatch(&tmq->lock);
|
||||
return pRsp;
|
||||
} else {
|
||||
tscInfo("consumer:0x%" PRIx64 " vgId:%d msg discard since epoch mismatch: msg epoch %d, consumer epoch %d",
|
||||
tmq->consumerId, pollRspWrapper->vgId, pollRspWrapper->batchMetaRsp.head.epoch, consumerEpoch);
|
||||
setVgIdle(tmq, pollRspWrapper->topicName, pollRspWrapper->vgId);
|
||||
tmqFreeRspWrapper(pRspWrapper);
|
||||
taosFreeQitem(pRspWrapper);
|
||||
}
|
||||
} else if (pRspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
|
||||
SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)pRspWrapper;
|
||||
int32_t consumerEpoch = atomic_load_32(&tmq->epoch);
|
||||
|
@ -2217,6 +2304,8 @@ tmq_res_t tmq_get_res_type(TAOS_RES* res) {
|
|||
return TMQ_RES_TABLE_META;
|
||||
} else if (TD_RES_TMQ_METADATA(res)) {
|
||||
return TMQ_RES_METADATA;
|
||||
} else if (TD_RES_TMQ_BATCH_META(res)) {
|
||||
return TMQ_RES_TABLE_META;
|
||||
} else {
|
||||
return TMQ_RES_INVALID;
|
||||
}
|
||||
|
@ -2226,7 +2315,7 @@ const char* tmq_get_topic_name(TAOS_RES* res) {
|
|||
if (res == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return strchr(((SMqRspObjCommon*)res)->topic, '.') + 1;
|
||||
} else if (TD_RES_TMQ_META(res)) {
|
||||
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
|
||||
|
@ -2241,7 +2330,7 @@ const char* tmq_get_db_name(TAOS_RES* res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return strchr(((SMqRspObjCommon*)res)->db, '.') + 1;
|
||||
} else if (TD_RES_TMQ_META(res)) {
|
||||
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
|
||||
|
@ -2255,7 +2344,7 @@ int32_t tmq_get_vgroup_id(TAOS_RES* res) {
|
|||
if (res == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) {
|
||||
return ((SMqRspObjCommon*)res)->vgId;
|
||||
} else if (TD_RES_TMQ_META(res)) {
|
||||
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
|
||||
|
@ -2282,6 +2371,11 @@ int64_t tmq_get_vgroup_offset(TAOS_RES* res) {
|
|||
if (pRspObj->metaRsp.rspOffset.type == TMQ_OFFSET__LOG) {
|
||||
return pRspObj->metaRsp.rspOffset.version;
|
||||
}
|
||||
} else if (TD_RES_TMQ_BATCH_META(res)) {
|
||||
SMqBatchMetaRspObj* pBtRspObj = (SMqBatchMetaRspObj*)res;
|
||||
if (pBtRspObj->rsp.rspOffset.type == TMQ_OFFSET__LOG) {
|
||||
return pBtRspObj->rsp.rspOffset.version;
|
||||
}
|
||||
} else {
|
||||
tscError("invalid tmq type:%d", *(int8_t*)res);
|
||||
}
|
||||
|
@ -2559,6 +2653,7 @@ void askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) {
|
|||
if (tSerializeSMqAskEpReq(pReq, tlen, &req) < 0) {
|
||||
tscError("consumer:0x%" PRIx64 ", tSerializeSMqAskEpReq %d failed", pTmq->consumerId, tlen);
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
taosMemoryFree(pReq);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -2566,6 +2661,7 @@ void askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) {
|
|||
if (pParam == NULL) {
|
||||
tscError("consumer:0x%" PRIx64 ", failed to malloc subscribe param", pTmq->consumerId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pReq);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -2576,6 +2672,7 @@ void askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) {
|
|||
SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pReq);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -2597,8 +2694,6 @@ void askEp(tmq_t* pTmq, void* param, bool sync, bool updateEpSet) {
|
|||
}
|
||||
|
||||
FAIL:
|
||||
taosMemoryFreeClear(pParam);
|
||||
taosMemoryFreeClear(pReq);
|
||||
askEpCb(pParam, NULL, code);
|
||||
}
|
||||
|
||||
|
@ -2705,7 +2800,6 @@ static int32_t tmqGetWalInfoCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
taosMemoryFree(pParam);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2809,8 +2903,6 @@ int64_t getCommittedFromServer(tmq_t* tmq, char* tname, int32_t vgId, SEpSet* ep
|
|||
int64_t transporterId = 0;
|
||||
code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, epSet, &transporterId, sendInfo);
|
||||
if (code != 0) {
|
||||
taosMemoryFree(buf);
|
||||
taosMemoryFree(sendInfo);
|
||||
tsem_destroy(&pParam->sem);
|
||||
taosMemoryFree(pParam);
|
||||
return code;
|
||||
|
@ -3067,6 +3159,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
|
|||
sendInfo->requestId = req.reqId;
|
||||
sendInfo->requestObjRefId = 0;
|
||||
sendInfo->param = pParam;
|
||||
sendInfo->paramFreeFp = taosMemoryFree;
|
||||
sendInfo->fp = tmqGetWalInfoCb;
|
||||
sendInfo->msgType = TDMT_VND_TMQ_VG_WALINFO;
|
||||
|
||||
|
@ -3078,8 +3171,6 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
|
|||
tmq->consumerId, pTopic->topicName, pClientVg->vgId, tmq->epoch, offsetFormatBuf, req.reqId);
|
||||
code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pClientVg->epSet, &transporterId, sendInfo);
|
||||
if (code != 0) {
|
||||
taosMemoryFree(pParam);
|
||||
taosMemoryFree(msg);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
@ -3235,8 +3326,6 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_
|
|||
int64_t transporterId = 0;
|
||||
code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
if (code != 0) {
|
||||
taosMemoryFree(msg);
|
||||
taosMemoryFree(sendInfo);
|
||||
tsem_destroy(&pParam->sem);
|
||||
taosMemoryFree(pParam);
|
||||
return code;
|
||||
|
|
|
@ -76,6 +76,7 @@ static const SSysDbTableSchema arbGroupsSchema[] = {
|
|||
{.name = "is_sync", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "assigned_dnode", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "assigned_token", .bytes = TSDB_ARB_TOKEN_SIZE + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "assigned_acked", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema clusterSchema[] = {
|
||||
|
|
|
@ -131,6 +131,7 @@ const char* columnEncodeStr(uint8_t type) {
|
|||
encode = TSDB_COLUMN_ENCODE_DISABLED;
|
||||
break;
|
||||
default:
|
||||
encode = TSDB_COLUMN_ENCODE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
return encode;
|
||||
|
@ -157,8 +158,8 @@ const char* columnCompressStr(uint16_t type) {
|
|||
case TSDB_COLVAL_COMPRESS_DISABLED:
|
||||
compress = TSDB_COLUMN_COMPRESS_DISABLED;
|
||||
break;
|
||||
|
||||
default:
|
||||
compress = TSDB_COLUMN_COMPRESS_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
return compress;
|
||||
|
|
|
@ -383,7 +383,9 @@ static int32_t tRowBuildKVRow(SArray *aColVal, const SRowBuildScanInfo *sinfo, c
|
|||
if (IS_VAR_DATA_TYPE(schema->columns[i].type)) {
|
||||
payloadSize += tPutI16v(payload + payloadSize, colValArray[colValIndex].cid);
|
||||
payloadSize += tPutU32v(payload + payloadSize, colValArray[colValIndex].value.nData);
|
||||
if (colValArray[colValIndex].value.nData > 0) {
|
||||
memcpy(payload + payloadSize, colValArray[colValIndex].value.pData, colValArray[colValIndex].value.nData);
|
||||
}
|
||||
payloadSize += colValArray[colValIndex].value.nData;
|
||||
} else {
|
||||
payloadSize += tPutI16v(payload + payloadSize, colValArray[colValIndex].cid);
|
||||
|
@ -2907,7 +2909,7 @@ int32_t tColDataAddValueByDataBlock(SColData *pColData, int8_t type, int32_t byt
|
|||
}
|
||||
} else {
|
||||
if (varDataTLen(data + offset) > bytes) {
|
||||
uError("var data length invalid, varDataTLen(data + offset):%d <= bytes:%d", (int)varDataTLen(data + offset),
|
||||
uError("var data length invalid, varDataTLen(data + offset):%d >= bytes:%d", (int)varDataTLen(data + offset),
|
||||
bytes);
|
||||
code = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||
goto _exit;
|
||||
|
|
|
@ -768,12 +768,23 @@ int32_t tSerializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq)
|
|||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->alterType) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfFields) < 0) return -1;
|
||||
|
||||
// if (pReq->alterType == )
|
||||
for (int32_t i = 0; i < pReq->numOfFields; ++i) {
|
||||
if (pReq->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION) {
|
||||
SFieldWithOptions *pField = taosArrayGet(pReq->pFields, i);
|
||||
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pField->compress) < 0) return -1;
|
||||
|
||||
} else {
|
||||
SField *pField = taosArrayGet(pReq->pFields, i);
|
||||
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
}
|
||||
}
|
||||
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->commentLen) < 0) return -1;
|
||||
if (pReq->commentLen > 0) {
|
||||
|
@ -802,6 +813,20 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq
|
|||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfFields; ++i) {
|
||||
if (pReq->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION) {
|
||||
|
||||
taosArrayDestroy(pReq->pFields);
|
||||
pReq->pFields = taosArrayInit(pReq->numOfFields, sizeof(SFieldWithOptions));
|
||||
SFieldWithOptions field = {0};
|
||||
if (tDecodeI8(&decoder, &field.type) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &field.compress) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pFields, &field) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
SField field = {0};
|
||||
if (tDecodeI8(&decoder, &field.type) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
|
@ -811,6 +836,7 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1;
|
||||
|
@ -5616,18 +5642,36 @@ int32_t tSerializeSVKillCompactReq(void *buf, int32_t bufLen, SVKillCompactReq *
|
|||
}
|
||||
|
||||
int32_t tDeserializeSVKillCompactReq(void *buf, int32_t bufLen, SVKillCompactReq *pReq) {
|
||||
int32_t code = 0;
|
||||
SDecoder decoder = {0};
|
||||
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tStartDecode(&decoder) < 0) {
|
||||
code = TSDB_CODE_MSG_DECODE_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (tDecodeI32(&decoder, &pReq->compactId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->compactId) < 0) {
|
||||
code = TSDB_CODE_MSG_DECODE_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (tDecodeI32(&decoder, &pReq->vgId) < 0) {
|
||||
code = TSDB_CODE_MSG_DECODE_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) {
|
||||
code = TSDB_CODE_MSG_DECODE_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
_exit:
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tSerializeSAlterVnodeConfigReq(void *buf, int32_t bufLen, SAlterVnodeConfigReq *pReq) {
|
||||
|
@ -6460,6 +6504,11 @@ int32_t tSerializeSMArbUpdateGroupBatchReq(void *buf, int32_t bufLen, SMArbUpdat
|
|||
if (tEncodeI64(&encoder, pGroup->version) < 0) return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMArbUpdateGroup *pGroup = taosArrayGet(pReq->updateArray, i);
|
||||
if (tEncodeI8(&encoder, pGroup->assignedLeader.acked) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -6492,8 +6541,18 @@ int32_t tDeserializeSMArbUpdateGroupBatchReq(void *buf, int32_t bufLen, SMArbUpd
|
|||
group.assignedLeader.token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, group.assignedLeader.token) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &group.version) < 0) return -1;
|
||||
group.assignedLeader.acked = false;
|
||||
|
||||
taosArrayPush(updateArray, &group);
|
||||
}
|
||||
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMArbUpdateGroup *pGroup = taosArrayGet(updateArray, i);
|
||||
if (tDecodeI8(&decoder, &pGroup->assignedLeader.acked) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
pReq->updateArray = updateArray;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
@ -7223,6 +7282,7 @@ int32_t tSerializeSMqPollReq(void *buf, int32_t bufLen, SMqPollReq *pReq) {
|
|||
pHead->vgId = htonl(pReq->head.vgId);
|
||||
pHead->contLen = htonl(tlen + headLen);
|
||||
}
|
||||
if (tEncodeI8(&encoder, pReq->enableBatchMeta) < 0) return -1;
|
||||
|
||||
return tlen + headLen;
|
||||
}
|
||||
|
@ -7252,6 +7312,12 @@ int32_t tDeserializeSMqPollReq(void *buf, int32_t bufLen, SMqPollReq *pReq) {
|
|||
if (tDecodeI8(&decoder, &pReq->sourceExcluded) < 0) return -1;
|
||||
}
|
||||
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
if (tDecodeI8(&decoder, &pReq->enableBatchMeta) < 0) return -1;
|
||||
} else {
|
||||
pReq->enableBatchMeta = false;
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -8386,6 +8452,18 @@ int tDecodeSVCreateTbBatchReq(SDecoder *pCoder, SVCreateTbBatchReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq *pReq) {
|
||||
for (int32_t iReq = 0; iReq < pReq->nReqs; iReq++) {
|
||||
SVCreateTbReq *pCreateReq = pReq->pReqs + iReq;
|
||||
taosMemoryFreeClear(pCreateReq->sql);
|
||||
taosMemoryFreeClear(pCreateReq->comment);
|
||||
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
||||
taosArrayDestroy(pCreateReq->ctb.tagName);
|
||||
pCreateReq->ctb.tagName = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbRsp(SEncoder *pCoder, const SVCreateTbRsp *pRsp) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
|
@ -8740,6 +8818,13 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
|
|||
if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1;
|
||||
if (tEncodeU32(pEncoder, pReq->compress) < 0) return -1;
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
|
||||
if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pReq->type) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pReq->flags) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pReq->bytes) < 0) return -1;
|
||||
if (tEncodeU32(pEncoder, pReq->compress) < 0) return -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -8795,6 +8880,12 @@ static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq)
|
|||
if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1;
|
||||
if (tDecodeU32(pDecoder, &pReq->compress) < 0) return -1;
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
|
||||
if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pReq->type) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pReq->flags) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pReq->bytes) < 0) return -1;
|
||||
if (tDecodeU32(pDecoder, &pReq->compress) < 0) return -1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -10581,3 +10672,55 @@ void tFreeFetchTtlExpiredTbsRsp(void *p) {
|
|||
SVFetchTtlExpiredTbsRsp *pRsp = p;
|
||||
taosArrayDestroy(pRsp->pExpiredTbs);
|
||||
}
|
||||
|
||||
int32_t tEncodeMqBatchMetaRsp(SEncoder *pEncoder, const SMqBatchMetaRsp *pRsp) {
|
||||
if (tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset) < 0) return -1;
|
||||
|
||||
int32_t size = taosArrayGetSize(pRsp->batchMetaReq);
|
||||
if (tEncodeI32(pEncoder, size) < 0) return -1;
|
||||
if (size > 0) {
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
void *pMetaReq = taosArrayGetP(pRsp->batchMetaReq, i);
|
||||
int32_t metaLen = *(int32_t *)taosArrayGet(pRsp->batchMetaLen, i);
|
||||
if (tEncodeBinary(pEncoder, pMetaReq, metaLen) < 0) return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeMqBatchMetaRsp(SDecoder *pDecoder, SMqBatchMetaRsp *pRsp) {
|
||||
int32_t size = 0;
|
||||
if (tDecodeI32(pDecoder, &size) < 0) return -1;
|
||||
if (size > 0) {
|
||||
pRsp->batchMetaReq = taosArrayInit(size, POINTER_BYTES);
|
||||
pRsp->batchMetaLen = taosArrayInit(size, sizeof(int32_t));
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
void *pCreate = NULL;
|
||||
uint64_t len = 0;
|
||||
if (tDecodeBinaryAlloc(pDecoder, &pCreate, &len) < 0) return -1;
|
||||
int32_t l = (int32_t)len;
|
||||
taosArrayPush(pRsp->batchMetaReq, &pCreate);
|
||||
taosArrayPush(pRsp->batchMetaLen, &l);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder *pDecoder, SMqBatchMetaRsp *pRsp) {
|
||||
if (tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset) < 0) return -1;
|
||||
if (pDecoder->size < pDecoder->pos) {
|
||||
return -1;
|
||||
}
|
||||
pRsp->metaBuffLen = TD_CODER_REMAIN_CAPACITY(pDecoder);
|
||||
pRsp->pMetaBuff = taosMemoryCalloc(1, pRsp->metaBuffLen);
|
||||
memcpy(pRsp->pMetaBuff, TD_CODER_CURRENT(pDecoder), pRsp->metaBuffLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tDeleteMqBatchMetaRsp(SMqBatchMetaRsp *pRsp) {
|
||||
taosMemoryFreeClear(pRsp->pMetaBuff);
|
||||
taosArrayDestroyP(pRsp->batchMetaReq, taosMemoryFree);
|
||||
taosArrayDestroy(pRsp->batchMetaLen);
|
||||
pRsp->batchMetaReq = NULL;
|
||||
pRsp->batchMetaLen = NULL;
|
||||
}
|
||||
|
|
|
@ -398,13 +398,6 @@ int mainWindows(int argc, char **argv) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(dmGetEncryptKey() != 0){
|
||||
dError("failed to start since failed to get encrypt key");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
};
|
||||
|
||||
if (taosConvInit() != 0) {
|
||||
dError("failed to init conv");
|
||||
taosCloseLog();
|
||||
|
@ -442,6 +435,13 @@ int mainWindows(int argc, char **argv) {
|
|||
osSetProcPath(argc, (char **)argv);
|
||||
taosCleanupArgs();
|
||||
|
||||
if(dmGetEncryptKey() != 0){
|
||||
dError("failed to start since failed to get encrypt key");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
};
|
||||
|
||||
if (dmInit() != 0) {
|
||||
if (terrno == TSDB_CODE_NOT_FOUND) {
|
||||
dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support");
|
||||
|
|
|
@ -415,3 +415,7 @@ void dmReportStartup(const char *pName, const char *pDesc) {
|
|||
}
|
||||
|
||||
int64_t dmGetClusterId() { return globalDnode.data.clusterId; }
|
||||
|
||||
bool dmReadyForTest() {
|
||||
return dmInstance()->data.dnodeVer > 0;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class TestServer {
|
|||
public:
|
||||
bool Start();
|
||||
void Stop();
|
||||
bool runnning;
|
||||
bool running;
|
||||
|
||||
private:
|
||||
TdThread threadId;
|
||||
|
|
|
@ -17,13 +17,11 @@
|
|||
|
||||
void* serverLoop(void* param) {
|
||||
TestServer* server = (TestServer*)param;
|
||||
server->runnning = false;
|
||||
|
||||
if (dmInit() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
server->runnning = true;
|
||||
if (dmRun() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -33,13 +31,18 @@ void* serverLoop(void* param) {
|
|||
}
|
||||
|
||||
bool TestServer::Start() {
|
||||
tstrncpy(tsVersionName, "trial", strlen("trial"));
|
||||
running = false;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
taosThreadCreate(&threadId, &thAttr, serverLoop, this);
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
taosMsleep(2100);
|
||||
return runnning;
|
||||
while (!dmReadyForTest()) {
|
||||
taosMsleep(500);
|
||||
}
|
||||
running = true;
|
||||
return running;
|
||||
}
|
||||
|
||||
void TestServer::Stop() {
|
||||
|
|
|
@ -255,6 +255,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char token[TSDB_ARB_TOKEN_SIZE];
|
||||
int8_t acked;
|
||||
} SArbAssignedLeader;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "mndVgroup.h"
|
||||
|
||||
#define ARBGROUP_VER_NUMBER 1
|
||||
#define ARBGROUP_RESERVE_SIZE 64
|
||||
#define ARBGROUP_RESERVE_SIZE 63
|
||||
|
||||
static SHashObj *arbUpdateHash = NULL;
|
||||
|
||||
|
@ -129,6 +129,7 @@ SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pLeader->dnodeId, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pLeader->token, TSDB_ARB_TOKEN_SIZE, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pGroup->version, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pLeader->acked, _OVER)
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, ARBGROUP_RESERVE_SIZE, _OVER)
|
||||
|
||||
|
@ -182,6 +183,7 @@ SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, dataPos, &pLeader->dnodeId, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pLeader->token, TSDB_ARB_TOKEN_SIZE, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pGroup->version, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pLeader->acked, _OVER)
|
||||
|
||||
pGroup->mutexInited = false;
|
||||
|
||||
|
@ -235,6 +237,7 @@ static int32_t mndArbGroupActionUpdate(SSdb *pSdb, SArbGroup *pOld, SArbGroup *p
|
|||
pOld->isSync = pNew->isSync;
|
||||
pOld->assignedLeader.dnodeId = pNew->assignedLeader.dnodeId;
|
||||
memcpy(pOld->assignedLeader.token, pNew->assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
|
||||
pOld->assignedLeader.acked = pNew->assignedLeader.acked;
|
||||
pOld->version++;
|
||||
|
||||
_OVER:
|
||||
|
@ -540,6 +543,14 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int64_t roleTimeMs = mndGetRoleTimeMs(pMnode);
|
||||
int64_t nowMs = taosGetTimestampMs();
|
||||
if (nowMs - roleTimeMs < tsArbHeartBeatIntervalSec * 1000 * 2) {
|
||||
mInfo("arb skip to check sync since mnd had just switch over, roleTime:%" PRId64 " now:%" PRId64, roleTimeMs,
|
||||
nowMs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SArray *pUpdateArray = taosArrayInit(16, sizeof(SArbGroup));
|
||||
|
||||
while (1) {
|
||||
|
@ -551,15 +562,14 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
|||
taosThreadMutexUnlock(&pArbGroup->mutex);
|
||||
|
||||
int32_t vgId = arbGroupDup.vgId;
|
||||
int64_t nowMs = taosGetTimestampMs();
|
||||
|
||||
bool member0IsTimeout = mndCheckArbMemberHbTimeout(&arbGroupDup, 0, nowMs);
|
||||
bool member1IsTimeout = mndCheckArbMemberHbTimeout(&arbGroupDup, 1, nowMs);
|
||||
SArbAssignedLeader *pAssignedLeader = &arbGroupDup.assignedLeader;
|
||||
int32_t currentAssignedDnodeId = pAssignedLeader->dnodeId;
|
||||
|
||||
// 1. has assigned && is sync => send req
|
||||
if (currentAssignedDnodeId != 0 && arbGroupDup.isSync == true) {
|
||||
// 1. has assigned && is sync && no response => send req
|
||||
if (currentAssignedDnodeId != 0 && arbGroupDup.isSync == true && pAssignedLeader->acked == false) {
|
||||
(void)mndSendArbSetAssignedLeaderReq(pMnode, currentAssignedDnodeId, vgId, arbToken, term,
|
||||
pAssignedLeader->token);
|
||||
mInfo("vgId:%d, arb send set assigned leader to dnodeId:%d", vgId, currentAssignedDnodeId);
|
||||
|
@ -651,6 +661,7 @@ static void mndInitArbUpdateGroup(SArbGroup *pGroup, SMArbUpdateGroup *outGroup)
|
|||
outGroup->isSync = pGroup->isSync;
|
||||
outGroup->assignedLeader.dnodeId = pGroup->assignedLeader.dnodeId;
|
||||
outGroup->assignedLeader.token = pGroup->assignedLeader.token; // just copy the pointer
|
||||
outGroup->assignedLeader.acked = pGroup->assignedLeader.acked;
|
||||
outGroup->version = pGroup->version;
|
||||
}
|
||||
|
||||
|
@ -766,6 +777,7 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
newGroup.isSync = pUpdateGroup->isSync;
|
||||
newGroup.assignedLeader.dnodeId = pUpdateGroup->assignedLeader.dnodeId;
|
||||
memcpy(newGroup.assignedLeader.token, pUpdateGroup->assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
|
||||
newGroup.assignedLeader.acked = pUpdateGroup->assignedLeader.acked;
|
||||
newGroup.version = pUpdateGroup->version;
|
||||
|
||||
SArbGroup *pOldGroup = sdbAcquire(pMnode->pSdb, SDB_ARBGROUP, &newGroup.vgId);
|
||||
|
@ -783,10 +795,10 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, used to update arbgroup:%d, member0:[%d][%s] member1:[%d][%s] isSync:%d assigned:[%d][%s]",
|
||||
mInfo("trans:%d, used to update arbgroup:%d, member0:[%d][%s] member1:[%d][%s] isSync:%d assigned:[%d][%s][%d]",
|
||||
pTrans->id, newGroup.vgId, newGroup.members[0].info.dnodeId, newGroup.members[0].state.token,
|
||||
newGroup.members[1].info.dnodeId, newGroup.members[1].state.token, newGroup.isSync,
|
||||
newGroup.assignedLeader.dnodeId, newGroup.assignedLeader.token);
|
||||
newGroup.assignedLeader.dnodeId, newGroup.assignedLeader.token, newGroup.assignedLeader.acked);
|
||||
|
||||
sdbRelease(pMnode->pSdb, pOldGroup);
|
||||
}
|
||||
|
@ -819,11 +831,13 @@ static void mndArbGroupSetAssignedLeader(SArbGroup *pGroup, int32_t index) {
|
|||
|
||||
pGroup->assignedLeader.dnodeId = pMember->info.dnodeId;
|
||||
strncpy(pGroup->assignedLeader.token, pMember->state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
pGroup->assignedLeader.acked = false;
|
||||
}
|
||||
|
||||
static void mndArbGroupResetAssignedLeader(SArbGroup *pGroup) {
|
||||
pGroup->assignedLeader.dnodeId = 0;
|
||||
memset(pGroup->assignedLeader.token, 0, TSDB_ARB_TOKEN_SIZE);
|
||||
pGroup->assignedLeader.acked = false;
|
||||
}
|
||||
|
||||
static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
||||
|
@ -834,10 +848,10 @@ static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, used to update arbgroup:%d, member0:[%d][%s] member1:[%d][%s] isSync:%d assigned:[%d][%s]",
|
||||
mInfo("trans:%d, used to update arbgroup:%d, member0:[%d][%s] member1:[%d][%s] isSync:%d assigned:[%d][%s][%d]",
|
||||
pTrans->id, pNew->vgId, pNew->members[0].info.dnodeId, pNew->members[0].state.token,
|
||||
pNew->members[1].info.dnodeId, pNew->members[1].state.token, pNew->isSync, pNew->assignedLeader.dnodeId,
|
||||
pNew->assignedLeader.token);
|
||||
pNew->assignedLeader.token, pNew->assignedLeader.acked);
|
||||
|
||||
mndTransAddArbGroupId(pTrans, pNew->vgId);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
|
@ -1103,11 +1117,12 @@ bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pGroup->isSync) {
|
||||
if (pGroup->assignedLeader.acked == false) {
|
||||
mndArbGroupDupObj(pGroup, pNewGroup);
|
||||
pNewGroup->isSync = false;
|
||||
pNewGroup->assignedLeader.acked = true;
|
||||
|
||||
mInfo("vgId:%d, arb isSync is setting to false", vgId);
|
||||
mInfo("vgId:%d, arb received assigned ack", vgId);
|
||||
updateAssigned = true;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -1217,12 +1232,18 @@ static int32_t mndRetrieveArbGroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
STR_WITH_MAXSIZE_TO_VARSTR(token, pGroup->assignedLeader.token, TSDB_ARB_TOKEN_SIZE + VARSTR_HEADER_SIZE);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)token, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->assignedLeader.acked, false);
|
||||
} else {
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetNULL(pColInfo, numOfRows);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetNULL(pColInfo, numOfRows);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetNULL(pColInfo, numOfRows);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pGroup->mutex);
|
||||
|
|
|
@ -662,6 +662,14 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
if(taosArrayGetSize(subscribe.topicNames) == 0){
|
||||
SMqConsumerObj *pConsumerTmp = mndAcquireConsumer(pMnode, subscribe.consumerId);
|
||||
if(pConsumerTmp == NULL){
|
||||
goto _over;
|
||||
}
|
||||
mndReleaseConsumer(pMnode, pConsumerTmp);
|
||||
}
|
||||
|
||||
code = checkAndSortTopic(pMnode, subscribe.topicNames);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
goto _over;
|
||||
|
|
|
@ -334,6 +334,8 @@ static int32_t minCronTime() {
|
|||
min = TMIN(min, tsStreamCheckpointInterval);
|
||||
min = TMIN(min, 6); // checkpointRemain
|
||||
min = TMIN(min, tsStreamNodeCheckInterval);
|
||||
min = TMIN(min, tsArbHeartBeatIntervalSec);
|
||||
min = TMIN(min, tsArbCheckSyncIntervalSec);
|
||||
|
||||
int64_t telemInt = TMIN(60, (tsTelemInterval - 1));
|
||||
min = TMIN(min, telemInt);
|
||||
|
@ -390,6 +392,18 @@ void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
|
|||
if (sec % tsUptimeInterval == 0) {
|
||||
mndIncreaseUpTime(pMnode);
|
||||
}
|
||||
|
||||
if (sec % (tsArbHeartBeatIntervalSec) == 0) {
|
||||
if (mndPullupArbHeartbeat(pMnode) != 0) {
|
||||
mError("failed to pullup arb heartbeat, since:%s", terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
if (sec % (tsArbCheckSyncIntervalSec) == 0) {
|
||||
if (mndPullupArbCheckSync(pMnode) != 0) {
|
||||
mError("failed to pullup arb check sync, since:%s", terrstr());
|
||||
}
|
||||
}
|
||||
}
|
||||
void mndDoTimerCheckTask(SMnode *pMnode, int64_t sec) {
|
||||
if (sec % (tsStatusInterval * 5) == 0) {
|
||||
|
@ -421,18 +435,6 @@ static void *mndThreadFp(void *param) {
|
|||
continue;
|
||||
}
|
||||
mndDoTimerPullupTask(pMnode, sec);
|
||||
|
||||
if (sec % (tsArbHeartBeatIntervalSec) == 0) {
|
||||
if (mndPullupArbHeartbeat(pMnode) != 0) {
|
||||
mError("failed to pullup arb heartbeat, since:%s", terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
if (sec % (tsArbCheckSyncIntervalSec) == 0) {
|
||||
if (mndPullupArbCheckSync(pMnode) != 0) {
|
||||
mError("failed to pullup arb check sync, since:%s", terrstr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -1076,6 +1078,11 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int64_t mndGetRoleTimeMs(SMnode *pMnode) {
|
||||
SSyncState state = syncGetState(pMnode->syncMgmt.sync);
|
||||
return state.roleTimeMs;
|
||||
}
|
||||
|
||||
void mndSetRestored(SMnode *pMnode, bool restored) {
|
||||
if (restored) {
|
||||
taosThreadRwlockWrlock(&pMnode->lock);
|
||||
|
|
|
@ -1779,7 +1779,8 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj *
|
|||
|
||||
return 0;
|
||||
}
|
||||
static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray *pFields, int32_t ncols) {
|
||||
static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray *pFields, int32_t ncols,
|
||||
int8_t withCompress) {
|
||||
if (pOld->numOfColumns + ncols + pOld->numOfTags > TSDB_MAX_COLUMNS) {
|
||||
terrno = TSDB_CODE_MND_TOO_MANY_COLUMNS;
|
||||
return -1;
|
||||
|
@ -1806,6 +1807,30 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray
|
|||
}
|
||||
|
||||
for (int32_t i = 0; i < ncols; i++) {
|
||||
if (withCompress) {
|
||||
SFieldWithOptions *pField = taosArrayGet(pFields, i);
|
||||
if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) {
|
||||
terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mndFindSuperTableTagIndex(pOld, pField->name) >= 0) {
|
||||
terrno = TSDB_CODE_MND_TAG_ALREADY_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSchema *pSchema = &pNew->pColumns[pOld->numOfColumns + i];
|
||||
pSchema->bytes = pField->bytes;
|
||||
pSchema->type = pField->type;
|
||||
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->colId = pNew->nextColId;
|
||||
pNew->nextColId++;
|
||||
|
||||
SColCmpr *pCmpr = &pNew->pCmpr[pOld->numOfColumns + i];
|
||||
pCmpr->id = pSchema->colId;
|
||||
pCmpr->alg = pField->compress;
|
||||
mInfo("stb:%s, start to add column %s", pNew->name, pSchema->name);
|
||||
} else {
|
||||
SField *pField = taosArrayGet(pFields, i);
|
||||
if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) {
|
||||
terrno = TSDB_CODE_MND_COLUMN_ALREADY_EXIST;
|
||||
|
@ -1827,9 +1852,9 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray
|
|||
SColCmpr *pCmpr = &pNew->pCmpr[pOld->numOfColumns + i];
|
||||
pCmpr->id = pSchema->colId;
|
||||
pCmpr->alg = createDefaultColCmprByType(pSchema->type);
|
||||
|
||||
mInfo("stb:%s, start to add column %s", pNew->name, pSchema->name);
|
||||
}
|
||||
}
|
||||
|
||||
pNew->colVer++;
|
||||
return 0;
|
||||
|
@ -2461,7 +2486,7 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p
|
|||
code = mndAlterStbTagBytes(pMnode, pOld, &stbObj, pField0);
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
code = mndAddSuperTableColumn(pOld, &stbObj, pAlter->pFields, pAlter->numOfFields);
|
||||
code = mndAddSuperTableColumn(pOld, &stbObj, pAlter->pFields, pAlter->numOfFields, 0);
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
||||
pField0 = taosArrayGet(pAlter->pFields, 0);
|
||||
|
@ -2478,6 +2503,9 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p
|
|||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS:
|
||||
code = mndUpdateSuperTableColumnCompress(pMnode, pOld, &stbObj, pAlter->pFields, pAlter->numOfFields);
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
|
||||
code = mndAddSuperTableColumn(pOld, &stbObj, pAlter->pFields, pAlter->numOfFields, 1);
|
||||
break;
|
||||
default:
|
||||
needRsp = false;
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
|
|
|
@ -1130,6 +1130,15 @@ static int32_t mndCheckNodeStatus(SMnode *pMnode) {
|
|||
ready = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pEntry->hTaskId != 0) {
|
||||
mDebug("s-task:0x%" PRIx64 "-0x%x (nodeId:%d) status:%s related fill-history task:0x%" PRIx64
|
||||
" exists, checkpoint not issued",
|
||||
pEntry->id.streamId, (int32_t)pEntry->id.taskId, pEntry->nodeId, streamTaskGetStatusStr(pEntry->status),
|
||||
pEntry->hTaskId);
|
||||
ready = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&execInfo.lock);
|
||||
|
@ -1639,11 +1648,11 @@ static int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SS
|
|||
// info
|
||||
if (pTask->info.taskLevel == TASK_LEVEL__SINK) {
|
||||
const char *sinkStr = "%.2fMiB";
|
||||
sprintf(buf, sinkStr, pe->sinkDataSize);
|
||||
snprintf(buf, tListLen(buf), sinkStr, pe->sinkDataSize);
|
||||
} else if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
|
||||
// offset info
|
||||
const char *offsetStr = "%" PRId64 " [%" PRId64 ", %" PRId64 "]";
|
||||
sprintf(buf, offsetStr, pe->processedVer, pe->verRange.minVer, pe->verRange.maxVer);
|
||||
snprintf(buf, tListLen(buf), offsetStr, pe->processedVer, pe->verRange.minVer, pe->verRange.maxVer);
|
||||
}
|
||||
|
||||
STR_TO_VARSTR(vbuf, buf);
|
||||
|
|
|
@ -1409,7 +1409,7 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
|
|||
mInfo("trans:%d, execute %d actions serial, current redoAction:%d", pTrans->id, numOfActions, pTrans->actionPos);
|
||||
|
||||
for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
|
||||
STransAction *pAction = taosArrayGet(pActions, pTrans->actionPos);
|
||||
STransAction *pAction = taosArrayGet(pActions, action);
|
||||
|
||||
code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf);
|
||||
if (code == 0) {
|
||||
|
|
|
@ -49,6 +49,7 @@ TEST_F(MndTestFunc, 01_Show_Func) {
|
|||
}
|
||||
|
||||
TEST_F(MndTestFunc, 02_Create_Func) {
|
||||
#ifndef WINDOWS
|
||||
{
|
||||
SCreateFuncReq createReq = {0};
|
||||
strcpy(createReq.name, "");
|
||||
|
@ -159,9 +160,11 @@ TEST_F(MndTestFunc, 02_Create_Func) {
|
|||
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "ins_functions", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(MndTestFunc, 03_Retrieve_Func) {
|
||||
#ifndef WINDOWS
|
||||
{
|
||||
SRetrieveFuncReq retrieveReq = {0};
|
||||
retrieveReq.numOfFuncs = 1;
|
||||
|
@ -376,9 +379,11 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
|
|||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_FUNC_NOT_EXIST);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(MndTestFunc, 04_Drop_Func) {
|
||||
#ifndef WINDOWS
|
||||
{
|
||||
SDropFuncReq dropReq = {0};
|
||||
strcpy(dropReq.name, "");
|
||||
|
@ -441,9 +446,11 @@ TEST_F(MndTestFunc, 04_Drop_Func) {
|
|||
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "ins_functions", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(MndTestFunc, 05_Actual_code) {
|
||||
#ifndef WINDOWS
|
||||
{
|
||||
SCreateFuncReq createReq = {0};
|
||||
strcpy(createReq.name, "udf1");
|
||||
|
@ -507,4 +514,5 @@ TEST_F(MndTestFunc, 05_Actual_code) {
|
|||
}
|
||||
tFreeSRetrieveFuncRsp(&retrieveRsp);
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -113,7 +113,7 @@ int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle);
|
|||
void tqDestroyTqHandle(void* data);
|
||||
|
||||
// tqRead
|
||||
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* offset);
|
||||
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatchMetaRsp* pBatchMetaRsp, STqOffsetVal* offset);
|
||||
int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset, const SMqPollReq* pRequest);
|
||||
int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, uint64_t reqId);
|
||||
|
||||
|
|
|
@ -355,6 +355,8 @@ typedef struct {
|
|||
int flush_count;
|
||||
} SCacheFlushState;
|
||||
|
||||
typedef struct SCompMonitor SCompMonitor;
|
||||
|
||||
struct STsdb {
|
||||
char * path;
|
||||
SVnode * pVnode;
|
||||
|
@ -375,8 +377,11 @@ struct STsdb {
|
|||
TdThreadMutex pgMutex;
|
||||
struct STFileSystem *pFS; // new
|
||||
SRocksCache rCache;
|
||||
// compact monitor
|
||||
struct SCompMonitor *pCompMonitor;
|
||||
SCompMonitor *pCompMonitor;
|
||||
struct {
|
||||
SVHashTable *ht;
|
||||
SArray *arr;
|
||||
} *commitInfo;
|
||||
};
|
||||
|
||||
struct TSDBKEY {
|
||||
|
|
|
@ -49,31 +49,21 @@ int32_t vnodeEncodeConfig(const void* pObj, SJson* pJson);
|
|||
int32_t vnodeDecodeConfig(const SJson* pJson, void* pObj);
|
||||
|
||||
// vnodeAsync.c
|
||||
typedef struct SVAsync SVAsync;
|
||||
|
||||
typedef enum {
|
||||
EVA_PRIORITY_HIGH = 0,
|
||||
EVA_PRIORITY_NORMAL,
|
||||
EVA_PRIORITY_LOW,
|
||||
} EVAPriority;
|
||||
|
||||
#define VNODE_ASYNC_VALID_CHANNEL_ID(channelId) ((channelId) > 0)
|
||||
#define VNODE_ASYNC_VALID_TASK_ID(taskId) ((taskId) > 0)
|
||||
|
||||
int32_t vnodeAsyncInit(SVAsync** async, char* label);
|
||||
int32_t vnodeAsyncDestroy(SVAsync** async);
|
||||
int32_t vnodeAChannelInit(SVAsync* async, int64_t* channelId);
|
||||
int32_t vnodeAChannelDestroy(SVAsync* async, int64_t channelId, bool waitRunning);
|
||||
int32_t vnodeAsync(SVAsync* async, EVAPriority priority, int32_t (*execute)(void*), void (*complete)(void*), void* arg,
|
||||
int64_t* taskId);
|
||||
int32_t vnodeAsyncC(SVAsync* async, int64_t channelId, EVAPriority priority, int32_t (*execute)(void*),
|
||||
void (*complete)(void*), void* arg, int64_t* taskId);
|
||||
int32_t vnodeAWait(SVAsync* async, int64_t taskId);
|
||||
int32_t vnodeACancel(SVAsync* async, int64_t taskId);
|
||||
int32_t vnodeAsyncSetWorkers(SVAsync* async, int32_t numWorkers);
|
||||
|
||||
// vnodeModule.c
|
||||
extern SVAsync* vnodeAsyncHandle[2];
|
||||
int32_t vnodeAsyncOpen(int32_t numOfThreads);
|
||||
int32_t vnodeAsyncClose();
|
||||
int32_t vnodeAChannelInit(int64_t async, SVAChannelID* channelID);
|
||||
int32_t vnodeAChannelDestroy(SVAChannelID* channelID, bool waitRunning);
|
||||
int32_t vnodeAsync(SVAChannelID* channelID, EVAPriority priority, int32_t (*execute)(void*), void (*complete)(void*),
|
||||
void* arg, SVATaskID* taskID);
|
||||
int32_t vnodeAWait(SVATaskID* taskID);
|
||||
int32_t vnodeACancel(SVATaskID* taskID);
|
||||
int32_t vnodeAsyncSetWorkers(int64_t async, int32_t numWorkers);
|
||||
|
||||
// vnodeBufPool.c
|
||||
typedef struct SVBufPoolNode SVBufPoolNode;
|
||||
|
|
|
@ -237,9 +237,6 @@ int32_t tsdbCacheNewSTableColumn(STsdb* pTsdb, SArray* uids, int16_t cid, int8_t
|
|||
int32_t tsdbCacheDropSTableColumn(STsdb* pTsdb, SArray* uids, int16_t cid, bool hasPrimayKey);
|
||||
int32_t tsdbCacheNewNTableColumn(STsdb* pTsdb, int64_t uid, int16_t cid, int8_t col_type);
|
||||
int32_t tsdbCacheDropNTableColumn(STsdb* pTsdb, int64_t uid, int16_t cid, bool hasPrimayKey);
|
||||
int32_t tsdbCompact(STsdb* pTsdb, SCompactInfo* pInfo);
|
||||
int32_t tsdbRetention(STsdb* tsdb, int64_t now, int32_t sync);
|
||||
int32_t tsdbS3Migrate(STsdb* tsdb, int64_t now, int32_t sync);
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq2* pMsg);
|
||||
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq2* pMsg, SSubmitRsp2* pRsp);
|
||||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitTbData* pSubmitTbData, int32_t* affectedRows);
|
||||
|
@ -470,6 +467,16 @@ typedef struct SVMonitorObj {
|
|||
taos_counter_t* insertCounter;
|
||||
} SVMonitorObj;
|
||||
|
||||
typedef struct {
|
||||
int64_t async;
|
||||
int64_t id;
|
||||
} SVAChannelID;
|
||||
|
||||
typedef struct {
|
||||
int64_t async;
|
||||
int64_t id;
|
||||
} SVATaskID;
|
||||
|
||||
struct SVnode {
|
||||
char* path;
|
||||
SVnodeCfg config;
|
||||
|
@ -491,8 +498,8 @@ struct SVnode {
|
|||
SVBufPool* onRecycle;
|
||||
|
||||
// commit variables
|
||||
int64_t commitChannel;
|
||||
int64_t commitTask;
|
||||
SVAChannelID commitChannel;
|
||||
SVATaskID commitTask;
|
||||
|
||||
SMeta* pMeta;
|
||||
SSma* pSma;
|
||||
|
@ -598,6 +605,24 @@ struct SCompactInfo {
|
|||
|
||||
void initStorageAPI(SStorageAPI* pAPI);
|
||||
|
||||
// a simple hash table impl
|
||||
typedef struct SVHashTable SVHashTable;
|
||||
|
||||
struct SVHashTable {
|
||||
uint32_t (*hash)(const void*);
|
||||
int32_t (*compare)(const void*, const void*);
|
||||
int32_t numEntries;
|
||||
uint32_t numBuckets;
|
||||
struct SVHashEntry** buckets;
|
||||
};
|
||||
|
||||
#define vHashNumEntries(ht) ((ht)->numEntries)
|
||||
int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*));
|
||||
int32_t vHashDestroy(SVHashTable** ht);
|
||||
int32_t vHashPut(SVHashTable* ht, void* obj);
|
||||
int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj);
|
||||
int32_t vHashDrop(SVHashTable* ht, const void* obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,7 @@ static int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
|||
static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
||||
int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add) {
|
||||
int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress) {
|
||||
int32_t nCols = pWp->nCols;
|
||||
int32_t ver = pWp->version;
|
||||
if (add) {
|
||||
|
@ -45,7 +45,7 @@ int8_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add) {
|
|||
|
||||
SColCmpr *pCol = p + nCols;
|
||||
pCol->id = pSchema->colId;
|
||||
pCol->alg = createDefaultColCmprByType(pSchema->type);
|
||||
pCol->alg = compress;
|
||||
pWp->nCols = nCols + 1;
|
||||
pWp->version = ver;
|
||||
pWp->pColCmpr = p;
|
||||
|
@ -1491,6 +1491,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
SSchema tScheam;
|
||||
switch (pAlterTbReq->action) {
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
|
||||
if (pColumn) {
|
||||
terrno = TSDB_CODE_VND_COL_ALREADY_EXISTS;
|
||||
goto _err;
|
||||
|
@ -1522,7 +1523,9 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
(void)tsdbCacheNewNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, col_type);
|
||||
}
|
||||
SSchema *pCol = &pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1];
|
||||
updataTableColCmpr(&entry.colCmpr, pCol, 1);
|
||||
uint32_t compress = pAlterTbReq->action == TSDB_ALTER_TABLE_ADD_COLUMN ? createDefaultColCmprByType(pCol->type)
|
||||
: pAlterTbReq->compress;
|
||||
updataTableColCmpr(&entry.colCmpr, pCol, 1, compress);
|
||||
freeColCmpr = true;
|
||||
ASSERT(entry.colCmpr.nCols == pSchema->nCols);
|
||||
break;
|
||||
|
@ -1560,7 +1563,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
(void)tsdbCacheDropNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, hasPrimayKey);
|
||||
}
|
||||
|
||||
updataTableColCmpr(&entry.colCmpr, &tScheam, 0);
|
||||
updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0);
|
||||
ASSERT(entry.colCmpr.nCols == pSchema->nCols);
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
|
||||
|
@ -2269,6 +2272,7 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta
|
|||
pMeta->changed = true;
|
||||
switch (pReq->action) {
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
|
||||
|
|
|
@ -622,8 +622,8 @@ int32_t smaRetention(SSma *pSma, int64_t now) {
|
|||
|
||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pSma->pRSmaTsdb[i]) {
|
||||
code = tsdbRetention(pSma->pRSmaTsdb[i], now, pSma->pVnode->config.sttTrigger == 1);
|
||||
if (code) goto _end;
|
||||
// code = tsdbRetention(pSma->pRSmaTsdb[i], now, pSma->pVnode->config.sttTrigger == 1);
|
||||
// if (code) goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,14 +99,7 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
|
|||
taosArrayDestroy(reqNew.pArray);
|
||||
}
|
||||
|
||||
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
||||
pCreateReq = req.pReqs + iReq;
|
||||
taosMemoryFreeClear(pCreateReq->comment);
|
||||
taosMemoryFreeClear(pCreateReq->sql);
|
||||
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
||||
taosArrayDestroy(pCreateReq->ctb.tagName);
|
||||
}
|
||||
}
|
||||
tDeleteSVCreateTbBatchReq(&req);
|
||||
} else if (msgType == TDMT_VND_ALTER_TABLE) {
|
||||
SVAlterTbReq req = {0};
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal*
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* pOffset) {
|
||||
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatchMetaRsp* pBatchMetaRsp, STqOffsetVal* pOffset) {
|
||||
const STqExecHandle* pExec = &pHandle->execHandle;
|
||||
qTaskInfo_t task = pExec->task;
|
||||
|
||||
|
@ -218,10 +218,10 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
|||
}
|
||||
|
||||
// get meta
|
||||
SMqMetaRsp* tmp = qStreamExtractMetaMsg(task);
|
||||
if (tmp->metaRspLen > 0) {
|
||||
SMqBatchMetaRsp* tmp = qStreamExtractMetaMsg(task);
|
||||
if (taosArrayGetSize(tmp->batchMetaReq) > 0) {
|
||||
qStreamExtractOffset(task, &tmp->rspOffset);
|
||||
*pMetaRsp = *tmp;
|
||||
*pBatchMetaRsp = *tmp;
|
||||
|
||||
tqDebug("tmqsnap task get meta");
|
||||
break;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
static int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
|
||||
const SMqMetaRsp* pRsp, int32_t vgId);
|
||||
static int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
|
||||
const SMqBatchMetaRsp* pRsp, int32_t vgId);
|
||||
|
||||
int32_t tqInitDataRsp(SMqDataRspCommon* pRsp, STqOffsetVal pOffset) {
|
||||
tOffsetCopy(&pRsp->reqOffset, &pOffset);
|
||||
|
@ -172,7 +174,7 @@ end : {
|
|||
}
|
||||
}
|
||||
|
||||
#define PROCESS_EXCLUDED_MSG(TYPE, DECODE_FUNC) \
|
||||
#define PROCESS_EXCLUDED_MSG(TYPE, DECODE_FUNC, DELETE_FUNC) \
|
||||
SDecoder decoder = {0};\
|
||||
TYPE req = {0}; \
|
||||
void* data = POINTER_SHIFT(pHead->body, sizeof(SMsgHead)); \
|
||||
|
@ -182,33 +184,37 @@ end : {
|
|||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, jump meta for, vgId:%d offset %" PRId64 " msgType %d", \
|
||||
pRequest->consumerId, pRequest->epoch, vgId, fetchVer, pHead->msgType); \
|
||||
fetchVer++; \
|
||||
DELETE_FUNC(&req); \
|
||||
tDecoderClear(&decoder); \
|
||||
continue; \
|
||||
} \
|
||||
DELETE_FUNC(&req); \
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
static void tDeleteCommon(void* parm) {
|
||||
}
|
||||
|
||||
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, STqOffsetVal* offset) {
|
||||
int code = 0;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
SMqMetaRsp metaRsp = {0};
|
||||
STaosxRsp taosxRsp = {0};
|
||||
SMqBatchMetaRsp btMetaRsp = {0};
|
||||
tqInitTaosxRsp(&taosxRsp.common, *offset);
|
||||
|
||||
if (offset->type != TMQ_OFFSET__LOG) {
|
||||
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, offset) < 0) {
|
||||
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &btMetaRsp, offset) < 0) {
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (metaRsp.metaRspLen > 0) {
|
||||
code = tqSendMetaPollRsp(pHandle, pMsg, pRequest, &metaRsp, vgId);
|
||||
if (taosArrayGetSize(btMetaRsp.batchMetaReq) > 0) {
|
||||
code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64
|
||||
",ts:%" PRId64,
|
||||
pRequest->consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid,
|
||||
metaRsp.rspOffset.ts);
|
||||
tDeleteMqMetaRsp(&metaRsp);
|
||||
pRequest->consumerId, pHandle->subKey, vgId, btMetaRsp.rspOffset.type, btMetaRsp.rspOffset.uid,
|
||||
btMetaRsp.rspOffset.ts);
|
||||
tDeleteMqBatchMetaRsp(&btMetaRsp);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -230,11 +236,18 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
|
||||
uint64_t st = taosGetTimestampMs();
|
||||
int totalRows = 0;
|
||||
int32_t totalMetaRows = 0;
|
||||
while (1) {
|
||||
int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
|
||||
ASSERT(savedEpoch <= pRequest->epoch);
|
||||
|
||||
if (tqFetchLog(pTq, pHandle, &fetchVer, pRequest->reqId) < 0) {
|
||||
if (totalMetaRows > 0) {
|
||||
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
|
||||
tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
|
||||
ASSERT(totalRows == 0);
|
||||
goto end;
|
||||
}
|
||||
tqOffsetResetToLog(&taosxRsp.common.rspOffset, fetchVer);
|
||||
code = tqSendDataRsp(
|
||||
pHandle, pMsg, pRequest, &taosxRsp,
|
||||
|
@ -258,17 +271,20 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
|
||||
if ((pRequest->sourceExcluded & TD_REQ_FROM_TAOX) != 0) {
|
||||
if (pHead->msgType == TDMT_VND_CREATE_TABLE) {
|
||||
PROCESS_EXCLUDED_MSG(SVCreateTbBatchReq, tDecodeSVCreateTbBatchReq)
|
||||
PROCESS_EXCLUDED_MSG(SVCreateTbBatchReq, tDecodeSVCreateTbBatchReq, tDeleteSVCreateTbBatchReq)
|
||||
} else if (pHead->msgType == TDMT_VND_ALTER_TABLE) {
|
||||
PROCESS_EXCLUDED_MSG(SVAlterTbReq, tDecodeSVAlterTbReq)
|
||||
PROCESS_EXCLUDED_MSG(SVAlterTbReq, tDecodeSVAlterTbReq, tDeleteCommon)
|
||||
} else if (pHead->msgType == TDMT_VND_CREATE_STB || pHead->msgType == TDMT_VND_ALTER_STB) {
|
||||
PROCESS_EXCLUDED_MSG(SVCreateStbReq, tDecodeSVCreateStbReq)
|
||||
PROCESS_EXCLUDED_MSG(SVCreateStbReq, tDecodeSVCreateStbReq, tDeleteCommon)
|
||||
} else if (pHead->msgType == TDMT_VND_DELETE) {
|
||||
PROCESS_EXCLUDED_MSG(SDeleteRes, tDecodeDeleteRes)
|
||||
PROCESS_EXCLUDED_MSG(SDeleteRes, tDecodeDeleteRes, tDeleteCommon)
|
||||
}
|
||||
}
|
||||
|
||||
tqDebug("fetch meta msg, ver:%" PRId64 ", type:%s", pHead->version, TMSG_INFO(pHead->msgType));
|
||||
tqDebug("fetch meta msg, ver:%" PRId64 ", vgId:%d, type:%s, enable batch meta:%d", pHead->version, vgId,
|
||||
TMSG_INFO(pHead->msgType), pRequest->enableBatchMeta);
|
||||
if (!pRequest->enableBatchMeta && !pRequest->useSnapshot) {
|
||||
SMqMetaRsp metaRsp = {0};
|
||||
tqOffsetResetToLog(&metaRsp.rspOffset, fetchVer + 1);
|
||||
metaRsp.resMsgType = pHead->msgType;
|
||||
metaRsp.metaRspLen = pHead->bodyLen;
|
||||
|
@ -277,6 +293,50 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
goto end;
|
||||
}
|
||||
|
||||
if (!btMetaRsp.batchMetaReq) {
|
||||
btMetaRsp.batchMetaReq = taosArrayInit(4, POINTER_BYTES);
|
||||
btMetaRsp.batchMetaLen = taosArrayInit(4, sizeof(int32_t));
|
||||
}
|
||||
fetchVer++;
|
||||
|
||||
SMqMetaRsp tmpMetaRsp = {0};
|
||||
tmpMetaRsp.resMsgType = pHead->msgType;
|
||||
tmpMetaRsp.metaRspLen = pHead->bodyLen;
|
||||
tmpMetaRsp.metaRsp = pHead->body;
|
||||
uint32_t len = 0;
|
||||
tEncodeSize(tEncodeMqMetaRsp, &tmpMetaRsp, len, code);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
|
||||
continue;
|
||||
}
|
||||
int32_t tLen = sizeof(SMqRspHead) + len;
|
||||
void* tBuf = taosMemoryCalloc(1, tLen);
|
||||
void* metaBuff = POINTER_SHIFT(tBuf, sizeof(SMqRspHead));
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, metaBuff, len);
|
||||
code = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
|
||||
if (code < 0) {
|
||||
tEncoderClear(&encoder);
|
||||
tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
|
||||
continue;
|
||||
}
|
||||
taosArrayPush(btMetaRsp.batchMetaReq, &tBuf);
|
||||
taosArrayPush(btMetaRsp.batchMetaLen, &tLen);
|
||||
totalMetaRows++;
|
||||
if ((taosArrayGetSize(btMetaRsp.batchMetaReq) >= tmqRowSize) || (taosGetTimestampMs() - st > 1000)) {
|
||||
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
|
||||
tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
|
||||
goto end;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (totalMetaRows > 0) {
|
||||
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
|
||||
tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// process data
|
||||
SPackedData submit = {
|
||||
.msgStr = POINTER_SHIFT(pHead->body, sizeof(SSubmitReq2Msg)),
|
||||
|
@ -304,7 +364,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
}
|
||||
|
||||
end:
|
||||
|
||||
tDeleteMqBatchMetaRsp(&btMetaRsp);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
|
@ -352,6 +412,40 @@ static void initMqRspHead(SMqRspHead* pMsgHead, int32_t type, int32_t epoch, int
|
|||
pMsgHead->walever = ever;
|
||||
}
|
||||
|
||||
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqBatchMetaRsp* pRsp,
|
||||
int32_t vgId) {
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
tEncodeSize(tEncodeMqBatchMetaRsp, pRsp, len, code);
|
||||
if (code < 0) {
|
||||
return -1;
|
||||
}
|
||||
int32_t tlen = sizeof(SMqRspHead) + len;
|
||||
void* buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t sver = 0, ever = 0;
|
||||
walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
|
||||
initMqRspHead(buf, TMQ_MSG_TYPE__POLL_BATCH_META_RSP, pReq->epoch, pReq->consumerId, sver, ever);
|
||||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
tEncodeMqBatchMetaRsp(&encoder, pRsp);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
|
||||
|
||||
tmsgSendRsp(&resp);
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type: batch meta, size:%ld offset type:%d", vgId,
|
||||
pReq->consumerId, pReq->epoch, taosArrayGetSize(pRsp->batchMetaReq), pRsp->rspOffset.type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp,
|
||||
int32_t vgId) {
|
||||
int32_t len = 0;
|
||||
|
|
|
@ -588,6 +588,13 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud
|
|||
tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud);
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < pLastCol->rowKey.numOfPKs; ++i) {
|
||||
SValue *pValue = &pLastCol->rowKey.pks[i];
|
||||
if (IS_VAR_DATA_TYPE(pValue->type)) {
|
||||
taosMemoryFree(pValue->pData);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type) /* && pLastCol->colVal.value.nData > 0*/) {
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
}
|
||||
|
@ -1072,6 +1079,8 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray
|
|||
SLastCol *PToFree = pLastCol;
|
||||
|
||||
if (IS_LAST_KEY(idxKey->key) && !COL_VAL_IS_VALUE(pColVal)) {
|
||||
taosMemoryFreeClear(PToFree);
|
||||
rocksdb_free(values_list[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1238,6 +1247,18 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo
|
|||
ctxArray = taosArrayInit(pBlockData->nColData, sizeof(SLastUpdateCtx));
|
||||
|
||||
// 1. prepare last
|
||||
STsdbRowKey tsdbRowKey = {0};
|
||||
tsdbRowGetKey(&lRow, &tsdbRowKey);
|
||||
|
||||
{
|
||||
SLastUpdateCtx updateCtx = {
|
||||
.lflag = LFLAG_LAST,
|
||||
.tsdbRowKey = tsdbRowKey,
|
||||
.colVal = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, ((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP,
|
||||
.val = lRow.pBlockData->aTSKEY[lRow.iRow]}))};
|
||||
taosArrayPush(ctxArray, &updateCtx);
|
||||
}
|
||||
|
||||
TSDBROW tRow = tsdbRowFromBlockData(pBlockData, 0);
|
||||
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; ++iColData) {
|
||||
|
@ -1263,9 +1284,6 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo
|
|||
}
|
||||
|
||||
// 2. prepare last row
|
||||
STsdbRowKey tsdbRowKey = {0};
|
||||
tsdbRowGetKey(&lRow, &tsdbRowKey);
|
||||
|
||||
STSDBRowIter iter = {0};
|
||||
tsdbRowIterOpen(&iter, &lRow, pTSchema);
|
||||
for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal; pColVal = tsdbRowIterNext(&iter)) {
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
#include "tsdbCommit2.h"
|
||||
|
||||
// extern dependencies
|
||||
typedef struct {
|
||||
int32_t fid;
|
||||
STFileSet *fset;
|
||||
} SFileSetCommitInfo;
|
||||
|
||||
typedef struct {
|
||||
STsdb *tsdb;
|
||||
TFileSetArray *fsetArr;
|
||||
TFileOpArray fopArray[1];
|
||||
|
||||
// SSkmInfo skmTb[1];
|
||||
// SSkmInfo skmRow[1];
|
||||
|
||||
int32_t minutes;
|
||||
int8_t precision;
|
||||
int32_t minRow;
|
||||
|
@ -32,34 +31,34 @@ typedef struct {
|
|||
int32_t sttTrigger;
|
||||
int32_t szPage;
|
||||
int64_t compactVersion;
|
||||
|
||||
struct {
|
||||
int64_t cid;
|
||||
int64_t now;
|
||||
TSKEY nextKey;
|
||||
int32_t fid;
|
||||
|
||||
struct {
|
||||
SFileSetCommitInfo *info;
|
||||
|
||||
int32_t expLevel;
|
||||
SDiskID did;
|
||||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
STFileSet *fset;
|
||||
TABLEID tbid[1];
|
||||
bool hasTSData;
|
||||
|
||||
bool skipTsRow;
|
||||
SHashObj *pColCmprObj;
|
||||
} ctx[1];
|
||||
|
||||
// reader
|
||||
TSttFileReaderArray sttReaderArray[1];
|
||||
|
||||
// iter
|
||||
TTsdbIterArray dataIterArray[1];
|
||||
SIterMerger *dataIterMerger;
|
||||
TTsdbIterArray tombIterArray[1];
|
||||
SIterMerger *tombIterMerger;
|
||||
|
||||
// writer
|
||||
SFSetWriter *writer;
|
||||
|
||||
TFileOpArray fopArray[1];
|
||||
} SCommitter2;
|
||||
|
||||
static int32_t tsdbCommitOpenWriter(SCommitter2 *committer) {
|
||||
|
@ -74,8 +73,8 @@ static int32_t tsdbCommitOpenWriter(SCommitter2 *committer) {
|
|||
.maxRow = committer->maxRow,
|
||||
.szPage = committer->szPage,
|
||||
.cmprAlg = committer->cmprAlg,
|
||||
.fid = committer->ctx->fid,
|
||||
.cid = committer->ctx->cid,
|
||||
.fid = committer->ctx->info->fid,
|
||||
.cid = committer->cid,
|
||||
.did = committer->ctx->did,
|
||||
.level = 0,
|
||||
};
|
||||
|
@ -83,11 +82,11 @@ static int32_t tsdbCommitOpenWriter(SCommitter2 *committer) {
|
|||
if (committer->sttTrigger == 1) {
|
||||
config.toSttOnly = false;
|
||||
|
||||
if (committer->ctx->fset) {
|
||||
if (committer->ctx->info->fset) {
|
||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ftype++) {
|
||||
if (committer->ctx->fset->farr[ftype] != NULL) {
|
||||
if (committer->ctx->info->fset->farr[ftype] != NULL) {
|
||||
config.files[ftype].exist = true;
|
||||
config.files[ftype].file = committer->ctx->fset->farr[ftype]->f[0];
|
||||
config.files[ftype].file = committer->ctx->info->fset->farr[ftype]->f[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +116,6 @@ static int32_t tsdbCommitTSData(SCommitter2 *committer) {
|
|||
|
||||
committer->ctx->tbid->suid = 0;
|
||||
committer->ctx->tbid->uid = 0;
|
||||
|
||||
for (SRowInfo *row; (row = tsdbIterMergerGetData(committer->dataIterMerger)) != NULL;) {
|
||||
if (row->uid != committer->ctx->tbid->uid) {
|
||||
committer->ctx->tbid->suid = row->suid;
|
||||
|
@ -132,7 +130,6 @@ static int32_t tsdbCommitTSData(SCommitter2 *committer) {
|
|||
|
||||
int64_t ts = TSDBROW_TS(&row->row);
|
||||
if (ts > committer->ctx->maxKey) {
|
||||
committer->ctx->nextKey = TMIN(committer->ctx->nextKey, ts);
|
||||
code = tsdbIterMergerSkipTableData(committer->dataIterMerger, committer->ctx->tbid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
continue;
|
||||
|
@ -152,7 +149,8 @@ _exit:
|
|||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d fid:%d commit %" PRId64 " rows", TD_VID(committer->tsdb->pVnode), committer->ctx->fid, numOfRow);
|
||||
tsdbDebug("vgId:%d fid:%d commit %" PRId64 " rows", TD_VID(committer->tsdb->pVnode), committer->ctx->info->fid,
|
||||
numOfRow);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -168,7 +166,7 @@ static int32_t tsdbCommitTombData(SCommitter2 *committer) {
|
|||
}
|
||||
|
||||
// do not need to write tomb data if there is no ts data
|
||||
bool skip = (committer->ctx->fset == NULL && !committer->ctx->hasTSData);
|
||||
bool skip = (committer->ctx->info->fset == NULL && !committer->ctx->hasTSData);
|
||||
|
||||
committer->ctx->tbid->suid = 0;
|
||||
committer->ctx->tbid->uid = 0;
|
||||
|
@ -187,12 +185,8 @@ static int32_t tsdbCommitTombData(SCommitter2 *committer) {
|
|||
if (record->ekey < committer->ctx->minKey) {
|
||||
// do nothing
|
||||
} else if (record->skey > committer->ctx->maxKey) {
|
||||
committer->ctx->nextKey = TMIN(record->skey, committer->ctx->nextKey);
|
||||
// committer->ctx->nextKey = TMIN(record->skey, committer->ctx->nextKey);
|
||||
} else {
|
||||
if (record->ekey > committer->ctx->maxKey) {
|
||||
committer->ctx->nextKey = TMIN(committer->ctx->nextKey, committer->ctx->maxKey + 1);
|
||||
}
|
||||
|
||||
record->skey = TMAX(record->skey, committer->ctx->minKey);
|
||||
record->ekey = TMIN(record->ekey, committer->ctx->maxKey);
|
||||
|
||||
|
@ -211,27 +205,32 @@ _exit:
|
|||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d fid:%d commit %" PRId64 " tomb records", TD_VID(committer->tsdb->pVnode), committer->ctx->fid,
|
||||
numRecord);
|
||||
tsdbDebug("vgId:%d fid:%d commit %" PRId64 " tomb records", TD_VID(committer->tsdb->pVnode),
|
||||
committer->ctx->info->fid, numRecord);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitCloseReader(SCommitter2 *committer) {
|
||||
TARRAY2_CLEAR(committer->sttReaderArray, tsdbSttFileReaderClose);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitOpenReader(SCommitter2 *committer) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
ASSERT(TARRAY2_SIZE(committer->sttReaderArray) == 0);
|
||||
|
||||
if (committer->ctx->fset == NULL //
|
||||
if (committer->ctx->info->fset == NULL //
|
||||
|| committer->sttTrigger > 1 //
|
||||
|| TARRAY2_SIZE(committer->ctx->fset->lvlArr) == 0 //
|
||||
|| TARRAY2_SIZE(committer->ctx->info->fset->lvlArr) == 0 //
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSttLvl *lvl;
|
||||
TARRAY2_FOREACH(committer->ctx->fset->lvlArr, lvl) {
|
||||
TARRAY2_FOREACH(committer->ctx->info->fset->lvlArr, lvl) {
|
||||
STFileObj *fobj = NULL;
|
||||
TARRAY2_FOREACH(lvl->fobjArr, fobj) {
|
||||
SSttFileReader *sttReader;
|
||||
|
@ -261,13 +260,17 @@ static int32_t tsdbCommitOpenReader(SCommitter2 *committer) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitCloseReader(committer);
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitCloseReader(SCommitter2 *committer) {
|
||||
TARRAY2_CLEAR(committer->sttReaderArray, tsdbSttFileReaderClose);
|
||||
static int32_t tsdbCommitCloseIter(SCommitter2 *committer) {
|
||||
tsdbIterMergerClose(&committer->tombIterMerger);
|
||||
tsdbIterMergerClose(&committer->dataIterMerger);
|
||||
TARRAY2_CLEAR(committer->tombIterArray, tsdbIterClose);
|
||||
TARRAY2_CLEAR(committer->dataIterArray, tsdbIterClose);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -289,7 +292,7 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) {
|
|||
config.from->version = VERSION_MIN;
|
||||
config.from->key = (SRowKey){
|
||||
.ts = committer->ctx->minKey,
|
||||
.numOfPKs = 0, // TODO: support multiple primary keys
|
||||
.numOfPKs = 0,
|
||||
};
|
||||
|
||||
code = tsdbIterOpen(&config, &iter);
|
||||
|
@ -341,40 +344,26 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitCloseIter(committer);
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitCloseIter(SCommitter2 *committer) {
|
||||
tsdbIterMergerClose(&committer->tombIterMerger);
|
||||
tsdbIterMergerClose(&committer->dataIterMerger);
|
||||
TARRAY2_CLEAR(committer->tombIterArray, tsdbIterClose);
|
||||
TARRAY2_CLEAR(committer->dataIterArray, tsdbIterClose);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STsdb *tsdb = committer->tsdb;
|
||||
|
||||
int32_t fid = tsdbKeyFid(committer->ctx->nextKey, committer->minutes, committer->precision);
|
||||
|
||||
// check if can commit
|
||||
tsdbFSCheckCommit(tsdb, fid);
|
||||
tsdbFSCheckCommit(tsdb, committer->ctx->info->fid);
|
||||
|
||||
committer->ctx->fid = fid;
|
||||
committer->ctx->expLevel = tsdbFidLevel(committer->ctx->fid, &tsdb->keepCfg, committer->ctx->now);
|
||||
tsdbFidKeyRange(committer->ctx->fid, committer->minutes, committer->precision, &committer->ctx->minKey,
|
||||
committer->ctx->expLevel = tsdbFidLevel(committer->ctx->info->fid, &tsdb->keepCfg, committer->now);
|
||||
tsdbFidKeyRange(committer->ctx->info->fid, committer->minutes, committer->precision, &committer->ctx->minKey,
|
||||
&committer->ctx->maxKey);
|
||||
code = tfsAllocDisk(committer->tsdb->pVnode->pTfs, committer->ctx->expLevel, &committer->ctx->did);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
tfsMkdirRecurAt(committer->tsdb->pVnode->pTfs, committer->tsdb->path, committer->ctx->did);
|
||||
STFileSet fset = {.fid = committer->ctx->fid};
|
||||
committer->ctx->fset = &fset;
|
||||
STFileSet **fsetPtr = TARRAY2_SEARCH(committer->fsetArr, &committer->ctx->fset, tsdbTFileSetCmprFn, TD_EQ);
|
||||
committer->ctx->fset = (fsetPtr == NULL) ? NULL : *fsetPtr;
|
||||
committer->ctx->tbid->suid = 0;
|
||||
committer->ctx->tbid->uid = 0;
|
||||
|
||||
|
@ -391,15 +380,13 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) {
|
|||
code = tsdbCommitOpenWriter(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// reset nextKey
|
||||
committer->ctx->nextKey = TSKEY_MAX;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, fid:%d minKey:%" PRId64 " maxKey:%" PRId64 " expLevel:%d", TD_VID(tsdb->pVnode),
|
||||
__func__, committer->ctx->fid, committer->ctx->minKey, committer->ctx->maxKey, committer->ctx->expLevel);
|
||||
__func__, committer->ctx->info->fid, committer->ctx->minKey, committer->ctx->maxKey,
|
||||
committer->ctx->expLevel);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -421,7 +408,7 @@ _exit:
|
|||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->fid);
|
||||
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->info->fid);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -449,7 +436,220 @@ _exit:
|
|||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->fid);
|
||||
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->info->fid);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tFileSetCommitInfoCompare(const void *arg1, const void *arg2) {
|
||||
SFileSetCommitInfo *info1 = (SFileSetCommitInfo *)arg1;
|
||||
SFileSetCommitInfo *info2 = (SFileSetCommitInfo *)arg2;
|
||||
|
||||
if (info1->fid < info2->fid) {
|
||||
return -1;
|
||||
} else if (info1->fid > info2->fid) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t tFileSetCommitInfoPCompare(const void *arg1, const void *arg2) {
|
||||
return tFileSetCommitInfoCompare(*(SFileSetCommitInfo **)arg1, *(SFileSetCommitInfo **)arg2);
|
||||
}
|
||||
|
||||
static uint32_t tFileSetCommitInfoHash(const void *arg) {
|
||||
SFileSetCommitInfo *info = (SFileSetCommitInfo *)arg;
|
||||
return MurmurHash3_32((const char *)&info->fid, sizeof(info->fid));
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (pTsdb->commitInfo) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) {
|
||||
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i);
|
||||
vHashDrop(pTsdb->commitInfo->ht, info);
|
||||
tsdbTFileSetClear(&info->fset);
|
||||
taosMemoryFree(info);
|
||||
}
|
||||
|
||||
vHashDestroy(&pTsdb->commitInfo->ht);
|
||||
taosArrayDestroy(pTsdb->commitInfo->arr);
|
||||
pTsdb->commitInfo->arr = NULL;
|
||||
taosMemoryFreeClear(pTsdb->commitInfo);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitInfoInit(STsdb *pTsdb) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
pTsdb->commitInfo = taosMemoryCalloc(1, sizeof(*pTsdb->commitInfo));
|
||||
if (pTsdb->commitInfo == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
}
|
||||
|
||||
code = vHashInit(&pTsdb->commitInfo->ht, tFileSetCommitInfoHash, tFileSetCommitInfoCompare);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pTsdb->commitInfo->arr = taosArrayInit(0, sizeof(SFileSetCommitInfo *));
|
||||
if (pTsdb->commitInfo->arr == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitInfoDestroy(pTsdb);
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitInfoAdd(STsdb *tsdb, int32_t fid) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
SFileSetCommitInfo *tinfo;
|
||||
|
||||
if ((tinfo = taosMemoryMalloc(sizeof(*tinfo))) == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
}
|
||||
tinfo->fid = fid;
|
||||
tinfo->fset = NULL;
|
||||
|
||||
code = vHashPut(tsdb->commitInfo->ht, tinfo);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
if ((taosArrayPush(tsdb->commitInfo->arr, &tinfo)) == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
}
|
||||
taosArraySort(tsdb->commitInfo->arr, tFileSetCommitInfoPCompare);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitInfoBuild(STsdb *tsdb) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
STFileSet *fset = NULL;
|
||||
SRBTreeIter iter;
|
||||
|
||||
code = tsdbCommitInfoInit(tsdb);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// scan time-series data
|
||||
iter = tRBTreeIterCreate(tsdb->imem->tbDataTree, 1);
|
||||
for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) {
|
||||
STbData *pTbData = TCONTAINER_OF(node, STbData, rbtn);
|
||||
|
||||
// scan time-series data
|
||||
STsdbRowKey from = {
|
||||
.key.ts = INT64_MIN,
|
||||
.key.numOfPKs = 0,
|
||||
.version = INT64_MIN,
|
||||
};
|
||||
for (;;) {
|
||||
int64_t minKey, maxKey;
|
||||
STbDataIter tbDataIter = {0};
|
||||
TSDBROW *row;
|
||||
int32_t fid;
|
||||
|
||||
tsdbTbDataIterOpen(pTbData, &from, 0, &tbDataIter);
|
||||
if ((row = tsdbTbDataIterGet(&tbDataIter)) == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
fid = tsdbKeyFid(TSDBROW_TS(row), tsdb->keepCfg.days, tsdb->keepCfg.precision);
|
||||
tsdbFidKeyRange(fid, tsdb->keepCfg.days, tsdb->keepCfg.precision, &minKey, &maxKey);
|
||||
|
||||
SFileSetCommitInfo *info;
|
||||
SFileSetCommitInfo tinfo = {
|
||||
.fid = fid,
|
||||
};
|
||||
vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info);
|
||||
if (info == NULL) {
|
||||
code = tsdbCommitInfoAdd(tsdb, fid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
from.key.ts = maxKey + 1;
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&tsdb->mutex);
|
||||
|
||||
// scan tomb data
|
||||
if (tsdb->imem->nDel > 0) {
|
||||
TARRAY2_FOREACH(tsdb->pFS->fSetArr, fset) {
|
||||
if (tsdbTFileSetIsEmpty(fset)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SFileSetCommitInfo *info;
|
||||
SFileSetCommitInfo tinfo = {
|
||||
.fid = fset->fid,
|
||||
};
|
||||
|
||||
// check if the file set already on the commit list
|
||||
vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info);
|
||||
if (info != NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t minKey, maxKey;
|
||||
bool hasDataToCommit = false;
|
||||
tsdbFidKeyRange(fset->fid, tsdb->keepCfg.days, tsdb->keepCfg.precision, &minKey, &maxKey);
|
||||
iter = tRBTreeIterCreate(tsdb->imem->tbDataTree, 1);
|
||||
for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) {
|
||||
STbData *pTbData = TCONTAINER_OF(node, STbData, rbtn);
|
||||
for (SDelData *pDelData = pTbData->pHead; pDelData; pDelData = pDelData->pNext) {
|
||||
if (pDelData->sKey > maxKey || pDelData->eKey < minKey) {
|
||||
continue;
|
||||
} else {
|
||||
hasDataToCommit = true;
|
||||
if ((code = tsdbCommitInfoAdd(tsdb, fset->fid))) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDataToCommit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// begin tasks on file set
|
||||
for (int i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) {
|
||||
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
|
||||
tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset);
|
||||
if (fset) {
|
||||
tsdbTFileSetInitCopy(tsdb, fset, &info->fset);
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitInfoDestroy(tsdb);
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -458,11 +658,7 @@ static int32_t tsdbOpenCommitter(STsdb *tsdb, SCommitInfo *info, SCommitter2 *co
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
memset(committer, 0, sizeof(committer[0]));
|
||||
|
||||
committer->tsdb = tsdb;
|
||||
code = tsdbFSCreateCopySnapshot(tsdb->pFS, &committer->fsetArr);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
committer->minutes = tsdb->keepCfg.days;
|
||||
committer->precision = tsdb->keepCfg.precision;
|
||||
committer->minRow = info->info.config.tsdbCfg.minRows;
|
||||
|
@ -471,21 +667,11 @@ static int32_t tsdbOpenCommitter(STsdb *tsdb, SCommitInfo *info, SCommitter2 *co
|
|||
committer->sttTrigger = info->info.config.sttTrigger;
|
||||
committer->szPage = info->info.config.tsdbPageSize;
|
||||
committer->compactVersion = INT64_MAX;
|
||||
committer->ctx->cid = tsdbFSAllocEid(tsdb->pFS);
|
||||
committer->ctx->now = taosGetTimestampSec();
|
||||
committer->cid = tsdbFSAllocEid(tsdb->pFS);
|
||||
committer->now = taosGetTimestampSec();
|
||||
|
||||
committer->ctx->nextKey = tsdb->imem->minKey;
|
||||
if (tsdb->imem->nDel > 0) {
|
||||
SRBTreeIter iter[1] = {tRBTreeIterCreate(tsdb->imem->tbDataTree, 1)};
|
||||
|
||||
for (SRBTreeNode *node = tRBTreeIterNext(iter); node; node = tRBTreeIterNext(iter)) {
|
||||
STbData *tbData = TCONTAINER_OF(node, STbData, rbtn);
|
||||
|
||||
for (SDelData *delData = tbData->pHead; delData; delData = delData->pNext) {
|
||||
committer->ctx->nextKey = TMIN(committer->ctx->nextKey, delData->sKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
code = tsdbCommitInfoBuild(tsdb);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
|
@ -516,14 +702,13 @@ static int32_t tsdbCloseCommitter(SCommitter2 *committer, int32_t eno) {
|
|||
TARRAY2_DESTROY(committer->sttReaderArray, NULL);
|
||||
TARRAY2_DESTROY(committer->fopArray, NULL);
|
||||
TARRAY2_DESTROY(committer->sttReaderArray, NULL);
|
||||
tsdbFSDestroyCopySnapshot(&committer->fsetArr);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s, eid:%" PRId64, TD_VID(committer->tsdb->pVnode), __func__, lino,
|
||||
tstrerror(code), committer->ctx->cid);
|
||||
tstrerror(code), committer->cid);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, eid:%" PRId64, TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->cid);
|
||||
tsdbDebug("vgId:%d %s done, eid:%" PRId64, TD_VID(committer->tsdb->pVnode), __func__, committer->cid);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -553,17 +738,18 @@ int32_t tsdbCommitBegin(STsdb *tsdb, SCommitInfo *info) {
|
|||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
tsdbUnrefMemTable(imem, NULL, true);
|
||||
} else {
|
||||
SCommitter2 committer[1];
|
||||
SCommitter2 committer = {0};
|
||||
|
||||
code = tsdbOpenCommitter(tsdb, info, committer);
|
||||
code = tsdbOpenCommitter(tsdb, info, &committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
while (committer->ctx->nextKey != TSKEY_MAX) {
|
||||
code = tsdbCommitFileSet(committer);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) {
|
||||
committer.ctx->info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
|
||||
code = tsdbCommitFileSet(&committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
code = tsdbCloseCommitter(committer, code);
|
||||
code = tsdbCloseCommitter(&committer, code);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -580,22 +766,33 @@ int32_t tsdbCommitCommit(STsdb *tsdb) {
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (tsdb->imem == NULL) goto _exit;
|
||||
|
||||
if (tsdb->imem) {
|
||||
SMemTable *pMemTable = tsdb->imem;
|
||||
|
||||
taosThreadMutexLock(&tsdb->mutex);
|
||||
code = tsdbFSEditCommit(tsdb->pFS);
|
||||
if (code) {
|
||||
|
||||
if ((code = tsdbFSEditCommit(tsdb->pFS))) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
tsdb->imem = NULL;
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) {
|
||||
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
|
||||
if (info->fset) {
|
||||
tsdbFinishTaskOnFileSet(tsdb, info->fid);
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
|
||||
tsdbCommitInfoDestroy(tsdb);
|
||||
tsdbUnrefMemTable(pMemTable, NULL, true);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s done", TD_VID(tsdb->pVnode), __func__);
|
||||
}
|
||||
|
@ -611,6 +808,16 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) {
|
|||
code = tsdbFSEditAbort(pTsdb->pFS);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
taosThreadMutexLock(&pTsdb->mutex);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) {
|
||||
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i);
|
||||
if (info->fset) {
|
||||
tsdbFinishTaskOnFileSet(pTsdb, info->fid);
|
||||
}
|
||||
}
|
||||
taosThreadMutexUnlock(&pTsdb->mutex);
|
||||
tsdbCommitInfoDestroy(pTsdb);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
|
|
|
@ -74,7 +74,7 @@ int32_t tsdbDataFileRAWReadBlockData(SDataFileRAWReader *reader, STsdbDataRAWBlo
|
|||
pBlock->file.stt->level = reader->config->file.stt->level;
|
||||
|
||||
int32_t encryptAlgorithm = reader->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||
char* encryptKey = reader->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
char *encryptKey = reader->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
code = tsdbReadFile(reader->fd, pBlock->offset, pBlock->data, pBlock->dataLength, 0, encryptAlgorithm, encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
|
@ -130,7 +130,7 @@ static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFil
|
|||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
int32_t encryptAlgorithm = writer->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||
char* encryptKey = writer->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
char *encryptKey = writer->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
|
||||
if (writer->fd) {
|
||||
code = tsdbFsyncFile(writer->fd, encryptAlgorithm, encryptKey);
|
||||
|
@ -212,7 +212,7 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t tsdbDataFileRAWWriteBlockData(SDataFileRAWWriter *writer, const STsdbDataRAWBlockHeader *pDataBlock,
|
||||
int32_t encryptAlgorithm, char* encryptKey) {
|
||||
int32_t encryptAlgorithm, char *encryptKey) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
|
||||
extern void remove_file(const char *fname);
|
||||
|
||||
#define TSDB_FS_EDIT_MIN TSDB_FEDIT_COMMIT
|
||||
#define TSDB_FS_EDIT_MAX (TSDB_FEDIT_MERGE + 1)
|
||||
|
||||
typedef struct STFileHashEntry {
|
||||
struct STFileHashEntry *next;
|
||||
char fname[TSDB_FILENAME_LEN];
|
||||
|
@ -290,10 +287,8 @@ static int32_t commit_edit(STFileSystem *fs) {
|
|||
current_fname(fs->tsdb, current, TSDB_FCURRENT);
|
||||
if (fs->etype == TSDB_FEDIT_COMMIT) {
|
||||
current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C);
|
||||
} else if (fs->etype == TSDB_FEDIT_MERGE) {
|
||||
current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M);
|
||||
}
|
||||
|
||||
int32_t code;
|
||||
|
@ -324,11 +319,8 @@ static int32_t abort_edit(STFileSystem *fs) {
|
|||
|
||||
if (fs->etype == TSDB_FEDIT_COMMIT) {
|
||||
current_fname(fs->tsdb, fname, TSDB_FCURRENT_C);
|
||||
} else if (fs->etype == TSDB_FEDIT_MERGE) {
|
||||
current_fname(fs->tsdb, fname, TSDB_FCURRENT_M);
|
||||
} else {
|
||||
tsdbError("vgId:%d %s failed since invalid etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype);
|
||||
ASSERT(0);
|
||||
current_fname(fs->tsdb, fname, TSDB_FCURRENT_M);
|
||||
}
|
||||
|
||||
int32_t code;
|
||||
|
@ -767,9 +759,12 @@ extern int32_t tsdbStopAllCompTask(STsdb *tsdb);
|
|||
|
||||
int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) {
|
||||
STFileSystem *fs = pTsdb->pFS;
|
||||
TARRAY2(int64_t) channelArr = {0};
|
||||
SArray *channelArray = taosArrayInit(0, sizeof(SVAChannelID));
|
||||
if (channelArray == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&fs->tsdb->mutex);
|
||||
taosThreadMutexLock(&pTsdb->mutex);
|
||||
|
||||
// disable
|
||||
pTsdb->bgTaskDisabled = true;
|
||||
|
@ -777,20 +772,23 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) {
|
|||
// collect channel
|
||||
STFileSet *fset;
|
||||
TARRAY2_FOREACH(fs->fSetArr, fset) {
|
||||
if (VNODE_ASYNC_VALID_CHANNEL_ID(fset->bgTaskChannel)) {
|
||||
TARRAY2_APPEND(&channelArr, fset->bgTaskChannel);
|
||||
fset->bgTaskChannel = 0;
|
||||
}
|
||||
if (fset->channelOpened) {
|
||||
taosArrayPush(channelArray, &fset->channel);
|
||||
fset->channel = (SVAChannelID){0};
|
||||
fset->mergeScheduled = false;
|
||||
tsdbFSSetBlockCommit(fset, false);
|
||||
fset->channelOpened = false;
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&fs->tsdb->mutex);
|
||||
taosThreadMutexUnlock(&pTsdb->mutex);
|
||||
|
||||
// destroy all channels
|
||||
int64_t channel;
|
||||
TARRAY2_FOREACH(&channelArr, channel) { vnodeAChannelDestroy(vnodeAsyncHandle[1], channel, true); }
|
||||
TARRAY2_DESTROY(&channelArr, NULL);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(channelArray); i++) {
|
||||
SVAChannelID *channel = taosArrayGet(channelArray, i);
|
||||
vnodeAChannelDestroy(channel, true);
|
||||
}
|
||||
taosArrayDestroy(channelArray);
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
tsdbStopAllCompTask(pTsdb);
|
||||
|
@ -832,15 +830,10 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e
|
|||
int32_t lino;
|
||||
char current_t[TSDB_FILENAME_LEN];
|
||||
|
||||
switch (etype) {
|
||||
case TSDB_FEDIT_COMMIT:
|
||||
if (etype == TSDB_FEDIT_COMMIT) {
|
||||
current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C);
|
||||
break;
|
||||
case TSDB_FEDIT_MERGE:
|
||||
} else {
|
||||
current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M);
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tsem_wait(&fs->canEdit);
|
||||
|
@ -932,8 +925,7 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) {
|
|||
arg->tsdb = fs->tsdb;
|
||||
arg->fid = fset->fid;
|
||||
|
||||
code = vnodeAsyncC(vnodeAsyncHandle[1], fset->bgTaskChannel, EVA_PRIORITY_HIGH, tsdbMerge, taosMemoryFree, arg,
|
||||
NULL);
|
||||
code = vnodeAsync(&fset->channel, EVA_PRIORITY_HIGH, tsdbMerge, taosMemoryFree, arg, NULL);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
fset->mergeScheduled = true;
|
||||
}
|
||||
|
@ -946,33 +938,6 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) {
|
|||
}
|
||||
}
|
||||
|
||||
// clear empty level and fset
|
||||
int32_t i = 0;
|
||||
while (i < TARRAY2_SIZE(fs->fSetArr)) {
|
||||
STFileSet *fset = TARRAY2_GET(fs->fSetArr, i);
|
||||
|
||||
int32_t j = 0;
|
||||
while (j < TARRAY2_SIZE(fset->lvlArr)) {
|
||||
SSttLvl *lvl = TARRAY2_GET(fset->lvlArr, j);
|
||||
|
||||
if (TARRAY2_SIZE(lvl->fobjArr) == 0) {
|
||||
TARRAY2_REMOVE(fset->lvlArr, j, tsdbSttLvlClear);
|
||||
} else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
if (tsdbTFileSetIsEmpty(fset)) {
|
||||
if (VNODE_ASYNC_VALID_CHANNEL_ID(fset->bgTaskChannel)) {
|
||||
vnodeAChannelDestroy(vnodeAsyncHandle[1], fset->bgTaskChannel, false);
|
||||
fset->bgTaskChannel = 0;
|
||||
}
|
||||
TARRAY2_REMOVE(fs->fSetArr, i, tsdbTFileSetClear);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(fs->tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
|
@ -1211,3 +1176,47 @@ _out:
|
|||
}
|
||||
|
||||
int32_t tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr) { return tsdbTFileSetRangeArrayDestroy(fsrArr); }
|
||||
|
||||
int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) {
|
||||
int16_t sttTrigger = tsdb->pVnode->config.sttTrigger;
|
||||
|
||||
tsdbFSGetFSet(tsdb->pFS, fid, fset);
|
||||
if (sttTrigger == 1 && (*fset)) {
|
||||
for (;;) {
|
||||
if ((*fset)->taskRunning) {
|
||||
(*fset)->numWaitTask++;
|
||||
|
||||
taosThreadCondWait(&(*fset)->beginTask, &tsdb->mutex);
|
||||
|
||||
tsdbFSGetFSet(tsdb->pFS, fid, fset);
|
||||
ASSERT(fset != NULL);
|
||||
|
||||
(*fset)->numWaitTask--;
|
||||
ASSERT((*fset)->numWaitTask >= 0);
|
||||
} else {
|
||||
(*fset)->taskRunning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tsdbInfo("vgId:%d begin task on file set:%d", TD_VID(tsdb->pVnode), fid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) {
|
||||
int16_t sttTrigger = tsdb->pVnode->config.sttTrigger;
|
||||
if (sttTrigger == 1) {
|
||||
STFileSet *fset = NULL;
|
||||
tsdbFSGetFSet(tsdb->pFS, fid, &fset);
|
||||
if (fset != NULL && fset->taskRunning) {
|
||||
fset->taskRunning = false;
|
||||
if (fset->numWaitTask > 0) {
|
||||
taosThreadCondSignal(&fset->beginTask);
|
||||
}
|
||||
tsdbInfo("vgId:%d finish task on file set:%d", TD_VID(tsdb->pVnode), fid);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -24,7 +24,9 @@ extern "C" {
|
|||
|
||||
typedef enum {
|
||||
TSDB_FEDIT_COMMIT = 1, //
|
||||
TSDB_FEDIT_MERGE
|
||||
TSDB_FEDIT_MERGE,
|
||||
TSDB_FEDIT_COMPACT,
|
||||
TSDB_FEDIT_RETENTION,
|
||||
} EFEditT;
|
||||
|
||||
typedef enum {
|
||||
|
@ -59,6 +61,8 @@ int32_t tsdbFSEditAbort(STFileSystem *fs);
|
|||
// other
|
||||
int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset);
|
||||
int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid);
|
||||
int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset);
|
||||
int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid);
|
||||
// utils
|
||||
int32_t save_fs(const TFileSetArray *arr, const char *fname);
|
||||
int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype);
|
||||
|
@ -72,10 +76,6 @@ struct STFileSystem {
|
|||
EFEditT etype;
|
||||
TFileSetArray fSetArr[1];
|
||||
TFileSetArray fSetArrTmp[1];
|
||||
|
||||
// background task queue
|
||||
bool stop;
|
||||
int64_t taskid;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -456,13 +456,14 @@ int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset) {
|
|||
TARRAY2_INIT(fset[0]->lvlArr);
|
||||
|
||||
// background task queue
|
||||
fset[0]->bgTaskChannel = 0;
|
||||
fset[0]->mergeScheduled = false;
|
||||
taosThreadCondInit(&(*fset)->beginTask, NULL);
|
||||
(*fset)->taskRunning = false;
|
||||
(*fset)->numWaitTask = 0;
|
||||
|
||||
// block commit variables
|
||||
taosThreadCondInit(&fset[0]->canCommit, NULL);
|
||||
fset[0]->numWaitCommit = 0;
|
||||
fset[0]->blockCommit = false;
|
||||
(*fset)->numWaitCommit = 0;
|
||||
(*fset)->blockCommit = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -598,21 +599,19 @@ int32_t tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbTFileSetClear(STFileSet **fset) {
|
||||
if (!fset[0]) return 0;
|
||||
|
||||
void tsdbTFileSetClear(STFileSet **fset) {
|
||||
if (fset && *fset) {
|
||||
for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||
if (fset[0]->farr[ftype] == NULL) continue;
|
||||
tsdbTFileObjUnref(fset[0]->farr[ftype]);
|
||||
if ((*fset)->farr[ftype] == NULL) continue;
|
||||
tsdbTFileObjUnref((*fset)->farr[ftype]);
|
||||
}
|
||||
|
||||
TARRAY2_DESTROY(fset[0]->lvlArr, tsdbSttLvlClear);
|
||||
TARRAY2_DESTROY((*fset)->lvlArr, tsdbSttLvlClear);
|
||||
|
||||
taosThreadCondDestroy(&fset[0]->canCommit);
|
||||
taosMemoryFree(fset[0]);
|
||||
fset[0] = NULL;
|
||||
|
||||
return 0;
|
||||
taosThreadCondDestroy(&(*fset)->beginTask);
|
||||
taosThreadCondDestroy(&(*fset)->canCommit);
|
||||
taosMemoryFreeClear(*fset);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tsdbTFileSetRemove(STFileSet *fset) {
|
||||
|
@ -665,6 +664,12 @@ bool tsdbTFileSetIsEmpty(const STFileSet *fset) {
|
|||
}
|
||||
|
||||
int32_t tsdbTFileSetOpenChannel(STFileSet *fset) {
|
||||
if (VNODE_ASYNC_VALID_CHANNEL_ID(fset->bgTaskChannel)) return 0;
|
||||
return vnodeAChannelInit(vnodeAsyncHandle[1], &fset->bgTaskChannel);
|
||||
int32_t code;
|
||||
if (!fset->channelOpened) {
|
||||
if ((code = vnodeAChannelInit(2, &fset->channel))) {
|
||||
return code;
|
||||
}
|
||||
fset->channelOpened = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef enum {
|
|||
int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset);
|
||||
int32_t tsdbTFileSetInitCopy(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset);
|
||||
int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset);
|
||||
int32_t tsdbTFileSetClear(STFileSet **fset);
|
||||
void tsdbTFileSetClear(STFileSet **fset);
|
||||
int32_t tsdbTFileSetRemove(STFileSet *fset);
|
||||
|
||||
int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_t ever, STFileSet **fset,
|
||||
|
@ -90,10 +90,16 @@ struct STFileSet {
|
|||
STFileObj *farr[TSDB_FTYPE_MAX]; // file array
|
||||
TSttLvlArray lvlArr[1]; // level array
|
||||
|
||||
// background task channel
|
||||
int64_t bgTaskChannel;
|
||||
// background task
|
||||
bool channelOpened;
|
||||
SVAChannelID channel;
|
||||
bool mergeScheduled;
|
||||
|
||||
// sttTrigger = 1
|
||||
TdThreadCond beginTask;
|
||||
bool taskRunning;
|
||||
int32_t numWaitTask;
|
||||
|
||||
// block commit variables
|
||||
TdThreadCond canCommit;
|
||||
int32_t numWaitCommit;
|
||||
|
|
|
@ -44,7 +44,7 @@ static const struct {
|
|||
};
|
||||
|
||||
void remove_file(const char *fname) {
|
||||
taosRemoveFile(fname);
|
||||
(void)taosRemoveFile(fname);
|
||||
tsdbInfo("file:%s is removed", fname);
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,11 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbMergeFileSetEndCloseReader(SMerger *merger) {
|
||||
TARRAY2_CLEAR(merger->sttReaderArr, tsdbSttFileReaderClose);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
@ -220,10 +225,12 @@ static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) {
|
|||
code = tsdbSttFileReaderOpen(fobj->fname, &config, &reader);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(merger->sttReaderArr, reader);
|
||||
if ((code = TARRAY2_APPEND(merger->sttReaderArr, reader))) {
|
||||
tsdbSttFileReaderClose(&reader);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (merger->ctx->level > TSDB_MAX_LEVEL) {
|
||||
merger->ctx->level = TSDB_MAX_LEVEL;
|
||||
|
@ -232,6 +239,7 @@ static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbMergeFileSetEndCloseReader(merger);
|
||||
TSDB_ERROR_LOG(TD_VID(merger->tsdb->pVnode), lino, code);
|
||||
}
|
||||
return code;
|
||||
|
@ -375,11 +383,6 @@ static int32_t tsdbMergeFileSetEndCloseIter(SMerger *merger) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbMergeFileSetEndCloseReader(SMerger *merger) {
|
||||
TARRAY2_CLEAR(merger->sttReaderArr, tsdbSttFileReaderClose);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbMergeFileSetEnd(SMerger *merger) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
@ -593,5 +596,6 @@ _exit:
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
tsdbTFileSetClear(&merger->fset);
|
||||
taosMemoryFree(arg);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ typedef struct {
|
|||
int64_t now;
|
||||
int64_t cid;
|
||||
|
||||
TFileSetArray *fsetArr;
|
||||
TFileOpArray fopArr[1];
|
||||
STFileSet *fset;
|
||||
TFileOpArray fopArr;
|
||||
} SRTNer;
|
||||
|
||||
static int32_t tsdbDoRemoveFileObject(SRTNer *rtner, const STFileObj *fobj) {
|
||||
|
@ -35,7 +35,7 @@ static int32_t tsdbDoRemoveFileObject(SRTNer *rtner, const STFileObj *fobj) {
|
|||
.of = fobj->f[0],
|
||||
};
|
||||
|
||||
return TARRAY2_APPEND(rtner->fopArr, op);
|
||||
return TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
}
|
||||
|
||||
static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFile *to) {
|
||||
|
@ -71,7 +71,7 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(rtner->tsdb->pVnode), __func__, code, lino);
|
||||
if (fdFrom) taosCloseFile(&fdFrom);
|
||||
if (fdTo) taosCloseFile(&fdTo);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(rtner->tsdb->pVnode), __func__, code, lino);
|
||||
taosCloseFile(&fdFrom);
|
||||
taosCloseFile(&fdTo);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ static int32_t tsdbDoMigrateFileObj(SRTNer *rtner, const STFileObj *fobj, const
|
|||
.of = fobj->f[0],
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(rtner->fopArr, op);
|
||||
code = TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// create new
|
||||
|
@ -152,7 +152,7 @@ static int32_t tsdbDoMigrateFileObj(SRTNer *rtner, const STFileObj *fobj, const
|
|||
},
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(rtner->fopArr, op);
|
||||
code = TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// do copy the file
|
||||
|
@ -167,7 +167,7 @@ static int32_t tsdbDoMigrateFileObj(SRTNer *rtner, const STFileObj *fobj, const
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(rtner->tsdb->pVnode), __func__, code, lino);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -176,38 +176,15 @@ typedef struct {
|
|||
STsdb *tsdb;
|
||||
int64_t now;
|
||||
int32_t fid;
|
||||
bool s3Migrate;
|
||||
} SRtnArg;
|
||||
|
||||
static int32_t tsdbDoRetentionBegin(SRtnArg *arg, SRTNer *rtner) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
STsdb *tsdb = arg->tsdb;
|
||||
|
||||
rtner->tsdb = tsdb;
|
||||
rtner->szPage = tsdb->pVnode->config.tsdbPageSize;
|
||||
rtner->now = arg->now;
|
||||
rtner->cid = tsdbFSAllocEid(tsdb->pFS);
|
||||
|
||||
code = tsdbFSCreateCopySnapshot(tsdb->pFS, &rtner->fsetArr);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
} else {
|
||||
tsdbDebug("vid:%d, cid:%" PRId64 ", %s done", TD_VID(rtner->tsdb->pVnode), rtner->cid, __func__);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbDoRetentionEnd(SRTNer *rtner) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (TARRAY2_SIZE(rtner->fopArr) == 0) goto _exit;
|
||||
|
||||
code = tsdbFSEditBegin(rtner->tsdb->pFS, rtner->fopArr, TSDB_FEDIT_MERGE);
|
||||
if (TARRAY2_SIZE(&rtner->fopArr) > 0) {
|
||||
code = tsdbFSEditBegin(rtner->tsdb->pFS, &rtner->fopArr, TSDB_FEDIT_RETENTION);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
taosThreadMutexLock(&rtner->tsdb->mutex);
|
||||
|
@ -220,36 +197,30 @@ static int32_t tsdbDoRetentionEnd(SRTNer *rtner) {
|
|||
|
||||
taosThreadMutexUnlock(&rtner->tsdb->mutex);
|
||||
|
||||
TARRAY2_DESTROY(rtner->fopArr, NULL);
|
||||
TARRAY2_DESTROY(&rtner->fopArr, NULL);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(rtner->tsdb->pVnode), __func__, code, lino);
|
||||
} else {
|
||||
tsdbDebug("vid:%d, cid:%" PRId64 ", %s done", TD_VID(rtner->tsdb->pVnode), rtner->cid, __func__);
|
||||
}
|
||||
tsdbFSDestroyCopySnapshot(&rtner->fsetArr);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbDoRetentionOnFileSet(SRTNer *rtner, STFileSet *fset) {
|
||||
static int32_t tsdbDoRetention(SRTNer *rtner) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STFileObj *fobj = NULL;
|
||||
STFileSet *fset = rtner->fset;
|
||||
int32_t expLevel = tsdbFidLevel(fset->fid, &rtner->tsdb->keepCfg, rtner->now);
|
||||
|
||||
if (expLevel < 0) { // remove the fileset
|
||||
for (int32_t ftype = 0; (ftype < TSDB_FTYPE_MAX) && (fobj = fset->farr[ftype], 1); ++ftype) {
|
||||
if (fobj == NULL) continue;
|
||||
/*
|
||||
int32_t nlevel = tfsGetLevel(rtner->tsdb->pVnode->pTfs);
|
||||
if (tsS3Enabled && nlevel > 1 && TSDB_FTYPE_DATA == ftype && fobj->f->did.level == nlevel - 1) {
|
||||
code = tsdbRemoveFileObjectS3(rtner, fobj);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {*/
|
||||
code = tsdbDoRemoveFileObject(rtner, fobj);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
//}
|
||||
}
|
||||
|
||||
SSttLvl *lvl;
|
||||
|
@ -275,10 +246,6 @@ static int32_t tsdbDoRetentionOnFileSet(SRTNer *rtner, STFileSet *fset) {
|
|||
if (fobj == NULL) continue;
|
||||
|
||||
if (fobj->f->did.level == did.level) {
|
||||
/*
|
||||
code = tsdbCheckMigrateS3(rtner, fobj, ftype, &did);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -306,91 +273,110 @@ static int32_t tsdbDoRetentionOnFileSet(SRTNer *rtner, STFileSet *fset) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(rtner->tsdb->pVnode), __func__, code, lino);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static void tsdbFreeRtnArg(void *arg) { taosMemoryFree(arg); }
|
||||
static void tsdbRetentionCancel(void *arg) { taosMemoryFree(arg); }
|
||||
|
||||
static int32_t tsdbDoRetentionAsync(void *arg) {
|
||||
static int32_t tsdbDoS3Migrate(SRTNer *rtner);
|
||||
|
||||
static int32_t tsdbRetention(void *arg) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SRTNer rtner[1] = {0};
|
||||
|
||||
code = tsdbDoRetentionBegin(arg, rtner);
|
||||
SRtnArg *rtnArg = (SRtnArg *)arg;
|
||||
STsdb *pTsdb = rtnArg->tsdb;
|
||||
SVnode *pVnode = pTsdb->pVnode;
|
||||
STFileSet *fset = NULL;
|
||||
SRTNer rtner = {
|
||||
.tsdb = pTsdb,
|
||||
.szPage = pVnode->config.tsdbPageSize,
|
||||
.now = rtnArg->now,
|
||||
.cid = tsdbFSAllocEid(pTsdb->pFS),
|
||||
};
|
||||
|
||||
// begin task
|
||||
taosThreadMutexLock(&pTsdb->mutex);
|
||||
tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset);
|
||||
if (fset && (code = tsdbTFileSetInitCopy(pTsdb, fset, &rtner.fset))) {
|
||||
taosThreadMutexUnlock(&pTsdb->mutex);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
taosThreadMutexUnlock(&pTsdb->mutex);
|
||||
|
||||
STFileSet *fset;
|
||||
TARRAY2_FOREACH(rtner->fsetArr, fset) {
|
||||
if (fset->fid != ((SRtnArg *)arg)->fid) continue;
|
||||
|
||||
code = tsdbDoRetentionOnFileSet(rtner, fset);
|
||||
// do retention
|
||||
if (rtner.fset) {
|
||||
if (rtnArg->s3Migrate) {
|
||||
code = tsdbDoS3Migrate(&rtner);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
code = tsdbDoRetention(&rtner);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
code = tsdbDoRetentionEnd(rtner);
|
||||
code = tsdbDoRetentionEnd(&rtner);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
if (TARRAY2_DATA(rtner->fopArr)) {
|
||||
TARRAY2_DESTROY(rtner->fopArr, NULL);
|
||||
}
|
||||
TFileSetArray **fsetArr = &rtner->fsetArr;
|
||||
if (fsetArr[0]) {
|
||||
tsdbFSDestroyCopySnapshot(&rtner->fsetArr);
|
||||
if (rtner.fset) {
|
||||
taosThreadMutexLock(&pTsdb->mutex);
|
||||
tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid);
|
||||
taosThreadMutexUnlock(&pTsdb->mutex);
|
||||
}
|
||||
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
// clear resources
|
||||
tsdbTFileSetClear(&rtner.fset);
|
||||
TARRAY2_DESTROY(&rtner.fopArr, NULL);
|
||||
taosMemoryFree(arg);
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(((SRtnArg *)arg)->tsdb->pVnode), __func__, code, lino);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbRetention(STsdb *tsdb, int64_t now, int32_t sync) {
|
||||
static int32_t tsdbAsyncRetentionImpl(STsdb *tsdb, int64_t now, bool s3Migrate) {
|
||||
int32_t code = 0;
|
||||
|
||||
taosThreadMutexLock(&tsdb->mutex);
|
||||
|
||||
if (tsdb->bgTaskDisabled) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return 0;
|
||||
}
|
||||
int32_t lino = 0;
|
||||
|
||||
STFileSet *fset;
|
||||
|
||||
if (!tsdb->bgTaskDisabled) {
|
||||
TARRAY2_FOREACH(tsdb->pFS->fSetArr, fset) {
|
||||
code = tsdbTFileSetOpenChannel(fset);
|
||||
if (code) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return code;
|
||||
}
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
SRtnArg *arg = taosMemoryMalloc(sizeof(*arg));
|
||||
if (arg == NULL) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
}
|
||||
|
||||
arg->tsdb = tsdb;
|
||||
arg->now = now;
|
||||
arg->fid = fset->fid;
|
||||
arg->s3Migrate = s3Migrate;
|
||||
|
||||
if (sync) {
|
||||
code = vnodeAsyncC(vnodeAsyncHandle[0], tsdb->pVnode->commitChannel, EVA_PRIORITY_LOW, tsdbDoRetentionAsync,
|
||||
tsdbFreeRtnArg, arg, NULL);
|
||||
} else {
|
||||
code = vnodeAsyncC(vnodeAsyncHandle[1], fset->bgTaskChannel, EVA_PRIORITY_LOW, tsdbDoRetentionAsync,
|
||||
tsdbFreeRtnArg, arg, NULL);
|
||||
if ((code = vnodeAsync(&fset->channel, EVA_PRIORITY_LOW, tsdbRetention, tsdbRetentionCancel, arg, NULL))) {
|
||||
taosMemoryFree(arg);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbFreeRtnArg(arg);
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
tsdbError("vgId:%d, %s failed, code:%d, line:%d", TD_VID(tsdb->pVnode), __func__, code, lino);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tsdbAsyncRetention(STsdb *tsdb, int64_t now) {
|
||||
int32_t code = 0;
|
||||
taosThreadMutexLock(&tsdb->mutex);
|
||||
code = tsdbAsyncRetentionImpl(tsdb, now, false);
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -462,7 +448,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
|
|||
.of = fobj->f[0],
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(rtner->fopArr, op);
|
||||
code = TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// create new
|
||||
|
@ -486,7 +472,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
|
|||
},
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(rtner->fopArr, op);
|
||||
code = TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
char fname[TSDB_FILENAME_LEN];
|
||||
|
@ -566,7 +552,7 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64
|
|||
.of = fobj->f[0],
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(rtner->fopArr, op);
|
||||
code = TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// create new
|
||||
|
@ -590,7 +576,7 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64
|
|||
},
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(rtner->fopArr, op);
|
||||
code = TARRAY2_APPEND(&rtner->fopArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
char fname[TSDB_FILENAME_LEN];
|
||||
|
@ -653,10 +639,11 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbDoS3MigrateOnFileSet(SRTNer *rtner, STFileSet *fset) {
|
||||
static int32_t tsdbDoS3Migrate(SRTNer *rtner) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
STFileSet *fset = rtner->fset;
|
||||
STFileObj *fobj = fset->farr[TSDB_FTYPE_DATA];
|
||||
if (!fobj) return code;
|
||||
|
||||
|
@ -720,41 +707,7 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbDoS3MigrateAsync(void *arg) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SRTNer rtner[1] = {0};
|
||||
|
||||
code = tsdbDoRetentionBegin(arg, rtner);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
STFileSet *fset;
|
||||
TARRAY2_FOREACH(rtner->fsetArr, fset) {
|
||||
if (fset->fid != ((SRtnArg *)arg)->fid) continue;
|
||||
|
||||
code = tsdbDoS3MigrateOnFileSet(rtner, fset);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
code = tsdbDoRetentionEnd(rtner);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
if (TARRAY2_DATA(rtner->fopArr)) {
|
||||
TARRAY2_DESTROY(rtner->fopArr, NULL);
|
||||
}
|
||||
TFileSetArray **fsetArr = &rtner->fsetArr;
|
||||
if (fsetArr[0]) {
|
||||
tsdbFSDestroyCopySnapshot(&rtner->fsetArr);
|
||||
}
|
||||
|
||||
TSDB_ERROR_LOG(TD_VID(rtner->tsdb->pVnode), lino, code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbS3Migrate(STsdb *tsdb, int64_t now, int32_t sync) {
|
||||
int32_t tsdbAsyncS3Migrate(STsdb *tsdb, int64_t now) {
|
||||
int32_t code = 0;
|
||||
|
||||
extern int8_t tsS3EnabledCfg;
|
||||
|
@ -772,45 +725,7 @@ int32_t tsdbS3Migrate(STsdb *tsdb, int64_t now, int32_t sync) {
|
|||
}
|
||||
|
||||
taosThreadMutexLock(&tsdb->mutex);
|
||||
|
||||
if (tsdb->bgTaskDisabled) {
|
||||
code = tsdbAsyncRetentionImpl(tsdb, now, true);
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
STFileSet *fset;
|
||||
TARRAY2_FOREACH(tsdb->pFS->fSetArr, fset) {
|
||||
code = tsdbTFileSetOpenChannel(fset);
|
||||
if (code) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
SRtnArg *arg = taosMemoryMalloc(sizeof(*arg));
|
||||
if (arg == NULL) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
arg->tsdb = tsdb;
|
||||
arg->now = now;
|
||||
arg->fid = fset->fid;
|
||||
|
||||
if (sync) {
|
||||
code = vnodeAsyncC(vnodeAsyncHandle[0], tsdb->pVnode->commitChannel, EVA_PRIORITY_LOW, tsdbDoS3MigrateAsync,
|
||||
tsdbFreeRtnArg, arg, NULL);
|
||||
} else {
|
||||
code = vnodeAsyncC(vnodeAsyncHandle[1], fset->bgTaskChannel, EVA_PRIORITY_LOW, tsdbDoS3MigrateAsync,
|
||||
tsdbFreeRtnArg, arg, NULL);
|
||||
}
|
||||
if (code) {
|
||||
tsdbFreeRtnArg(arg);
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -321,10 +321,10 @@ int32_t tDeserializeTsdbFSetPartList(void* buf, int32_t bufLen, STsdbFSetPartLis
|
|||
if (tDecodeI64(&decoder, &r.minVer) < 0) goto _err;
|
||||
if (tDecodeI64(&decoder, &r.maxVer) < 0) goto _err;
|
||||
if (tDecodeI64(&decoder, &reserved64) < 0) goto _err;
|
||||
TARRAY2_APPEND(iList, r);
|
||||
if (TARRAY2_APPEND(iList, r)) goto _err;
|
||||
}
|
||||
}
|
||||
TARRAY2_APPEND(pList, p);
|
||||
if (TARRAY2_APPEND(pList, p)) goto _err;
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,20 @@ struct STsdbSnapReader {
|
|||
STombBlock tombBlock[1];
|
||||
};
|
||||
|
||||
static int32_t tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
TARRAY2_CLEAR(reader->sttReaderArr, tsdbSttFileReaderClose);
|
||||
tsdbDataFileReaderClose(&reader->dataReader);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
@ -100,27 +114,16 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) {
|
|||
code = tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(reader->sttReaderArr, sttReader);
|
||||
if ((code = TARRAY2_APPEND(reader->sttReaderArr, sttReader))) {
|
||||
tsdbSttFileReaderClose(&sttReader);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
TARRAY2_CLEAR(reader->sttReaderArr, tsdbSttFileReaderClose);
|
||||
tsdbDataFileReaderClose(&reader->dataReader);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbSnapReadFileSetCloseReader(reader);
|
||||
TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino);
|
||||
}
|
||||
return code;
|
||||
|
|
|
@ -141,6 +141,7 @@ static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbSnapRAWReadFileSetCloseReader(reader);
|
||||
TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino);
|
||||
}
|
||||
return code;
|
||||
|
|
|
@ -896,7 +896,7 @@ static int32_t tsdbSttFWriterCloseAbort(SSttFileWriter *writer) {
|
|||
char fname[TSDB_FILENAME_LEN];
|
||||
tsdbTFileName(writer->config->tsdb, writer->file, fname);
|
||||
tsdbCloseFile(&writer->fd);
|
||||
taosRemoveFile(fname);
|
||||
(void)taosRemoveFile(fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record) {
|
|||
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * idx, &tombBlock->buffers[i]);
|
||||
tBufferGetI64(&br, &record->data[i]);
|
||||
int32_t code = tBufferGetI64(&br, &record->data[i]);
|
||||
if (code) return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -182,7 +183,8 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
if (block->numOfRecords > 0) {
|
||||
int64_t lastUid;
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * (block->numOfRecords - 1), &block->uids);
|
||||
tBufferGetI64(&br, &lastUid);
|
||||
int32_t code = tBufferGetI64(&br, &lastUid);
|
||||
if (code) return code;
|
||||
|
||||
if (lastUid == row->uid) {
|
||||
return tStatisBlockUpdate(block, row);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "vnd.h"
|
||||
#include "vnodeHash.h"
|
||||
|
||||
typedef struct SVAsync SVAsync;
|
||||
typedef struct SVATask SVATask;
|
||||
typedef struct SVAChannel SVAChannel;
|
||||
|
||||
|
@ -54,7 +55,7 @@ struct SVATask {
|
|||
int32_t priorScore;
|
||||
SVAChannel *channel;
|
||||
int32_t (*execute)(void *);
|
||||
void (*complete)(void *);
|
||||
void (*cancel)(void *);
|
||||
void *arg;
|
||||
EVATaskState state;
|
||||
|
||||
|
@ -67,6 +68,11 @@ struct SVATask {
|
|||
struct SVATask *next;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
void (*cancel)(void *);
|
||||
void *arg;
|
||||
} SVATaskCancelInfo;
|
||||
|
||||
#define VATASK_PIORITY(task_) ((task_)->priority - ((task_)->priorScore / 4))
|
||||
|
||||
// async channel
|
||||
|
@ -112,6 +118,10 @@ struct SVAsync {
|
|||
SVHashTable *taskTable;
|
||||
};
|
||||
|
||||
SVAsync *vnodeAsyncs[3];
|
||||
#define MIN_ASYNC_ID 1
|
||||
#define MAX_ASYNC_ID (sizeof(vnodeAsyncs) / sizeof(vnodeAsyncs[0]) - 1)
|
||||
|
||||
static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) {
|
||||
int32_t ret;
|
||||
|
||||
|
@ -160,11 +170,6 @@ static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) {
|
|||
}
|
||||
async->numTasks--;
|
||||
|
||||
// call complete callback
|
||||
if (task->complete) {
|
||||
task->complete(task->arg);
|
||||
}
|
||||
|
||||
if (task->numWait == 0) {
|
||||
taosThreadCondDestroy(&task->waitCond);
|
||||
taosMemoryFree(task);
|
||||
|
@ -176,7 +181,7 @@ static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodeAsyncCancelAllTasks(SVAsync *async) {
|
||||
static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) {
|
||||
while (async->queue[0].next != &async->queue[0] || async->queue[1].next != &async->queue[1] ||
|
||||
async->queue[2].next != &async->queue[2]) {
|
||||
for (int32_t i = 0; i < EVA_PRIORITY_MAX; i++) {
|
||||
|
@ -184,6 +189,12 @@ static int32_t vnodeAsyncCancelAllTasks(SVAsync *async) {
|
|||
SVATask *task = async->queue[i].next;
|
||||
task->prev->next = task->next;
|
||||
task->next->prev = task->prev;
|
||||
if (task->cancel) {
|
||||
taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
||||
.cancel = task->cancel,
|
||||
.arg = task->arg,
|
||||
});
|
||||
}
|
||||
vnodeAsyncTaskDone(async, task);
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +205,7 @@ static int32_t vnodeAsyncCancelAllTasks(SVAsync *async) {
|
|||
static void *vnodeAsyncLoop(void *arg) {
|
||||
SVWorker *worker = (SVWorker *)arg;
|
||||
SVAsync *async = worker->async;
|
||||
SArray *cancelArray = taosArrayInit(0, sizeof(SVATaskCancelInfo));
|
||||
|
||||
setThreadName(async->label);
|
||||
|
||||
|
@ -209,12 +221,12 @@ static void *vnodeAsyncLoop(void *arg) {
|
|||
for (;;) {
|
||||
if (async->stop || worker->workerId >= async->numWorkers) {
|
||||
if (async->stop) { // cancel all tasks
|
||||
vnodeAsyncCancelAllTasks(async);
|
||||
vnodeAsyncCancelAllTasks(async, cancelArray);
|
||||
}
|
||||
worker->state = EVA_WORKER_STATE_STOP;
|
||||
async->numLaunchWorkers--;
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
return NULL;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < EVA_PRIORITY_MAX; i++) {
|
||||
|
@ -259,6 +271,12 @@ static void *vnodeAsyncLoop(void *arg) {
|
|||
worker->runningTask->execute(worker->runningTask->arg);
|
||||
}
|
||||
|
||||
_exit:
|
||||
for (int32_t i = 0; i < taosArrayGetSize(cancelArray); i++) {
|
||||
SVATaskCancelInfo *cancel = (SVATaskCancelInfo *)taosArrayGet(cancelArray, i);
|
||||
cancel->cancel(cancel->arg);
|
||||
}
|
||||
taosArrayDestroy(cancelArray);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -294,7 +312,7 @@ static int32_t vnodeAsyncChannelCompare(const void *obj1, const void *obj2) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAsyncInit(SVAsync **async, char *label) {
|
||||
static int32_t vnodeAsyncInit(SVAsync **async, const char *label) {
|
||||
int32_t ret;
|
||||
|
||||
if (async == NULL) {
|
||||
|
@ -360,7 +378,7 @@ int32_t vnodeAsyncInit(SVAsync **async, char *label) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAsyncDestroy(SVAsync **async) {
|
||||
static int32_t vnodeAsyncDestroy(SVAsync **async) {
|
||||
if ((*async) == NULL) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
@ -433,20 +451,39 @@ static int32_t vnodeAsyncLaunchWorker(SVAsync *async) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef BUILD_NO_CALL
|
||||
int32_t vnodeAsync(SVAsync *async, EVAPriority priority, int32_t (*execute)(void *), void (*complete)(void *),
|
||||
void *arg, int64_t *taskId) {
|
||||
return vnodeAsyncC(async, 0, priority, execute, complete, arg, taskId);
|
||||
}
|
||||
#endif
|
||||
int32_t vnodeAsyncOpen(int32_t numOfThreads) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
int32_t vnodeAsyncC(SVAsync *async, int64_t channelId, EVAPriority priority, int32_t (*execute)(void *),
|
||||
void (*complete)(void *), void *arg, int64_t *taskId) {
|
||||
if (async == NULL || execute == NULL || channelId < 0) {
|
||||
// vnode-commit
|
||||
code = vnodeAsyncInit(&vnodeAsyncs[1], "vnode-commit");
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
vnodeAsyncSetWorkers(1, numOfThreads);
|
||||
|
||||
// vnode-merge
|
||||
code = vnodeAsyncInit(&vnodeAsyncs[2], "vnode-merge");
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
vnodeAsyncSetWorkers(2, numOfThreads);
|
||||
|
||||
_exit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAsyncClose() {
|
||||
vnodeAsyncDestroy(&vnodeAsyncs[1]);
|
||||
vnodeAsyncDestroy(&vnodeAsyncs[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*execute)(void *), void (*cancel)(void *),
|
||||
void *arg, SVATaskID *taskID) {
|
||||
if (channelID == NULL || channelID->async < MIN_ASYNC_ID || channelID->async > MAX_ASYNC_ID || execute == NULL ||
|
||||
channelID->id < 0) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int64_t id;
|
||||
SVAsync *async = vnodeAsyncs[channelID->async];
|
||||
|
||||
// create task object
|
||||
SVATask *task = (SVATask *)taosMemoryCalloc(1, sizeof(SVATask));
|
||||
|
@ -457,7 +494,7 @@ int32_t vnodeAsyncC(SVAsync *async, int64_t channelId, EVAPriority priority, int
|
|||
task->priority = priority;
|
||||
task->priorScore = 0;
|
||||
task->execute = execute;
|
||||
task->complete = complete;
|
||||
task->cancel = cancel;
|
||||
task->arg = arg;
|
||||
task->state = EVA_TASK_STATE_WAITTING;
|
||||
task->numWait = 0;
|
||||
|
@ -466,10 +503,12 @@ int32_t vnodeAsyncC(SVAsync *async, int64_t channelId, EVAPriority priority, int
|
|||
// schedule task
|
||||
taosThreadMutexLock(&async->mutex);
|
||||
|
||||
if (channelId == 0) {
|
||||
if (channelID->id == 0) {
|
||||
task->channel = NULL;
|
||||
} else {
|
||||
SVAChannel channel = {.channelId = channelId};
|
||||
SVAChannel channel = {
|
||||
.channelId = channelID->id,
|
||||
};
|
||||
vHashGet(async->channelTable, &channel, (void **)&task->channel);
|
||||
if (task->channel == NULL) {
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
|
@ -540,20 +579,24 @@ int32_t vnodeAsyncC(SVAsync *async, int64_t channelId, EVAPriority priority, int
|
|||
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
|
||||
if (taskId != NULL) {
|
||||
*taskId = id;
|
||||
if (taskID != NULL) {
|
||||
taskID->async = channelID->async;
|
||||
taskID->id = id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAWait(SVAsync *async, int64_t taskId) {
|
||||
if (async == NULL || taskId <= 0) {
|
||||
int32_t vnodeAWait(SVATaskID *taskID) {
|
||||
if (taskID == NULL || taskID->async < MIN_ASYNC_ID || taskID->async > MAX_ASYNC_ID || taskID->id <= 0) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
SVAsync *async = vnodeAsyncs[taskID->async];
|
||||
SVATask *task = NULL;
|
||||
SVATask task2 = {.taskId = taskId};
|
||||
SVATask task2 = {
|
||||
.taskId = taskID->id,
|
||||
};
|
||||
|
||||
taosThreadMutexLock(&async->mutex);
|
||||
|
||||
|
@ -574,21 +617,27 @@ int32_t vnodeAWait(SVAsync *async, int64_t taskId) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeACancel(SVAsync *async, int64_t taskId) {
|
||||
if (async == NULL) {
|
||||
int32_t vnodeACancel(SVATaskID *taskID) {
|
||||
if (taskID == NULL || taskID->async < MIN_ASYNC_ID || taskID->async > MAX_ASYNC_ID || taskID->id <= 0) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
SVAsync *async = vnodeAsyncs[taskID->async];
|
||||
SVATask *task = NULL;
|
||||
SVATask task2 = {.taskId = taskId};
|
||||
SVATask task2 = {
|
||||
.taskId = taskID->id,
|
||||
};
|
||||
void (*cancel)(void *) = NULL;
|
||||
void *arg = NULL;
|
||||
|
||||
taosThreadMutexLock(&async->mutex);
|
||||
|
||||
vHashGet(async->taskTable, &task2, (void **)&task);
|
||||
if (task) {
|
||||
if (task->state == EVA_TASK_STATE_WAITTING) {
|
||||
// remove from queue
|
||||
cancel = task->cancel;
|
||||
arg = task->arg;
|
||||
task->next->prev = task->prev;
|
||||
task->prev->next = task->next;
|
||||
vnodeAsyncTaskDone(async, task);
|
||||
|
@ -599,14 +648,18 @@ int32_t vnodeACancel(SVAsync *async, int64_t taskId) {
|
|||
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
|
||||
if (cancel) {
|
||||
cancel(arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t vnodeAsyncSetWorkers(SVAsync *async, int32_t numWorkers) {
|
||||
if (async == NULL || numWorkers <= 0 || numWorkers > VNODE_ASYNC_MAX_WORKERS) {
|
||||
int32_t vnodeAsyncSetWorkers(int64_t asyncID, int32_t numWorkers) {
|
||||
if (asyncID < MIN_ASYNC_ID || asyncID > MAX_ASYNC_ID || numWorkers <= 0 || numWorkers > VNODE_ASYNC_MAX_WORKERS) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
SVAsync *async = vnodeAsyncs[asyncID];
|
||||
taosThreadMutexLock(&async->mutex);
|
||||
async->numWorkers = numWorkers;
|
||||
if (async->numIdleWorkers > 0) {
|
||||
|
@ -617,11 +670,13 @@ int32_t vnodeAsyncSetWorkers(SVAsync *async, int32_t numWorkers) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAChannelInit(SVAsync *async, int64_t *channelId) {
|
||||
if (async == NULL || channelId == NULL) {
|
||||
int32_t vnodeAChannelInit(int64_t asyncID, SVAChannelID *channelID) {
|
||||
if (channelID == NULL || asyncID < MIN_ASYNC_ID || asyncID > MAX_ASYNC_ID) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
SVAsync *async = vnodeAsyncs[asyncID];
|
||||
|
||||
// create channel object
|
||||
SVAChannel *channel = (SVAChannel *)taosMemoryMalloc(sizeof(SVAChannel));
|
||||
if (channel == NULL) {
|
||||
|
@ -637,7 +692,7 @@ int32_t vnodeAChannelInit(SVAsync *async, int64_t *channelId) {
|
|||
// register channel
|
||||
taosThreadMutexLock(&async->mutex);
|
||||
|
||||
channel->channelId = *channelId = ++async->nextChannelId;
|
||||
channel->channelId = channelID->id = ++async->nextChannelId;
|
||||
|
||||
// add to hash table
|
||||
int32_t ret = vHashPut(async->channelTable, channel);
|
||||
|
@ -657,16 +712,24 @@ int32_t vnodeAChannelInit(SVAsync *async, int64_t *channelId) {
|
|||
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
|
||||
channelID->async = asyncID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAChannelDestroy(SVAsync *async, int64_t channelId, bool waitRunning) {
|
||||
if (async == NULL || channelId <= 0) {
|
||||
int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) {
|
||||
if (channelID == NULL || channelID->async < MIN_ASYNC_ID || channelID->async > MAX_ASYNC_ID || channelID->id <= 0) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
SVAsync *async = vnodeAsyncs[channelID->async];
|
||||
SVAChannel *channel = NULL;
|
||||
SVAChannel channel2 = {.channelId = channelId};
|
||||
SVAChannel channel2 = {
|
||||
.channelId = channelID->id,
|
||||
};
|
||||
SArray *cancelArray = taosArrayInit(0, sizeof(SVATaskCancelInfo));
|
||||
if (cancelArray == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&async->mutex);
|
||||
|
||||
|
@ -684,6 +747,12 @@ int32_t vnodeAChannelDestroy(SVAsync *async, int64_t channelId, bool waitRunning
|
|||
SVATask *task = channel->queue[i].next;
|
||||
task->prev->next = task->next;
|
||||
task->next->prev = task->prev;
|
||||
if (task->cancel) {
|
||||
taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
||||
.cancel = task->cancel,
|
||||
.arg = task->arg,
|
||||
});
|
||||
}
|
||||
vnodeAsyncTaskDone(async, task);
|
||||
}
|
||||
}
|
||||
|
@ -693,6 +762,12 @@ int32_t vnodeAChannelDestroy(SVAsync *async, int64_t channelId, bool waitRunning
|
|||
if (channel->scheduled) {
|
||||
channel->scheduled->prev->next = channel->scheduled->next;
|
||||
channel->scheduled->next->prev = channel->scheduled->prev;
|
||||
if (channel->scheduled->cancel) {
|
||||
taosArrayPush(cancelArray, &(SVATaskCancelInfo){
|
||||
.cancel = channel->scheduled->cancel,
|
||||
.arg = channel->scheduled->arg,
|
||||
});
|
||||
}
|
||||
vnodeAsyncTaskDone(async, channel->scheduled);
|
||||
}
|
||||
taosMemoryFree(channel);
|
||||
|
@ -713,12 +788,16 @@ int32_t vnodeAChannelDestroy(SVAsync *async, int64_t channelId, bool waitRunning
|
|||
channel->state = EVA_CHANNEL_STATE_CLOSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&async->mutex);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(cancelArray); i++) {
|
||||
SVATaskCancelInfo *cancel = (SVATaskCancelInfo *)taosArrayGet(cancelArray, i);
|
||||
cancel->cancel(cancel->arg);
|
||||
}
|
||||
taosArrayDestroy(cancelArray);
|
||||
|
||||
channelID->async = 0;
|
||||
channelID->id = 0;
|
||||
return 0;
|
||||
}
|
|
@ -160,6 +160,12 @@ int vnodeShouldCommit(SVnode *pVnode, bool atExit) {
|
|||
(atExit && (pVnode->inUse->size > 0 || pVnode->pMeta->changed ||
|
||||
pVnode->state.applied - pVnode->state.committed > 4096));
|
||||
}
|
||||
vTrace("vgId:%d, should commit:%d, disk available:%d, buffer size:%" PRId64 ", node size:%" PRId64
|
||||
", meta changed:%d"
|
||||
", state:[%" PRId64 ",%" PRId64 "]",
|
||||
TD_VID(pVnode), needCommit, diskAvail, pVnode->inUse ? pVnode->inUse->size : 0,
|
||||
pVnode->inUse ? pVnode->inUse->node.size : 0, pVnode->pMeta->changed, pVnode->state.applied,
|
||||
pVnode->state.committed);
|
||||
taosThreadMutexUnlock(&pVnode->mutex);
|
||||
return needCommit;
|
||||
}
|
||||
|
@ -289,7 +295,7 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
|
|||
int64_t lastCommitted = pInfo->info.state.committed;
|
||||
|
||||
// wait last commit task
|
||||
vnodeAWait(vnodeAsyncHandle[0], pVnode->commitTask);
|
||||
vnodeAWait(&pVnode->commitTask);
|
||||
|
||||
if (syncNodeGetConfig(pVnode->sync, &pVnode->config.syncCfg) != 0) goto _exit;
|
||||
|
||||
|
@ -361,15 +367,14 @@ static void vnodeReturnBufPool(SVnode *pVnode) {
|
|||
|
||||
taosThreadMutexUnlock(&pVnode->mutex);
|
||||
}
|
||||
static int32_t vnodeCommitTask(void *arg) {
|
||||
static int32_t vnodeCommit(void *arg) {
|
||||
int32_t code = 0;
|
||||
|
||||
SCommitInfo *pInfo = (SCommitInfo *)arg;
|
||||
SVnode *pVnode = pInfo->pVnode;
|
||||
|
||||
// commit
|
||||
code = vnodeCommitImpl(pInfo);
|
||||
if (code) {
|
||||
if ((code = vnodeCommitImpl(pInfo))) {
|
||||
vFatal("vgId:%d, failed to commit vnode since %s", TD_VID(pVnode), terrstr());
|
||||
taosMsleep(100);
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -379,37 +384,34 @@ static int32_t vnodeCommitTask(void *arg) {
|
|||
vnodeReturnBufPool(pVnode);
|
||||
|
||||
_exit:
|
||||
taosMemoryFree(arg);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void vnodeCompleteCommit(void *arg) { taosMemoryFree(arg); }
|
||||
static void vnodeCommitCancel(void *arg) { taosMemoryFree(arg); }
|
||||
|
||||
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
SCommitInfo *pInfo = (SCommitInfo *)taosMemoryCalloc(1, sizeof(*pInfo));
|
||||
if (NULL == pInfo) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
}
|
||||
|
||||
// prepare to commit
|
||||
code = vnodePrepareCommit(pVnode, pInfo);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// schedule the task
|
||||
code = vnodeAsyncC(vnodeAsyncHandle[0], pVnode->commitChannel, EVA_PRIORITY_HIGH, vnodeCommitTask,
|
||||
vnodeCompleteCommit, pInfo, &pVnode->commitTask);
|
||||
code =
|
||||
vnodeAsync(&pVnode->commitChannel, EVA_PRIORITY_HIGH, vnodeCommit, vnodeCommitCancel, pInfo, &pVnode->commitTask);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
if (NULL != pInfo) {
|
||||
taosMemoryFree(pInfo);
|
||||
}
|
||||
vError("vgId:%d, %s failed since %s, commit id:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code),
|
||||
pVnode->state.commitID);
|
||||
vError("vgId:%d %s failed at line %d since %s" PRId64, TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
} else {
|
||||
vInfo("vgId:%d, vnode async commit done, commitId:%" PRId64 " term:%" PRId64 " applied:%" PRId64, TD_VID(pVnode),
|
||||
pVnode->state.commitID, pVnode->state.applyTerm, pVnode->state.applied);
|
||||
|
@ -419,7 +421,7 @@ _exit:
|
|||
|
||||
int vnodeSyncCommit(SVnode *pVnode) {
|
||||
vnodeAsyncCommit(pVnode);
|
||||
vnodeAWait(vnodeAsyncHandle[0], pVnode->commitTask);
|
||||
vnodeAWait(&pVnode->commitTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,23 +22,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SVHashTable SVHashTable;
|
||||
|
||||
struct SVHashTable {
|
||||
uint32_t (*hash)(const void*);
|
||||
int32_t (*compare)(const void*, const void*);
|
||||
int32_t numEntries;
|
||||
uint32_t numBuckets;
|
||||
struct SVHashEntry** buckets;
|
||||
};
|
||||
|
||||
#define vHashNumEntries(ht) ((ht)->numEntries)
|
||||
int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*));
|
||||
int32_t vHashDestroy(SVHashTable** ht);
|
||||
int32_t vHashPut(SVHashTable* ht, void* obj);
|
||||
int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj);
|
||||
int32_t vHashDrop(SVHashTable* ht, const void* obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
static volatile int32_t VINIT = 0;
|
||||
|
||||
SVAsync* vnodeAsyncHandle[2];
|
||||
|
||||
int vnodeInit(int nthreads) {
|
||||
int32_t init;
|
||||
|
||||
|
@ -28,13 +26,9 @@ int vnodeInit(int nthreads) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// vnode-commit
|
||||
vnodeAsyncInit(&vnodeAsyncHandle[0], "vnode-commit");
|
||||
vnodeAsyncSetWorkers(vnodeAsyncHandle[0], nthreads);
|
||||
|
||||
// vnode-merge
|
||||
vnodeAsyncInit(&vnodeAsyncHandle[1], "vnode-merge");
|
||||
vnodeAsyncSetWorkers(vnodeAsyncHandle[1], nthreads);
|
||||
if (vnodeAsyncOpen(nthreads) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (walInit() < 0) {
|
||||
return -1;
|
||||
|
@ -48,8 +42,7 @@ void vnodeCleanup() {
|
|||
if (init == 0) return;
|
||||
|
||||
// set stop
|
||||
vnodeAsyncDestroy(&vnodeAsyncHandle[0]);
|
||||
vnodeAsyncDestroy(&vnodeAsyncHandle[1]);
|
||||
vnodeAsyncClose();
|
||||
|
||||
walCleanUp();
|
||||
smaCleanUp();
|
||||
|
|
|
@ -399,7 +399,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
|
|||
taosThreadMutexInit(&pVnode->mutex, NULL);
|
||||
taosThreadCondInit(&pVnode->poolNotEmpty, NULL);
|
||||
|
||||
if (vnodeAChannelInit(vnodeAsyncHandle[0], &pVnode->commitChannel) != 0) {
|
||||
if (vnodeAChannelInit(1, &pVnode->commitChannel) != 0) {
|
||||
vError("vgId:%d, failed to init commit channel", TD_VID(pVnode));
|
||||
goto _err;
|
||||
}
|
||||
|
@ -527,8 +527,8 @@ void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); }
|
|||
|
||||
void vnodeClose(SVnode *pVnode) {
|
||||
if (pVnode) {
|
||||
vnodeAWait(vnodeAsyncHandle[0], pVnode->commitTask);
|
||||
vnodeAChannelDestroy(vnodeAsyncHandle[0], pVnode->commitChannel, true);
|
||||
vnodeAWait(&pVnode->commitTask);
|
||||
vnodeAChannelDestroy(&pVnode->commitChannel, true);
|
||||
vnodeSyncClose(pVnode);
|
||||
vnodeQueryClose(pVnode);
|
||||
tqClose(pVnode->pTq);
|
||||
|
|
|
@ -15,20 +15,15 @@
|
|||
|
||||
#include "vnd.h"
|
||||
|
||||
int32_t vnodeDoRetention(SVnode *pVnode, int64_t now) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
extern int32_t tsdbAsyncRetention(STsdb *tsdb, int64_t now);
|
||||
extern int32_t tsdbAsyncS3Migrate(STsdb *tsdb, int64_t now);
|
||||
|
||||
code = tsdbRetention(pVnode->pTsdb, now, pVnode->config.sttTrigger == 1);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) code = smaRetention(pVnode->pSma, now);
|
||||
|
||||
return code;
|
||||
int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now) {
|
||||
// async retention
|
||||
return tsdbAsyncRetention(pVnode->pTsdb, now);
|
||||
}
|
||||
|
||||
int32_t vnodeDoS3Migrate(SVnode *pVnode, int64_t now) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
code = tsdbS3Migrate(pVnode->pTsdb, now, pVnode->config.sttTrigger == 1);
|
||||
|
||||
return code;
|
||||
int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now) {
|
||||
// async migration
|
||||
return tsdbAsyncS3Migrate(pVnode->pTsdb, now);
|
||||
}
|
||||
|
|
|
@ -622,13 +622,13 @@ extern int32_t tsdbEnableBgTask(STsdb *pTsdb);
|
|||
static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) {
|
||||
tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
|
||||
vnodeSyncCommit(pVnode);
|
||||
vnodeAChannelDestroy(vnodeAsyncHandle[0], pVnode->commitChannel, true);
|
||||
vnodeAChannelDestroy(&pVnode->commitChannel, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodeEnableBgTask(SVnode *pVnode) {
|
||||
tsdbEnableBgTask(pVnode->pTsdb);
|
||||
vnodeAChannelInit(vnodeAsyncHandle[0], &pVnode->commitChannel);
|
||||
vnodeAChannelInit(1, &pVnode->commitChannel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t l
|
|||
|
||||
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
|
||||
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
|
||||
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void* pReq, int32_t len, SRpcMsg* pRsp);
|
||||
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
||||
extern int32_t vnodeProcessKillCompactReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
extern int32_t vnodeQueryCompactProgress(SVnode *pVnode, SRpcMsg *pMsg);
|
||||
|
@ -866,7 +866,7 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
|
|||
pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
|
||||
}
|
||||
|
||||
extern int32_t vnodeDoRetention(SVnode *pVnode, int64_t now);
|
||||
extern int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now);
|
||||
|
||||
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
|
@ -880,13 +880,13 @@ static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int3
|
|||
|
||||
vInfo("vgId:%d, trim vnode request will be processed, time:%d", pVnode->config.vgId, trimReq.timestamp);
|
||||
|
||||
code = vnodeDoRetention(pVnode, trimReq.timestamp);
|
||||
code = vnodeAsyncRetention(pVnode, trimReq.timestamp);
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
extern int32_t vnodeDoS3Migrate(SVnode *pVnode, int64_t now);
|
||||
extern int32_t vnodeAsyncS3Migrate(SVnode *pVnode, int64_t now);
|
||||
|
||||
static int32_t vnodeProcessS3MigrateReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
|
@ -900,7 +900,7 @@ static int32_t vnodeProcessS3MigrateReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
|
||||
vInfo("vgId:%d, s3migrate vnode request will be processed, time:%d", pVnode->config.vgId, s3migrateReq.timestamp);
|
||||
|
||||
code = vnodeDoS3Migrate(pVnode, s3migrateReq.timestamp);
|
||||
code = vnodeAsyncS3Migrate(pVnode, s3migrateReq.timestamp);
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
|
@ -931,13 +931,13 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void* pReq, int32_t len, SRpcMsg* pRsp) {
|
||||
static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = -1;
|
||||
SMetaReader mr = {0};
|
||||
SVDropTtlTableReq ttlReq = {0};
|
||||
SVFetchTtlExpiredTbsRsp rsp = {0};
|
||||
SEncoder encoder = {0};
|
||||
SArray* pNames = NULL;
|
||||
SArray *pNames = NULL;
|
||||
pRsp->msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
pRsp->pCont = NULL;
|
||||
|
@ -965,12 +965,12 @@ static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void*
|
|||
}
|
||||
char buf[TSDB_TABLE_NAME_LEN];
|
||||
for (int32_t i = 0; i < ttlReq.nUids; ++i) {
|
||||
tb_uid_t* uid = taosArrayGet(ttlReq.pTbUids, i);
|
||||
tb_uid_t *uid = taosArrayGet(ttlReq.pTbUids, i);
|
||||
expiredTb.suid = *uid;
|
||||
terrno = metaReaderGetTableEntryByUid(&mr, *uid);
|
||||
if (terrno < 0) goto _end;
|
||||
strncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
void* p = taosArrayPush(pNames, buf);
|
||||
void *p = taosArrayPush(pNames, buf);
|
||||
expiredTb.name = p;
|
||||
if (mr.me.type == TSDB_CHILD_TABLE) {
|
||||
expiredTb.suid = mr.me.ctbEntry.suid;
|
||||
|
@ -1144,7 +1144,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
if (i < tbNames->size - 1) {
|
||||
taosStringBuilderAppendChar(&sb, ',');
|
||||
}
|
||||
//taosMemoryFreeClear(*key);
|
||||
// taosMemoryFreeClear(*key);
|
||||
}
|
||||
|
||||
size_t len = 0;
|
||||
|
@ -1158,12 +1158,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
}
|
||||
|
||||
_exit:
|
||||
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
||||
pCreateReq = req.pReqs + iReq;
|
||||
taosMemoryFree(pCreateReq->sql);
|
||||
taosMemoryFree(pCreateReq->comment);
|
||||
taosArrayDestroy(pCreateReq->ctb.tagName);
|
||||
}
|
||||
tDeleteSVCreateTbBatchReq(&req);
|
||||
taosArrayDestroyEx(rsp.pArray, tFreeSVCreateTbRsp);
|
||||
taosArrayDestroy(tbUids);
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -2241,14 +2236,14 @@ static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
extern int32_t vnodeProcessCompactVnodeReqImpl(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
extern int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
||||
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
if (!pVnode->restored) {
|
||||
vInfo("vgId:%d, ignore compact req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
|
||||
return 0;
|
||||
}
|
||||
return vnodeProcessCompactVnodeReqImpl(pVnode, ver, pReq, len, pRsp);
|
||||
return vnodeAsyncCompact(pVnode, ver, pReq, len, pRsp);
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
|
@ -2355,8 +2350,6 @@ _OVER:
|
|||
}
|
||||
|
||||
#ifndef TD_ENTERPRISE
|
||||
int32_t vnodeProcessCompactVnodeReqImpl(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
return 0;
|
||||
}
|
||||
int32_t vnodeAsyncCompact(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { return 0; }
|
||||
int32_t tsdbAsyncCompact(STsdb *tsdb, const STimeWindow *tw, bool sync) { return 0; }
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,7 @@ typedef struct STaskStopInfo {
|
|||
|
||||
typedef struct {
|
||||
STqOffsetVal currentOffset; // for tmq
|
||||
SMqMetaRsp metaRsp; // for tmq fetching meta
|
||||
SMqBatchMetaRsp btMetaRsp; // for tmq fetching meta
|
||||
int8_t sourceExcluded;
|
||||
int64_t snapshotVer;
|
||||
SSchemaWrapper* schema;
|
||||
|
|
|
@ -67,7 +67,12 @@ static void clearWinStateBuff(SCountWindowResult* pBuff) {
|
|||
|
||||
static SCountWindowResult* getCountWinStateInfo(SCountWindowSupp* pCountSup) {
|
||||
SCountWindowResult* pBuffInfo = taosArrayGet(pCountSup->pWinStates, pCountSup->stateIndex);
|
||||
pCountSup->stateIndex = (pCountSup->stateIndex + 1) % taosArrayGetSize(pCountSup->pWinStates);
|
||||
int32_t size = taosArrayGetSize(pCountSup->pWinStates);
|
||||
// coverity scan
|
||||
ASSERTS(size > 0, "WinStates is empty");
|
||||
if (size > 0) {
|
||||
pCountSup->stateIndex = (pCountSup->stateIndex + 1) % size;
|
||||
}
|
||||
return pBuffInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
|||
goto _error;
|
||||
}
|
||||
|
||||
tmemory_barrier();
|
||||
SRetrieveTableRsp* pRsp = pDataInfo->pRsp;
|
||||
SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, pDataInfo->index);
|
||||
|
||||
|
@ -428,6 +429,7 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
}
|
||||
|
||||
tmemory_barrier();
|
||||
pSourceDataInfo->status = EX_SOURCE_DATA_READY;
|
||||
code = tsem_post(&pExchangeInfo->ready);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -1078,9 +1078,9 @@ const char* qExtractTbnameFromTask(qTaskInfo_t tinfo) {
|
|||
return pTaskInfo->streamInfo.tbName;
|
||||
}
|
||||
|
||||
SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
|
||||
SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
return &pTaskInfo->streamInfo.metaRsp;
|
||||
return &pTaskInfo->streamInfo.btMetaRsp;
|
||||
}
|
||||
|
||||
void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
||||
|
|
|
@ -1363,6 +1363,12 @@ static SSDataBlock* readPreVersionData(SOperatorInfo* pTableScanOp, uint64_t tbU
|
|||
}
|
||||
|
||||
bool comparePrimaryKey(SColumnInfoData* pCol, int32_t rowId, void* pVal) {
|
||||
// coverity scan
|
||||
ASSERTS(pVal != NULL, "pVal should not be NULL");
|
||||
if (!pVal) {
|
||||
qError("failed to compare primary key, since primary key is null");
|
||||
return false;
|
||||
}
|
||||
void* pData = colDataGetData(pCol, rowId);
|
||||
if (IS_VAR_DATA_TYPE(pCol->info.type)) {
|
||||
int32_t colLen = varDataLen(pData);
|
||||
|
@ -1469,8 +1475,13 @@ static bool prepareRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_
|
|||
}
|
||||
|
||||
STableScanInfo* pTScanInfo = pInfo->pTableScanOp->info;
|
||||
qDebug("prepare range scan start:%" PRId64 ",end:%" PRId64 ",maxVer:%" PRIu64, win.skey, win.ekey, pInfo->pUpdateInfo->maxDataVersion);
|
||||
// coverity scan
|
||||
ASSERTS(pInfo->pUpdateInfo != NULL, "Failed to set data version, since pInfo->pUpdateInfo is NULL");
|
||||
if (pInfo->pUpdateInfo) {
|
||||
qDebug("prepare range scan start:%" PRId64 ",end:%" PRId64 ",maxVer:%" PRIu64, win.skey, win.ekey,
|
||||
pInfo->pUpdateInfo->maxDataVersion);
|
||||
resetTableScanInfo(pInfo->pTableScanOp->info, &win, pInfo->pUpdateInfo->maxDataVersion);
|
||||
}
|
||||
pInfo->pTableScanOp->status = OP_OPENED;
|
||||
return true;
|
||||
}
|
||||
|
@ -2845,8 +2856,8 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
|
||||
SStreamRawScanInfo* pInfo = pOperator->info;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pTaskInfo->streamInfo.metaRsp.metaRspLen = 0; // use metaRspLen !=0 to judge if data is meta
|
||||
pTaskInfo->streamInfo.metaRsp.metaRsp = NULL;
|
||||
pTaskInfo->streamInfo.btMetaRsp.batchMetaReq = NULL; // use batchMetaReq != NULL to judge if data is meta
|
||||
pTaskInfo->streamInfo.btMetaRsp.batchMetaLen = NULL;
|
||||
|
||||
qDebug("tmqsnap doRawScan called");
|
||||
if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
|
@ -2893,6 +2904,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
} else if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_META) {
|
||||
SSnapContext* sContext = pInfo->sContext;
|
||||
for(int32_t i = 0; i < tmqRowSize; i++) {
|
||||
void* data = NULL;
|
||||
int32_t dataLen = 0;
|
||||
int16_t type = 0;
|
||||
|
@ -2900,7 +2912,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
if (pAPI->snapshotFn.getTableInfoFromSnapshot(sContext, &data, &dataLen, &type, &uid) < 0) {
|
||||
qError("tmqsnap getTableInfoFromSnapshot error");
|
||||
taosMemoryFreeClear(data);
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!sContext->queryMeta) { // change to get data next poll request
|
||||
|
@ -2908,13 +2920,44 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
SValue val = {0};
|
||||
tqOffsetResetToData(&offset, 0, INT64_MIN, val);
|
||||
qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
|
||||
break;
|
||||
} else {
|
||||
tqOffsetResetToMeta(&pTaskInfo->streamInfo.currentOffset, uid);
|
||||
pTaskInfo->streamInfo.metaRsp.resMsgType = type;
|
||||
pTaskInfo->streamInfo.metaRsp.metaRspLen = dataLen;
|
||||
pTaskInfo->streamInfo.metaRsp.metaRsp = data;
|
||||
SMqMetaRsp tmpMetaRsp = {0};
|
||||
tmpMetaRsp.resMsgType = type;
|
||||
tmpMetaRsp.metaRspLen = dataLen;
|
||||
tmpMetaRsp.metaRsp = data;
|
||||
if (!pTaskInfo->streamInfo.btMetaRsp.batchMetaReq) {
|
||||
pTaskInfo->streamInfo.btMetaRsp.batchMetaReq = taosArrayInit(4, POINTER_BYTES);
|
||||
pTaskInfo->streamInfo.btMetaRsp.batchMetaLen = taosArrayInit(4, sizeof(int32_t));
|
||||
}
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
uint32_t len = 0;
|
||||
tEncodeSize(tEncodeMqMetaRsp, &tmpMetaRsp, len, code);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
qError("tmqsnap tEncodeMqMetaRsp error");
|
||||
taosMemoryFreeClear(data);
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t tLen = sizeof(SMqRspHead) + len;
|
||||
void* tBuf = taosMemoryCalloc(1, tLen);
|
||||
void* metaBuff = POINTER_SHIFT(tBuf, sizeof(SMqRspHead));
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, metaBuff, len);
|
||||
code = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
|
||||
if (code < 0) {
|
||||
qError("tmqsnap tEncodeMqMetaRsp error");
|
||||
tEncoderClear(&encoder);
|
||||
taosMemoryFreeClear(tBuf);
|
||||
taosMemoryFreeClear(data);
|
||||
break;
|
||||
}
|
||||
taosMemoryFreeClear(data);
|
||||
taosArrayPush(pTaskInfo->streamInfo.btMetaRsp.batchMetaReq, &tBuf);
|
||||
taosArrayPush(pTaskInfo->streamInfo.btMetaRsp.batchMetaLen, &tLen);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -677,6 +677,14 @@ SOperatorInfo* createStreamCountAggOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->twAggSup = (STimeWindowAggSupp){
|
||||
.waterMark = pCountNode->window.watermark,
|
||||
.calTrigger = pCountNode->window.triggerType,
|
||||
.maxTs = INT64_MIN,
|
||||
.minTs = INT64_MAX,
|
||||
.deleteMark = getDeleteMark(&pCountNode->window, 0),
|
||||
};
|
||||
|
||||
pInfo->primaryTsIndex = ((SColumnNode*)pCountNode->window.pTspk)->slotId;
|
||||
code = initStreamAggSupporter(&pInfo->streamAggSup, pExpSup, numOfCols, 0,
|
||||
pTaskInfo->streamInfo.pState, sizeof(COUNT_TYPE), 0, &pTaskInfo->storageAPI.stateStore, pHandle,
|
||||
|
@ -687,13 +695,6 @@ SOperatorInfo* createStreamCountAggOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
pInfo->streamAggSup.windowCount = pCountNode->windowCount;
|
||||
pInfo->streamAggSup.windowSliding = pCountNode->windowSliding;
|
||||
|
||||
pInfo->twAggSup = (STimeWindowAggSupp){
|
||||
.waterMark = pCountNode->window.watermark,
|
||||
.calTrigger = pCountNode->window.triggerType,
|
||||
.maxTs = INT64_MIN,
|
||||
.minTs = INT64_MAX,
|
||||
};
|
||||
|
||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
||||
|
||||
pInfo->binfo.pRes = pResBlock;
|
||||
|
|
|
@ -364,7 +364,7 @@ static void doStreamEventAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
|
|||
}
|
||||
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||
code = saveResult(curWin.winInfo, pSeUpdated);
|
||||
saveResult(curWin.winInfo, pSeUpdated);
|
||||
}
|
||||
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
|
||||
|
|
|
@ -1427,7 +1427,9 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
|||
pInfo->twAggSup.minTs = TMIN(pInfo->twAggSup.minTs, pBlock->info.window.skey);
|
||||
}
|
||||
|
||||
if (IS_FINAL_INTERVAL_OP(pOperator) && !pInfo->destHasPrimaryKey) {
|
||||
removeDeleteResults(pInfo->pUpdatedMap, pInfo->pDelWins);
|
||||
}
|
||||
if (IS_FINAL_INTERVAL_OP(pOperator)) {
|
||||
closeStreamIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval,
|
||||
pInfo->pPullDataMap, pInfo->pUpdatedMap, pInfo->pDelWins, pOperator);
|
||||
|
@ -2845,7 +2847,9 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
|||
closeSessionWindow(pAggSup->pResultRows, &pInfo->twAggSup, pInfo->pStUpdated);
|
||||
closeChildSessionWindow(pInfo->pChildren, pInfo->twAggSup.maxTs);
|
||||
copyUpdateResult(&pInfo->pStUpdated, pInfo->pUpdated, sessionKeyCompareAsc);
|
||||
if (!pInfo->destHasPrimaryKey) {
|
||||
removeSessionDeleteResults(pInfo->pStDeleted, pInfo->pUpdated);
|
||||
}
|
||||
if (pInfo->isHistoryOp) {
|
||||
getMaxTsWins(pInfo->pUpdated, pInfo->historyWins);
|
||||
}
|
||||
|
@ -4131,7 +4135,9 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
pInfo->twAggSup.minTs = TMIN(pInfo->twAggSup.minTs, pBlock->info.window.skey);
|
||||
}
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
if (!pInfo->destHasPrimaryKey) {
|
||||
removeDeleteResults(pInfo->pUpdatedMap, pInfo->pDelWins);
|
||||
}
|
||||
closeStreamIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, NULL,
|
||||
pInfo->pUpdatedMap, pInfo->pDelWins, pOperator);
|
||||
if (pInfo->destHasPrimaryKey && IS_NORMAL_INTERVAL_OP(pOperator)) {
|
||||
|
|
|
@ -511,7 +511,6 @@ static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB
|
|||
}
|
||||
|
||||
pInfo->isPrevRowSet = false;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -825,8 +824,12 @@ static void genInterpAfterDataBlock(STimeSliceOperatorInfo* pSliceInfo, SOperato
|
|||
SSDataBlock* pResBlock = pSliceInfo->pRes;
|
||||
SInterval* pInterval = &pSliceInfo->interval;
|
||||
|
||||
while (pSliceInfo->current <= pSliceInfo->win.ekey && pSliceInfo->fillType != TSDB_FILL_NEXT &&
|
||||
pSliceInfo->fillType != TSDB_FILL_LINEAR) {
|
||||
if (pSliceInfo->fillType == TSDB_FILL_NEXT || pSliceInfo->fillType == TSDB_FILL_LINEAR ||
|
||||
pSliceInfo->pPrevGroupKey == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (pSliceInfo->current <= pSliceInfo->win.ekey) {
|
||||
genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pResBlock, NULL, index, false);
|
||||
pSliceInfo->current =
|
||||
taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision);
|
||||
|
@ -1068,6 +1071,8 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode
|
|||
|
||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
|
||||
// int32_t code = initKeeperInfo(pSliceInfo, pBlock, &pOperator->exprSupp);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item);
|
|||
/**
|
||||
* @brief API PRIVATE Pop the first item off of the list
|
||||
*/
|
||||
void *taos_linked_list_pop(taos_linked_list_t *self);
|
||||
//void *taos_linked_list_pop(taos_linked_list_t *self);
|
||||
|
||||
/**
|
||||
* @brief API PRIVATE Returns the item at the head of the list or NULL if not present
|
||||
|
|
|
@ -33,6 +33,8 @@ taos_map_t *taos_collector_default_collect(taos_collector_t *self) { return self
|
|||
taos_collector_t *taos_collector_new(const char *name) {
|
||||
int r = 0;
|
||||
taos_collector_t *self = (taos_collector_t *)taos_malloc(sizeof(taos_collector_t));
|
||||
if (self == NULL) return NULL;
|
||||
memset(self, 0, sizeof(taos_collector_t));
|
||||
self->name = taos_strdup(name);
|
||||
self->metrics = taos_map_new();
|
||||
if (self->metrics == NULL) {
|
||||
|
@ -66,9 +68,11 @@ int taos_collector_destroy(taos_collector_t *self) {
|
|||
if (r) ret = r;
|
||||
self->metrics = NULL;
|
||||
|
||||
if(self->string_builder != NULL){
|
||||
r = taos_string_builder_destroy(self->string_builder);
|
||||
if (r) ret = r;
|
||||
self->string_builder = NULL;
|
||||
}
|
||||
|
||||
taos_free((char *)self->name);
|
||||
self->name = NULL;
|
||||
|
|
|
@ -59,6 +59,7 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) {
|
|||
r = pthread_rwlock_init(self->lock, NULL);
|
||||
if (r) {
|
||||
TAOS_LOG("failed to initialize rwlock");
|
||||
taos_free(self);
|
||||
return NULL;
|
||||
}
|
||||
return self;
|
||||
|
@ -301,6 +302,9 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self,
|
|||
|
||||
_OVER:
|
||||
tjsonDelete(pJson);
|
||||
if(tmp_builder != NULL){
|
||||
taos_string_builder_destroy(tmp_builder);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -117,6 +117,7 @@ int taos_linked_list_push(taos_linked_list_t *self, void *item) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
void *taos_linked_list_pop(taos_linked_list_t *self) {
|
||||
TAOS_ASSERT(self != NULL);
|
||||
if (self == NULL) return NULL;
|
||||
|
@ -141,6 +142,7 @@ void *taos_linked_list_pop(taos_linked_list_t *self) {
|
|||
}
|
||||
return item;
|
||||
}
|
||||
*/
|
||||
|
||||
int taos_linked_list_remove(taos_linked_list_t *self, void *item) {
|
||||
TAOS_ASSERT(self != NULL);
|
||||
|
|
|
@ -90,7 +90,7 @@ taos_map_t *taos_map_new() {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
self->addrs = taos_malloc(sizeof(taos_linked_list_t) * self->max_size);
|
||||
self->addrs = taos_malloc(sizeof(taos_linked_list_t*) * self->max_size);
|
||||
self->free_value_fn = destroy_map_node_value_no_op;
|
||||
|
||||
for (int i = 0; i < self->max_size; i++) {
|
||||
|
@ -273,7 +273,7 @@ int taos_map_ensure_space(taos_map_t *self) {
|
|||
if (r) return r;
|
||||
|
||||
// Create a new array of addrs
|
||||
taos_linked_list_t **new_addrs = taos_malloc(sizeof(taos_linked_list_t) * new_max);
|
||||
taos_linked_list_t **new_addrs = taos_malloc(sizeof(taos_linked_list_t*) * new_max);
|
||||
|
||||
// Initialize the new array
|
||||
for (int i = 0; i < new_max; i++) {
|
||||
|
|
|
@ -33,6 +33,8 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name,
|
|||
size_t label_key_count, const char **label_keys) {
|
||||
int r = 0;
|
||||
taos_metric_t *self = (taos_metric_t *)taos_malloc(sizeof(taos_metric_t));
|
||||
if (self == NULL) return NULL;
|
||||
memset(self, 0, sizeof(taos_metric_t));
|
||||
self->type = metric_type;
|
||||
int len = strlen(name) + 1;
|
||||
self->name = taos_malloc(len);
|
||||
|
@ -79,6 +81,7 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name,
|
|||
r = pthread_rwlock_init(self->rwlock, NULL);
|
||||
if (r) {
|
||||
TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR);
|
||||
taos_free(self);
|
||||
return NULL;
|
||||
}
|
||||
return self;
|
||||
|
@ -91,9 +94,11 @@ int taos_metric_destroy(taos_metric_t *self) {
|
|||
int r = 0;
|
||||
int ret = 0;
|
||||
|
||||
if(self->samples != NULL){
|
||||
r = taos_map_destroy(self->samples);
|
||||
self->samples = NULL;
|
||||
if (r) ret = r;
|
||||
}
|
||||
|
||||
r = taos_metric_formatter_destroy(self->formatter);
|
||||
self->formatter = NULL;
|
||||
|
@ -152,8 +157,7 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const
|
|||
return NULL;
|
||||
|
||||
// Get l_value
|
||||
r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys,
|
||||
label_values);
|
||||
r = taos_metric_formatter_load_l_value(self->formatter, self->name, NULL, self->label_key_count, self->label_keys, label_values);
|
||||
if (r) {
|
||||
TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK();
|
||||
}
|
||||
|
@ -170,10 +174,12 @@ taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const
|
|||
sample = taos_metric_sample_new(self->type, l_value, 0.0);
|
||||
r = taos_map_set(self->samples, l_value, sample);
|
||||
if (r) {
|
||||
taos_free((void *)l_value);
|
||||
TAOS_METRIC_SAMPLE_FROM_LABELS_HANDLE_UNLOCK();
|
||||
}
|
||||
}
|
||||
pthread_rwlock_unlock(self->rwlock);
|
||||
r = pthread_rwlock_unlock(self->rwlock);
|
||||
if (r) TAOS_LOG(TAOS_PTHREAD_RWLOCK_UNLOCK_ERROR);
|
||||
taos_free((void *)l_value);
|
||||
return sample;
|
||||
}
|
||||
|
|
|
@ -845,6 +845,7 @@ static int32_t selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) {
|
|||
COPY_SCALAR_FIELD(precision);
|
||||
COPY_SCALAR_FIELD(isEmptyResult);
|
||||
COPY_SCALAR_FIELD(timeLineResMode);
|
||||
COPY_SCALAR_FIELD(timeLineFromOrderBy);
|
||||
COPY_SCALAR_FIELD(timeLineCurMode);
|
||||
COPY_SCALAR_FIELD(hasAggFuncs);
|
||||
COPY_SCALAR_FIELD(hasRepeatScanFuncs);
|
||||
|
@ -862,6 +863,8 @@ static int32_t setOperatorCopy(const SSetOperator* pSrc, SSetOperator* pDst) {
|
|||
COPY_CHAR_ARRAY_FIELD(stmtName);
|
||||
COPY_SCALAR_FIELD(precision);
|
||||
COPY_SCALAR_FIELD(timeLineResMode);
|
||||
COPY_SCALAR_FIELD(timeLineFromOrderBy);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -240,6 +240,26 @@ int32_t nodesCreateAllocator(int64_t queryId, int32_t chunkSize, int64_t* pAlloc
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t nodesSimAcquireAllocator(int64_t allocatorId) {
|
||||
if (allocatorId <= 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNodeAllocator* pAllocator = taosAcquireRef(g_allocatorReqRefPool, allocatorId);
|
||||
if (NULL == pAllocator) {
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t nodesSimReleaseAllocator(int64_t allocatorId) {
|
||||
if (allocatorId <= 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
return taosReleaseRef(g_allocatorReqRefPool, allocatorId);
|
||||
}
|
||||
|
||||
int32_t nodesAcquireAllocator(int64_t allocatorId) {
|
||||
if (allocatorId <= 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -120,8 +120,9 @@ SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode
|
|||
|
||||
SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName);
|
||||
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral);
|
||||
SNode* createRawValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode *pNode);
|
||||
SNode* createRawValueNodeExt(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode *pLeft, SNode *pRight);
|
||||
SNode* createRawValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode* pNode);
|
||||
SNode* createRawValueNodeExt(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode* pLeft,
|
||||
SNode* pRight);
|
||||
SNodeList* createHintNodeList(SAstCreateContext* pCxt, const SToken* pLiteral);
|
||||
SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral);
|
||||
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral);
|
||||
|
@ -139,7 +140,8 @@ SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList);
|
|||
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);
|
||||
SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias);
|
||||
SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const SToken* pTableAlias);
|
||||
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, EJoinSubType stype, SNode* pLeft, SNode* pRight, SNode* pJoinCond);
|
||||
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, EJoinSubType stype, SNode* pLeft, SNode* pRight,
|
||||
SNode* pJoinCond);
|
||||
SNode* createViewNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pViewName);
|
||||
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset);
|
||||
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
|
||||
|
@ -170,7 +172,8 @@ SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery);
|
|||
SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill);
|
||||
SNode* addJLimitClause(SAstCreateContext* pCxt, SNode* pJoin, SNode* pJLimit);
|
||||
SNode* addWindowOffsetClause(SAstCreateContext* pCxt, SNode* pJoin, SNode* pWinOffset);
|
||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint);
|
||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable,
|
||||
SNodeList* pHint);
|
||||
SNode* setSelectStmtTagMode(SAstCreateContext* pCxt, SNode* pStmt, bool bSelectTags);
|
||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||
|
||||
|
@ -205,8 +208,12 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
|
|||
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
|
||||
SDataType dataType);
|
||||
SNode* createAlterTableAddModifyColOptions(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
|
||||
SNode* pOptions);
|
||||
|
||||
SNode* createAlterTableAddModifyColOptions2(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
SToken* pColName, SDataType dataType, SNode* pOptions);
|
||||
|
||||
SNode* createAlterTableAddModifyColOptions(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
SToken* pColName, SNode* pOptions);
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName);
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
|
||||
SToken* pNewColName);
|
||||
|
@ -217,7 +224,8 @@ SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind);
|
|||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type);
|
||||
SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName,
|
||||
EOperatorType tableCondType);
|
||||
SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, SNode* pTbName, EOperatorType tableCondType);
|
||||
SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, SNode* pTbName,
|
||||
EOperatorType tableCondType);
|
||||
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||
SNode* createShowAliveStmt(SAstCreateContext* pCxt, SNode* pDbName, ENodeType type);
|
||||
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
||||
|
|
|
@ -353,7 +353,7 @@ cmd ::= ALTER STABLE alter_table_clause(A).
|
|||
|
||||
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) ADD COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D); }
|
||||
full_table_name(B) ADD COLUMN column_name(C) type_name(D) column_options(E). { A = createAlterTableAddModifyColOptions2(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D, E); }
|
||||
alter_table_clause(A) ::= full_table_name(B) DROP COLUMN column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_COLUMN, &C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) MODIFY COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &C, D); }
|
||||
|
|
|
@ -176,7 +176,8 @@ static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool demandDb)
|
|||
|
||||
static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) {
|
||||
trimEscape(pTableName);
|
||||
if (NULL != pTableName && pTableName->type != TK_NK_NIL && (pTableName->n >= TSDB_TABLE_NAME_LEN || pTableName->n == 0)) {
|
||||
if (NULL != pTableName && pTableName->type != TK_NK_NIL &&
|
||||
(pTableName->n >= TSDB_TABLE_NAME_LEN || pTableName->n == 0)) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z);
|
||||
return false;
|
||||
}
|
||||
|
@ -185,7 +186,8 @@ static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) {
|
|||
|
||||
static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) {
|
||||
trimEscape(pColumnName);
|
||||
if (NULL != pColumnName && pColumnName->type != TK_NK_NIL && (pColumnName->n >= TSDB_COL_NAME_LEN || pColumnName->n == 0)) {
|
||||
if (NULL != pColumnName && pColumnName->type != TK_NK_NIL &&
|
||||
(pColumnName->n >= TSDB_COL_NAME_LEN || pColumnName->n == 0)) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z);
|
||||
return false;
|
||||
}
|
||||
|
@ -1893,6 +1895,38 @@ SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable,
|
|||
pStmt->dataType = dataType;
|
||||
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
||||
}
|
||||
SNode* createAlterTableAddModifyColOptions2(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
SToken* pColName, SDataType dataType, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkColumnName(pCxt, pColName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SAlterTableStmt* pStmt = (SAlterTableStmt*)nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName);
|
||||
pStmt->dataType = dataType;
|
||||
pStmt->pColOptions = (SColumnOptions*)pOptions;
|
||||
|
||||
if (pOptions != NULL) {
|
||||
SColumnOptions* pOption = (SColumnOptions*)pOptions;
|
||||
if (pOption->bPrimaryKey == false && pOption->commentNull == true) {
|
||||
if (strlen(pOption->compress) != 0 || strlen(pOption->compressLevel) || strlen(pOption->encode) != 0) {
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION;
|
||||
} else {
|
||||
// pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
|
||||
// "not support alter column with option except compress");
|
||||
// return NULL;
|
||||
}
|
||||
} else {
|
||||
pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
|
||||
"not support alter column with option except compress");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
||||
}
|
||||
|
||||
SNode* createAlterTableAddModifyColOptions(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||
SToken* pColName, SNode* pOptions) {
|
||||
|
@ -2816,9 +2850,10 @@ SNode* createBalanceVgroupLeaderStmt(SAstCreateContext* pCxt, const SToken* pVgI
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createBalanceVgroupLeaderDBNameStmt(SAstCreateContext* pCxt, const SToken* pDbName){
|
||||
SNode* createBalanceVgroupLeaderDBNameStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SBalanceVgroupLeaderStmt* pStmt = (SBalanceVgroupLeaderStmt*)nodesMakeNode(QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT);
|
||||
SBalanceVgroupLeaderStmt* pStmt =
|
||||
(SBalanceVgroupLeaderStmt*)nodesMakeNode(QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
if (NULL != pDbName) {
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName);
|
||||
|
|
|
@ -959,7 +959,8 @@ static bool isTimeLineQuery(SNode* pStmt) {
|
|||
return (TIME_LINE_MULTI == ((SSelectStmt*)pStmt)->timeLineCurMode) ||
|
||||
(TIME_LINE_GLOBAL == ((SSelectStmt*)pStmt)->timeLineCurMode);
|
||||
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pStmt)) {
|
||||
return TIME_LINE_GLOBAL == ((SSetOperator*)pStmt)->timeLineResMode;
|
||||
return (TIME_LINE_MULTI == ((SSetOperator*)pStmt)->timeLineResMode) ||
|
||||
(TIME_LINE_GLOBAL == ((SSetOperator*)pStmt)->timeLineResMode);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -1000,18 +1001,65 @@ static bool isBlockTimeLineAlignedQuery(SNode* pStmt) {
|
|||
return false;
|
||||
}
|
||||
|
||||
SNodeList* buildPartitionListFromOrderList(SNodeList* pOrderList, int32_t nodesNum) {
|
||||
SNodeList* pPartitionList = NULL;
|
||||
SNode* pNode = NULL;
|
||||
if (pOrderList->length <= nodesNum) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pNode = nodesListGetNode(pOrderList, nodesNum);
|
||||
SOrderByExprNode* pOrder = (SOrderByExprNode*)pNode;
|
||||
if (!isPrimaryKeyImpl(pOrder->pExpr)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < nodesNum; ++i) {
|
||||
pNode = nodesListGetNode(pOrderList, i);
|
||||
pOrder = (SOrderByExprNode*)pNode;
|
||||
nodesListMakeStrictAppend(&pPartitionList, nodesCloneNode(pOrder->pExpr));
|
||||
}
|
||||
|
||||
return pPartitionList;
|
||||
}
|
||||
|
||||
static bool isTimeLineAlignedQuery(SNode* pStmt) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||
if (!isTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
||||
return false;
|
||||
}
|
||||
if (QUERY_NODE_SELECT_STMT != nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
||||
return false;
|
||||
}
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
||||
SSelectStmt* pSub = (SSelectStmt*)((STempTableNode*)pSelect->pFromTable)->pSubquery;
|
||||
if (pSelect->pPartitionByList && nodesListMatch(pSelect->pPartitionByList, pSub->pPartitionByList)) {
|
||||
if (pSelect->pPartitionByList) {
|
||||
if (!pSub->timeLineFromOrderBy && nodesListMatch(pSelect->pPartitionByList, pSub->pPartitionByList)) {
|
||||
return true;
|
||||
}
|
||||
if (pSub->timeLineFromOrderBy && pSub->pOrderByList->length > 1) {
|
||||
SNodeList* pPartitionList =
|
||||
buildPartitionListFromOrderList(pSub->pOrderByList, pSelect->pPartitionByList->length);
|
||||
bool match = nodesListMatch(pSelect->pPartitionByList, pPartitionList);
|
||||
nodesDestroyList(pPartitionList);
|
||||
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (QUERY_NODE_SET_OPERATOR == nodeType(((STempTableNode*)pSelect->pFromTable)->pSubquery)) {
|
||||
SSetOperator* pSub = (SSetOperator*)((STempTableNode*)pSelect->pFromTable)->pSubquery;
|
||||
if (pSelect->pPartitionByList && pSub->timeLineFromOrderBy && pSub->pOrderByList->length > 1) {
|
||||
SNodeList* pPartitionList =
|
||||
buildPartitionListFromOrderList(pSub->pOrderByList, pSelect->pPartitionByList->length);
|
||||
bool match = nodesListMatch(pSelect->pPartitionByList, pPartitionList);
|
||||
nodesDestroyList(pPartitionList);
|
||||
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -6025,9 +6073,19 @@ static void resetResultTimeline(SSelectStmt* pSelect) {
|
|||
if ((QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) && isPrimaryKeyImpl(pOrder)) ||
|
||||
(QUERY_NODE_TEMP_TABLE != nodeType(pSelect->pFromTable) && isPrimaryKeyImpl(pOrder))) {
|
||||
pSelect->timeLineResMode = TIME_LINE_GLOBAL;
|
||||
} else {
|
||||
pSelect->timeLineResMode = TIME_LINE_NONE;
|
||||
return;
|
||||
} else if (pSelect->pOrderByList->length > 1) {
|
||||
for (int32_t i = 1; i < pSelect->pOrderByList->length; ++i) {
|
||||
pOrder = ((SOrderByExprNode*)nodesListGetNode(pSelect->pOrderByList, i))->pExpr;
|
||||
if (isPrimaryKeyImpl(pOrder)) {
|
||||
pSelect->timeLineResMode = TIME_LINE_MULTI;
|
||||
pSelect->timeLineFromOrderBy = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pSelect->timeLineResMode = TIME_LINE_NONE;
|
||||
}
|
||||
|
||||
static int32_t replaceOrderByAliasForSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
|
@ -6180,17 +6238,14 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS
|
|||
}
|
||||
snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName);
|
||||
SNode* pProj = createSetOperProject(pSetOperator->stmtName, pLeft);
|
||||
if (QUERY_NODE_COLUMN == nodeType(pLeft) && QUERY_NODE_COLUMN == nodeType(pRight)) {
|
||||
SColumnNode* pLCol = (SColumnNode*)pLeft;
|
||||
SColumnNode* pRCol = (SColumnNode*)pRight;
|
||||
bool isLeftPrimTs = isPrimaryKeyImpl(pLeft);
|
||||
bool isRightPrimTs = isPrimaryKeyImpl(pRight);
|
||||
|
||||
if (isLeftPrimTs && isRightPrimTs) {
|
||||
SColumnNode* pFCol = (SColumnNode*)pProj;
|
||||
if (pLCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID && pRCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
pFCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
if (pLCol->isPrimTs && pRCol->isPrimTs) {
|
||||
pFCol->isPrimTs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, pProj)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -6225,10 +6280,20 @@ static int32_t translateSetOperOrderBy(STranslateContext* pCxt, SSetOperator* pS
|
|||
SNode* pOrder = ((SOrderByExprNode*)nodesListGetNode(pSetOperator->pOrderByList, 0))->pExpr;
|
||||
if (isPrimaryKeyImpl(pOrder)) {
|
||||
pSetOperator->timeLineResMode = TIME_LINE_GLOBAL;
|
||||
} else {
|
||||
pSetOperator->timeLineResMode = TIME_LINE_NONE;
|
||||
return code;
|
||||
} else if (pSetOperator->pOrderByList->length > 1) {
|
||||
for (int32_t i = 1; i < pSetOperator->pOrderByList->length; ++i) {
|
||||
pOrder = ((SOrderByExprNode*)nodesListGetNode(pSetOperator->pOrderByList, i))->pExpr;
|
||||
if (isPrimaryKeyImpl(pOrder)) {
|
||||
pSetOperator->timeLineResMode = TIME_LINE_MULTI;
|
||||
pSetOperator->timeLineFromOrderBy = true;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pSetOperator->timeLineResMode = TIME_LINE_NONE;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -8092,9 +8157,9 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt*
|
|||
}
|
||||
|
||||
switch (pStmt->alterType) {
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
case TSDB_ALTER_TABLE_ADD_TAG:
|
||||
case TSDB_ALTER_TABLE_DROP_TAG:
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
|
||||
case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: {
|
||||
|
@ -8129,6 +8194,31 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt*
|
|||
taosArrayPush(pAlterReq->pFields, &field);
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: {
|
||||
taosArrayDestroy(pAlterReq->pFields);
|
||||
|
||||
pAlterReq->pFields = taosArrayInit(1, sizeof(SFieldWithOptions));
|
||||
SFieldWithOptions field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)};
|
||||
// TAOS_FIELD field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)};
|
||||
strcpy(field.name, pStmt->colName);
|
||||
if (pStmt->pColOptions != NULL) {
|
||||
if (!checkColumnEncodeOrSetDefault(pStmt->dataType.type, pStmt->pColOptions->encode))
|
||||
return TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
|
||||
if (!checkColumnCompressOrSetDefault(pStmt->dataType.type, pStmt->pColOptions->compress))
|
||||
return TSDB_CODE_TSC_COMPRESS_PARAM_ERROR;
|
||||
if (!checkColumnLevelOrSetDefault(pStmt->dataType.type, pStmt->pColOptions->compressLevel))
|
||||
return TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
|
||||
int32_t code = setColCompressByOption(pStmt->dataType.type, columnEncodeVal(pStmt->pColOptions->encode),
|
||||
columnCompressVal(pStmt->pColOptions->compress),
|
||||
columnLevelVal(pStmt->pColOptions->compressLevel), false,
|
||||
(uint32_t*)&field.compress);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
taosArrayPush(pAlterReq->pFields, &field);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -10578,7 +10668,7 @@ static int32_t translateBalanceVgroup(STranslateContext* pCxt, SBalanceVgroupStm
|
|||
static int32_t translateBalanceVgroupLeader(STranslateContext* pCxt, SBalanceVgroupLeaderStmt* pStmt) {
|
||||
SBalanceVgroupLeaderReq req = {0};
|
||||
req.vgId = pStmt->vgId;
|
||||
if(pStmt->dbName != NULL) strcpy(req.db, pStmt->dbName);
|
||||
if (pStmt->dbName != NULL) strcpy(req.db, pStmt->dbName);
|
||||
int32_t code =
|
||||
buildCmdMsg(pCxt, TDMT_MND_BALANCE_VGROUP_LEADER, (FSerializeFunc)tSerializeSBalanceVgroupLeaderReq, &req);
|
||||
tFreeSBalanceVgroupLeaderReq(&req);
|
||||
|
@ -10993,7 +11083,8 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm
|
|||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pReq->deleteMark = convertTimePrecision(tsmaDataDeleteMark, TSDB_TIME_PRECISION_MILLI, pTableMeta->tableInfo.precision);
|
||||
pReq->deleteMark =
|
||||
convertTimePrecision(tsmaDataDeleteMark, TSDB_TIME_PRECISION_MILLI, pTableMeta->tableInfo.precision);
|
||||
code = getSmaIndexSql(pCxt, &pReq->sql, &pReq->sqlLen);
|
||||
}
|
||||
|
||||
|
@ -12793,6 +12884,11 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
|
|||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
|
||||
}
|
||||
|
||||
// only super and normal support
|
||||
if (pStmt->pColOptions != NULL && TSDB_CHILD_TABLE == pTableMeta->tableType) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||
}
|
||||
|
||||
pReq->colName = taosStrdup(pStmt->colName);
|
||||
if (NULL == pReq->colName) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -12801,6 +12897,17 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
|
|||
pReq->type = pStmt->dataType.type;
|
||||
pReq->flags = COL_SMA_ON;
|
||||
pReq->bytes = calcTypeBytes(pStmt->dataType);
|
||||
if (pStmt->pColOptions != NULL) {
|
||||
if (!checkColumnEncodeOrSetDefault(pReq->type, pStmt->pColOptions->encode)) return TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
|
||||
if (!checkColumnCompressOrSetDefault(pReq->type, pStmt->pColOptions->compress))
|
||||
return TSDB_CODE_TSC_COMPRESS_PARAM_ERROR;
|
||||
if (!checkColumnLevelOrSetDefault(pReq->type, pStmt->pColOptions->compressLevel))
|
||||
return TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
|
||||
int8_t code = setColCompressByOption(pReq->type, columnEncodeVal(pStmt->pColOptions->encode),
|
||||
columnCompressVal(pStmt->pColOptions->compress),
|
||||
columnLevelVal(pStmt->pColOptions->compressLevel), true, &pReq->compress);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -12947,6 +13054,7 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt,
|
|||
case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:
|
||||
return buildUpdateTagValReq(pCxt, pStmt, pTableMeta, pReq);
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
|
||||
return buildAddColReq(pCxt, pStmt, pTableMeta, pReq);
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
||||
return buildDropColReq(pCxt, pStmt, pTableMeta, pReq);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1587,6 +1587,7 @@ static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator
|
|||
TSWAP(pProject->node.pLimit, pSetOperator->pLimit);
|
||||
}
|
||||
pProject->ignoreGroupId = true;
|
||||
pProject->isSetOpProj = true;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
|
|
@ -3284,9 +3284,23 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan*
|
|||
SNodeList* pNewChildTargets = nodesMakeList();
|
||||
|
||||
if (NULL == pProjectNode->node.pParent) {
|
||||
SNode* pProjection = NULL;
|
||||
SNode *pProjection = NULL, *pChildTarget = NULL;
|
||||
bool needOrderMatch = QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pChild) && ((SProjectLogicNode*)pChild)->isSetOpProj;
|
||||
bool orderMatch = true;
|
||||
if (needOrderMatch) {
|
||||
// For sql: select ... from (select ... union all select ...);
|
||||
// When eliminating the outer proj (the outer select), we have to make sure that the outer proj projections and
|
||||
// union all project targets have same columns in the same order. See detail in TD-30188
|
||||
FORBOTH(pProjection, pProjectNode->pProjections, pChildTarget, pChild->pTargets) {
|
||||
if (!pProjection) break;
|
||||
if (0 != strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)) {
|
||||
orderMatch = false;
|
||||
break;
|
||||
}
|
||||
nodesListAppend(pNewChildTargets, nodesCloneNode(pChildTarget));
|
||||
}
|
||||
} else {
|
||||
FOREACH(pProjection, pProjectNode->pProjections) {
|
||||
SNode* pChildTarget = NULL;
|
||||
FOREACH(pChildTarget, pChild->pTargets) {
|
||||
if (0 == strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)) {
|
||||
nodesListAppend(pNewChildTargets, nodesCloneNode(pChildTarget));
|
||||
|
@ -3294,8 +3308,10 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan*
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eliminateProjOptCanChildConditionUseChildTargets(pChild, pNewChildTargets)) {
|
||||
if (eliminateProjOptCanChildConditionUseChildTargets(pChild, pNewChildTargets) &&
|
||||
(!needOrderMatch || (needOrderMatch && orderMatch))) {
|
||||
nodesDestroyList(pChild->pTargets);
|
||||
pChild->pTargets = pNewChildTargets;
|
||||
} else {
|
||||
|
|
|
@ -798,6 +798,7 @@ TEST(queryTest, normalCase) {
|
|||
|
||||
schedulerFreeJob(&job, 0);
|
||||
|
||||
taosThreadJoin(thread1, NULL);
|
||||
}
|
||||
|
||||
TEST(queryTest, readyFirstCase) {
|
||||
|
@ -907,6 +908,8 @@ TEST(queryTest, readyFirstCase) {
|
|||
schedulerDestroy();
|
||||
|
||||
schedulerFreeJob(&job, 0);
|
||||
|
||||
taosThreadJoin(thread1, NULL);
|
||||
}
|
||||
|
||||
TEST(queryTest, flowCtrlCase) {
|
||||
|
@ -1001,6 +1004,8 @@ TEST(queryTest, flowCtrlCase) {
|
|||
schedulerDestroy();
|
||||
|
||||
schedulerFreeJob(&job, 0);
|
||||
|
||||
taosThreadJoin(thread1, NULL);
|
||||
}
|
||||
|
||||
TEST(insertTest, normalCase) {
|
||||
|
@ -1061,6 +1066,8 @@ TEST(insertTest, normalCase) {
|
|||
schedulerFreeJob(&insertJobRefId, 0);
|
||||
|
||||
schedulerDestroy();
|
||||
|
||||
taosThreadJoin(thread1, NULL);
|
||||
}
|
||||
|
||||
TEST(multiThread, forceFree) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue