Merge remote-tracking branch 'origin/3.0' into enh/3.0_planner_optimize
This commit is contained in:
commit
27a687aba8
|
@ -6,7 +6,8 @@ description: TDengine 保留关键字的详细列表
|
||||||
|
|
||||||
## 保留关键字
|
## 保留关键字
|
||||||
|
|
||||||
目前 TDengine 有将近 200 个内部保留关键字,这些关键字无论大小写均不可以用作库名、表名、STable 名、数据列名及标签列名等。这些关键字列表如下:
|
目前 TDengine 有将近 200 个内部保留关键字,这些关键字无论大小写如果需要用作库名、表名、STable 名、数据列名及标签列名等,需要使用符合``将关键字括起来使用,例如`ADD`。
|
||||||
|
关键字列表如下:
|
||||||
|
|
||||||
### A
|
### A
|
||||||
|
|
||||||
|
@ -239,6 +240,7 @@ description: TDengine 保留关键字的详细列表
|
||||||
- TOPICS
|
- TOPICS
|
||||||
- TRIGGER
|
- TRIGGER
|
||||||
- TSERIES
|
- TSERIES
|
||||||
|
- TTL
|
||||||
|
|
||||||
### U
|
### U
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,6 @@ typedef enum {
|
||||||
TSDB_STATIS_NONE = 1, // statis part not exist
|
TSDB_STATIS_NONE = 1, // statis part not exist
|
||||||
} ETsdbStatisStatus;
|
} ETsdbStatisStatus;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TSDB_SMA_STAT_UNKNOWN = -1, // unknown
|
|
||||||
TSDB_SMA_STAT_OK = 0, // ready to provide service
|
|
||||||
TSDB_SMA_STAT_EXPIRED = 1, // not ready or expired
|
|
||||||
TSDB_SMA_STAT_DROPPED = 2, // sma dropped
|
|
||||||
} ETsdbSmaStat; // bit operation
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_SMA_TYPE_BLOCK = 0, // Block-wise SMA
|
TSDB_SMA_TYPE_BLOCK = 0, // Block-wise SMA
|
||||||
TSDB_SMA_TYPE_TIME_RANGE = 1, // Time-range-wise SMA
|
TSDB_SMA_TYPE_TIME_RANGE = 1, // Time-range-wise SMA
|
||||||
|
|
|
@ -184,7 +184,6 @@ typedef struct SQueryTableDataCond {
|
||||||
STimeWindow twindows;
|
STimeWindow twindows;
|
||||||
int64_t startVersion;
|
int64_t startVersion;
|
||||||
int64_t endVersion;
|
int64_t endVersion;
|
||||||
int64_t schemaVersion;
|
|
||||||
} SQueryTableDataCond;
|
} SQueryTableDataCond;
|
||||||
|
|
||||||
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
|
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
|
||||||
|
|
|
@ -845,6 +845,8 @@ typedef struct {
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
int32_t vgNum;
|
int32_t vgNum;
|
||||||
|
int16_t hashPrefix;
|
||||||
|
int16_t hashSuffix;
|
||||||
int8_t hashMethod;
|
int8_t hashMethod;
|
||||||
SArray* pVgroupInfos; // Array of SVgroupInfo
|
SArray* pVgroupInfos; // Array of SVgroupInfo
|
||||||
} SUseDbRsp;
|
} SUseDbRsp;
|
||||||
|
@ -1070,6 +1072,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int32_t syncState;
|
int32_t syncState;
|
||||||
|
int64_t cacheUsage;
|
||||||
int64_t numOfTables;
|
int64_t numOfTables;
|
||||||
int64_t numOfTimeSeries;
|
int64_t numOfTimeSeries;
|
||||||
int64_t totalStorage;
|
int64_t totalStorage;
|
||||||
|
|
|
@ -116,6 +116,8 @@ typedef struct STableMeta {
|
||||||
|
|
||||||
typedef struct SDBVgInfo {
|
typedef struct SDBVgInfo {
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
|
int16_t hashPrefix;
|
||||||
|
int16_t hashSuffix;
|
||||||
int8_t hashMethod;
|
int8_t hashMethod;
|
||||||
int32_t numOfTable; // DB's table num, unit is TSDB_TABLE_NUM_UNIT
|
int32_t numOfTable; // DB's table num, unit is TSDB_TABLE_NUM_UNIT
|
||||||
SHashObj* vgHash; // key:vgId, value:SVgroupInfo
|
SHashObj* vgHash; // key:vgId, value:SVgroupInfo
|
||||||
|
|
|
@ -616,6 +616,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_RSMA_FETCH_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x3155)
|
#define TSDB_CODE_RSMA_FETCH_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x3155)
|
||||||
#define TSDB_CODE_RSMA_EMPTY_INFO TAOS_DEF_ERROR_CODE(0, 0x3156)
|
#define TSDB_CODE_RSMA_EMPTY_INFO TAOS_DEF_ERROR_CODE(0, 0x3156)
|
||||||
#define TSDB_CODE_RSMA_INVALID_SCHEMA TAOS_DEF_ERROR_CODE(0, 0x3157)
|
#define TSDB_CODE_RSMA_INVALID_SCHEMA TAOS_DEF_ERROR_CODE(0, 0x3157)
|
||||||
|
#define TSDB_CODE_RSMA_REGEX_MATCH TAOS_DEF_ERROR_CODE(0, 0x3158)
|
||||||
|
|
||||||
//index
|
//index
|
||||||
#define TSDB_CODE_INDEX_REBUILDING TAOS_DEF_ERROR_CODE(0, 0x3200)
|
#define TSDB_CODE_INDEX_REBUILDING TAOS_DEF_ERROR_CODE(0, 0x3200)
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_UTIL_RBTREE_H_
|
||||||
|
#define _TD_UTIL_RBTREE_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct SRBTree SRBTree;
|
||||||
|
typedef struct SRBTreeNode SRBTreeNode;
|
||||||
|
typedef struct SRBTreeIter SRBTreeIter;
|
||||||
|
|
||||||
|
typedef int32_t (*tRBTreeCmprFn)(const void *, const void *);
|
||||||
|
|
||||||
|
// SRBTree =============================================
|
||||||
|
#define tRBTreeMin(T) ((T)->min == ((T)->NIL) ? NULL : (T)->min)
|
||||||
|
#define tRBTreeMax(T) ((T)->max == ((T)->NIL) ? NULL : (T)->max)
|
||||||
|
|
||||||
|
void tRBTreeCreate(SRBTree *pTree, tRBTreeCmprFn cmprFn);
|
||||||
|
SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *z);
|
||||||
|
void tRBTreeDrop(SRBTree *pTree, SRBTreeNode *z);
|
||||||
|
SRBTreeNode *tRBTreeDropByKey(SRBTree *pTree, void *pKey);
|
||||||
|
SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey);
|
||||||
|
|
||||||
|
// SRBTreeIter =============================================
|
||||||
|
#define tRBTreeIterCreate(tree, ascend) \
|
||||||
|
(SRBTreeIter) { .asc = (ascend), .pTree = (tree), .pNode = (ascend) ? (tree)->min : (tree)->max }
|
||||||
|
|
||||||
|
SRBTreeNode *tRBTreeIterNext(SRBTreeIter *pIter);
|
||||||
|
|
||||||
|
// STRUCT =============================================
|
||||||
|
typedef enum { RED, BLACK } ECOLOR;
|
||||||
|
struct SRBTreeNode {
|
||||||
|
ECOLOR color;
|
||||||
|
SRBTreeNode *parent;
|
||||||
|
SRBTreeNode *left;
|
||||||
|
SRBTreeNode *right;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RBTREE_NODE_PAYLOAD(N) ((const void *)&(N)[1])
|
||||||
|
|
||||||
|
struct SRBTree {
|
||||||
|
tRBTreeCmprFn cmprFn;
|
||||||
|
int64_t n;
|
||||||
|
SRBTreeNode *root;
|
||||||
|
SRBTreeNode *min;
|
||||||
|
SRBTreeNode *max;
|
||||||
|
SRBTreeNode *NIL;
|
||||||
|
SRBTreeNode NILNODE;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SRBTreeIter {
|
||||||
|
int8_t asc;
|
||||||
|
SRBTree *pTree;
|
||||||
|
SRBTreeNode *pNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_UTIL_RBTREE_H_*/
|
|
@ -488,7 +488,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
||||||
*/
|
*/
|
||||||
uint64_t generateRequestId() {
|
uint64_t generateRequestId() {
|
||||||
static uint64_t hashId = 0;
|
static uint64_t hashId = 0;
|
||||||
static int32_t requestSerialId = 0;
|
static uint32_t requestSerialId = 0;
|
||||||
|
|
||||||
if (hashId == 0) {
|
if (hashId == 0) {
|
||||||
char uid[64] = {0};
|
char uid[64] = {0};
|
||||||
|
@ -507,7 +507,8 @@ uint64_t generateRequestId() {
|
||||||
while (true) {
|
while (true) {
|
||||||
int64_t ts = taosGetTimestampMs();
|
int64_t ts = taosGetTimestampMs();
|
||||||
uint64_t pid = taosGetPId();
|
uint64_t pid = taosGetPId();
|
||||||
int32_t val = atomic_add_fetch_32(&requestSerialId, 1);
|
uint32_t val = atomic_add_fetch_32(&requestSerialId, 1);
|
||||||
|
if (val >= 0xFFFF) atomic_store_32(&requestSerialId, 0);
|
||||||
|
|
||||||
id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
||||||
if (id) {
|
if (id) {
|
||||||
|
|
|
@ -73,6 +73,8 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
||||||
|
|
||||||
vgInfo->vgVersion = rsp->vgVersion;
|
vgInfo->vgVersion = rsp->vgVersion;
|
||||||
vgInfo->hashMethod = rsp->hashMethod;
|
vgInfo->hashMethod = rsp->hashMethod;
|
||||||
|
vgInfo->hashPrefix = rsp->hashPrefix;
|
||||||
|
vgInfo->hashSuffix = rsp->hashSuffix;
|
||||||
vgInfo->vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
vgInfo->vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||||
if (NULL == vgInfo->vgHash) {
|
if (NULL == vgInfo->vgHash) {
|
||||||
taosMemoryFree(vgInfo);
|
taosMemoryFree(vgInfo);
|
||||||
|
|
|
@ -1672,7 +1672,12 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!needConvert) return TSDB_CODE_SUCCESS;
|
|
||||||
|
if (!needConvert) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
tscDebug("start to convert form json format string");
|
||||||
|
|
||||||
char* p = (char*)pResultInfo->pData;
|
char* p = (char*)pResultInfo->pData;
|
||||||
int32_t dataLen = estimateJsonLen(pResultInfo, numOfCols, numOfRows);
|
int32_t dataLen = estimateJsonLen(pResultInfo, numOfCols, numOfRows);
|
||||||
|
|
|
@ -765,6 +765,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
||||||
}
|
}
|
||||||
taosArrayPush(pRequest->tableList, &pName);
|
taosArrayPush(pRequest->tableList, &pName);
|
||||||
|
|
||||||
|
pCreateReq->flags |= TD_CREATE_IF_NOT_EXISTS;
|
||||||
// change tag cid to new cid
|
// change tag cid to new cid
|
||||||
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
if (pCreateReq->type == TSDB_CHILD_TABLE) {
|
||||||
STableMeta* pTableMeta = NULL;
|
STableMeta* pTableMeta = NULL;
|
||||||
|
|
|
@ -207,6 +207,7 @@ static const SSysDbTableSchema vgroupsSchema[] = {
|
||||||
{.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
{.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||||
{.name = "v3_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
{.name = "v3_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||||
{.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
{.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||||
|
{.name = "cacheload", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||||
{.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
{.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||||
{.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
{.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||||
{.name = "tsma", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
|
{.name = "tsma", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
|
||||||
|
|
|
@ -2120,6 +2120,7 @@ void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_
|
||||||
int32_t* rows = (int32_t*)data;
|
int32_t* rows = (int32_t*)data;
|
||||||
*rows = pBlock->info.rows;
|
*rows = pBlock->info.rows;
|
||||||
data += sizeof(int32_t);
|
data += sizeof(int32_t);
|
||||||
|
ASSERT(*rows > 0);
|
||||||
|
|
||||||
int32_t* cols = (int32_t*)data;
|
int32_t* cols = (int32_t*)data;
|
||||||
*cols = numOfCols;
|
*cols = numOfCols;
|
||||||
|
@ -2183,6 +2184,8 @@ void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_
|
||||||
|
|
||||||
*actualLen = *dataLen;
|
*actualLen = *dataLen;
|
||||||
*groupId = pBlock->info.groupId;
|
*groupId = pBlock->info.groupId;
|
||||||
|
ASSERT(*dataLen > 0);
|
||||||
|
uDebug("build data block, actualLen:%d, rows:%d, cols:%d", *dataLen, *rows, *cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* blockDecode(SSDataBlock* pBlock, const char* pData) {
|
const char* blockDecode(SSDataBlock* pBlock, const char* pData) {
|
||||||
|
|
|
@ -129,10 +129,6 @@ int32_t tsMinIntervalTime = 1;
|
||||||
int32_t tsQueryBufferSize = -1;
|
int32_t tsQueryBufferSize = -1;
|
||||||
int64_t tsQueryBufferSizeBytes = -1;
|
int64_t tsQueryBufferSizeBytes = -1;
|
||||||
|
|
||||||
// tsdb config
|
|
||||||
// For backward compatibility
|
|
||||||
bool tsdbForceKeepFile = false;
|
|
||||||
|
|
||||||
int32_t tsDiskCfgNum = 0;
|
int32_t tsDiskCfgNum = 0;
|
||||||
SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0};
|
SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0};
|
||||||
|
|
||||||
|
|
|
@ -994,6 +994,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
||||||
SVnodeLoad *pload = taosArrayGet(pReq->pVloads, i);
|
SVnodeLoad *pload = taosArrayGet(pReq->pVloads, i);
|
||||||
if (tEncodeI32(&encoder, pload->vgId) < 0) return -1;
|
if (tEncodeI32(&encoder, pload->vgId) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pload->syncState) < 0) return -1;
|
if (tEncodeI32(&encoder, pload->syncState) < 0) return -1;
|
||||||
|
if (tEncodeI64(&encoder, pload->cacheUsage) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pload->numOfTables) < 0) return -1;
|
if (tEncodeI64(&encoder, pload->numOfTables) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pload->numOfTimeSeries) < 0) return -1;
|
if (tEncodeI64(&encoder, pload->numOfTimeSeries) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pload->totalStorage) < 0) return -1;
|
if (tEncodeI64(&encoder, pload->totalStorage) < 0) return -1;
|
||||||
|
@ -1063,6 +1064,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
||||||
SVnodeLoad vload = {0};
|
SVnodeLoad vload = {0};
|
||||||
if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1;
|
if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &vload.syncState) < 0) return -1;
|
if (tDecodeI32(&decoder, &vload.syncState) < 0) return -1;
|
||||||
|
if (tDecodeI64(&decoder, &vload.cacheUsage) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &vload.numOfTables) < 0) return -1;
|
if (tDecodeI64(&decoder, &vload.numOfTables) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &vload.numOfTimeSeries) < 0) return -1;
|
if (tDecodeI64(&decoder, &vload.numOfTimeSeries) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &vload.totalStorage) < 0) return -1;
|
if (tDecodeI64(&decoder, &vload.totalStorage) < 0) return -1;
|
||||||
|
@ -2461,6 +2463,8 @@ int32_t tSerializeSUseDbRspImp(SEncoder *pEncoder, const SUseDbRsp *pRsp) {
|
||||||
if (tEncodeI64(pEncoder, pRsp->uid) < 0) return -1;
|
if (tEncodeI64(pEncoder, pRsp->uid) < 0) return -1;
|
||||||
if (tEncodeI32(pEncoder, pRsp->vgVersion) < 0) return -1;
|
if (tEncodeI32(pEncoder, pRsp->vgVersion) < 0) return -1;
|
||||||
if (tEncodeI32(pEncoder, pRsp->vgNum) < 0) return -1;
|
if (tEncodeI32(pEncoder, pRsp->vgNum) < 0) return -1;
|
||||||
|
if (tEncodeI16(pEncoder, pRsp->hashPrefix) < 0) return -1;
|
||||||
|
if (tEncodeI16(pEncoder, pRsp->hashSuffix) < 0) return -1;
|
||||||
if (tEncodeI8(pEncoder, pRsp->hashMethod) < 0) return -1;
|
if (tEncodeI8(pEncoder, pRsp->hashMethod) < 0) return -1;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRsp->vgNum; ++i) {
|
for (int32_t i = 0; i < pRsp->vgNum; ++i) {
|
||||||
|
@ -2512,6 +2516,8 @@ int32_t tDeserializeSUseDbRspImp(SDecoder *pDecoder, SUseDbRsp *pRsp) {
|
||||||
if (tDecodeI64(pDecoder, &pRsp->uid) < 0) return -1;
|
if (tDecodeI64(pDecoder, &pRsp->uid) < 0) return -1;
|
||||||
if (tDecodeI32(pDecoder, &pRsp->vgVersion) < 0) return -1;
|
if (tDecodeI32(pDecoder, &pRsp->vgVersion) < 0) return -1;
|
||||||
if (tDecodeI32(pDecoder, &pRsp->vgNum) < 0) return -1;
|
if (tDecodeI32(pDecoder, &pRsp->vgNum) < 0) return -1;
|
||||||
|
if (tDecodeI16(pDecoder, &pRsp->hashPrefix) < 0) return -1;
|
||||||
|
if (tDecodeI16(pDecoder, &pRsp->hashSuffix) < 0) return -1;
|
||||||
if (tDecodeI8(pDecoder, &pRsp->hashMethod) < 0) return -1;
|
if (tDecodeI8(pDecoder, &pRsp->hashMethod) < 0) return -1;
|
||||||
|
|
||||||
if (pRsp->vgNum <= 0) {
|
if (pRsp->vgNum <= 0) {
|
||||||
|
|
|
@ -538,12 +538,12 @@ bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset,
|
||||||
} else {
|
} else {
|
||||||
pVal->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
pVal->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tdGetBitmapValType(pIter->pBitmap, pIter->colIdx - 1, &pVal->valType, 0) != TSDB_CODE_SUCCESS) {
|
if (tdGetBitmapValType(pIter->pBitmap, pIter->colIdx - 1, &pVal->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||||
pVal->valType = TD_VTYPE_NONE;
|
pVal->valType = TD_VTYPE_NONE;
|
||||||
return terrno;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pVal->valType == TD_VTYPE_NORM) {
|
if (pVal->valType == TD_VTYPE_NORM) {
|
||||||
|
|
|
@ -343,6 +343,7 @@ typedef struct {
|
||||||
uint32_t hashEnd;
|
uint32_t hashEnd;
|
||||||
char dbName[TSDB_DB_FNAME_LEN];
|
char dbName[TSDB_DB_FNAME_LEN];
|
||||||
int64_t dbUid;
|
int64_t dbUid;
|
||||||
|
int64_t cacheUsage;
|
||||||
int64_t numOfTables;
|
int64_t numOfTables;
|
||||||
int64_t numOfTimeSeries;
|
int64_t numOfTimeSeries;
|
||||||
int64_t totalStorage;
|
int64_t totalStorage;
|
||||||
|
|
|
@ -1171,6 +1171,8 @@ int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUs
|
||||||
pRsp->vgVersion = pDb->vgVersion;
|
pRsp->vgVersion = pDb->vgVersion;
|
||||||
pRsp->vgNum = taosArrayGetSize(pRsp->pVgroupInfos);
|
pRsp->vgNum = taosArrayGetSize(pRsp->pVgroupInfos);
|
||||||
pRsp->hashMethod = pDb->cfg.hashMethod;
|
pRsp->hashMethod = pDb->cfg.hashMethod;
|
||||||
|
pRsp->hashPrefix = pDb->cfg.hashPrefix;
|
||||||
|
pRsp->hashSuffix = pDb->cfg.hashSuffix;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1303,6 +1305,8 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
|
||||||
usedbRsp.vgVersion = pDb->vgVersion;
|
usedbRsp.vgVersion = pDb->vgVersion;
|
||||||
usedbRsp.vgNum = (int32_t)taosArrayGetSize(usedbRsp.pVgroupInfos);
|
usedbRsp.vgNum = (int32_t)taosArrayGetSize(usedbRsp.pVgroupInfos);
|
||||||
usedbRsp.hashMethod = pDb->cfg.hashMethod;
|
usedbRsp.hashMethod = pDb->cfg.hashMethod;
|
||||||
|
usedbRsp.hashPrefix = pDb->cfg.hashPrefix;
|
||||||
|
usedbRsp.hashSuffix = pDb->cfg.hashSuffix;
|
||||||
|
|
||||||
taosArrayPush(batchUseRsp.pArray, &usedbRsp);
|
taosArrayPush(batchUseRsp.pArray, &usedbRsp);
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
|
|
@ -347,6 +347,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
|
SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
|
||||||
if (pVgroup != NULL) {
|
if (pVgroup != NULL) {
|
||||||
if (pVload->syncState == TAOS_SYNC_STATE_LEADER) {
|
if (pVload->syncState == TAOS_SYNC_STATE_LEADER) {
|
||||||
|
pVgroup->cacheUsage = pVload->cacheUsage;
|
||||||
pVgroup->numOfTables = pVload->numOfTables;
|
pVgroup->numOfTables = pVload->numOfTables;
|
||||||
pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
|
pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
|
||||||
pVgroup->totalStorage = pVload->totalStorage;
|
pVgroup->totalStorage = pVload->totalStorage;
|
||||||
|
|
|
@ -696,6 +696,9 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataAppendNULL(pColInfo, numOfRows);
|
colDataAppendNULL(pColInfo, numOfRows);
|
||||||
|
|
||||||
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->cacheUsage, false);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataAppendNULL(pColInfo, numOfRows);
|
colDataAppendNULL(pColInfo, numOfRows);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ target_sources(
|
||||||
# sma
|
# sma
|
||||||
"src/sma/smaEnv.c"
|
"src/sma/smaEnv.c"
|
||||||
"src/sma/smaUtil.c"
|
"src/sma/smaUtil.c"
|
||||||
|
"src/sma/smaFS.c"
|
||||||
"src/sma/smaOpen.c"
|
"src/sma/smaOpen.c"
|
||||||
"src/sma/smaCommit.c"
|
"src/sma/smaCommit.c"
|
||||||
"src/sma/smaRollup.c"
|
"src/sma/smaRollup.c"
|
||||||
|
@ -49,6 +50,10 @@ target_sources(
|
||||||
"src/tsdb/tsdbSnapshot.c"
|
"src/tsdb/tsdbSnapshot.c"
|
||||||
"src/tsdb/tsdbCacheRead.c"
|
"src/tsdb/tsdbCacheRead.c"
|
||||||
"src/tsdb/tsdbRetention.c"
|
"src/tsdb/tsdbRetention.c"
|
||||||
|
"src/tsdb/tsdbDiskData.c"
|
||||||
|
"src/tsdb/tsdbCompress.c"
|
||||||
|
"src/tsdb/tsdbCompact.c"
|
||||||
|
"src/tsdb/tsdbMergeTree.c"
|
||||||
|
|
||||||
# tq
|
# tq
|
||||||
"src/tq/tq.c"
|
"src/tq/tq.c"
|
||||||
|
|
|
@ -155,6 +155,7 @@ int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int6
|
||||||
|
|
||||||
void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity);
|
void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity);
|
||||||
size_t tsdbCacheGetCapacity(SVnode *pVnode);
|
size_t tsdbCacheGetCapacity(SVnode *pVnode);
|
||||||
|
size_t tsdbCacheGetUsage(SVnode *pVnode);
|
||||||
|
|
||||||
// tq
|
// tq
|
||||||
typedef struct SMetaTableInfo {
|
typedef struct SMetaTableInfo {
|
||||||
|
|
|
@ -38,9 +38,10 @@ typedef struct SSmaEnv SSmaEnv;
|
||||||
typedef struct SSmaStat SSmaStat;
|
typedef struct SSmaStat SSmaStat;
|
||||||
typedef struct STSmaStat STSmaStat;
|
typedef struct STSmaStat STSmaStat;
|
||||||
typedef struct SRSmaStat SRSmaStat;
|
typedef struct SRSmaStat SRSmaStat;
|
||||||
typedef struct SSmaKey SSmaKey;
|
typedef struct SRSmaRef SRSmaRef;
|
||||||
typedef struct SRSmaInfo SRSmaInfo;
|
typedef struct SRSmaInfo SRSmaInfo;
|
||||||
typedef struct SRSmaInfoItem SRSmaInfoItem;
|
typedef struct SRSmaInfoItem SRSmaInfoItem;
|
||||||
|
typedef struct SRSmaFS SRSmaFS;
|
||||||
typedef struct SQTaskFile SQTaskFile;
|
typedef struct SQTaskFile SQTaskFile;
|
||||||
typedef struct SQTaskFReader SQTaskFReader;
|
typedef struct SQTaskFReader SQTaskFReader;
|
||||||
typedef struct SQTaskFWriter SQTaskFWriter;
|
typedef struct SQTaskFWriter SQTaskFWriter;
|
||||||
|
@ -54,10 +55,21 @@ struct SSmaEnv {
|
||||||
|
|
||||||
#define SMA_ENV_FLG_CLOSE ((int8_t)0x1)
|
#define SMA_ENV_FLG_CLOSE ((int8_t)0x1)
|
||||||
|
|
||||||
|
struct SRSmaRef {
|
||||||
|
int64_t refId; // for SRSmaStat
|
||||||
|
int64_t suid;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t inited;
|
int8_t inited;
|
||||||
int32_t rsetId;
|
int32_t rsetId;
|
||||||
void *tmrHandle; // shared by all fetch tasks
|
void *tmrHandle; // shared by all fetch tasks
|
||||||
|
/**
|
||||||
|
* @brief key: void* of SRSmaInfoItem, value: SRSmaRef
|
||||||
|
* N.B. Although there is a very small possibility that "void*" point to different objects while with the same
|
||||||
|
* address after release/renew, the functionality is not affected as it just used to fetch the rsma results.
|
||||||
|
*/
|
||||||
|
SHashObj *refHash; // shared by all vgroups
|
||||||
} SSmaMgmt;
|
} SSmaMgmt;
|
||||||
|
|
||||||
#define SMA_ENV_LOCK(env) (&(env)->lock)
|
#define SMA_ENV_LOCK(env) (&(env)->lock)
|
||||||
|
@ -73,22 +85,27 @@ struct STSmaStat {
|
||||||
|
|
||||||
struct SQTaskFile {
|
struct SQTaskFile {
|
||||||
volatile int32_t nRef;
|
volatile int32_t nRef;
|
||||||
int64_t commitID;
|
int32_t padding;
|
||||||
|
int64_t version;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SQTaskFReader {
|
struct SQTaskFReader {
|
||||||
SSma *pSma;
|
SSma *pSma;
|
||||||
SQTaskFile fTask;
|
int64_t version;
|
||||||
TdFilePtr pReadH;
|
TdFilePtr pReadH;
|
||||||
};
|
};
|
||||||
struct SQTaskFWriter {
|
struct SQTaskFWriter {
|
||||||
SSma *pSma;
|
SSma *pSma;
|
||||||
SQTaskFile fTask;
|
int64_t version;
|
||||||
TdFilePtr pWriteH;
|
TdFilePtr pWriteH;
|
||||||
char *fname;
|
char *fname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SRSmaFS {
|
||||||
|
SArray *aQTaskInf; // array of SQTaskFile
|
||||||
|
};
|
||||||
|
|
||||||
struct SRSmaStat {
|
struct SRSmaStat {
|
||||||
SSma *pSma;
|
SSma *pSma;
|
||||||
int64_t commitAppliedVer; // vnode applied version for async commit
|
int64_t commitAppliedVer; // vnode applied version for async commit
|
||||||
|
@ -98,7 +115,7 @@ struct SRSmaStat {
|
||||||
volatile int32_t nFetchAll; // active number of fetch all
|
volatile int32_t nFetchAll; // active number of fetch all
|
||||||
int8_t triggerStat; // shared by fetch tasks
|
int8_t triggerStat; // shared by fetch tasks
|
||||||
int8_t commitStat; // 0 not in committing, 1 in committing
|
int8_t commitStat; // 0 not in committing, 1 in committing
|
||||||
SArray *aTaskFile; // qTaskFiles committed recently(for recovery/snapshot r/w)
|
SRSmaFS fs; // for recovery/snapshot r/w
|
||||||
SHashObj *infoHash; // key: suid, value: SRSmaInfo
|
SHashObj *infoHash; // key: suid, value: SRSmaInfo
|
||||||
tsem_t notEmpty; // has items in queue buffer
|
tsem_t notEmpty; // has items in queue buffer
|
||||||
};
|
};
|
||||||
|
@ -118,6 +135,7 @@ struct SSmaStat {
|
||||||
#define RSMA_TRIGGER_STAT(r) (&(r)->triggerStat)
|
#define RSMA_TRIGGER_STAT(r) (&(r)->triggerStat)
|
||||||
#define RSMA_COMMIT_STAT(r) (&(r)->commitStat)
|
#define RSMA_COMMIT_STAT(r) (&(r)->commitStat)
|
||||||
#define RSMA_REF_ID(r) ((r)->refId)
|
#define RSMA_REF_ID(r) ((r)->refId)
|
||||||
|
#define RSMA_FS(r) (&(r)->fs)
|
||||||
#define RSMA_FS_LOCK(r) (&(r)->lock)
|
#define RSMA_FS_LOCK(r) (&(r)->lock)
|
||||||
|
|
||||||
struct SRSmaInfoItem {
|
struct SRSmaInfoItem {
|
||||||
|
@ -130,9 +148,9 @@ struct SRSmaInfoItem {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SRSmaInfo {
|
struct SRSmaInfo {
|
||||||
|
SSma *pSma;
|
||||||
STSchema *pTSchema;
|
STSchema *pTSchema;
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
int64_t refId; // refId of SRSmaStat
|
|
||||||
int64_t lastRecv; // ms
|
int64_t lastRecv; // ms
|
||||||
int8_t assigned; // 0 idle, 1 assgined for exec
|
int8_t assigned; // 0 idle, 1 assgined for exec
|
||||||
int8_t delFlag;
|
int8_t delFlag;
|
||||||
|
@ -163,14 +181,6 @@ enum {
|
||||||
TASK_TRIGGER_STAT_DROPPED = 5,
|
TASK_TRIGGER_STAT_DROPPED = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
|
||||||
RSMA_ROLE_CREATE = 0,
|
|
||||||
RSMA_ROLE_DROP = 1,
|
|
||||||
RSMA_ROLE_SUBMIT = 2,
|
|
||||||
RSMA_ROLE_FETCH = 3,
|
|
||||||
RSMA_ROLE_ITERATE = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RSMA_RESTORE_REBOOT = 1,
|
RSMA_RESTORE_REBOOT = 1,
|
||||||
RSMA_RESTORE_SYNC = 2,
|
RSMA_RESTORE_SYNC = 2,
|
||||||
|
@ -182,88 +192,34 @@ typedef enum {
|
||||||
RSMA_EXEC_COMMIT = 3, // triggered by commit
|
RSMA_EXEC_COMMIT = 3, // triggered by commit
|
||||||
} ERsmaExecType;
|
} ERsmaExecType;
|
||||||
|
|
||||||
|
// sma
|
||||||
|
int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType);
|
||||||
void tdDestroySmaEnv(SSmaEnv *pSmaEnv);
|
void tdDestroySmaEnv(SSmaEnv *pSmaEnv);
|
||||||
void *tdFreeSmaEnv(SSmaEnv *pSmaEnv);
|
void *tdFreeSmaEnv(SSmaEnv *pSmaEnv);
|
||||||
|
|
||||||
int32_t tdDropTSma(SSma *pSma, char *pMsg);
|
|
||||||
int32_t tdDropTSmaData(SSma *pSma, int64_t indexUid);
|
|
||||||
int32_t tdInsertRSmaData(SSma *pSma, char *msg);
|
|
||||||
|
|
||||||
int32_t tdRefSmaStat(SSma *pSma, SSmaStat *pStat);
|
int32_t tdRefSmaStat(SSma *pSma, SSmaStat *pStat);
|
||||||
int32_t tdUnRefSmaStat(SSma *pSma, SSmaStat *pStat);
|
int32_t tdUnRefSmaStat(SSma *pSma, SSmaStat *pStat);
|
||||||
int32_t tdRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo);
|
int32_t tdLockSma(SSma *pSma);
|
||||||
int32_t tdUnRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo);
|
int32_t tdUnLockSma(SSma *pSma);
|
||||||
|
|
||||||
void *tdAcquireSmaRef(int32_t rsetId, int64_t refId);
|
void *tdAcquireSmaRef(int32_t rsetId, int64_t refId);
|
||||||
int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId);
|
int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId);
|
||||||
|
|
||||||
int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType);
|
// rsma
|
||||||
|
int32_t tdRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo);
|
||||||
int32_t tdLockSma(SSma *pSma);
|
int32_t tdUnRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo);
|
||||||
int32_t tdUnLockSma(SSma *pSma);
|
void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree);
|
||||||
|
int32_t tdRSmaFSOpen(SSma *pSma, int64_t version);
|
||||||
static FORCE_INLINE int8_t tdSmaStat(STSmaStat *pTStat) {
|
void tdRSmaFSClose(SRSmaFS *fs);
|
||||||
if (pTStat) {
|
int32_t tdRSmaFSRef(SSma *pSma, SRSmaStat *pStat, int64_t version);
|
||||||
return atomic_load_8(&pTStat->state);
|
void tdRSmaFSUnRef(SSma *pSma, SRSmaStat *pStat, int64_t version);
|
||||||
}
|
int32_t tdRSmaFSUpsertQTaskFile(SRSmaFS *pFS, SQTaskFile *qTaskFile);
|
||||||
return TSDB_SMA_STAT_UNKNOWN;
|
int32_t tdRSmaRestore(SSma *pSma, int8_t type, int64_t committedVer);
|
||||||
}
|
int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName);
|
||||||
|
int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type);
|
||||||
static FORCE_INLINE bool tdSmaStatIsOK(STSmaStat *pTStat, int8_t *state) {
|
int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash);
|
||||||
if (!pTStat) {
|
int32_t tdRSmaProcessRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state) {
|
|
||||||
*state = atomic_load_8(&pTStat->state);
|
|
||||||
return *state == TSDB_SMA_STAT_OK;
|
|
||||||
}
|
|
||||||
return atomic_load_8(&pTStat->state) == TSDB_SMA_STAT_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE bool tdSmaStatIsExpired(STSmaStat *pTStat) {
|
|
||||||
return pTStat ? (atomic_load_8(&pTStat->state) & TSDB_SMA_STAT_EXPIRED) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE bool tdSmaStatIsDropped(STSmaStat *pTStat) {
|
|
||||||
return pTStat ? (atomic_load_8(&pTStat->state) & TSDB_SMA_STAT_DROPPED) : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void tdSmaStatSetOK(STSmaStat *pTStat) {
|
|
||||||
if (pTStat) {
|
|
||||||
atomic_store_8(&pTStat->state, TSDB_SMA_STAT_OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void tdSmaStatSetExpired(STSmaStat *pTStat) {
|
|
||||||
if (pTStat) {
|
|
||||||
atomic_or_fetch_8(&pTStat->state, TSDB_SMA_STAT_EXPIRED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void tdSmaStatSetDropped(STSmaStat *pTStat) {
|
|
||||||
if (pTStat) {
|
|
||||||
atomic_or_fetch_8(&pTStat->state, TSDB_SMA_STAT_DROPPED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tdRSmaQTaskInfoGetFileName(int32_t vid, int64_t version, char *outputName);
|
void tdRSmaQTaskInfoGetFileName(int32_t vid, int64_t version, char *outputName);
|
||||||
void tdRSmaQTaskInfoGetFullName(int32_t vid, int64_t version, const char *path, char *outputName);
|
void tdRSmaQTaskInfoGetFullName(int32_t vid, int64_t version, const char *path, char *outputName);
|
||||||
int32_t tdCloneRSmaInfo(SSma *pSma, SRSmaInfo *pInfo);
|
|
||||||
void tdFreeQTaskInfo(qTaskInfo_t *taskHandle, int32_t vgId, int32_t level);
|
|
||||||
static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType);
|
|
||||||
void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType);
|
|
||||||
void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree);
|
|
||||||
int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash);
|
|
||||||
int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type);
|
|
||||||
|
|
||||||
int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName);
|
|
||||||
int32_t tdProcessRSmaRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer);
|
|
||||||
int32_t tdRsmaRestore(SSma *pSma, int8_t type, int64_t committedVer);
|
|
||||||
|
|
||||||
int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg);
|
|
||||||
int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg);
|
|
||||||
int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days);
|
|
||||||
|
|
||||||
// smaFileUtil ================
|
// smaFileUtil ================
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,15 @@ typedef struct SMemTable SMemTable;
|
||||||
typedef struct STbDataIter STbDataIter;
|
typedef struct STbDataIter STbDataIter;
|
||||||
typedef struct SMapData SMapData;
|
typedef struct SMapData SMapData;
|
||||||
typedef struct SBlockIdx SBlockIdx;
|
typedef struct SBlockIdx SBlockIdx;
|
||||||
typedef struct SBlock SBlock;
|
typedef struct SDataBlk SDataBlk;
|
||||||
typedef struct SBlockL SBlockL;
|
typedef struct SSttBlk SSttBlk;
|
||||||
typedef struct SColData SColData;
|
typedef struct SColData SColData;
|
||||||
typedef struct SDiskDataHdr SDiskDataHdr;
|
typedef struct SDiskDataHdr SDiskDataHdr;
|
||||||
typedef struct SBlockData SBlockData;
|
typedef struct SBlockData SBlockData;
|
||||||
typedef struct SDelFile SDelFile;
|
typedef struct SDelFile SDelFile;
|
||||||
typedef struct SHeadFile SHeadFile;
|
typedef struct SHeadFile SHeadFile;
|
||||||
typedef struct SDataFile SDataFile;
|
typedef struct SDataFile SDataFile;
|
||||||
typedef struct SLastFile SLastFile;
|
typedef struct SSttFile SSttFile;
|
||||||
typedef struct SSmaFile SSmaFile;
|
typedef struct SSmaFile SSmaFile;
|
||||||
typedef struct SDFileSet SDFileSet;
|
typedef struct SDFileSet SDFileSet;
|
||||||
typedef struct SDataFWriter SDataFWriter;
|
typedef struct SDataFWriter SDataFWriter;
|
||||||
|
@ -64,10 +64,15 @@ typedef struct STsdbReadSnap STsdbReadSnap;
|
||||||
typedef struct SBlockInfo SBlockInfo;
|
typedef struct SBlockInfo SBlockInfo;
|
||||||
typedef struct SSmaInfo SSmaInfo;
|
typedef struct SSmaInfo SSmaInfo;
|
||||||
typedef struct SBlockCol SBlockCol;
|
typedef struct SBlockCol SBlockCol;
|
||||||
|
typedef struct SVersionRange SVersionRange;
|
||||||
|
typedef struct SLDataIter SLDataIter;
|
||||||
|
|
||||||
#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F)
|
#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F)
|
||||||
#define TSDB_MAX_SUBBLOCKS 8
|
#define TSDB_MAX_SUBBLOCKS 8
|
||||||
|
#define TSDB_MAX_STT_FILE 16
|
||||||
|
#define TSDB_DEFAULT_STT_FILE 8
|
||||||
#define TSDB_FHDR_SIZE 512
|
#define TSDB_FHDR_SIZE 512
|
||||||
|
#define TSDB_DEFAULT_PAGE_SIZE 4096
|
||||||
|
|
||||||
#define HAS_NONE ((int8_t)0x1)
|
#define HAS_NONE ((int8_t)0x1)
|
||||||
#define HAS_NULL ((int8_t)0x2)
|
#define HAS_NULL ((int8_t)0x2)
|
||||||
|
@ -79,6 +84,14 @@ typedef struct SBlockCol SBlockCol;
|
||||||
#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN})
|
#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN})
|
||||||
#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX})
|
#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX})
|
||||||
|
|
||||||
|
#define PAGE_CONTENT_SIZE(PAGE) ((PAGE) - sizeof(TSCKSUM))
|
||||||
|
#define LOGIC_TO_FILE_OFFSET(LOFFSET, PAGE) \
|
||||||
|
((LOFFSET) / PAGE_CONTENT_SIZE(PAGE) * (PAGE) + (LOFFSET) % PAGE_CONTENT_SIZE(PAGE))
|
||||||
|
#define FILE_TO_LOGIC_OFFSET(OFFSET, PAGE) ((OFFSET) / (PAGE)*PAGE_CONTENT_SIZE(PAGE) + (OFFSET) % (PAGE))
|
||||||
|
#define PAGE_OFFSET(PGNO, PAGE) (((PGNO)-1) * (PAGE))
|
||||||
|
#define OFFSET_PGNO(OFFSET, PAGE) ((OFFSET) / (PAGE) + 1)
|
||||||
|
#define LOGIC_TO_FILE_SIZE(LSIZE, PAGE) OFFSET_PGNO(LOGIC_TO_FILE_OFFSET(LSIZE, PAGE), PAGE) * (PAGE)
|
||||||
|
|
||||||
// tsdbUtil.c ==============================================================================================
|
// tsdbUtil.c ==============================================================================================
|
||||||
// TSDBROW
|
// TSDBROW
|
||||||
#define TSDBROW_TS(ROW) (((ROW)->type == 0) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
|
#define TSDBROW_TS(ROW) (((ROW)->type == 0) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
|
||||||
|
@ -111,15 +124,15 @@ int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
||||||
int32_t tPutBlockCol(uint8_t *p, void *ph);
|
int32_t tPutBlockCol(uint8_t *p, void *ph);
|
||||||
int32_t tGetBlockCol(uint8_t *p, void *ph);
|
int32_t tGetBlockCol(uint8_t *p, void *ph);
|
||||||
int32_t tBlockColCmprFn(const void *p1, const void *p2);
|
int32_t tBlockColCmprFn(const void *p1, const void *p2);
|
||||||
// SBlock
|
// SDataBlk
|
||||||
void tBlockReset(SBlock *pBlock);
|
void tDataBlkReset(SDataBlk *pBlock);
|
||||||
int32_t tPutBlock(uint8_t *p, void *ph);
|
int32_t tPutDataBlk(uint8_t *p, void *ph);
|
||||||
int32_t tGetBlock(uint8_t *p, void *ph);
|
int32_t tGetDataBlk(uint8_t *p, void *ph);
|
||||||
int32_t tBlockCmprFn(const void *p1, const void *p2);
|
int32_t tDataBlkCmprFn(const void *p1, const void *p2);
|
||||||
bool tBlockHasSma(SBlock *pBlock);
|
bool tDataBlkHasSma(SDataBlk *pDataBlk);
|
||||||
// SBlockL
|
// SSttBlk
|
||||||
int32_t tPutBlockL(uint8_t *p, void *ph);
|
int32_t tPutSttBlk(uint8_t *p, void *ph);
|
||||||
int32_t tGetBlockL(uint8_t *p, void *ph);
|
int32_t tGetSttBlk(uint8_t *p, void *ph);
|
||||||
// SBlockIdx
|
// SBlockIdx
|
||||||
int32_t tPutBlockIdx(uint8_t *p, void *ph);
|
int32_t tPutBlockIdx(uint8_t *p, void *ph);
|
||||||
int32_t tGetBlockIdx(uint8_t *p, void *ph);
|
int32_t tGetBlockIdx(uint8_t *p, void *ph);
|
||||||
|
@ -170,6 +183,7 @@ int32_t tGetDelData(uint8_t *p, void *ph);
|
||||||
void tMapDataReset(SMapData *pMapData);
|
void tMapDataReset(SMapData *pMapData);
|
||||||
void tMapDataClear(SMapData *pMapData);
|
void tMapDataClear(SMapData *pMapData);
|
||||||
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *));
|
int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(uint8_t *, void *));
|
||||||
|
int32_t tMapDataCopy(SMapData *pFrom, SMapData *pTo);
|
||||||
void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *));
|
void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *));
|
||||||
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
|
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
|
||||||
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem);
|
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem);
|
||||||
|
@ -191,7 +205,6 @@ int32_t tsdbCmprColData(SColData *pColData, int8_t cmprAlg, SBlockCol *pBlockCol
|
||||||
uint8_t **ppBuf);
|
uint8_t **ppBuf);
|
||||||
int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, int32_t nVal, SColData *pColData,
|
int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, int32_t nVal, SColData *pColData,
|
||||||
uint8_t **ppBuf);
|
uint8_t **ppBuf);
|
||||||
int32_t tsdbReadAndCheck(TdFilePtr pFD, int64_t offset, uint8_t **ppOut, int32_t size, int8_t toCheck);
|
|
||||||
// tsdbMemTable ==============================================================================================
|
// tsdbMemTable ==============================================================================================
|
||||||
// SMemTable
|
// SMemTable
|
||||||
int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable);
|
int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable);
|
||||||
|
@ -215,7 +228,7 @@ bool tsdbDelFileIsSame(SDelFile *pDelFile1, SDelFile *pDelFile2);
|
||||||
int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype);
|
int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype);
|
||||||
int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile);
|
int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile);
|
||||||
int32_t tPutDataFile(uint8_t *p, SDataFile *pDataFile);
|
int32_t tPutDataFile(uint8_t *p, SDataFile *pDataFile);
|
||||||
int32_t tPutLastFile(uint8_t *p, SLastFile *pLastFile);
|
int32_t tPutSttFile(uint8_t *p, SSttFile *pSttFile);
|
||||||
int32_t tPutSmaFile(uint8_t *p, SSmaFile *pSmaFile);
|
int32_t tPutSmaFile(uint8_t *p, SSmaFile *pSmaFile);
|
||||||
int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile);
|
int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile);
|
||||||
int32_t tGetDelFile(uint8_t *p, SDelFile *pDelFile);
|
int32_t tGetDelFile(uint8_t *p, SDelFile *pDelFile);
|
||||||
|
@ -224,7 +237,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet);
|
||||||
|
|
||||||
void tsdbHeadFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SHeadFile *pHeadF, char fname[]);
|
void tsdbHeadFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SHeadFile *pHeadF, char fname[]);
|
||||||
void tsdbDataFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SDataFile *pDataF, char fname[]);
|
void tsdbDataFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SDataFile *pDataF, char fname[]);
|
||||||
void tsdbLastFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SLastFile *pLastF, char fname[]);
|
void tsdbSttFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSttFile *pSttF, char fname[]);
|
||||||
void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, char fname[]);
|
void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, char fname[]);
|
||||||
// SDelFile
|
// SDelFile
|
||||||
void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]);
|
void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]);
|
||||||
|
@ -250,7 +263,7 @@ int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync);
|
||||||
int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter);
|
int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter);
|
||||||
int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx);
|
int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx);
|
||||||
int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, SBlockIdx *pBlockIdx);
|
int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *pMapData, SBlockIdx *pBlockIdx);
|
||||||
int32_t tsdbWriteBlockL(SDataFWriter *pWriter, SArray *aBlockL);
|
int32_t tsdbWriteSttBlk(SDataFWriter *pWriter, SArray *aSttBlk);
|
||||||
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo,
|
int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlockInfo *pBlkInfo, SSmaInfo *pSmaInfo,
|
||||||
int8_t cmprAlg, int8_t toLast);
|
int8_t cmprAlg, int8_t toLast);
|
||||||
|
|
||||||
|
@ -260,10 +273,10 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
|
||||||
int32_t tsdbDataFReaderClose(SDataFReader **ppReader);
|
int32_t tsdbDataFReaderClose(SDataFReader **ppReader);
|
||||||
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
||||||
int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *pMapData);
|
int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *pMapData);
|
||||||
int32_t tsdbReadBlockL(SDataFReader *pReader, SArray *aBlockL);
|
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
|
||||||
int32_t tsdbReadBlockSma(SDataFReader *pReader, SBlock *pBlock, SArray *aColumnDataAgg);
|
int32_t tsdbReadBlockSma(SDataFReader *pReader, SDataBlk *pBlock, SArray *aColumnDataAgg);
|
||||||
int32_t tsdbReadDataBlock(SDataFReader *pReader, SBlock *pBlock, SBlockData *pBlockData);
|
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pBlock, SBlockData *pBlockData);
|
||||||
int32_t tsdbReadLastBlock(SDataFReader *pReader, SBlockL *pBlockL, SBlockData *pBlockData);
|
int32_t tsdbReadSttBlock(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk, SBlockData *pBlockData);
|
||||||
// SDelFWriter
|
// SDelFWriter
|
||||||
int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb);
|
int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb);
|
||||||
int32_t tsdbDelFWriterClose(SDelFWriter **ppWriter, int8_t sync);
|
int32_t tsdbDelFWriterClose(SDelFWriter **ppWriter, int8_t sync);
|
||||||
|
@ -278,6 +291,8 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx);
|
||||||
// tsdbRead.c ==============================================================================================
|
// tsdbRead.c ==============================================================================================
|
||||||
int32_t tsdbTakeReadSnap(STsdb *pTsdb, STsdbReadSnap **ppSnap);
|
int32_t tsdbTakeReadSnap(STsdb *pTsdb, STsdbReadSnap **ppSnap);
|
||||||
void tsdbUntakeReadSnap(STsdb *pTsdb, STsdbReadSnap *pSnap);
|
void tsdbUntakeReadSnap(STsdb *pTsdb, STsdbReadSnap *pSnap);
|
||||||
|
// tsdbMerge.c ==============================================================================================
|
||||||
|
int32_t tsdbMerge(STsdb *pTsdb);
|
||||||
|
|
||||||
#define TSDB_CACHE_NO(c) ((c).cacheLast == 0)
|
#define TSDB_CACHE_NO(c) ((c).cacheLast == 0)
|
||||||
#define TSDB_CACHE_LAST_ROW(c) (((c).cacheLast & 1) > 0)
|
#define TSDB_CACHE_LAST_ROW(c) (((c).cacheLast & 1) > 0)
|
||||||
|
@ -324,6 +339,11 @@ struct TSDBKEY {
|
||||||
TSKEY ts;
|
TSKEY ts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SVersionRange {
|
||||||
|
uint64_t minVer;
|
||||||
|
uint64_t maxVer;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct SMemSkipListNode SMemSkipListNode;
|
typedef struct SMemSkipListNode SMemSkipListNode;
|
||||||
struct SMemSkipListNode {
|
struct SMemSkipListNode {
|
||||||
int8_t level;
|
int8_t level;
|
||||||
|
@ -416,7 +436,7 @@ struct SSmaInfo {
|
||||||
int32_t size;
|
int32_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SBlock {
|
struct SDataBlk {
|
||||||
TSDBKEY minKey;
|
TSDBKEY minKey;
|
||||||
TSDBKEY maxKey;
|
TSDBKEY maxKey;
|
||||||
int64_t minVer;
|
int64_t minVer;
|
||||||
|
@ -428,7 +448,7 @@ struct SBlock {
|
||||||
SSmaInfo smaInfo;
|
SSmaInfo smaInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SBlockL {
|
struct SSttBlk {
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
int64_t minUid;
|
int64_t minUid;
|
||||||
int64_t maxUid;
|
int64_t maxUid;
|
||||||
|
@ -467,12 +487,6 @@ struct SBlockData {
|
||||||
SArray *aColData; // SArray<SColData>
|
SArray *aColData; // SArray<SColData>
|
||||||
};
|
};
|
||||||
|
|
||||||
// ================== TSDB global config
|
|
||||||
extern bool tsdbForceKeepFile;
|
|
||||||
|
|
||||||
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
|
|
||||||
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
|
|
||||||
|
|
||||||
struct TABLEID {
|
struct TABLEID {
|
||||||
tb_uid_t suid;
|
tb_uid_t suid;
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
|
@ -536,7 +550,7 @@ struct SDataFile {
|
||||||
int64_t size;
|
int64_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SLastFile {
|
struct SSttFile {
|
||||||
volatile int32_t nRef;
|
volatile int32_t nRef;
|
||||||
|
|
||||||
int64_t commitID;
|
int64_t commitID;
|
||||||
|
@ -556,8 +570,9 @@ struct SDFileSet {
|
||||||
int32_t fid;
|
int32_t fid;
|
||||||
SHeadFile *pHeadF;
|
SHeadFile *pHeadF;
|
||||||
SDataFile *pDataF;
|
SDataFile *pDataF;
|
||||||
SLastFile *pLastF;
|
|
||||||
SSmaFile *pSmaF;
|
SSmaFile *pSmaF;
|
||||||
|
uint8_t nSttF;
|
||||||
|
SSttFile *aSttF[TSDB_MAX_STT_FILE];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SRowIter {
|
struct SRowIter {
|
||||||
|
@ -572,37 +587,76 @@ struct SRowMerger {
|
||||||
SArray *pArray; // SArray<SColVal>
|
SArray *pArray; // SArray<SColVal>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *path;
|
||||||
|
int32_t szPage;
|
||||||
|
int32_t flag;
|
||||||
|
TdFilePtr pFD;
|
||||||
|
int64_t pgno;
|
||||||
|
uint8_t *pBuf;
|
||||||
|
int64_t szFile;
|
||||||
|
} STsdbFD;
|
||||||
|
|
||||||
struct SDelFWriter {
|
struct SDelFWriter {
|
||||||
STsdb *pTsdb;
|
STsdb *pTsdb;
|
||||||
SDelFile fDel;
|
SDelFile fDel;
|
||||||
TdFilePtr pWriteH;
|
STsdbFD *pWriteH;
|
||||||
|
|
||||||
uint8_t *aBuf[1];
|
uint8_t *aBuf[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SDataFWriter {
|
|
||||||
STsdb *pTsdb;
|
|
||||||
SDFileSet wSet;
|
|
||||||
|
|
||||||
TdFilePtr pHeadFD;
|
|
||||||
TdFilePtr pDataFD;
|
|
||||||
TdFilePtr pLastFD;
|
|
||||||
TdFilePtr pSmaFD;
|
|
||||||
|
|
||||||
SHeadFile fHead;
|
|
||||||
SDataFile fData;
|
|
||||||
SLastFile fLast;
|
|
||||||
SSmaFile fSma;
|
|
||||||
|
|
||||||
uint8_t *aBuf[4];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct STsdbReadSnap {
|
struct STsdbReadSnap {
|
||||||
SMemTable *pMem;
|
SMemTable *pMem;
|
||||||
SMemTable *pIMem;
|
SMemTable *pIMem;
|
||||||
STsdbFS fs;
|
STsdbFS fs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SDataFWriter {
|
||||||
|
STsdb *pTsdb;
|
||||||
|
SDFileSet wSet;
|
||||||
|
|
||||||
|
STsdbFD *pHeadFD;
|
||||||
|
STsdbFD *pDataFD;
|
||||||
|
STsdbFD *pSmaFD;
|
||||||
|
STsdbFD *pSttFD;
|
||||||
|
|
||||||
|
SHeadFile fHead;
|
||||||
|
SDataFile fData;
|
||||||
|
SSmaFile fSma;
|
||||||
|
SSttFile fStt[TSDB_MAX_STT_FILE];
|
||||||
|
|
||||||
|
uint8_t *aBuf[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SDataFReader {
|
||||||
|
STsdb *pTsdb;
|
||||||
|
SDFileSet *pSet;
|
||||||
|
STsdbFD *pHeadFD;
|
||||||
|
STsdbFD *pDataFD;
|
||||||
|
STsdbFD *pSmaFD;
|
||||||
|
STsdbFD *aSttFD[TSDB_MAX_STT_FILE];
|
||||||
|
uint8_t *aBuf[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t suid;
|
||||||
|
int64_t uid;
|
||||||
|
TSDBROW row;
|
||||||
|
} SRowInfo;
|
||||||
|
|
||||||
|
typedef struct SMergeTree {
|
||||||
|
int8_t backward;
|
||||||
|
SRBTree rbt;
|
||||||
|
SArray *pIterList;
|
||||||
|
SLDataIter *pIter;
|
||||||
|
} SMergeTree;
|
||||||
|
|
||||||
|
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
|
||||||
|
STimeWindow *pTimeWindow, SVersionRange *pVerRange);
|
||||||
|
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
|
||||||
|
bool tMergeTreeNext(SMergeTree *pMTree);
|
||||||
|
TSDBROW tMergeTreeGetRow(SMergeTree *pMTree);
|
||||||
|
void tMergeTreeClose(SMergeTree *pMTree);
|
||||||
|
|
||||||
// ========== inline functions ==========
|
// ========== inline functions ==========
|
||||||
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
||||||
TSDBKEY *pKey1 = (TSDBKEY *)p1;
|
TSDBKEY *pKey1 = (TSDBKEY *)p1;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "tlosertree.h"
|
#include "tlosertree.h"
|
||||||
#include "tlrucache.h"
|
#include "tlrucache.h"
|
||||||
#include "tmsgcb.h"
|
#include "tmsgcb.h"
|
||||||
|
#include "trbtree.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
#include "tstream.h"
|
#include "tstream.h"
|
||||||
|
@ -70,8 +71,8 @@ typedef struct SStreamTaskReader SStreamTaskReader;
|
||||||
typedef struct SStreamTaskWriter SStreamTaskWriter;
|
typedef struct SStreamTaskWriter SStreamTaskWriter;
|
||||||
typedef struct SStreamStateReader SStreamStateReader;
|
typedef struct SStreamStateReader SStreamStateReader;
|
||||||
typedef struct SStreamStateWriter SStreamStateWriter;
|
typedef struct SStreamStateWriter SStreamStateWriter;
|
||||||
typedef struct SRsmaSnapReader SRsmaSnapReader;
|
typedef struct SRSmaSnapReader SRSmaSnapReader;
|
||||||
typedef struct SRsmaSnapWriter SRsmaSnapWriter;
|
typedef struct SRSmaSnapWriter SRSmaSnapWriter;
|
||||||
typedef struct SSnapDataHdr SSnapDataHdr;
|
typedef struct SSnapDataHdr SSnapDataHdr;
|
||||||
|
|
||||||
#define VNODE_META_DIR "meta"
|
#define VNODE_META_DIR "meta"
|
||||||
|
@ -103,7 +104,7 @@ int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq*
|
||||||
int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
|
int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
|
||||||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList);
|
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList);
|
||||||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq, STableMetaRsp** pMetaRsp);
|
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq, STableMetaRsp** pMetaRsp);
|
||||||
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids);
|
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids, int64_t *tbUid);
|
||||||
int metaTtlDropTable(SMeta* pMeta, int64_t ttl, SArray* tbUids);
|
int metaTtlDropTable(SMeta* pMeta, int64_t ttl, SArray* tbUids);
|
||||||
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
|
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
|
||||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||||
|
@ -207,7 +208,7 @@ int32_t tdProcessRSmaCreate(SSma* pSma, SVCreateStbReq* pReq);
|
||||||
int32_t tdProcessRSmaSubmit(SSma* pSma, void* pMsg, int32_t inputType);
|
int32_t tdProcessRSmaSubmit(SSma* pSma, void* pMsg, int32_t inputType);
|
||||||
int32_t tdProcessRSmaDrop(SSma* pSma, SVDropStbReq* pReq);
|
int32_t tdProcessRSmaDrop(SSma* pSma, SVDropStbReq* pReq);
|
||||||
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
|
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
|
||||||
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore);
|
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore, bool isAdd);
|
||||||
void tdUidStoreDestory(STbUidStore* pStore);
|
void tdUidStoreDestory(STbUidStore* pStore);
|
||||||
void* tdUidStoreFree(STbUidStore* pStore);
|
void* tdUidStoreFree(STbUidStore* pStore);
|
||||||
|
|
||||||
|
@ -247,14 +248,14 @@ int32_t tqOffsetSnapWrite(STqOffsetWriter* pWriter, uint8_t* pData, uint32_t nDa
|
||||||
// SStreamTaskReader ======================================
|
// SStreamTaskReader ======================================
|
||||||
// SStreamStateWriter =====================================
|
// SStreamStateWriter =====================================
|
||||||
// SStreamStateReader =====================================
|
// SStreamStateReader =====================================
|
||||||
// SRsmaSnapReader ========================================
|
// SRSmaSnapReader ========================================
|
||||||
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRsmaSnapReader** ppReader);
|
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapReader** ppReader);
|
||||||
int32_t rsmaSnapReaderClose(SRsmaSnapReader** ppReader);
|
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader);
|
||||||
int32_t rsmaSnapRead(SRsmaSnapReader* pReader, uint8_t** ppData);
|
int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData);
|
||||||
// SRsmaSnapWriter ========================================
|
// SRSmaSnapWriter ========================================
|
||||||
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, SRsmaSnapWriter** ppWriter);
|
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapWriter** ppWriter);
|
||||||
int32_t rsmaSnapWrite(SRsmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
int32_t rsmaSnapWrite(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||||
int32_t rsmaSnapWriterClose(SRsmaSnapWriter** ppWriter, int8_t rollback);
|
int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t streamType; // sma or other
|
int8_t streamType; // sma or other
|
||||||
|
|
|
@ -291,6 +291,38 @@ _query:
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
{ // Traverse to find the previous qualified data
|
||||||
|
TBC *pCur;
|
||||||
|
tdbTbcOpen(pMeta->pTbDb, &pCur, NULL);
|
||||||
|
STbDbKey key = {.version = sver, .uid = INT64_MAX};
|
||||||
|
int c = 0;
|
||||||
|
tdbTbcMoveTo(pCur, &key, sizeof(key), &c);
|
||||||
|
if(c < 0){
|
||||||
|
tdbTbcMoveToPrev(pCur);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pKey = NULL;
|
||||||
|
void *pVal = NULL;
|
||||||
|
int vLen = 0, kLen = 0;
|
||||||
|
while(1){
|
||||||
|
int32_t ret = tdbTbcPrev(pCur, &pKey, &kLen, &pVal, &vLen);
|
||||||
|
if (ret < 0) break;
|
||||||
|
|
||||||
|
STbDbKey *tmp = (STbDbKey*)pKey;
|
||||||
|
if(tmp->uid != uid){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
SDecoder dcNew = {0};
|
||||||
|
SMetaEntry meNew = {0};
|
||||||
|
tDecoderInit(&dcNew, pVal, vLen);
|
||||||
|
metaDecodeEntry(&dcNew, &meNew);
|
||||||
|
pSchema = tCloneSSchemaWrapper(&meNew.stbEntry.schemaRow);
|
||||||
|
tDecoderClear(&dcNew);
|
||||||
|
tdbTbcClose(pCur);
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
tdbTbcClose(pCur);
|
||||||
|
}
|
||||||
} else if (me.type == TSDB_CHILD_TABLE) {
|
} else if (me.type == TSDB_CHILD_TABLE) {
|
||||||
uid = me.ctbEntry.suid;
|
uid = me.ctbEntry.suid;
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
|
|
|
@ -474,7 +474,7 @@ _err:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) {
|
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids, tb_uid_t *tbUid) {
|
||||||
void *pData = NULL;
|
void *pData = NULL;
|
||||||
int nData = 0;
|
int nData = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
@ -496,6 +496,10 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
||||||
taosArrayPush(tbUids, &uid);
|
taosArrayPush(tbUids, &uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((type == TSDB_CHILD_TABLE) && tbUid) {
|
||||||
|
*tbUid = uid;
|
||||||
|
}
|
||||||
|
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,15 @@
|
||||||
|
|
||||||
#include "sma.h"
|
#include "sma.h"
|
||||||
|
|
||||||
|
extern SSmaMgmt smaMgmt;
|
||||||
|
|
||||||
static int32_t tdProcessRSmaSyncPreCommitImpl(SSma *pSma);
|
static int32_t tdProcessRSmaSyncPreCommitImpl(SSma *pSma);
|
||||||
static int32_t tdProcessRSmaSyncCommitImpl(SSma *pSma);
|
static int32_t tdProcessRSmaSyncCommitImpl(SSma *pSma);
|
||||||
static int32_t tdProcessRSmaSyncPostCommitImpl(SSma *pSma);
|
static int32_t tdProcessRSmaSyncPostCommitImpl(SSma *pSma);
|
||||||
static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma);
|
static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma);
|
||||||
static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma);
|
static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma);
|
||||||
static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma);
|
static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma);
|
||||||
static int32_t tdCleanupQTaskInfoFiles(SSma *pSma, SRSmaStat *pRSmaStat);
|
static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pRSmaStat);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Only applicable to Rollup SMA
|
* @brief Only applicable to Rollup SMA
|
||||||
|
@ -166,114 +168,51 @@ static int32_t tdProcessRSmaSyncCommitImpl(SSma *pSma) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tdCleanupQTaskInfoFiles(SSma *pSma, SRSmaStat *pRSmaStat) {
|
|
||||||
SVnode *pVnode = pSma->pVnode;
|
|
||||||
int64_t committed = pRSmaStat->commitAppliedVer;
|
|
||||||
TdDirPtr pDir = NULL;
|
|
||||||
TdDirEntryPtr pDirEntry = NULL;
|
|
||||||
char dir[TSDB_FILENAME_LEN];
|
|
||||||
const char *pattern = "v[0-9]+qinf\\.v([0-9]+)?$";
|
|
||||||
regex_t regex;
|
|
||||||
int code = 0;
|
|
||||||
|
|
||||||
tdGetVndDirName(TD_VID(pVnode), tfsGetPrimaryPath(pVnode->pTfs), VNODE_RSMA_DIR, true, dir);
|
|
||||||
|
|
||||||
// Resource allocation and init
|
|
||||||
if ((code = regcomp(®ex, pattern, REG_EXTENDED)) != 0) {
|
|
||||||
char errbuf[128];
|
|
||||||
regerror(code, ®ex, errbuf, sizeof(errbuf));
|
|
||||||
smaWarn("vgId:%d, rsma post commit, regcomp for %s failed since %s", TD_VID(pVnode), dir, errbuf);
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((pDir = taosOpenDir(dir)) == NULL) {
|
|
||||||
regfree(®ex);
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
smaDebug("vgId:%d, rsma post commit, open dir %s failed since %s", TD_VID(pVnode), dir, terrstr());
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t dirLen = strlen(dir);
|
|
||||||
char *dirEnd = POINTER_SHIFT(dir, dirLen);
|
|
||||||
regmatch_t regMatch[2];
|
|
||||||
while ((pDirEntry = taosReadDir(pDir)) != NULL) {
|
|
||||||
char *entryName = taosGetDirEntryName(pDirEntry);
|
|
||||||
if (!entryName) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = regexec(®ex, entryName, 2, regMatch, 0);
|
|
||||||
|
|
||||||
if (code == 0) {
|
|
||||||
// match
|
|
||||||
int64_t version = -1;
|
|
||||||
sscanf((const char *)POINTER_SHIFT(entryName, regMatch[1].rm_so), "%" PRIi64, &version);
|
|
||||||
if ((version < committed) && (version > -1)) {
|
|
||||||
strncpy(dirEnd, entryName, TSDB_FILENAME_LEN - dirLen);
|
|
||||||
if (taosRemoveFile(dir) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
smaWarn("vgId:%d, committed version:%" PRIi64 ", failed to remove %s since %s", TD_VID(pVnode), committed,
|
|
||||||
dir, terrstr());
|
|
||||||
} else {
|
|
||||||
smaDebug("vgId:%d, committed version:%" PRIi64 ", success to remove %s", TD_VID(pVnode), committed, dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (code == REG_NOMATCH) {
|
|
||||||
// not match
|
|
||||||
smaTrace("vgId:%d, rsma post commit, not match %s", TD_VID(pVnode), entryName);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// has other error
|
|
||||||
char errbuf[128];
|
|
||||||
regerror(code, ®ex, errbuf, sizeof(errbuf));
|
|
||||||
smaWarn("vgId:%d, rsma post commit, regexec failed since %s", TD_VID(pVnode), errbuf);
|
|
||||||
|
|
||||||
taosCloseDir(&pDir);
|
|
||||||
regfree(®ex);
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
taosCloseDir(&pDir);
|
|
||||||
regfree(®ex);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SQTaskFile ======================================================
|
// SQTaskFile ======================================================
|
||||||
// int32_t tCmprQTaskFile(void const *lhs, void const *rhs) {
|
|
||||||
// int64_t *lCommitted = *(int64_t *)lhs;
|
|
||||||
// SQTaskFile *rQTaskF = (SQTaskFile *)rhs;
|
|
||||||
|
|
||||||
// if (lCommitted < rQTaskF->commitID) {
|
|
||||||
// return -1;
|
|
||||||
// } else if (lCommitted > rQTaskF->commitID) {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/**
|
/**
|
||||||
* @brief At most time, there is only one qtaskinfo file committed latest in aTaskFile. Sometimes, there would be
|
* @brief At most time, there is only one qtaskinfo file committed latest in aTaskFile. Sometimes, there would be
|
||||||
* multiple qtaskinfo files supporting snapshot replication.
|
* multiple qtaskinfo files supporting snapshot replication.
|
||||||
*
|
*
|
||||||
* @param pSma
|
* @param pSma
|
||||||
* @param pRSmaStat
|
* @param pStat
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t tdCleanupQTaskInfoFiles(SSma *pSma, SRSmaStat *pRSmaStat) {
|
static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
|
||||||
SVnode *pVnode = pSma->pVnode;
|
SVnode *pVnode = pSma->pVnode;
|
||||||
int64_t committed = pRSmaStat->commitAppliedVer;
|
SRSmaFS *pFS = RSMA_FS(pStat);
|
||||||
SArray *aTaskFile = pRSmaStat->aTaskFile;
|
int64_t committed = pStat->commitAppliedVer;
|
||||||
|
char qTaskInfoFullName[TSDB_FILENAME_LEN];
|
||||||
|
|
||||||
void *qTaskFile = taosArraySearch(aTaskFile, committed, tCmprQTaskFile, TD_LE);
|
taosWLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(pFS->aQTaskInf);) {
|
||||||
|
SQTaskFile *pTaskF = taosArrayGet(pFS->aQTaskInf, i);
|
||||||
|
int32_t oldVal = atomic_fetch_sub_32(&pTaskF->nRef, 1);
|
||||||
|
if ((oldVal <= 1) && (pTaskF->version < committed)) {
|
||||||
|
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->version, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
|
||||||
|
if (taosRemoveFile(qTaskInfoFullName) < 0) {
|
||||||
|
smaWarn("vgId:%d, cleanup qinf, committed %" PRIi64 ", failed to remove %s since %s", TD_VID(pVnode), committed,
|
||||||
|
qTaskInfoFullName, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||||
|
} else {
|
||||||
|
smaDebug("vgId:%d, cleanup qinf, committed %" PRIi64 ", success to remove %s", TD_VID(pVnode), committed,
|
||||||
|
qTaskInfoFullName);
|
||||||
|
}
|
||||||
|
taosArrayRemove(pFS->aQTaskInf, i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
SQTaskFile qFile = {.nRef = 1, .padding = 0, .version = committed, .size = 0};
|
||||||
|
if (tdRSmaFSUpsertQTaskFile(pFS, &qFile) < 0) {
|
||||||
|
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief post-commit for rollup sma
|
* @brief post-commit for rollup sma
|
||||||
|
@ -290,8 +229,7 @@ static int32_t tdProcessRSmaSyncPostCommitImpl(SSma *pSma) {
|
||||||
|
|
||||||
SRSmaStat *pRSmaStat = SMA_RSMA_STAT(pSma);
|
SRSmaStat *pRSmaStat = SMA_RSMA_STAT(pSma);
|
||||||
|
|
||||||
// cleanup outdated qtaskinfo files
|
tdUpdateQTaskInfoFiles(pSma, pRSmaStat);
|
||||||
tdCleanupQTaskInfoFiles(pSma, pRSmaStat);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -428,7 +366,6 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||||
SArray *rsmaDeleted = NULL;
|
|
||||||
|
|
||||||
// step 1: merge qTaskInfo and iQTaskInfo
|
// step 1: merge qTaskInfo and iQTaskInfo
|
||||||
// lock
|
// lock
|
||||||
|
@ -441,11 +378,7 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
|
||||||
if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
|
if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
|
||||||
int32_t refVal = T_REF_VAL_GET(pRSmaInfo);
|
int32_t refVal = T_REF_VAL_GET(pRSmaInfo);
|
||||||
if (refVal == 0) {
|
if (refVal == 0) {
|
||||||
if (!rsmaDeleted) {
|
taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid));
|
||||||
if ((rsmaDeleted = taosArrayInit(1, sizeof(tb_uid_t)))) {
|
|
||||||
taosArrayPush(rsmaDeleted, pSuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
smaDebug(
|
smaDebug(
|
||||||
"vgId:%d, rsma async post commit, not free rsma info since ref is %d although already deleted for "
|
"vgId:%d, rsma async post commit, not free rsma info since ref is %d although already deleted for "
|
||||||
|
@ -471,25 +404,10 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(rsmaDeleted); ++i) {
|
|
||||||
tb_uid_t *pSuid = taosArrayGet(rsmaDeleted, i);
|
|
||||||
void *pRSmaInfo = taosHashGet(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(tb_uid_t));
|
|
||||||
if ((pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
|
||||||
tdFreeRSmaInfo(pSma, pRSmaInfo, true);
|
|
||||||
smaDebug(
|
|
||||||
"vgId:%d, rsma async post commit, free rsma info since already deleted and ref is 0 for "
|
|
||||||
"table:%" PRIi64,
|
|
||||||
SMA_VID(pSma), *pSuid);
|
|
||||||
}
|
|
||||||
taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(tb_uid_t));
|
|
||||||
}
|
|
||||||
taosArrayDestroy(rsmaDeleted);
|
|
||||||
|
|
||||||
// unlock
|
// unlock
|
||||||
// taosWUnLockLatch(SMA_ENV_LOCK(pEnv));
|
// taosWUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||||
|
|
||||||
// step 2: cleanup outdated qtaskinfo files
|
tdUpdateQTaskInfoFiles(pSma, pRSmaStat);
|
||||||
tdCleanupQTaskInfoFiles(pSma, pRSmaStat);
|
|
||||||
|
|
||||||
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ static int32_t tdInitSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv);
|
||||||
static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma);
|
static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma);
|
||||||
static int32_t tdRsmaStartExecutor(const SSma *pSma);
|
static int32_t tdRsmaStartExecutor(const SSma *pSma);
|
||||||
static int32_t tdRsmaStopExecutor(const SSma *pSma);
|
static int32_t tdRsmaStopExecutor(const SSma *pSma);
|
||||||
|
static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType);
|
||||||
|
static void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType);
|
||||||
static void *tdFreeTSmaStat(STSmaStat *pStat);
|
static void *tdFreeTSmaStat(STSmaStat *pStat);
|
||||||
static void tdDestroyRSmaStat(void *pRSmaStat);
|
static void tdDestroyRSmaStat(void *pRSmaStat);
|
||||||
|
|
||||||
|
@ -59,12 +61,23 @@ int32_t smaInit() {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t type = (8 == POINTER_BYTES) ? TSDB_DATA_TYPE_UBIGINT : TSDB_DATA_TYPE_UINT;
|
||||||
|
smaMgmt.refHash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_ENTRY_LOCK);
|
||||||
|
if (!smaMgmt.refHash) {
|
||||||
|
taosCloseRef(smaMgmt.rsetId);
|
||||||
|
atomic_store_8(&smaMgmt.inited, 0);
|
||||||
|
smaError("failed to init sma tmr hanle since %s", terrstr());
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
// init fetch timer handle
|
// init fetch timer handle
|
||||||
smaMgmt.tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA");
|
smaMgmt.tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA");
|
||||||
if (!smaMgmt.tmrHandle) {
|
if (!smaMgmt.tmrHandle) {
|
||||||
taosCloseRef(smaMgmt.rsetId);
|
taosCloseRef(smaMgmt.rsetId);
|
||||||
|
taosHashCleanup(smaMgmt.refHash);
|
||||||
|
smaMgmt.refHash = NULL;
|
||||||
atomic_store_8(&smaMgmt.inited, 0);
|
atomic_store_8(&smaMgmt.inited, 0);
|
||||||
smaError("failed to init sma tmr hanle since %s", terrstr());
|
smaError("failed to init sma tmr handle since %s", terrstr());
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +106,8 @@ void smaCleanUp() {
|
||||||
|
|
||||||
if (old == 1) {
|
if (old == 1) {
|
||||||
taosCloseRef(smaMgmt.rsetId);
|
taosCloseRef(smaMgmt.rsetId);
|
||||||
|
taosHashCleanup(smaMgmt.refHash);
|
||||||
|
smaMgmt.refHash = NULL;
|
||||||
taosTmrCleanUp(smaMgmt.tmrHandle);
|
taosTmrCleanUp(smaMgmt.tmrHandle);
|
||||||
smaInfo("sma mgmt env is cleaned up, rsetId:%d, tmrHandle:%p", smaMgmt.rsetId, smaMgmt.tmrHandle);
|
smaInfo("sma mgmt env is cleaned up, rsetId:%d, tmrHandle:%p", smaMgmt.rsetId, smaMgmt.tmrHandle);
|
||||||
atomic_store_8(&smaMgmt.inited, 0);
|
atomic_store_8(&smaMgmt.inited, 0);
|
||||||
|
@ -195,6 +210,21 @@ int32_t tdUnRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tRSmaInfoHashFreeNode(void *data) {
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
SRSmaInfoItem *pItem = NULL;
|
||||||
|
|
||||||
|
if ((pRSmaInfo = *(SRSmaInfo **)data)) {
|
||||||
|
if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 0)) && pItem->level) {
|
||||||
|
taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
|
||||||
|
}
|
||||||
|
if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 1)) && pItem->level) {
|
||||||
|
taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
|
||||||
|
}
|
||||||
|
tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma) {
|
static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma) {
|
||||||
ASSERT(pSmaStat != NULL);
|
ASSERT(pSmaStat != NULL);
|
||||||
|
|
||||||
|
@ -240,10 +270,16 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
||||||
if (!RSMA_INFO_HASH(pRSmaStat)) {
|
if (!RSMA_INFO_HASH(pRSmaStat)) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
taosHashSetFreeFp(RSMA_INFO_HASH(pRSmaStat), tRSmaInfoHashFreeNode);
|
||||||
|
|
||||||
if (tdRsmaStartExecutor(pSma) < 0) {
|
if (tdRsmaStartExecutor(pSma) < 0) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(RSMA_FS(pRSmaStat)->aQTaskInf = taosArrayInit(1, sizeof(SQTaskFile)))) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
// TODO
|
// TODO
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,14 +314,6 @@ static void tdDestroyRSmaStat(void *pRSmaStat) {
|
||||||
tsem_destroy(&(pStat->notEmpty));
|
tsem_destroy(&(pStat->notEmpty));
|
||||||
|
|
||||||
// step 2: destroy the rsma info and associated fetch tasks
|
// step 2: destroy the rsma info and associated fetch tasks
|
||||||
if (taosHashGetSize(RSMA_INFO_HASH(pStat)) > 0) {
|
|
||||||
void *infoHash = taosHashIterate(RSMA_INFO_HASH(pStat), NULL);
|
|
||||||
while (infoHash) {
|
|
||||||
SRSmaInfo *pSmaInfo = *(SRSmaInfo **)infoHash;
|
|
||||||
tdFreeRSmaInfo(pSma, pSmaInfo, true);
|
|
||||||
infoHash = taosHashIterate(RSMA_INFO_HASH(pStat), infoHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
taosHashCleanup(RSMA_INFO_HASH(pStat));
|
taosHashCleanup(RSMA_INFO_HASH(pStat));
|
||||||
|
|
||||||
// step 3: wait for all triggered fetch tasks to finish
|
// step 3: wait for all triggered fetch tasks to finish
|
||||||
|
@ -307,12 +335,15 @@ static void tdDestroyRSmaStat(void *pRSmaStat) {
|
||||||
// step 4:
|
// step 4:
|
||||||
tdRsmaStopExecutor(pSma);
|
tdRsmaStopExecutor(pSma);
|
||||||
|
|
||||||
// step 5: free pStat
|
// step 5:
|
||||||
|
tdRSmaFSClose(RSMA_FS(pStat));
|
||||||
|
|
||||||
|
// step 6: free pStat
|
||||||
taosMemoryFreeClear(pStat);
|
taosMemoryFreeClear(pStat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
static void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||||
tdDestroySmaState(pSmaStat, smaType);
|
tdDestroySmaState(pSmaStat, smaType);
|
||||||
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
taosMemoryFreeClear(pSmaStat);
|
taosMemoryFreeClear(pSmaStat);
|
||||||
|
@ -329,7 +360,7 @@ void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||||
if (pSmaStat) {
|
if (pSmaStat) {
|
||||||
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
tdDestroyTSmaStat(SMA_STAT_TSMA(pSmaStat));
|
tdDestroyTSmaStat(SMA_STAT_TSMA(pSmaStat));
|
||||||
|
@ -337,7 +368,7 @@ int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||||
SRSmaStat *pRSmaStat = &pSmaStat->rsmaStat;
|
SRSmaStat *pRSmaStat = &pSmaStat->rsmaStat;
|
||||||
int32_t vid = SMA_VID(pRSmaStat->pSma);
|
int32_t vid = SMA_VID(pRSmaStat->pSma);
|
||||||
int64_t refId = RSMA_REF_ID(pRSmaStat);
|
int64_t refId = RSMA_REF_ID(pRSmaStat);
|
||||||
if (taosRemoveRef(smaMgmt.rsetId, RSMA_REF_ID(pRSmaStat)) < 0) {
|
if (taosRemoveRef(smaMgmt.rsetId, refId) < 0) {
|
||||||
smaError("vgId:%d, remove refId:%" PRIi64 " from rsmaRef:%" PRIi32 " failed since %s", vid, refId,
|
smaError("vgId:%d, remove refId:%" PRIi64 " from rsmaRef:%" PRIi32 " failed since %s", vid, refId,
|
||||||
smaMgmt.rsetId, terrstr());
|
smaMgmt.rsetId, terrstr());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,252 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sma.h"
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
static int32_t tdFetchQTaskInfoFiles(SSma *pSma, int64_t version, SArray **output);
|
||||||
|
static int32_t tdQTaskInfCmprFn1(const void *p1, const void *p2);
|
||||||
|
static int32_t tdQTaskInfCmprFn2(const void *p1, const void *p2);
|
||||||
|
/**
|
||||||
|
* @brief Open RSma FS from qTaskInfo files
|
||||||
|
*
|
||||||
|
* @param pSma
|
||||||
|
* @param version
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tdRSmaFSOpen(SSma *pSma, int64_t version) {
|
||||||
|
SVnode *pVnode = pSma->pVnode;
|
||||||
|
int64_t commitID = pVnode->state.commitID;
|
||||||
|
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||||
|
SRSmaStat *pStat = NULL;
|
||||||
|
SArray *output = NULL;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
if (!pEnv) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tdFetchQTaskInfoFiles(pSma, version, &output) < 0) {
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
|
||||||
|
pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(output); ++i) {
|
||||||
|
int32_t vid = 0;
|
||||||
|
int64_t version = -1;
|
||||||
|
sscanf((const char *)taosArrayGetP(output, i), "v%dqinfo.v%" PRIi64, &vid, &version);
|
||||||
|
SQTaskFile qTaskFile = {.version = version, .nRef = 1};
|
||||||
|
if ((terrno = tdRSmaFSUpsertQTaskFile(RSMA_FS(pStat), &qTaskFile)) < 0) {
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
smaInfo("vgId:%d, open fs, version:%" PRIi64 ", ref:%" PRIi64, TD_VID(pVnode), qTaskFile.version, qTaskFile.nRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(output); ++i) {
|
||||||
|
void *ptr = taosArrayGetP(output, i);
|
||||||
|
taosMemoryFreeClear(ptr);
|
||||||
|
}
|
||||||
|
taosArrayDestroy(output);
|
||||||
|
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
smaError("vgId:%d, open rsma fs failed since %s", TD_VID(pVnode), terrstr());
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tdRSmaFSClose(SRSmaFS *fs) { taosArrayDestroy(fs->aQTaskInf); }
|
||||||
|
|
||||||
|
static int32_t tdQTaskInfCmprFn1(const void *p1, const void *p2) {
|
||||||
|
if (*(int64_t *)p1 < ((SQTaskFile *)p2)->version) {
|
||||||
|
return -1;
|
||||||
|
} else if (*(int64_t *)p1 > ((SQTaskFile *)p2)->version) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tdRSmaFSRef(SSma *pSma, SRSmaStat *pStat, int64_t version) {
|
||||||
|
SArray *aQTaskInf = RSMA_FS(pStat)->aQTaskInf;
|
||||||
|
SQTaskFile *pTaskF = NULL;
|
||||||
|
int32_t oldVal = 0;
|
||||||
|
|
||||||
|
taosRLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
|
if ((pTaskF = taosArraySearch(aQTaskInf, &version, tdQTaskInfCmprFn1, TD_EQ))) {
|
||||||
|
oldVal = atomic_fetch_add_32(&pTaskF->nRef, 1);
|
||||||
|
ASSERT(oldVal > 0);
|
||||||
|
}
|
||||||
|
taosRUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
|
return oldVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tdRSmaFSUnRef(SSma *pSma, SRSmaStat *pStat, int64_t version) {
|
||||||
|
SVnode *pVnode = pSma->pVnode;
|
||||||
|
SArray *aQTaskInf = RSMA_FS(pStat)->aQTaskInf;
|
||||||
|
char qTaskFullName[TSDB_FILENAME_LEN];
|
||||||
|
SQTaskFile *pTaskF = NULL;
|
||||||
|
int32_t idx = -1;
|
||||||
|
|
||||||
|
taosWLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
|
if ((idx = taosArraySearchIdx(aQTaskInf, &version, tdQTaskInfCmprFn1, TD_EQ)) >= 0) {
|
||||||
|
ASSERT(idx < taosArrayGetSize(aQTaskInf));
|
||||||
|
pTaskF = taosArrayGet(aQTaskInf, idx);
|
||||||
|
if (atomic_sub_fetch_32(&pTaskF->nRef, 1) <= 0) {
|
||||||
|
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->version, tfsGetPrimaryPath(pVnode->pTfs), qTaskFullName);
|
||||||
|
if (taosRemoveFile(qTaskFullName) < 0) {
|
||||||
|
smaWarn("vgId:%d, failed to remove %s since %s", TD_VID(pVnode), qTaskFullName,
|
||||||
|
tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||||
|
} else {
|
||||||
|
smaDebug("vgId:%d, success to remove %s", TD_VID(pVnode), qTaskFullName);
|
||||||
|
}
|
||||||
|
taosArrayRemove(aQTaskInf, idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fetch qtaskfiles LE than version
|
||||||
|
*
|
||||||
|
* @param pSma
|
||||||
|
* @param version
|
||||||
|
* @param output
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
static int32_t tdFetchQTaskInfoFiles(SSma *pSma, int64_t version, SArray **output) {
|
||||||
|
SVnode *pVnode = pSma->pVnode;
|
||||||
|
TdDirPtr pDir = NULL;
|
||||||
|
TdDirEntryPtr pDirEntry = NULL;
|
||||||
|
char dir[TSDB_FILENAME_LEN];
|
||||||
|
const char *pattern = "v[0-9]+qinf\\.v([0-9]+)?$";
|
||||||
|
regex_t regex;
|
||||||
|
int code = 0;
|
||||||
|
|
||||||
|
tdGetVndDirName(TD_VID(pVnode), tfsGetPrimaryPath(pVnode->pTfs), VNODE_RSMA_DIR, true, dir);
|
||||||
|
|
||||||
|
if (!taosCheckExistFile(dir)) {
|
||||||
|
smaDebug("vgId:%d, fetch qtask files, no need as dir %s not exist", TD_VID(pVnode), dir);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resource allocation and init
|
||||||
|
if ((code = regcomp(®ex, pattern, REG_EXTENDED)) != 0) {
|
||||||
|
terrno = TSDB_CODE_RSMA_REGEX_MATCH;
|
||||||
|
char errbuf[128];
|
||||||
|
regerror(code, ®ex, errbuf, sizeof(errbuf));
|
||||||
|
smaWarn("vgId:%d, fetch qtask files, regcomp for %s failed since %s", TD_VID(pVnode), dir, errbuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(pDir = taosOpenDir(dir))) {
|
||||||
|
regfree(®ex);
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
smaError("vgId:%d, fetch qtask files, open dir %s failed since %s", TD_VID(pVnode), dir, terrstr());
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dirLen = strlen(dir);
|
||||||
|
char *dirEnd = POINTER_SHIFT(dir, dirLen);
|
||||||
|
regmatch_t regMatch[2];
|
||||||
|
while ((pDirEntry = taosReadDir(pDir))) {
|
||||||
|
char *entryName = taosGetDirEntryName(pDirEntry);
|
||||||
|
if (!entryName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = regexec(®ex, entryName, 2, regMatch, 0);
|
||||||
|
|
||||||
|
if (code == 0) {
|
||||||
|
// match
|
||||||
|
smaInfo("vgId:%d, fetch qtask files, max ver:%" PRIi64 ", %s found", TD_VID(pVnode), version, entryName);
|
||||||
|
|
||||||
|
int64_t ver = -1;
|
||||||
|
sscanf((const char *)POINTER_SHIFT(entryName, regMatch[1].rm_so), "%" PRIi64, &ver);
|
||||||
|
if ((ver <= version) && (ver > -1)) {
|
||||||
|
if (!(*output)) {
|
||||||
|
if (!(*output = taosArrayInit(1, POINTER_BYTES))) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
char *entryDup = strdup(entryName);
|
||||||
|
if (!entryDup) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
if (!taosArrayPush(*output, &entryDup)) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
} else if (code == REG_NOMATCH) {
|
||||||
|
// not match
|
||||||
|
smaTrace("vgId:%d, fetch qtask files, not match %s", TD_VID(pVnode), entryName);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
// has other error
|
||||||
|
char errbuf[128];
|
||||||
|
regerror(code, ®ex, errbuf, sizeof(errbuf));
|
||||||
|
smaWarn("vgId:%d, fetch qtask files, regexec failed since %s", TD_VID(pVnode), errbuf);
|
||||||
|
terrno = TSDB_CODE_RSMA_REGEX_MATCH;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_end:
|
||||||
|
taosCloseDir(&pDir);
|
||||||
|
regfree(®ex);
|
||||||
|
return terrno == 0 ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tdQTaskFileCmprFn2(const void *p1, const void *p2) {
|
||||||
|
if (((SQTaskFile *)p1)->version < ((SQTaskFile *)p2)->version) {
|
||||||
|
return -1;
|
||||||
|
} else if (((SQTaskFile *)p1)->version > ((SQTaskFile *)p2)->version) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tdRSmaFSUpsertQTaskFile(SRSmaFS *pFS, SQTaskFile *qTaskFile) {
|
||||||
|
int32_t code = 0;
|
||||||
|
int32_t idx = taosArraySearchIdx(pFS->aQTaskInf, qTaskFile, tdQTaskFileCmprFn2, TD_GE);
|
||||||
|
|
||||||
|
if (idx < 0) {
|
||||||
|
idx = taosArrayGetSize(pFS->aQTaskInf);
|
||||||
|
} else {
|
||||||
|
SQTaskFile *pTaskF = (SQTaskFile *)taosArrayGet(pFS->aQTaskInf, idx);
|
||||||
|
int32_t c = tdQTaskFileCmprFn2(pTaskF, qTaskFile);
|
||||||
|
if (c == 0) {
|
||||||
|
pTaskF->nRef = qTaskFile->nRef;
|
||||||
|
pTaskF->version = qTaskFile->version;
|
||||||
|
pTaskF->size = qTaskFile->size;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosArrayInsert(pFS->aQTaskInf, idx, qTaskFile) == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return code;
|
||||||
|
}
|
|
@ -150,7 +150,7 @@ int32_t smaOpen(SVnode *pVnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore the rsma
|
// restore the rsma
|
||||||
if (tdRsmaRestore(pSma, RSMA_RESTORE_REBOOT, pVnode->state.committed) < 0) {
|
if (tdRSmaRestore(pSma, RSMA_RESTORE_REBOOT, pVnode->state.committed) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,8 +181,8 @@ int32_t smaClose(SSma *pSma) {
|
||||||
* @param committedVer
|
* @param committedVer
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tdRsmaRestore(SSma *pSma, int8_t type, int64_t committedVer) {
|
int32_t tdRSmaRestore(SSma *pSma, int8_t type, int64_t committedVer) {
|
||||||
ASSERT(VND_IS_RSMA(pSma->pVnode));
|
ASSERT(VND_IS_RSMA(pSma->pVnode));
|
||||||
|
|
||||||
return tdProcessRSmaRestoreImpl(pSma, type, committedVer);
|
return tdRSmaProcessRestoreImpl(pSma, type, committedVer);
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@
|
||||||
#define RSMA_QTASKEXEC_SMOOTH_SIZE (100) // cnt
|
#define RSMA_QTASKEXEC_SMOOTH_SIZE (100) // cnt
|
||||||
#define RSMA_SUBMIT_BATCH_SIZE (1024) // cnt
|
#define RSMA_SUBMIT_BATCH_SIZE (1024) // cnt
|
||||||
#define RSMA_FETCH_DELAY_MAX (900000) // ms
|
#define RSMA_FETCH_DELAY_MAX (900000) // ms
|
||||||
#define RSMA_FETCH_ACTIVE_MAX (1800) // ms
|
#define RSMA_FETCH_ACTIVE_MAX (1000) // ms
|
||||||
#define RSMA_FETCH_INTERVAL (5000) // ms
|
#define RSMA_FETCH_INTERVAL (5000) // ms
|
||||||
|
|
||||||
SSmaMgmt smaMgmt = {
|
SSmaMgmt smaMgmt = {
|
||||||
|
@ -34,7 +34,7 @@ typedef struct SRSmaQTaskInfoItem SRSmaQTaskInfoItem;
|
||||||
typedef struct SRSmaQTaskInfoIter SRSmaQTaskInfoIter;
|
typedef struct SRSmaQTaskInfoIter SRSmaQTaskInfoIter;
|
||||||
|
|
||||||
static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
||||||
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids);
|
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids, bool isAdd);
|
||||||
static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo,
|
static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo,
|
||||||
int8_t idx);
|
int8_t idx);
|
||||||
static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize, int32_t inputType, SRSmaInfo *pInfo,
|
static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize, int32_t inputType, SRSmaInfo *pInfo,
|
||||||
|
@ -42,10 +42,12 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSiz
|
||||||
static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid);
|
static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid);
|
||||||
static void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo);
|
static void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo);
|
||||||
static void tdFreeRSmaSubmitItems(SArray *pItems);
|
static void tdFreeRSmaSubmitItems(SArray *pItems);
|
||||||
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo, SArray *pSubmitArr);
|
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo);
|
||||||
static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSmaInfoItem *pItem, STSchema *pTSchema,
|
static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSmaInfoItem *pItem, STSchema *pTSchema,
|
||||||
int64_t suid);
|
int64_t suid);
|
||||||
static void tdRSmaFetchTrigger(void *param, void *tmrId);
|
static void tdRSmaFetchTrigger(void *param, void *tmrId);
|
||||||
|
static int32_t tdRSmaInfoClone(SSma *pSma, SRSmaInfo *pInfo);
|
||||||
|
static void tdRSmaQTaskInfoFree(qTaskInfo_t *taskHandle, int32_t vgId, int32_t level);
|
||||||
static int32_t tdRSmaQTaskInfoIterInit(SRSmaQTaskInfoIter *pIter, STFile *pTFile);
|
static int32_t tdRSmaQTaskInfoIterInit(SRSmaQTaskInfoIter *pIter, STFile *pTFile);
|
||||||
static int32_t tdRSmaQTaskInfoIterNextBlock(SRSmaQTaskInfoIter *pIter, bool *isFinish);
|
static int32_t tdRSmaQTaskInfoIterNextBlock(SRSmaQTaskInfoIter *pIter, bool *isFinish);
|
||||||
static int32_t tdRSmaQTaskInfoRestore(SSma *pSma, int8_t type, SRSmaQTaskInfoIter *pIter);
|
static int32_t tdRSmaQTaskInfoRestore(SSma *pSma, int8_t type, SRSmaQTaskInfoIter *pIter);
|
||||||
|
@ -96,7 +98,7 @@ static FORCE_INLINE int32_t tdRSmaQTaskInfoContLen(int32_t lenWithHead) {
|
||||||
|
|
||||||
static FORCE_INLINE void tdRSmaQTaskInfoIterDestroy(SRSmaQTaskInfoIter *pIter) { taosMemoryFreeClear(pIter->pBuf); }
|
static FORCE_INLINE void tdRSmaQTaskInfoIterDestroy(SRSmaQTaskInfoIter *pIter) { taosMemoryFreeClear(pIter->pBuf); }
|
||||||
|
|
||||||
void tdFreeQTaskInfo(qTaskInfo_t *taskHandle, int32_t vgId, int32_t level) {
|
static void tdRSmaQTaskInfoFree(qTaskInfo_t *taskHandle, int32_t vgId, int32_t level) {
|
||||||
// Note: free/kill may in RC
|
// Note: free/kill may in RC
|
||||||
if (!taskHandle || !(*taskHandle)) return;
|
if (!taskHandle || !(*taskHandle)) return;
|
||||||
qTaskInfo_t otaskHandle = atomic_load_ptr(taskHandle);
|
qTaskInfo_t otaskHandle = atomic_load_ptr(taskHandle);
|
||||||
|
@ -123,20 +125,20 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree) {
|
||||||
SRSmaInfoItem *pItem = &pInfo->items[i];
|
SRSmaInfoItem *pItem = &pInfo->items[i];
|
||||||
|
|
||||||
if (isDeepFree && pItem->tmrId) {
|
if (isDeepFree && pItem->tmrId) {
|
||||||
smaDebug("vgId:%d, stop fetch timer %p for table %" PRIi64 " level %d", SMA_VID(pSma), pInfo->suid,
|
smaDebug("vgId:%d, stop fetch timer %p for table %" PRIi64 " level %d", SMA_VID(pSma), pItem->tmrId,
|
||||||
pItem->tmrId, i + 1);
|
pInfo->suid, i + 1);
|
||||||
taosTmrStopA(&pItem->tmrId);
|
taosTmrStopA(&pItem->tmrId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDeepFree && pInfo->taskInfo[i]) {
|
if (isDeepFree && pInfo->taskInfo[i]) {
|
||||||
tdFreeQTaskInfo(&pInfo->taskInfo[i], SMA_VID(pSma), i + 1);
|
tdRSmaQTaskInfoFree(&pInfo->taskInfo[i], SMA_VID(pSma), i + 1);
|
||||||
} else {
|
} else {
|
||||||
smaDebug("vgId:%d, table %" PRIi64 " no need to destroy rsma info level %d since empty taskInfo", SMA_VID(pSma),
|
smaDebug("vgId:%d, table %" PRIi64 " no need to destroy rsma info level %d since empty taskInfo", SMA_VID(pSma),
|
||||||
pInfo->suid, i + 1);
|
pInfo->suid, i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInfo->iTaskInfo[i]) {
|
if (pInfo->iTaskInfo[i]) {
|
||||||
tdFreeQTaskInfo(&pInfo->iTaskInfo[i], SMA_VID(pSma), i + 1);
|
tdRSmaQTaskInfoFree(&pInfo->iTaskInfo[i], SMA_VID(pSma), i + 1);
|
||||||
} else {
|
} else {
|
||||||
smaDebug("vgId:%d, table %" PRIi64 " no need to destroy rsma info level %d since empty iTaskInfo",
|
smaDebug("vgId:%d, table %" PRIi64 " no need to destroy rsma info level %d since empty iTaskInfo",
|
||||||
SMA_VID(pSma), pInfo->suid, i + 1);
|
SMA_VID(pSma), pInfo->suid, i + 1);
|
||||||
|
@ -173,7 +175,7 @@ static FORCE_INLINE int32_t tdUidStoreInit(STbUidStore **pStore) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids) {
|
static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids, bool isAdd) {
|
||||||
SRSmaInfo *pRSmaInfo = NULL;
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
if (!suid || !tbUids) {
|
if (!suid || !tbUids) {
|
||||||
|
@ -197,7 +199,7 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids)
|
||||||
|
|
||||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||||
if (pRSmaInfo->taskInfo[i]) {
|
if (pRSmaInfo->taskInfo[i]) {
|
||||||
if (((terrno = qUpdateQualifiedTableId(pRSmaInfo->taskInfo[i], tbUids, true)) < 0)) {
|
if (((terrno = qUpdateQualifiedTableId(pRSmaInfo->taskInfo[i], tbUids, isAdd)) < 0)) {
|
||||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||||
smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " level %d since %s", SMA_VID(pSma), *suid, i,
|
smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " level %d since %s", SMA_VID(pSma), *suid, i,
|
||||||
terrstr());
|
terrstr());
|
||||||
|
@ -213,12 +215,12 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tdUpdateTbUidList(SSma *pSma, STbUidStore *pStore) {
|
int32_t tdUpdateTbUidList(SSma *pSma, STbUidStore *pStore, bool isAdd) {
|
||||||
if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) {
|
if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tdUpdateTbUidListImpl(pSma, &pStore->suid, pStore->tbUids) != TSDB_CODE_SUCCESS) {
|
if (tdUpdateTbUidListImpl(pSma, &pStore->suid, pStore->tbUids, isAdd) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +229,7 @@ int32_t tdUpdateTbUidList(SSma *pSma, STbUidStore *pStore) {
|
||||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||||
SArray *pTbUids = *(SArray **)pIter;
|
SArray *pTbUids = *(SArray **)pIter;
|
||||||
|
|
||||||
if (tdUpdateTbUidListImpl(pSma, pTbSuid, pTbUids) != TSDB_CODE_SUCCESS) {
|
if (tdUpdateTbUidListImpl(pSma, pTbSuid, pTbUids, isAdd) != TSDB_CODE_SUCCESS) {
|
||||||
taosHashCancelIterate(pStore->uidHash, pIter);
|
taosHashCancelIterate(pStore->uidHash, pIter);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -313,10 +315,17 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
||||||
}
|
}
|
||||||
|
|
||||||
pItem->level = idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2;
|
pItem->level = idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2;
|
||||||
|
ASSERT(pItem->level > 0);
|
||||||
|
|
||||||
|
SRSmaRef rsmaRef = {.refId = pStat->refId, .suid = pRSmaInfo->suid};
|
||||||
|
taosHashPut(smaMgmt.refHash, &pItem, POINTER_BYTES, &rsmaRef, sizeof(rsmaRef));
|
||||||
|
|
||||||
taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
||||||
smaInfo("vgId:%d, table:%" PRIi64 " level:%" PRIi8 " maxdelay:%" PRIi64 " watermark:%" PRIi64
|
|
||||||
|
smaInfo("vgId:%d, item:%p table:%" PRIi64 " level:%" PRIi8 " maxdelay:%" PRIi64 " watermark:%" PRIi64
|
||||||
", finally maxdelay:%" PRIi32,
|
", finally maxdelay:%" PRIi32,
|
||||||
TD_VID(pVnode), pRSmaInfo->suid, idx + 1, param->maxdelay[idx], param->watermark[idx], pItem->maxDelay);
|
TD_VID(pVnode), pItem, pRSmaInfo->suid, idx + 1, param->maxdelay[idx], param->watermark[idx],
|
||||||
|
pItem->maxDelay);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +339,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
||||||
* @param tbName
|
* @param tbName
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName) {
|
int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName) {
|
||||||
if ((param->qmsgLen[0] == 0) && (param->qmsgLen[1] == 0)) {
|
if ((param->qmsgLen[0] == 0) && (param->qmsgLen[1] == 0)) {
|
||||||
smaDebug("vgId:%d, no qmsg1/qmsg2 for rollup table %s %" PRIi64, SMA_VID(pSma), tbName, suid);
|
smaDebug("vgId:%d, no qmsg1/qmsg2 for rollup table %s %" PRIi64, SMA_VID(pSma), tbName, suid);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -368,7 +377,10 @@ int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
|
||||||
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
pRSmaInfo->pSma = pSma;
|
||||||
pRSmaInfo->pTSchema = pTSchema;
|
pRSmaInfo->pTSchema = pTSchema;
|
||||||
|
pRSmaInfo->suid = suid;
|
||||||
|
T_REF_INIT_VAL(pRSmaInfo, 1);
|
||||||
if (!(pRSmaInfo->queue = taosOpenQueue())) {
|
if (!(pRSmaInfo->queue = taosOpenQueue())) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -382,9 +394,6 @@ int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
|
||||||
if (!(pRSmaInfo->iQall = taosAllocateQall())) {
|
if (!(pRSmaInfo->iQall = taosAllocateQall())) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
pRSmaInfo->suid = suid;
|
|
||||||
pRSmaInfo->refId = RSMA_REF_ID(pStat);
|
|
||||||
T_REF_INIT_VAL(pRSmaInfo, 1);
|
|
||||||
|
|
||||||
if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0) {
|
if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -427,7 +436,7 @@ int32_t tdProcessRSmaCreate(SSma *pSma, SVCreateStbReq *pReq) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tdProcessRSmaCreateImpl(pSma, &pReq->rsmaParam, pReq->suid, pReq->name);
|
return tdRSmaProcessCreateImpl(pSma, &pReq->rsmaParam, pReq->suid, pReq->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -654,15 +663,15 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
||||||
|
|
||||||
if (taosArrayGetSize(pResList) == 0) {
|
if (taosArrayGetSize(pResList) == 0) {
|
||||||
if (terrno == 0) {
|
if (terrno == 0) {
|
||||||
// smaDebug("vgId:%d, no rsma %" PRIi8 " data fetched yet", SMA_VID(pSma), pItem->level);
|
// smaDebug("vgId:%d, no rsma level %" PRIi8 " data fetched yet", SMA_VID(pSma), pItem->level);
|
||||||
} else {
|
} else {
|
||||||
smaDebug("vgId:%d, no rsma %" PRIi8 " data fetched since %s", SMA_VID(pSma), pItem->level, terrstr());
|
smaDebug("vgId:%d, no rsma level %" PRIi8 " data fetched since %s", SMA_VID(pSma), pItem->level, terrstr());
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
smaDebug("vgId:%d, rsma %" PRIi8 " data fetched", SMA_VID(pSma), pItem->level);
|
smaDebug("vgId:%d, rsma level %" PRIi8 " data fetched", SMA_VID(pSma), pItem->level);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
char flag[10] = {0};
|
char flag[10] = {0};
|
||||||
|
@ -676,21 +685,22 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
||||||
|
|
||||||
// TODO: the schema update should be handled later(TD-17965)
|
// TODO: the schema update should be handled later(TD-17965)
|
||||||
if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, SMA_VID(pSma), suid) < 0) {
|
if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, SMA_VID(pSma), suid) < 0) {
|
||||||
smaError("vgId:%d, build submit req for rsma stable %" PRIi64 " level %" PRIi8 " failed since %s",
|
smaError("vgId:%d, build submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s", SMA_VID(pSma),
|
||||||
SMA_VID(pSma), suid, pItem->level, terrstr());
|
suid, pItem->level, terrstr());
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
|
if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
|
||||||
taosMemoryFreeClear(pReq);
|
taosMemoryFreeClear(pReq);
|
||||||
smaError("vgId:%d, process submit req for rsma stable %" PRIi64 " level %" PRIi8 " failed since %s",
|
smaError("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s",
|
||||||
SMA_VID(pSma), suid, pItem->level, terrstr());
|
SMA_VID(pSma), suid, pItem->level, terrstr());
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
taosMemoryFreeClear(pReq);
|
|
||||||
|
|
||||||
smaDebug("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " version:%" PRIi64,
|
smaDebug("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " ver %" PRIi64 " len %" PRIu32,
|
||||||
SMA_VID(pSma), suid, pItem->level, output->info.version);
|
SMA_VID(pSma), suid, pItem->level, output->info.version, htonl(pReq->header.contLen));
|
||||||
|
|
||||||
|
taosMemoryFreeClear(pReq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -817,6 +827,95 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t tdCloneQTaskInfo(SSma *pSma, qTaskInfo_t dstTaskInfo, qTaskInfo_t srcTaskInfo, SRSmaParam *param,
|
||||||
|
tb_uid_t suid, int8_t idx) {
|
||||||
|
SVnode *pVnode = pSma->pVnode;
|
||||||
|
char *pOutput = NULL;
|
||||||
|
int32_t len = 0;
|
||||||
|
|
||||||
|
if ((terrno = qSerializeTaskStatus(srcTaskInfo, &pOutput, &len)) < 0) {
|
||||||
|
smaError("vgId:%d, rsma clone, table %" PRIi64 " serialize qTaskInfo failed since %s", TD_VID(pVnode), suid,
|
||||||
|
terrstr());
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
SReadHandle handle = {
|
||||||
|
.meta = pVnode->pMeta,
|
||||||
|
.vnode = pVnode,
|
||||||
|
.initTqReader = 1,
|
||||||
|
};
|
||||||
|
ASSERT(!dstTaskInfo);
|
||||||
|
dstTaskInfo = qCreateStreamExecTaskInfo(param->qmsg[idx], &handle);
|
||||||
|
if (!dstTaskInfo) {
|
||||||
|
terrno = TSDB_CODE_RSMA_QTASKINFO_CREATE;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qDeserializeTaskStatus(dstTaskInfo, pOutput, len) < 0) {
|
||||||
|
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
||||||
|
terrstr());
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
smaDebug("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " succeed", TD_VID(pVnode), suid);
|
||||||
|
|
||||||
|
taosMemoryFreeClear(pOutput);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
_err:
|
||||||
|
taosMemoryFreeClear(pOutput);
|
||||||
|
tdRSmaQTaskInfoFree(dstTaskInfo, TD_VID(pVnode), idx + 1);
|
||||||
|
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
||||||
|
terrstr());
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clone qTaskInfo of SRSmaInfo
|
||||||
|
*
|
||||||
|
* @param pSma
|
||||||
|
* @param pInfo
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
static int32_t tdRSmaInfoClone(SSma *pSma, SRSmaInfo *pInfo) {
|
||||||
|
SRSmaParam *param = NULL;
|
||||||
|
if (!pInfo) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMetaReader mr = {0};
|
||||||
|
metaReaderInit(&mr, SMA_META(pSma), 0);
|
||||||
|
smaDebug("vgId:%d, rsma clone qTaskInfo for suid:%" PRIi64, SMA_VID(pSma), pInfo->suid);
|
||||||
|
if (metaGetTableEntryByUid(&mr, pInfo->suid) < 0) {
|
||||||
|
smaError("vgId:%d, rsma clone, failed to get table meta for %" PRIi64 " since %s", SMA_VID(pSma), pInfo->suid,
|
||||||
|
terrstr());
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
ASSERT(mr.me.type == TSDB_SUPER_TABLE);
|
||||||
|
ASSERT(mr.me.uid == pInfo->suid);
|
||||||
|
if (TABLE_IS_ROLLUP(mr.me.flags)) {
|
||||||
|
param = &mr.me.stbEntry.rsmaParam;
|
||||||
|
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||||
|
if (!pInfo->iTaskInfo[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tdCloneQTaskInfo(pSma, pInfo->taskInfo[i], pInfo->iTaskInfo[i], param, pInfo->suid, i) < 0) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
smaDebug("vgId:%d, rsma clone env success for %" PRIi64, SMA_VID(pSma), pInfo->suid);
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
metaReaderClear(&mr);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
_err:
|
||||||
|
metaReaderClear(&mr);
|
||||||
|
smaError("vgId:%d, rsma clone env failed for %" PRIi64 " since %s", SMA_VID(pSma), pInfo->suid, terrstr());
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief During async commit, the SRSmaInfo object would be COW from iRSmaInfoHash and write lock should be applied.
|
* @brief During async commit, the SRSmaInfo object would be COW from iRSmaInfoHash and write lock should be applied.
|
||||||
*
|
*
|
||||||
|
@ -848,7 +947,7 @@ static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!pRSmaInfo->taskInfo[0]) {
|
if (!pRSmaInfo->taskInfo[0]) {
|
||||||
if (tdCloneRSmaInfo(pSma, pRSmaInfo) < 0) {
|
if (tdRSmaInfoClone(pSma, pRSmaInfo) < 0) {
|
||||||
// taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
// taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1105,7 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
||||||
" qmsgLen:%" PRIi32,
|
" qmsgLen:%" PRIi32,
|
||||||
TD_VID(pVnode), suid, i, param->maxdelay[i], param->watermark[i], param->qmsgLen[i]);
|
TD_VID(pVnode), suid, i, param->maxdelay[i], param->watermark[i], param->qmsgLen[i]);
|
||||||
}
|
}
|
||||||
if (tdProcessRSmaCreateImpl(pSma, &mr.me.stbEntry.rsmaParam, suid, mr.me.name) < 0) {
|
if (tdRSmaProcessCreateImpl(pSma, &mr.me.stbEntry.rsmaParam, suid, mr.me.name) < 0) {
|
||||||
smaError("vgId:%d, rsma restore env failed for %" PRIi64 " since %s", TD_VID(pVnode), suid, terrstr());
|
smaError("vgId:%d, rsma restore env failed for %" PRIi64 " since %s", TD_VID(pVnode), suid, terrstr());
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1118,7 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tdUpdateTbUidList(pVnode->pSma, &uidStore) < 0) {
|
if (tdUpdateTbUidList(pVnode->pSma, &uidStore, true) < 0) {
|
||||||
smaError("vgId:%d, rsma restore, update tb uid list failed for %" PRIi64 " since %s", TD_VID(pVnode), suid,
|
smaError("vgId:%d, rsma restore, update tb uid list failed for %" PRIi64 " since %s", TD_VID(pVnode), suid,
|
||||||
terrstr());
|
terrstr());
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -1118,7 +1217,7 @@ static int32_t tdRSmaRestoreTSDataReload(SSma *pSma) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tdProcessRSmaRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer) {
|
int32_t tdRSmaProcessRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer) {
|
||||||
// step 1: iterate all stables to restore the rsma env
|
// step 1: iterate all stables to restore the rsma env
|
||||||
int64_t nTables = 0;
|
int64_t nTables = 0;
|
||||||
if (tdRSmaRestoreQTaskInfoInit(pSma, &nTables) < 0) {
|
if (tdRSmaRestoreQTaskInfoInit(pSma, &nTables) < 0) {
|
||||||
|
@ -1139,6 +1238,12 @@ int32_t tdProcessRSmaRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer)
|
||||||
if (tdRSmaRestoreTSDataReload(pSma) < 0) {
|
if (tdRSmaRestoreTSDataReload(pSma) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// step 4: open SRSmaFS for qTaskFiles
|
||||||
|
if (tdRSmaFSOpen(pSma, qtaskFileVer) < 0) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
smaInfo("vgId:%d, restore rsma task %" PRIi8 " from qtaskf %" PRIi64 " succeed", SMA_VID(pSma), type, qtaskFileVer);
|
smaInfo("vgId:%d, restore rsma task %" PRIi8 " from qtaskf %" PRIi64 " succeed", SMA_VID(pSma), type, qtaskFileVer);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
_err:
|
_err:
|
||||||
|
@ -1468,26 +1573,46 @@ _err:
|
||||||
* @param tmrId
|
* @param tmrId
|
||||||
*/
|
*/
|
||||||
static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
||||||
SRSmaInfoItem *pItem = param;
|
SRSmaRef *pRSmaRef = NULL;
|
||||||
SSma *pSma = NULL;
|
SSma *pSma = NULL;
|
||||||
SRSmaInfo *pRSmaInfo = tdGetRSmaInfoByItem(pItem);
|
SRSmaStat *pStat = NULL;
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
SRSmaInfoItem *pItem = NULL;
|
||||||
|
|
||||||
if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
|
if (!(pRSmaRef = taosHashGet(smaMgmt.refHash, ¶m, POINTER_BYTES))) {
|
||||||
smaDebug("rsma fetch task not start since rsma info already deleted, rsetId:%" PRIi64 " refId:%d)", smaMgmt.rsetId,
|
smaDebug("rsma fetch task not start since rsma info item:%p not exist in refHash:%p, rsetId:%" PRIi64, param,
|
||||||
pRSmaInfo->refId);
|
*(int64_t *)¶m, smaMgmt.refHash, smaMgmt.rsetId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRSmaStat *pStat = (SRSmaStat *)tdAcquireSmaRef(smaMgmt.rsetId, pRSmaInfo->refId);
|
if (!(pStat = (SRSmaStat *)tdAcquireSmaRef(smaMgmt.rsetId, pRSmaRef->refId))) {
|
||||||
|
|
||||||
if (!pStat) {
|
|
||||||
smaDebug("rsma fetch task not start since rsma stat already destroyed, rsetId:%" PRIi64 " refId:%d)",
|
smaDebug("rsma fetch task not start since rsma stat already destroyed, rsetId:%" PRIi64 " refId:%d)",
|
||||||
smaMgmt.rsetId, pRSmaInfo->refId);
|
smaMgmt.rsetId, pRSmaRef->refId); // pRSmaRef freed in taosHashRemove
|
||||||
|
taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSma = pStat->pSma;
|
pSma = pStat->pSma;
|
||||||
|
|
||||||
|
if (!(pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, pRSmaRef->suid))) {
|
||||||
|
smaDebug("rsma fetch task not start since rsma info not exist, rsetId:%" PRIi64 " refId:%d)", smaMgmt.rsetId,
|
||||||
|
pRSmaRef->refId); // pRSmaRef freed in taosHashRemove
|
||||||
|
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId);
|
||||||
|
taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
|
||||||
|
smaDebug("rsma fetch task not start since rsma info already deleted, rsetId:%" PRIi64 " refId:%d)", smaMgmt.rsetId,
|
||||||
|
pRSmaRef->refId); // pRSmaRef freed in taosHashRemove
|
||||||
|
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||||
|
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId);
|
||||||
|
taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pItem = *(SRSmaInfoItem **)¶m;
|
||||||
|
|
||||||
// if rsma trigger stat in paused, cancelled or finished, not start fetch task
|
// if rsma trigger stat in paused, cancelled or finished, not start fetch task
|
||||||
int8_t rsmaTriggerStat = atomic_load_8(RSMA_TRIGGER_STAT(pStat));
|
int8_t rsmaTriggerStat = atomic_load_8(RSMA_TRIGGER_STAT(pStat));
|
||||||
switch (rsmaTriggerStat) {
|
switch (rsmaTriggerStat) {
|
||||||
|
@ -1495,11 +1620,12 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
||||||
case TASK_TRIGGER_STAT_CANCELLED: {
|
case TASK_TRIGGER_STAT_CANCELLED: {
|
||||||
smaDebug("vgId:%d, rsma fetch task not start for level %" PRIi8 " since stat is %" PRIi8
|
smaDebug("vgId:%d, rsma fetch task not start for level %" PRIi8 " since stat is %" PRIi8
|
||||||
", rsetId rsetId:%" PRIi64 " refId:%d",
|
", rsetId rsetId:%" PRIi64 " refId:%d",
|
||||||
SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pRSmaInfo->refId);
|
SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pRSmaRef->refId);
|
||||||
if (rsmaTriggerStat == TASK_TRIGGER_STAT_PAUSED) {
|
if (rsmaTriggerStat == TASK_TRIGGER_STAT_PAUSED) {
|
||||||
taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
||||||
}
|
}
|
||||||
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaInfo->refId);
|
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||||
|
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -1544,11 +1670,11 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
||||||
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaInfo->refId);
|
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||||
|
tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tdFreeRSmaSubmitItems(SArray *pItems) {
|
static void tdFreeRSmaSubmitItems(SArray *pItems) {
|
||||||
ASSERT(taosArrayGetSize(pItems) > 0);
|
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pItems); ++i) {
|
for (int32_t i = 0; i < taosArrayGetSize(pItems); ++i) {
|
||||||
taosFreeQitem(*(void **)taosArrayGet(pItems, i));
|
taosFreeQitem(*(void **)taosArrayGet(pItems, i));
|
||||||
}
|
}
|
||||||
|
@ -1560,10 +1686,9 @@ static void tdFreeRSmaSubmitItems(SArray *pItems) {
|
||||||
*
|
*
|
||||||
* @param pSma
|
* @param pSma
|
||||||
* @param pInfo
|
* @param pInfo
|
||||||
* @param pSubmitArr
|
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo, SArray *pSubmitArr) {
|
static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) {
|
||||||
SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL};
|
SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL};
|
||||||
for (int8_t i = 1; i <= TSDB_RETENTION_L2; ++i) {
|
for (int8_t i = 1; i <= TSDB_RETENTION_L2; ++i) {
|
||||||
SRSmaInfoItem *pItem = RSMA_INFO_ITEM(pInfo, i - 1);
|
SRSmaInfoItem *pItem = RSMA_INFO_ITEM(pInfo, i - 1);
|
||||||
|
@ -1576,15 +1701,15 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo, SArray *pSubmi
|
||||||
|
|
||||||
int64_t curMs = taosGetTimestampMs();
|
int64_t curMs = taosGetTimestampMs();
|
||||||
if ((pItem->nSkipped * pItem->maxDelay) > RSMA_FETCH_DELAY_MAX) {
|
if ((pItem->nSkipped * pItem->maxDelay) > RSMA_FETCH_DELAY_MAX) {
|
||||||
smaInfo("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nSkipped:%" PRIi8 " maxDelay:%d, fetch executed",
|
smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nSkipped:%" PRIi8 " maxDelay:%d, fetch executed",
|
||||||
SMA_VID(pSma), pInfo->suid, i, pItem->nSkipped, pItem->maxDelay);
|
SMA_VID(pSma), pInfo->suid, i, pItem->nSkipped, pItem->maxDelay);
|
||||||
} else if (((curMs - pInfo->lastRecv) < RSMA_FETCH_ACTIVE_MAX)) {
|
} else if (((curMs - pInfo->lastRecv) < RSMA_FETCH_ACTIVE_MAX)) {
|
||||||
++pItem->nSkipped;
|
++pItem->nSkipped;
|
||||||
smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " curMs:%" PRIi64 " lastRecv:%" PRIi64 ", fetch skipped ",
|
smaTrace("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " curMs:%" PRIi64 " lastRecv:%" PRIi64 ", fetch skipped ",
|
||||||
SMA_VID(pSma), pInfo->suid, i, curMs, pInfo->lastRecv);
|
SMA_VID(pSma), pInfo->suid, i, curMs, pInfo->lastRecv);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
smaInfo("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " curMs:%" PRIi64 " lastRecv:%" PRIi64 ", fetch executed ",
|
smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " curMs:%" PRIi64 " lastRecv:%" PRIi64 ", fetch executed ",
|
||||||
SMA_VID(pSma), pInfo->suid, i, curMs, pInfo->lastRecv);
|
SMA_VID(pSma), pInfo->suid, i, curMs, pInfo->lastRecv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1609,10 +1734,8 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo, SArray *pSubmi
|
||||||
}
|
}
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
tdReleaseRSmaInfo(pSma, pInfo);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
_err:
|
_err:
|
||||||
tdReleaseRSmaInfo(pSma, pInfo);
|
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1709,7 +1832,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
||||||
if (oldStat == 0 ||
|
if (oldStat == 0 ||
|
||||||
((oldStat == 2) && atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat)) < TASK_TRIGGER_STAT_PAUSED)) {
|
((oldStat == 2) && atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat)) < TASK_TRIGGER_STAT_PAUSED)) {
|
||||||
atomic_fetch_add_32(&pRSmaStat->nFetchAll, 1);
|
atomic_fetch_add_32(&pRSmaStat->nFetchAll, 1);
|
||||||
tdRSmaFetchAllResult(pSma, pInfo, pSubmitArr);
|
tdRSmaFetchAllResult(pSma, pInfo);
|
||||||
if (0 == atomic_sub_fetch_32(&pRSmaStat->nFetchAll, 1)) {
|
if (0 == atomic_sub_fetch_32(&pRSmaStat->nFetchAll, 1)) {
|
||||||
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,13 @@
|
||||||
|
|
||||||
#include "sma.h"
|
#include "sma.h"
|
||||||
|
|
||||||
static int32_t rsmaSnapReadQTaskInfo(SRsmaSnapReader* pReader, uint8_t** ppData);
|
static int32_t rsmaSnapReadQTaskInfo(SRSmaSnapReader* pReader, uint8_t** ppData);
|
||||||
static int32_t rsmaSnapWriteQTaskInfo(SRsmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
static int32_t rsmaSnapWriteQTaskInfo(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||||
|
static int32_t rsmaQTaskInfSnapReaderOpen(SRSmaSnapReader* pReader, int64_t version);
|
||||||
|
static int32_t rsmaQTaskInfSnapReaderClose(SQTaskFReader** ppReader);
|
||||||
|
|
||||||
// SRsmaSnapReader ========================================
|
// SRSmaSnapReader ========================================
|
||||||
struct SRsmaSnapReader {
|
struct SRSmaSnapReader {
|
||||||
SSma* pSma;
|
SSma* pSma;
|
||||||
int64_t sver;
|
int64_t sver;
|
||||||
int64_t ever;
|
int64_t ever;
|
||||||
|
@ -33,13 +35,13 @@ struct SRsmaSnapReader {
|
||||||
SQTaskFReader* pQTaskFReader;
|
SQTaskFReader* pQTaskFReader;
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRsmaSnapReader** ppReader) {
|
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapReader** ppReader) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SVnode* pVnode = pSma->pVnode;
|
SVnode* pVnode = pSma->pVnode;
|
||||||
SRsmaSnapReader* pReader = NULL;
|
SRSmaSnapReader* pReader = NULL;
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
pReader = (SRsmaSnapReader*)taosMemoryCalloc(1, sizeof(*pReader));
|
pReader = (SRSmaSnapReader*)taosMemoryCalloc(1, sizeof(*pReader));
|
||||||
if (pReader == NULL) {
|
if (pReader == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -48,7 +50,7 @@ int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRsmaSnapRead
|
||||||
pReader->sver = sver;
|
pReader->sver = sver;
|
||||||
pReader->ever = ever;
|
pReader->ever = ever;
|
||||||
|
|
||||||
// rsma1/rsma2
|
// open rsma1/rsma2
|
||||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||||
if (pSma->pRSmaTsdb[i]) {
|
if (pSma->pRSmaTsdb[i]) {
|
||||||
code = tsdbSnapReaderOpen(pSma->pRSmaTsdb[i], sver, ever, i == 0 ? SNAP_DATA_RSMA1 : SNAP_DATA_RSMA2,
|
code = tsdbSnapReaderOpen(pSma->pRSmaTsdb[i], sver, ever, i == 0 ? SNAP_DATA_RSMA1 : SNAP_DATA_RSMA2,
|
||||||
|
@ -59,51 +61,112 @@ int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRsmaSnapRead
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// qtaskinfo
|
// open qtaskinfo
|
||||||
// 1. add ref to qtaskinfo.v${ever} if exists and then start to replicate
|
if ((code = rsmaQTaskInfSnapReaderOpen(pReader, ever)) < 0) {
|
||||||
char qTaskInfoFullName[TSDB_FILENAME_LEN];
|
|
||||||
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), ever, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
|
|
||||||
|
|
||||||
if (!taosCheckExistFile(qTaskInfoFullName)) {
|
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma reader for qtaskinfo not need as %s not exists", TD_VID(pVnode),
|
|
||||||
qTaskInfoFullName);
|
|
||||||
} else {
|
|
||||||
pReader->pQTaskFReader = taosMemoryCalloc(1, sizeof(SQTaskFReader));
|
|
||||||
if (!pReader->pQTaskFReader) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
TdFilePtr qTaskF = taosOpenFile(qTaskInfoFullName, TD_FILE_READ);
|
|
||||||
if (!qTaskF) {
|
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
pReader->pQTaskFReader->pReadH = qTaskF;
|
|
||||||
#if 0
|
|
||||||
SQTaskFile* pQTaskF = &pReader->pQTaskFReader->fTask;
|
|
||||||
pQTaskF->nRef = 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
*ppReader = pReader;
|
*ppReader = pReader;
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma reader opened %s succeed", TD_VID(pVnode), qTaskInfoFullName);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
_err:
|
_err:
|
||||||
smaError("vgId:%d, vnode snapshot rsma reader opened failed since %s", TD_VID(pVnode), tstrerror(code));
|
smaError("vgId:%d, vnode snapshot rsma reader open failed since %s", TD_VID(pVnode), tstrerror(code));
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t rsmaSnapReadQTaskInfo(SRsmaSnapReader* pReader, uint8_t** ppBuf) {
|
static int32_t rsmaQTaskInfSnapReaderOpen(SRSmaSnapReader* pReader, int64_t version) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SSma* pSma = pReader->pSma;
|
||||||
|
SVnode* pVnode = pSma->pVnode;
|
||||||
|
SSmaEnv* pEnv = NULL;
|
||||||
|
SRSmaStat* pStat = NULL;
|
||||||
|
|
||||||
|
if (!(pEnv = SMA_RSMA_ENV(pSma))) {
|
||||||
|
smaInfo("vgId:%d, vnode snapshot rsma reader for qtaskinfo version %" PRIi64 " not need as env is NULL",
|
||||||
|
TD_VID(pVnode), version);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pStat = (SRSmaStat*)SMA_ENV_STAT(pEnv);
|
||||||
|
|
||||||
|
int32_t ref = tdRSmaFSRef(pReader->pSma, pStat, version);
|
||||||
|
if (ref < 1) {
|
||||||
|
smaInfo("vgId:%d, vnode snapshot rsma reader for qtaskinfo version %" PRIi64 " not need as ref is %d",
|
||||||
|
TD_VID(pVnode), version, ref);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
char qTaskInfoFullName[TSDB_FILENAME_LEN];
|
||||||
|
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), version, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
|
||||||
|
|
||||||
|
if (!taosCheckExistFile(qTaskInfoFullName)) {
|
||||||
|
tdRSmaFSUnRef(pSma, pStat, version);
|
||||||
|
smaInfo("vgId:%d, vnode snapshot rsma reader for qtaskinfo version %" PRIi64 " not need as %s not exists",
|
||||||
|
TD_VID(pVnode), qTaskInfoFullName);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pReader->pQTaskFReader = taosMemoryCalloc(1, sizeof(SQTaskFReader));
|
||||||
|
if (!pReader->pQTaskFReader) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
|
||||||
|
TdFilePtr fp = taosOpenFile(qTaskInfoFullName, TD_FILE_READ);
|
||||||
|
if (!fp) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
taosMemoryFreeClear(pReader->pQTaskFReader);
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
|
||||||
|
pReader->pQTaskFReader->pReadH = fp;
|
||||||
|
pReader->pQTaskFReader->pSma = pSma;
|
||||||
|
pReader->pQTaskFReader->version = pReader->ever;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if (code < 0) {
|
||||||
|
tdRSmaFSUnRef(pSma, pStat, version);
|
||||||
|
smaError("vgId:%d, vnode snapshot rsma reader open %s succeed", TD_VID(pVnode), qTaskInfoFullName);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
smaInfo("vgId:%d, vnode snapshot rsma reader open %s succeed", TD_VID(pVnode), qTaskInfoFullName);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rsmaQTaskInfSnapReaderClose(SQTaskFReader** ppReader) {
|
||||||
|
if (!(*ppReader)) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSma* pSma = (*ppReader)->pSma;
|
||||||
|
SRSmaStat* pStat = SMA_RSMA_STAT(pSma);
|
||||||
|
int64_t version = (*ppReader)->version;
|
||||||
|
|
||||||
|
taosCloseFile(&(*ppReader)->pReadH);
|
||||||
|
tdRSmaFSUnRef(pSma, pStat, version);
|
||||||
|
taosMemoryFreeClear(*ppReader);
|
||||||
|
smaInfo("vgId:%d, vnode snapshot rsma reader closed for qTaskInfo version %" PRIi64, SMA_VID(pSma), version);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rsmaSnapReadQTaskInfo(SRSmaSnapReader* pReader, uint8_t** ppBuf) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSma* pSma = pReader->pSma;
|
SSma* pSma = pReader->pSma;
|
||||||
int64_t n = 0;
|
int64_t n = 0;
|
||||||
uint8_t* pBuf = NULL;
|
uint8_t* pBuf = NULL;
|
||||||
SQTaskFReader* qReader = pReader->pQTaskFReader;
|
SQTaskFReader* qReader = pReader->pQTaskFReader;
|
||||||
|
|
||||||
|
if (!qReader) {
|
||||||
|
*ppBuf = NULL;
|
||||||
|
smaInfo("vgId:%d, vnode snapshot rsma reader qtaskinfo, qTaskReader is NULL", SMA_VID(pSma));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!qReader->pReadH) {
|
if (!qReader->pReadH) {
|
||||||
*ppBuf = NULL;
|
*ppBuf = NULL;
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma reader qtaskinfo, readh is empty", SMA_VID(pSma));
|
smaInfo("vgId:%d, vnode snapshot rsma reader qtaskinfo, readh is NULL", SMA_VID(pSma));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +216,7 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rsmaSnapRead(SRsmaSnapReader* pReader, uint8_t** ppData) {
|
int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
*ppData = NULL;
|
*ppData = NULL;
|
||||||
|
@ -205,9 +268,9 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rsmaSnapReaderClose(SRsmaSnapReader** ppReader) {
|
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SRsmaSnapReader* pReader = *ppReader;
|
SRSmaSnapReader* pReader = *ppReader;
|
||||||
|
|
||||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||||
if (pReader->pDataReader[i]) {
|
if (pReader->pDataReader[i]) {
|
||||||
|
@ -215,11 +278,7 @@ int32_t rsmaSnapReaderClose(SRsmaSnapReader** ppReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReader->pQTaskFReader) {
|
rsmaQTaskInfSnapReaderClose(&pReader->pQTaskFReader);
|
||||||
taosCloseFile(&pReader->pQTaskFReader->pReadH);
|
|
||||||
taosMemoryFreeClear(pReader->pQTaskFReader);
|
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma reader closed for qTaskInfo", SMA_VID(pReader->pSma));
|
|
||||||
}
|
|
||||||
|
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma));
|
smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma));
|
||||||
|
|
||||||
|
@ -227,8 +286,8 @@ int32_t rsmaSnapReaderClose(SRsmaSnapReader** ppReader) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SRsmaSnapWriter ========================================
|
// SRSmaSnapWriter ========================================
|
||||||
struct SRsmaSnapWriter {
|
struct SRSmaSnapWriter {
|
||||||
SSma* pSma;
|
SSma* pSma;
|
||||||
int64_t sver;
|
int64_t sver;
|
||||||
int64_t ever;
|
int64_t ever;
|
||||||
|
@ -244,13 +303,13 @@ struct SRsmaSnapWriter {
|
||||||
SQTaskFWriter* pQTaskFWriter;
|
SQTaskFWriter* pQTaskFWriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, SRsmaSnapWriter** ppWriter) {
|
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapWriter** ppWriter) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SRsmaSnapWriter* pWriter = NULL;
|
SRSmaSnapWriter* pWriter = NULL;
|
||||||
SVnode* pVnode = pSma->pVnode;
|
SVnode* pVnode = pSma->pVnode;
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
pWriter = (SRsmaSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
|
pWriter = (SRSmaSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
|
||||||
if (pWriter == NULL) {
|
if (pWriter == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -301,9 +360,9 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rsmaSnapWriterClose(SRsmaSnapWriter** ppWriter, int8_t rollback) {
|
int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SRsmaSnapWriter* pWriter = *ppWriter;
|
SRSmaSnapWriter* pWriter = *ppWriter;
|
||||||
SVnode* pVnode = pWriter->pSma->pVnode;
|
SVnode* pVnode = pWriter->pSma->pVnode;
|
||||||
|
|
||||||
if (rollback) {
|
if (rollback) {
|
||||||
|
@ -332,7 +391,7 @@ int32_t rsmaSnapWriterClose(SRsmaSnapWriter** ppWriter, int8_t rollback) {
|
||||||
pWriter->pQTaskFWriter->fname, qTaskInfoFullName);
|
pWriter->pQTaskFWriter->fname, qTaskInfoFullName);
|
||||||
|
|
||||||
// rsma restore
|
// rsma restore
|
||||||
if ((code = tdRsmaRestore(pWriter->pSma, RSMA_RESTORE_SYNC, pWriter->ever)) < 0) {
|
if ((code = tdRSmaRestore(pWriter->pSma, RSMA_RESTORE_SYNC, pWriter->ever)) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma writer restore from %s succeed", SMA_VID(pWriter->pSma), qTaskInfoFullName);
|
smaInfo("vgId:%d, vnode snapshot rsma writer restore from %s succeed", SMA_VID(pWriter->pSma), qTaskInfoFullName);
|
||||||
|
@ -349,7 +408,7 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rsmaSnapWrite(SRsmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
int32_t rsmaSnapWrite(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSnapDataHdr* pHdr = (SSnapDataHdr*)pData;
|
SSnapDataHdr* pHdr = (SSnapDataHdr*)pData;
|
||||||
|
|
||||||
|
@ -377,7 +436,7 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t rsmaSnapWriteQTaskInfo(SRsmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
static int32_t rsmaSnapWriteQTaskInfo(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SQTaskFWriter* qWriter = pWriter->pQTaskFWriter;
|
SQTaskFWriter* qWriter = pWriter->pQTaskFWriter;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
#define SMA_STORAGE_MINUTES_DAY 1440
|
#define SMA_STORAGE_MINUTES_DAY 1440
|
||||||
#define SMA_STORAGE_SPLIT_FACTOR 14400 // least records in tsma file
|
#define SMA_STORAGE_SPLIT_FACTOR 14400 // least records in tsma file
|
||||||
|
|
||||||
|
static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg);
|
||||||
|
static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg);
|
||||||
|
static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days);
|
||||||
|
|
||||||
// TODO: Who is responsible for resource allocate and release?
|
// TODO: Who is responsible for resource allocate and release?
|
||||||
int32_t tdProcessTSmaInsert(SSma *pSma, int64_t indexUid, const char *msg) {
|
int32_t tdProcessTSmaInsert(SSma *pSma, int64_t indexUid, const char *msg) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
@ -59,7 +63,7 @@ int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *
|
||||||
* @param days unit is minute
|
* @param days unit is minute
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) {
|
static int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) {
|
||||||
SDecoder coder = {0};
|
SDecoder coder = {0};
|
||||||
tDecoderInit(&coder, pCont, contLen);
|
tDecoderInit(&coder, pCont, contLen);
|
||||||
|
|
||||||
|
@ -106,7 +110,7 @@ _err:
|
||||||
* @param pMsg
|
* @param pMsg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg) {
|
static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg) {
|
||||||
SSmaCfg *pCfg = (SSmaCfg *)pMsg;
|
SSmaCfg *pCfg = (SSmaCfg *)pMsg;
|
||||||
|
|
||||||
if (TD_VID(pSma->pVnode) == pCfg->dstVgId) {
|
if (TD_VID(pSma->pVnode) == pCfg->dstVgId) {
|
||||||
|
@ -145,7 +149,7 @@ int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg) {
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
|
static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
|
||||||
const SArray *pDataBlocks = (const SArray *)msg;
|
const SArray *pDataBlocks = (const SArray *)msg;
|
||||||
// TODO: destroy SSDataBlocks(msg)
|
// TODO: destroy SSDataBlocks(msg)
|
||||||
if (!pDataBlocks) {
|
if (!pDataBlocks) {
|
||||||
|
|
|
@ -306,92 +306,3 @@ int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId) {
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tdCloneQTaskInfo(SSma *pSma, qTaskInfo_t dstTaskInfo, qTaskInfo_t srcTaskInfo, SRSmaParam *param,
|
|
||||||
tb_uid_t suid, int8_t idx) {
|
|
||||||
SVnode *pVnode = pSma->pVnode;
|
|
||||||
char *pOutput = NULL;
|
|
||||||
int32_t len = 0;
|
|
||||||
|
|
||||||
if ((terrno = qSerializeTaskStatus(srcTaskInfo, &pOutput, &len)) < 0) {
|
|
||||||
smaError("vgId:%d, rsma clone, table %" PRIi64 " serialize qTaskInfo failed since %s", TD_VID(pVnode), suid,
|
|
||||||
terrstr());
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
SReadHandle handle = {
|
|
||||||
.meta = pVnode->pMeta,
|
|
||||||
.vnode = pVnode,
|
|
||||||
.initTqReader = 1,
|
|
||||||
};
|
|
||||||
ASSERT(!dstTaskInfo);
|
|
||||||
dstTaskInfo = qCreateStreamExecTaskInfo(param->qmsg[idx], &handle);
|
|
||||||
if (!dstTaskInfo) {
|
|
||||||
terrno = TSDB_CODE_RSMA_QTASKINFO_CREATE;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qDeserializeTaskStatus(dstTaskInfo, pOutput, len) < 0) {
|
|
||||||
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
|
||||||
terrstr());
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
smaDebug("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " succeed", TD_VID(pVnode), suid);
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pOutput);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
_err:
|
|
||||||
taosMemoryFreeClear(pOutput);
|
|
||||||
tdFreeQTaskInfo(dstTaskInfo, TD_VID(pVnode), idx + 1);
|
|
||||||
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
|
||||||
terrstr());
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clone qTaskInfo of SRSmaInfo
|
|
||||||
*
|
|
||||||
* @param pSma
|
|
||||||
* @param pInfo
|
|
||||||
* @return int32_t
|
|
||||||
*/
|
|
||||||
int32_t tdCloneRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) {
|
|
||||||
SRSmaParam *param = NULL;
|
|
||||||
if (!pInfo) {
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMetaReader mr = {0};
|
|
||||||
metaReaderInit(&mr, SMA_META(pSma), 0);
|
|
||||||
smaDebug("vgId:%d, rsma clone qTaskInfo for suid:%" PRIi64, SMA_VID(pSma), pInfo->suid);
|
|
||||||
if (metaGetTableEntryByUid(&mr, pInfo->suid) < 0) {
|
|
||||||
smaError("vgId:%d, rsma clone, failed to get table meta for %" PRIi64 " since %s", SMA_VID(pSma), pInfo->suid,
|
|
||||||
terrstr());
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
ASSERT(mr.me.type == TSDB_SUPER_TABLE);
|
|
||||||
ASSERT(mr.me.uid == pInfo->suid);
|
|
||||||
if (TABLE_IS_ROLLUP(mr.me.flags)) {
|
|
||||||
param = &mr.me.stbEntry.rsmaParam;
|
|
||||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
|
||||||
if (!pInfo->iTaskInfo[i]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (tdCloneQTaskInfo(pSma, pInfo->taskInfo[i], pInfo->iTaskInfo[i], param, pInfo->suid, i) < 0) {
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
smaDebug("vgId:%d, rsma clone env success for %" PRIi64, SMA_VID(pSma), pInfo->suid);
|
|
||||||
} else {
|
|
||||||
terrno = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
metaReaderClear(&mr);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
_err:
|
|
||||||
metaReaderClear(&mr);
|
|
||||||
smaError("vgId:%d, rsma clone env failed for %" PRIi64 " since %s", SMA_VID(pSma), pInfo->suid, terrstr());
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
|
@ -420,29 +420,15 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SFSLASTNEXTROWSTATES state; // [input]
|
SFSLASTNEXTROWSTATES state; // [input]
|
||||||
STsdb *pTsdb; // [input]
|
STsdb *pTsdb; // [input]
|
||||||
SBlockIdx *pBlockIdxExp; // [input]
|
|
||||||
STSchema *pTSchema; // [input]
|
|
||||||
tb_uid_t suid;
|
tb_uid_t suid;
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
int32_t nFileSet;
|
int32_t nFileSet;
|
||||||
int32_t iFileSet;
|
int32_t iFileSet;
|
||||||
SArray *aDFileSet;
|
SArray *aDFileSet;
|
||||||
SDataFReader *pDataFReader;
|
SDataFReader *pDataFReader;
|
||||||
SArray *aBlockL;
|
|
||||||
SBlockL *pBlockL;
|
|
||||||
SBlockData *pBlockDataL;
|
|
||||||
SBlockData blockDataL;
|
|
||||||
int32_t nRow;
|
|
||||||
int32_t iRow;
|
|
||||||
TSDBROW row;
|
TSDBROW row;
|
||||||
/*
|
|
||||||
SArray *aBlockIdx;
|
SMergeTree mergeTree;
|
||||||
SBlockIdx *pBlockIdx;
|
|
||||||
SMapData blockMap;
|
|
||||||
int32_t nBlock;
|
|
||||||
int32_t iBlock;
|
|
||||||
SBlock block;
|
|
||||||
*/
|
|
||||||
} SFSLastNextRowIter;
|
} SFSLastNextRowIter;
|
||||||
|
|
||||||
static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) {
|
static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) {
|
||||||
|
@ -451,22 +437,16 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) {
|
||||||
|
|
||||||
switch (state->state) {
|
switch (state->state) {
|
||||||
case SFSLASTNEXTROW_FS:
|
case SFSLASTNEXTROW_FS:
|
||||||
// state->aDFileSet = state->pTsdb->pFS->cState->aDFileSet;
|
|
||||||
state->nFileSet = taosArrayGetSize(state->aDFileSet);
|
state->nFileSet = taosArrayGetSize(state->aDFileSet);
|
||||||
state->iFileSet = state->nFileSet;
|
state->iFileSet = state->nFileSet;
|
||||||
|
|
||||||
state->pBlockDataL = NULL;
|
|
||||||
|
|
||||||
case SFSLASTNEXTROW_FILESET: {
|
case SFSLASTNEXTROW_FILESET: {
|
||||||
SDFileSet *pFileSet = NULL;
|
SDFileSet *pFileSet = NULL;
|
||||||
_next_fileset:
|
_next_fileset:
|
||||||
if (--state->iFileSet >= 0) {
|
if (--state->iFileSet >= 0) {
|
||||||
pFileSet = (SDFileSet *)taosArrayGet(state->aDFileSet, state->iFileSet);
|
pFileSet = (SDFileSet *)taosArrayGet(state->aDFileSet, state->iFileSet);
|
||||||
} else {
|
} else {
|
||||||
if (state->pBlockDataL) {
|
// tMergeTreeClose(&state->mergeTree);
|
||||||
tBlockDataDestroy(state->pBlockDataL, 1);
|
|
||||||
state->pBlockDataL = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ppRow = NULL;
|
*ppRow = NULL;
|
||||||
return code;
|
return code;
|
||||||
|
@ -475,68 +455,24 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) {
|
||||||
code = tsdbDataFReaderOpen(&state->pDataFReader, state->pTsdb, pFileSet);
|
code = tsdbDataFReaderOpen(&state->pDataFReader, state->pTsdb, pFileSet);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
if (!state->aBlockL) {
|
tMergeTreeOpen(&state->mergeTree, 1, state->pDataFReader, state->suid, state->uid,
|
||||||
state->aBlockL = taosArrayInit(0, sizeof(SBlockL));
|
&(STimeWindow){.skey = TSKEY_MIN, .ekey = TSKEY_MAX},
|
||||||
} else {
|
&(SVersionRange){.minVer = 0, .maxVer = UINT64_MAX});
|
||||||
taosArrayClear(state->aBlockL);
|
bool hasVal = tMergeTreeNext(&state->mergeTree);
|
||||||
}
|
if (!hasVal) {
|
||||||
|
state->state = SFSLASTNEXTROW_FILESET;
|
||||||
code = tsdbReadBlockL(state->pDataFReader, state->aBlockL);
|
// tMergeTreeClose(&state->mergeTree);
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
// SBlockL *pBlockL = (SBlockL *)taosArrayGet(state->aBlockL, state->iBlockL);
|
|
||||||
|
|
||||||
state->pBlockL = taosArraySearch(state->aBlockL, state->pBlockIdxExp, tCmprBlockL, TD_EQ);
|
|
||||||
if (!state->pBlockL) {
|
|
||||||
goto _next_fileset;
|
goto _next_fileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t suid = state->pBlockL->suid;
|
|
||||||
int64_t uid = state->pBlockL->maxUid;
|
|
||||||
|
|
||||||
if (!state->pBlockDataL) {
|
|
||||||
state->pBlockDataL = &state->blockDataL;
|
|
||||||
|
|
||||||
tBlockDataCreate(state->pBlockDataL);
|
|
||||||
}
|
|
||||||
code = tBlockDataInit(state->pBlockDataL, suid, suid ? 0 : uid, state->pTSchema);
|
|
||||||
if (code) goto _err;
|
|
||||||
}
|
|
||||||
case SFSLASTNEXTROW_BLOCKDATA:
|
|
||||||
code = tsdbReadLastBlock(state->pDataFReader, state->pBlockL, state->pBlockDataL);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
state->nRow = state->blockDataL.nRow;
|
|
||||||
state->iRow = state->nRow - 1;
|
|
||||||
|
|
||||||
if (!state->pBlockDataL->uid) {
|
|
||||||
while (state->pBlockIdxExp->uid != state->pBlockDataL->aUid[state->iRow]) {
|
|
||||||
--state->iRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
state->state = SFSLASTNEXTROW_BLOCKROW;
|
state->state = SFSLASTNEXTROW_BLOCKROW;
|
||||||
|
}
|
||||||
case SFSLASTNEXTROW_BLOCKROW:
|
case SFSLASTNEXTROW_BLOCKROW:
|
||||||
if (state->pBlockDataL->uid) {
|
state->row = tMergeTreeGetRow(&state->mergeTree);
|
||||||
if (state->iRow >= 0) {
|
|
||||||
state->row = tsdbRowFromBlockData(state->pBlockDataL, state->iRow);
|
|
||||||
*ppRow = &state->row;
|
*ppRow = &state->row;
|
||||||
|
bool hasVal = tMergeTreeNext(&state->mergeTree);
|
||||||
if (--state->iRow < 0) {
|
if (!hasVal) {
|
||||||
state->state = SFSLASTNEXTROW_FILESET;
|
state->state = SFSLASTNEXTROW_FILESET;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (state->iRow >= 0 && state->pBlockIdxExp->uid == state->pBlockDataL->aUid[state->iRow]) {
|
|
||||||
state->row = tsdbRowFromBlockData(state->pBlockDataL, state->iRow);
|
|
||||||
*ppRow = &state->row;
|
|
||||||
|
|
||||||
if (--state->iRow < 0 || state->pBlockIdxExp->uid != state->pBlockDataL->aUid[state->iRow]) {
|
|
||||||
state->state = SFSLASTNEXTROW_FILESET;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
@ -548,15 +484,6 @@ _err:
|
||||||
tsdbDataFReaderClose(&state->pDataFReader);
|
tsdbDataFReaderClose(&state->pDataFReader);
|
||||||
state->pDataFReader = NULL;
|
state->pDataFReader = NULL;
|
||||||
}
|
}
|
||||||
if (state->aBlockL) {
|
|
||||||
taosArrayDestroy(state->aBlockL);
|
|
||||||
state->aBlockL = NULL;
|
|
||||||
}
|
|
||||||
if (state->pBlockDataL) {
|
|
||||||
tBlockDataDestroy(state->pBlockDataL, 1);
|
|
||||||
state->pBlockDataL = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ppRow = NULL;
|
*ppRow = NULL;
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -574,14 +501,6 @@ int32_t clearNextRowFromFSLast(void *iter) {
|
||||||
tsdbDataFReaderClose(&state->pDataFReader);
|
tsdbDataFReaderClose(&state->pDataFReader);
|
||||||
state->pDataFReader = NULL;
|
state->pDataFReader = NULL;
|
||||||
}
|
}
|
||||||
if (state->aBlockL) {
|
|
||||||
taosArrayDestroy(state->aBlockL);
|
|
||||||
state->aBlockL = NULL;
|
|
||||||
}
|
|
||||||
if (state->pBlockDataL) {
|
|
||||||
tBlockDataDestroy(state->pBlockDataL, 1);
|
|
||||||
state->pBlockDataL = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -609,7 +528,7 @@ typedef struct SFSNextRowIter {
|
||||||
SMapData blockMap;
|
SMapData blockMap;
|
||||||
int32_t nBlock;
|
int32_t nBlock;
|
||||||
int32_t iBlock;
|
int32_t iBlock;
|
||||||
SBlock block;
|
SDataBlk block;
|
||||||
SBlockData blockData;
|
SBlockData blockData;
|
||||||
SBlockData *pBlockData;
|
SBlockData *pBlockData;
|
||||||
int32_t nRow;
|
int32_t nRow;
|
||||||
|
@ -684,13 +603,13 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
||||||
}
|
}
|
||||||
case SFSNEXTROW_BLOCKDATA:
|
case SFSNEXTROW_BLOCKDATA:
|
||||||
if (state->iBlock >= 0) {
|
if (state->iBlock >= 0) {
|
||||||
SBlock block = {0};
|
SDataBlk block = {0};
|
||||||
|
|
||||||
tBlockReset(&block);
|
tDataBlkReset(&block);
|
||||||
// tBlockDataReset(&state->blockData);
|
// tBlockDataReset(&state->blockData);
|
||||||
tBlockDataReset(state->pBlockData);
|
tBlockDataReset(state->pBlockData);
|
||||||
|
|
||||||
tMapDataGetItemByIdx(&state->blockMap, state->iBlock, &block, tGetBlock);
|
tMapDataGetItemByIdx(&state->blockMap, state->iBlock, &block, tGetDataBlk);
|
||||||
/* code = tsdbReadBlockData(state->pDataFReader, &state->blockIdx, &block, &state->blockData, NULL, NULL); */
|
/* code = tsdbReadBlockData(state->pDataFReader, &state->blockIdx, &block, &state->blockData, NULL, NULL); */
|
||||||
tBlockDataReset(state->pBlockData);
|
tBlockDataReset(state->pBlockData);
|
||||||
code = tBlockDataInit(state->pBlockData, state->suid, state->uid, state->pTSchema);
|
code = tBlockDataInit(state->pBlockData, state->suid, state->uid, state->pTSchema);
|
||||||
|
@ -878,7 +797,7 @@ static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int64_t *iSkyline) {
|
||||||
if (key->ts > pItemBack->ts) {
|
if (key->ts > pItemBack->ts) {
|
||||||
return false;
|
return false;
|
||||||
} else if (key->ts >= pItemFront->ts && key->ts <= pItemBack->ts) {
|
} else if (key->ts >= pItemFront->ts && key->ts <= pItemBack->ts) {
|
||||||
if ((key->version <= pItemFront->version || key->ts == pItemBack->ts && key->version <= pItemBack->version)) {
|
if (key->version <= pItemFront->version || (key->ts == pItemBack->ts && key->version <= pItemBack->version)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -972,8 +891,6 @@ static int32_t nextRowIterOpen(CacheNextRowIter *pIter, tb_uid_t uid, STsdb *pTs
|
||||||
pIter->fsLastState.state = (SFSLASTNEXTROWSTATES)SFSNEXTROW_FS;
|
pIter->fsLastState.state = (SFSLASTNEXTROWSTATES)SFSNEXTROW_FS;
|
||||||
pIter->fsLastState.pTsdb = pTsdb;
|
pIter->fsLastState.pTsdb = pTsdb;
|
||||||
pIter->fsLastState.aDFileSet = pIter->pReadSnap->fs.aDFileSet;
|
pIter->fsLastState.aDFileSet = pIter->pReadSnap->fs.aDFileSet;
|
||||||
pIter->fsLastState.pBlockIdxExp = &pIter->idx;
|
|
||||||
pIter->fsLastState.pTSchema = pTSchema;
|
|
||||||
pIter->fsLastState.suid = suid;
|
pIter->fsLastState.suid = suid;
|
||||||
pIter->fsLastState.uid = uid;
|
pIter->fsLastState.uid = uid;
|
||||||
|
|
||||||
|
@ -1372,8 +1289,11 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand
|
||||||
// getTableCacheKeyS(uid, "l", key, &keyLen);
|
// getTableCacheKeyS(uid, "l", key, &keyLen);
|
||||||
getTableCacheKey(uid, 1, key, &keyLen);
|
getTableCacheKey(uid, 1, key, &keyLen);
|
||||||
LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen);
|
LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||||
if (h) {
|
if (!h) {
|
||||||
} else {
|
taosThreadMutexLock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
|
h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||||
|
if (!h) {
|
||||||
SArray *pLastArray = NULL;
|
SArray *pLastArray = NULL;
|
||||||
code = mergeLast(uid, pTsdb, &pLastArray);
|
code = mergeLast(uid, pTsdb, &pLastArray);
|
||||||
// if table's empty or error, return code of -1
|
// if table's empty or error, return code of -1
|
||||||
|
@ -1384,13 +1304,18 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand
|
||||||
}
|
}
|
||||||
|
|
||||||
_taos_lru_deleter_t deleter = deleteTableCacheLast;
|
_taos_lru_deleter_t deleter = deleteTableCacheLast;
|
||||||
LRUStatus status =
|
LRUStatus status = taosLRUCacheInsert(pCache, key, keyLen, pLastArray, pLastArray->capacity, deleter, NULL,
|
||||||
taosLRUCacheInsert(pCache, key, keyLen, pLastArray, pLastArray->capacity, deleter, NULL, TAOS_LRU_PRIORITY_LOW);
|
TAOS_LRU_PRIORITY_LOW);
|
||||||
if (status != TAOS_LRU_STATUS_OK) {
|
if (status != TAOS_LRU_STATUS_OK) {
|
||||||
code = -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
h = taosLRUCacheLookup(pCache, key, keyLen);
|
h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||||
|
} else {
|
||||||
|
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = h;
|
*handle = h;
|
||||||
|
@ -1411,3 +1336,5 @@ void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t tsdbCacheGetCapacity(SVnode *pVnode) { return taosLRUCacheGetCapacity(pVnode->pTsdb->lruCache); }
|
size_t tsdbCacheGetCapacity(SVnode *pVnode) { return taosLRUCacheGetCapacity(pVnode->pTsdb->lruCache); }
|
||||||
|
|
||||||
|
size_t tsdbCacheGetUsage(SVnode *pVnode) { return taosLRUCacheGetUsage(pVnode->pTsdb->lruCache); }
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tsdb.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
STsdb *pTsdb;
|
||||||
|
STsdbFS fs;
|
||||||
|
} STsdbCompactor;
|
||||||
|
|
||||||
|
int32_t tsdbCompact(STsdb *pTsdb) {
|
||||||
|
int32_t code = 0;
|
||||||
|
// TODO
|
||||||
|
return code;
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tsdb.h"
|
||||||
|
|
||||||
|
// Integer =====================================================
|
||||||
|
typedef struct {
|
||||||
|
int8_t rawCopy;
|
||||||
|
int64_t prevVal;
|
||||||
|
int32_t nVal;
|
||||||
|
int32_t nBuf;
|
||||||
|
uint8_t *pBuf;
|
||||||
|
} SIntCompressor;
|
||||||
|
|
||||||
|
#define I64_SAFE_ADD(a, b) (((a) >= 0 && (b) <= INT64_MAX - (b)) || ((a) < 0 && (b) >= INT64_MIN - (a)))
|
||||||
|
#define SIMPLE8B_MAX ((uint64_t)1152921504606846974LL)
|
||||||
|
|
||||||
|
static int32_t tsdbCmprI64(SIntCompressor *pCompressor, int64_t val) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
// raw copy
|
||||||
|
if (pCompressor->rawCopy) {
|
||||||
|
memcpy(pCompressor->pBuf + pCompressor->nBuf, &val, sizeof(val));
|
||||||
|
pCompressor->nBuf += sizeof(val);
|
||||||
|
pCompressor->nVal++;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!I64_SAFE_ADD(val, pCompressor->prevVal)) {
|
||||||
|
pCompressor->rawCopy = 1;
|
||||||
|
// TODO: decompress and copy
|
||||||
|
pCompressor->nVal++;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t diff = val - pCompressor->prevVal;
|
||||||
|
uint8_t zigzag = ZIGZAGE(int64_t, diff);
|
||||||
|
|
||||||
|
if (zigzag >= SIMPLE8B_MAX) {
|
||||||
|
pCompressor->rawCopy = 1;
|
||||||
|
// TODO: decompress and copy
|
||||||
|
pCompressor->nVal++;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timestamp =====================================================
|
||||||
|
|
||||||
|
// Float =====================================================
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tsdb.h"
|
||||||
|
|
||||||
|
typedef struct SDiskColBuilder SDiskColBuilder;
|
||||||
|
struct SDiskColBuilder {
|
||||||
|
uint8_t flags;
|
||||||
|
uint8_t *pBitMap;
|
||||||
|
int32_t *aOffset;
|
||||||
|
int32_t nData;
|
||||||
|
uint8_t *pData;
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t tDiskColAddVal(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
||||||
|
int32_t code = 0;
|
||||||
|
// TODO
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
||||||
|
struct SDiskDataBuilder {
|
||||||
|
SDiskDataHdr hdr;
|
||||||
|
SArray *aBlockCol; // SArray<SBlockCol>
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t tDiskDataBuilderCreate(SDiskDataBuilder **ppBuilder) {
|
||||||
|
int32_t code = 0;
|
||||||
|
// TODO
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tDiskDataBuilderDestroy(SDiskDataBuilder *pBuilder) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void tDiskDataBuilderInit(SDiskDataBuilder *pBuilder, int64_t suid, int64_t uid, STSchema *pTSchema, int8_t cmprAlg) {
|
||||||
|
pBuilder->hdr = (SDiskDataHdr){.delimiter = TSDB_FILE_DLMT, //
|
||||||
|
.fmtVer = 0,
|
||||||
|
.suid = suid,
|
||||||
|
.uid = uid,
|
||||||
|
.cmprAlg = cmprAlg};
|
||||||
|
}
|
||||||
|
|
||||||
|
void tDiskDataBuilderReset(SDiskDataBuilder *pBuilder) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tDiskDataBuilderAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTSchema, int64_t uid) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
// uid (todo)
|
||||||
|
|
||||||
|
// version (todo)
|
||||||
|
|
||||||
|
// TSKEY (todo)
|
||||||
|
|
||||||
|
SRowIter iter = {0};
|
||||||
|
tRowIterInit(&iter, pRow, pTSchema);
|
||||||
|
|
||||||
|
for (int32_t iDiskCol = 0; iDiskCol < 0; iDiskCol++) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tDiskDataBuilderGet(SDiskDataBuilder *pBuilder, uint8_t **ppData) {
|
||||||
|
int32_t code = 0;
|
||||||
|
// TODO
|
||||||
|
return code;
|
||||||
|
}
|
|
@ -21,6 +21,9 @@ static int32_t tsdbEncodeFS(uint8_t *p, STsdbFS *pFS) {
|
||||||
int8_t hasDel = pFS->pDelFile ? 1 : 0;
|
int8_t hasDel = pFS->pDelFile ? 1 : 0;
|
||||||
uint32_t nSet = taosArrayGetSize(pFS->aDFileSet);
|
uint32_t nSet = taosArrayGetSize(pFS->aDFileSet);
|
||||||
|
|
||||||
|
// version
|
||||||
|
n += tPutI8(p ? p + n : p, 0);
|
||||||
|
|
||||||
// SDelFile
|
// SDelFile
|
||||||
n += tPutI8(p ? p + n : p, hasDel);
|
n += tPutI8(p ? p + n : p, hasDel);
|
||||||
if (hasDel) {
|
if (hasDel) {
|
||||||
|
@ -110,7 +113,7 @@ _err:
|
||||||
// taosRemoveFile(fname);
|
// taosRemoveFile(fname);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // last
|
// // stt
|
||||||
// if (isSameDisk && pFrom->pLastF->commitID == pTo->pLastF->commitID) {
|
// if (isSameDisk && pFrom->pLastF->commitID == pTo->pLastF->commitID) {
|
||||||
// if (pFrom->pLastF->size > pTo->pLastF->size) {
|
// if (pFrom->pLastF->size > pTo->pLastF->size) {
|
||||||
// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE);
|
// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE);
|
||||||
|
@ -140,7 +143,7 @@ _err:
|
||||||
// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname);
|
// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname);
|
||||||
// taosRemoveFile(fname);
|
// taosRemoveFile(fname);
|
||||||
|
|
||||||
// // last
|
// // stt
|
||||||
// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname);
|
// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname);
|
||||||
// taosRemoveFile(fname);
|
// taosRemoveFile(fname);
|
||||||
|
|
||||||
|
@ -254,8 +257,10 @@ void tsdbFSDestroy(STsdbFS *pFS) {
|
||||||
SDFileSet *pSet = (SDFileSet *)taosArrayGet(pFS->aDFileSet, iSet);
|
SDFileSet *pSet = (SDFileSet *)taosArrayGet(pFS->aDFileSet, iSet);
|
||||||
taosMemoryFree(pSet->pHeadF);
|
taosMemoryFree(pSet->pHeadF);
|
||||||
taosMemoryFree(pSet->pDataF);
|
taosMemoryFree(pSet->pDataF);
|
||||||
taosMemoryFree(pSet->pLastF);
|
|
||||||
taosMemoryFree(pSet->pSmaF);
|
taosMemoryFree(pSet->pSmaF);
|
||||||
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
taosMemoryFree(pSet->aSttF[iStt]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pFS->aDFileSet);
|
taosArrayDestroy(pFS->aDFileSet);
|
||||||
|
@ -290,7 +295,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (size != pSet->pHeadF->size) {
|
if (size != LOGIC_TO_FILE_SIZE(pSet->pHeadF->size, TSDB_DEFAULT_PAGE_SIZE)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -301,38 +306,40 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (size < pSet->pDataF->size) {
|
if (size < LOGIC_TO_FILE_SIZE(pSet->pDataF->size, TSDB_DEFAULT_PAGE_SIZE)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
goto _err;
|
goto _err;
|
||||||
} else if (size > pSet->pDataF->size) {
|
} else if (size > LOGIC_TO_FILE_SIZE(pSet->pDataF->size, TSDB_DEFAULT_PAGE_SIZE)) {
|
||||||
code = tsdbDFileRollback(pTsdb, pSet, TSDB_DATA_FILE);
|
code = tsdbDFileRollback(pTsdb, pSet, TSDB_DATA_FILE);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last ===========
|
|
||||||
tsdbLastFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pLastF, fname);
|
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
if (size != pSet->pLastF->size) {
|
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sma =============
|
// sma =============
|
||||||
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
|
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (size < pSet->pSmaF->size) {
|
if (size < LOGIC_TO_FILE_SIZE(pSet->pSmaF->size, TSDB_DEFAULT_PAGE_SIZE)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
goto _err;
|
goto _err;
|
||||||
} else if (size > pSet->pSmaF->size) {
|
} else if (size > LOGIC_TO_FILE_SIZE(pSet->pSmaF->size, TSDB_DEFAULT_PAGE_SIZE)) {
|
||||||
code = tsdbDFileRollback(pTsdb, pSet, TSDB_SMA_FILE);
|
code = tsdbDFileRollback(pTsdb, pSet, TSDB_SMA_FILE);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stt ===========
|
||||||
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
|
||||||
|
if (taosStatFile(fname, &size, NULL)) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
if (size != LOGIC_TO_FILE_SIZE(pSet->aSttF[iStt]->size, TSDB_DEFAULT_PAGE_SIZE)) {
|
||||||
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -360,10 +367,12 @@ static int32_t tsdbRecoverFS(STsdb *pTsdb, uint8_t *pData, int64_t nData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int8_t hasDel;
|
int8_t hasDel;
|
||||||
uint32_t nSet;
|
uint32_t nSet;
|
||||||
int32_t n;
|
int32_t n = 0;
|
||||||
|
|
||||||
|
// version
|
||||||
|
n += tGetI8(pData + n, NULL);
|
||||||
|
|
||||||
// SDelFile
|
// SDelFile
|
||||||
n = 0;
|
|
||||||
n += tGetI8(pData + n, &hasDel);
|
n += tGetI8(pData + n, &hasDel);
|
||||||
if (hasDel) {
|
if (hasDel) {
|
||||||
pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile));
|
pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile));
|
||||||
|
@ -382,41 +391,15 @@ static int32_t tsdbRecoverFS(STsdb *pTsdb, uint8_t *pData, int64_t nData) {
|
||||||
taosArrayClear(pTsdb->fs.aDFileSet);
|
taosArrayClear(pTsdb->fs.aDFileSet);
|
||||||
n += tGetU32v(pData + n, &nSet);
|
n += tGetU32v(pData + n, &nSet);
|
||||||
for (uint32_t iSet = 0; iSet < nSet; iSet++) {
|
for (uint32_t iSet = 0; iSet < nSet; iSet++) {
|
||||||
SDFileSet fSet;
|
SDFileSet fSet = {0};
|
||||||
|
|
||||||
// head
|
int32_t nt = tGetDFileSet(pData + n, &fSet);
|
||||||
fSet.pHeadF = (SHeadFile *)taosMemoryCalloc(1, sizeof(SHeadFile));
|
if (nt < 0) {
|
||||||
if (fSet.pHeadF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
fSet.pHeadF->nRef = 1;
|
|
||||||
|
|
||||||
// data
|
n += nt;
|
||||||
fSet.pDataF = (SDataFile *)taosMemoryCalloc(1, sizeof(SDataFile));
|
|
||||||
if (fSet.pDataF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
fSet.pDataF->nRef = 1;
|
|
||||||
|
|
||||||
// last
|
|
||||||
fSet.pLastF = (SLastFile *)taosMemoryCalloc(1, sizeof(SLastFile));
|
|
||||||
if (fSet.pLastF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
fSet.pLastF->nRef = 1;
|
|
||||||
|
|
||||||
// sma
|
|
||||||
fSet.pSmaF = (SSmaFile *)taosMemoryCalloc(1, sizeof(SSmaFile));
|
|
||||||
if (fSet.pSmaF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
fSet.pSmaF->nRef = 1;
|
|
||||||
|
|
||||||
n += tGetDFileSet(pData + n, &fSet);
|
|
||||||
|
|
||||||
if (taosArrayPush(pTsdb->fs.aDFileSet, &fSet) == NULL) {
|
if (taosArrayPush(pTsdb->fs.aDFileSet, &fSet) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -532,13 +515,15 @@ int32_t tsdbFSClose(STsdb *pTsdb) {
|
||||||
ASSERT(pSet->pDataF->nRef == 1);
|
ASSERT(pSet->pDataF->nRef == 1);
|
||||||
taosMemoryFree(pSet->pDataF);
|
taosMemoryFree(pSet->pDataF);
|
||||||
|
|
||||||
// last
|
|
||||||
ASSERT(pSet->pLastF->nRef == 1);
|
|
||||||
taosMemoryFree(pSet->pLastF);
|
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
ASSERT(pSet->pSmaF->nRef == 1);
|
ASSERT(pSet->pSmaF->nRef == 1);
|
||||||
taosMemoryFree(pSet->pSmaF);
|
taosMemoryFree(pSet->pSmaF);
|
||||||
|
|
||||||
|
// stt
|
||||||
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
ASSERT(pSet->aSttF[iStt]->nRef == 1);
|
||||||
|
taosMemoryFree(pSet->aSttF[iStt]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pTsdb->fs.aDFileSet);
|
taosArrayDestroy(pTsdb->fs.aDFileSet);
|
||||||
|
@ -586,15 +571,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
}
|
}
|
||||||
*fSet.pDataF = *pSet->pDataF;
|
*fSet.pDataF = *pSet->pDataF;
|
||||||
|
|
||||||
// data
|
// sma
|
||||||
fSet.pLastF = (SLastFile *)taosMemoryMalloc(sizeof(SLastFile));
|
|
||||||
if (fSet.pLastF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
*fSet.pLastF = *pSet->pLastF;
|
|
||||||
|
|
||||||
// last
|
|
||||||
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
|
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
|
||||||
if (fSet.pSmaF == NULL) {
|
if (fSet.pSmaF == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -602,6 +579,16 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
}
|
}
|
||||||
*fSet.pSmaF = *pSet->pSmaF;
|
*fSet.pSmaF = *pSet->pSmaF;
|
||||||
|
|
||||||
|
// stt
|
||||||
|
for (fSet.nSttF = 0; fSet.nSttF < pSet->nSttF; fSet.nSttF++) {
|
||||||
|
fSet.aSttF[fSet.nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (fSet.aSttF[fSet.nSttF] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
*fSet.aSttF[fSet.nSttF] = *pSet->aSttF[fSet.nSttF];
|
||||||
|
}
|
||||||
|
|
||||||
if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
|
if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
@ -651,14 +638,38 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
*pDFileSet->pHeadF = *pSet->pHeadF;
|
*pDFileSet->pHeadF = *pSet->pHeadF;
|
||||||
*pDFileSet->pDataF = *pSet->pDataF;
|
*pDFileSet->pDataF = *pSet->pDataF;
|
||||||
*pDFileSet->pLastF = *pSet->pLastF;
|
|
||||||
*pDFileSet->pSmaF = *pSet->pSmaF;
|
*pDFileSet->pSmaF = *pSet->pSmaF;
|
||||||
|
// stt
|
||||||
|
if (pSet->nSttF > pDFileSet->nSttF) {
|
||||||
|
ASSERT(pSet->nSttF == pDFileSet->nSttF + 1);
|
||||||
|
|
||||||
|
pDFileSet->aSttF[pDFileSet->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (pDFileSet->aSttF[pDFileSet->nSttF] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
*pDFileSet->aSttF[pDFileSet->nSttF] = *pSet->aSttF[pSet->nSttF - 1];
|
||||||
|
pDFileSet->nSttF++;
|
||||||
|
} else if (pSet->nSttF < pDFileSet->nSttF) {
|
||||||
|
ASSERT(pSet->nSttF == 1);
|
||||||
|
for (int32_t iStt = 1; iStt < pDFileSet->nSttF; iStt++) {
|
||||||
|
taosMemoryFree(pDFileSet->aSttF[iStt]);
|
||||||
|
}
|
||||||
|
|
||||||
|
*pDFileSet->aSttF[0] = *pSet->aSttF[0];
|
||||||
|
pDFileSet->nSttF = 1;
|
||||||
|
} else {
|
||||||
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
*pDFileSet->aSttF[iStt] = *pSet->aSttF[iStt];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDFileSet fSet = {.diskId = pSet->diskId, .fid = pSet->fid};
|
ASSERT(pSet->nSttF == 1);
|
||||||
|
SDFileSet fSet = {.diskId = pSet->diskId, .fid = pSet->fid, .nSttF = 1};
|
||||||
|
|
||||||
// head
|
// head
|
||||||
fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
||||||
|
@ -676,15 +687,7 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
|
||||||
}
|
}
|
||||||
*fSet.pDataF = *pSet->pDataF;
|
*fSet.pDataF = *pSet->pDataF;
|
||||||
|
|
||||||
// data
|
// sma
|
||||||
fSet.pLastF = (SLastFile *)taosMemoryMalloc(sizeof(SLastFile));
|
|
||||||
if (fSet.pLastF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
*fSet.pLastF = *pSet->pLastF;
|
|
||||||
|
|
||||||
// last
|
|
||||||
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
|
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
|
||||||
if (fSet.pSmaF == NULL) {
|
if (fSet.pSmaF == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -692,6 +695,14 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
|
||||||
}
|
}
|
||||||
*fSet.pSmaF = *pSet->pSmaF;
|
*fSet.pSmaF = *pSet->pSmaF;
|
||||||
|
|
||||||
|
// stt
|
||||||
|
fSet.aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (fSet.aSttF[0] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
*fSet.aSttF[0] = *pSet->aSttF[0];
|
||||||
|
|
||||||
if (taosArrayInsert(pFS->aDFileSet, idx, &fSet) == NULL) {
|
if (taosArrayInsert(pFS->aDFileSet, idx, &fSet) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
@ -836,27 +847,6 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
pSetOld->pDataF->size = pSetNew->pDataF->size;
|
pSetOld->pDataF->size = pSetNew->pDataF->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
|
||||||
fSet.pLastF = pSetOld->pLastF;
|
|
||||||
if ((!sameDisk) || (pSetOld->pLastF->commitID != pSetNew->pLastF->commitID)) {
|
|
||||||
pSetOld->pLastF = (SLastFile *)taosMemoryMalloc(sizeof(SLastFile));
|
|
||||||
if (pSetOld->pLastF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
*pSetOld->pLastF = *pSetNew->pLastF;
|
|
||||||
pSetOld->pLastF->nRef = 1;
|
|
||||||
|
|
||||||
nRef = atomic_sub_fetch_32(&fSet.pLastF->nRef, 1);
|
|
||||||
if (nRef == 0) {
|
|
||||||
tsdbLastFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pLastF, fname);
|
|
||||||
taosRemoveFile(fname);
|
|
||||||
taosMemoryFree(fSet.pLastF);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ASSERT(pSetOld->pLastF->size == pSetNew->pLastF->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
fSet.pSmaF = pSetOld->pSmaF;
|
fSet.pSmaF = pSetOld->pSmaF;
|
||||||
if ((!sameDisk) || (pSetOld->pSmaF->commitID != pSetNew->pSmaF->commitID)) {
|
if ((!sameDisk) || (pSetOld->pSmaF->commitID != pSetNew->pSmaF->commitID)) {
|
||||||
|
@ -879,6 +869,84 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
pSetOld->pSmaF->size = pSetNew->pSmaF->size;
|
pSetOld->pSmaF->size = pSetNew->pSmaF->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stt
|
||||||
|
if (sameDisk) {
|
||||||
|
if (pSetNew->nSttF > pSetOld->nSttF) {
|
||||||
|
ASSERT(pSetNew->nSttF = pSetOld->nSttF + 1);
|
||||||
|
pSetOld->aSttF[pSetOld->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (pSetOld->aSttF[pSetOld->nSttF] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
*pSetOld->aSttF[pSetOld->nSttF] = *pSetNew->aSttF[pSetOld->nSttF];
|
||||||
|
pSetOld->aSttF[pSetOld->nSttF]->nRef = 1;
|
||||||
|
pSetOld->nSttF++;
|
||||||
|
} else if (pSetNew->nSttF < pSetOld->nSttF) {
|
||||||
|
ASSERT(pSetNew->nSttF == 1);
|
||||||
|
for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
|
||||||
|
SSttFile *pSttFile = pSetOld->aSttF[iStt];
|
||||||
|
nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
|
||||||
|
if (nRef == 0) {
|
||||||
|
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
|
||||||
|
taosRemoveFile(fname);
|
||||||
|
taosMemoryFree(pSttFile);
|
||||||
|
}
|
||||||
|
pSetOld->aSttF[iStt] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSetOld->nSttF = 1;
|
||||||
|
pSetOld->aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (pSetOld->aSttF[0] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
*pSetOld->aSttF[0] = *pSetNew->aSttF[0];
|
||||||
|
pSetOld->aSttF[0]->nRef = 1;
|
||||||
|
} else {
|
||||||
|
for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
|
||||||
|
if (pSetOld->aSttF[iStt]->commitID != pSetNew->aSttF[iStt]->commitID) {
|
||||||
|
SSttFile *pSttFile = pSetOld->aSttF[iStt];
|
||||||
|
nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
|
||||||
|
if (nRef == 0) {
|
||||||
|
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
|
||||||
|
taosRemoveFile(fname);
|
||||||
|
taosMemoryFree(pSttFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (pSetOld->aSttF[iStt] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
*pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt];
|
||||||
|
pSetOld->aSttF[iStt]->nRef = 1;
|
||||||
|
} else {
|
||||||
|
ASSERT(pSetOld->aSttF[iStt]->size == pSetOld->aSttF[iStt]->size);
|
||||||
|
ASSERT(pSetOld->aSttF[iStt]->offset == pSetOld->aSttF[iStt]->offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ASSERT(pSetOld->nSttF == pSetNew->nSttF);
|
||||||
|
for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
|
||||||
|
SSttFile *pSttFile = pSetOld->aSttF[iStt];
|
||||||
|
nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
|
||||||
|
if (nRef == 0) {
|
||||||
|
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
|
||||||
|
taosRemoveFile(fname);
|
||||||
|
taosMemoryFree(pSttFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (pSetOld->aSttF[iStt] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
*pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt];
|
||||||
|
pSetOld->aSttF[iStt]->nRef = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!sameDisk) {
|
if (!sameDisk) {
|
||||||
pSetOld->diskId = pSetNew->diskId;
|
pSetOld->diskId = pSetNew->diskId;
|
||||||
}
|
}
|
||||||
|
@ -902,13 +970,6 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
taosMemoryFree(pSetOld->pDataF);
|
taosMemoryFree(pSetOld->pDataF);
|
||||||
}
|
}
|
||||||
|
|
||||||
nRef = atomic_sub_fetch_32(&pSetOld->pLastF->nRef, 1);
|
|
||||||
if (nRef == 0) {
|
|
||||||
tsdbLastFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pLastF, fname);
|
|
||||||
taosRemoveFile(fname);
|
|
||||||
taosMemoryFree(pSetOld->pLastF);
|
|
||||||
}
|
|
||||||
|
|
||||||
nRef = atomic_sub_fetch_32(&pSetOld->pSmaF->nRef, 1);
|
nRef = atomic_sub_fetch_32(&pSetOld->pSmaF->nRef, 1);
|
||||||
if (nRef == 0) {
|
if (nRef == 0) {
|
||||||
tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pSmaF, fname);
|
tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pSmaF, fname);
|
||||||
|
@ -916,12 +977,20 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
taosMemoryFree(pSetOld->pSmaF);
|
taosMemoryFree(pSetOld->pSmaF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int8_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
|
||||||
|
nRef = atomic_sub_fetch_32(&pSetOld->aSttF[iStt]->nRef, 1);
|
||||||
|
if (nRef == 0) {
|
||||||
|
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->aSttF[iStt], fname);
|
||||||
|
taosRemoveFile(fname);
|
||||||
|
taosMemoryFree(pSetOld->aSttF[iStt]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
taosArrayRemove(pTsdb->fs.aDFileSet, iOld);
|
taosArrayRemove(pTsdb->fs.aDFileSet, iOld);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_add_new:
|
_add_new:
|
||||||
fSet.diskId = pSetNew->diskId;
|
fSet = (SDFileSet){.diskId = pSetNew->diskId, .fid = pSetNew->fid, .nSttF = 1};
|
||||||
fSet.fid = pSetNew->fid;
|
|
||||||
|
|
||||||
// head
|
// head
|
||||||
fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
|
||||||
|
@ -941,15 +1010,6 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
*fSet.pDataF = *pSetNew->pDataF;
|
*fSet.pDataF = *pSetNew->pDataF;
|
||||||
fSet.pDataF->nRef = 1;
|
fSet.pDataF->nRef = 1;
|
||||||
|
|
||||||
// last
|
|
||||||
fSet.pLastF = (SLastFile *)taosMemoryMalloc(sizeof(SLastFile));
|
|
||||||
if (fSet.pLastF == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
*fSet.pLastF = *pSetNew->pLastF;
|
|
||||||
fSet.pLastF->nRef = 1;
|
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
|
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
|
||||||
if (fSet.pSmaF == NULL) {
|
if (fSet.pSmaF == NULL) {
|
||||||
|
@ -959,6 +1019,16 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
|
||||||
*fSet.pSmaF = *pSetNew->pSmaF;
|
*fSet.pSmaF = *pSetNew->pSmaF;
|
||||||
fSet.pSmaF->nRef = 1;
|
fSet.pSmaF->nRef = 1;
|
||||||
|
|
||||||
|
// stt
|
||||||
|
ASSERT(pSetNew->nSttF == 1);
|
||||||
|
fSet.aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
|
||||||
|
if (fSet.aSttF[0] == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
*fSet.aSttF[0] = *pSetNew->aSttF[0];
|
||||||
|
fSet.aSttF[0]->nRef = 1;
|
||||||
|
|
||||||
if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) {
|
if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -1002,12 +1072,14 @@ int32_t tsdbFSRef(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
nRef = atomic_fetch_add_32(&pSet->pDataF->nRef, 1);
|
nRef = atomic_fetch_add_32(&pSet->pDataF->nRef, 1);
|
||||||
ASSERT(nRef > 0);
|
ASSERT(nRef > 0);
|
||||||
|
|
||||||
nRef = atomic_fetch_add_32(&pSet->pLastF->nRef, 1);
|
|
||||||
ASSERT(nRef > 0);
|
|
||||||
|
|
||||||
nRef = atomic_fetch_add_32(&pSet->pSmaF->nRef, 1);
|
nRef = atomic_fetch_add_32(&pSet->pSmaF->nRef, 1);
|
||||||
ASSERT(nRef > 0);
|
ASSERT(nRef > 0);
|
||||||
|
|
||||||
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
nRef = atomic_fetch_add_32(&pSet->aSttF[iStt]->nRef, 1);
|
||||||
|
ASSERT(nRef > 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
|
if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
@ -1053,15 +1125,6 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
taosMemoryFree(pSet->pDataF);
|
taosMemoryFree(pSet->pDataF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// last
|
|
||||||
nRef = atomic_sub_fetch_32(&pSet->pLastF->nRef, 1);
|
|
||||||
ASSERT(nRef >= 0);
|
|
||||||
if (nRef == 0) {
|
|
||||||
tsdbLastFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pLastF, fname);
|
|
||||||
taosRemoveFile(fname);
|
|
||||||
taosMemoryFree(pSet->pLastF);
|
|
||||||
}
|
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1);
|
nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1);
|
||||||
ASSERT(nRef >= 0);
|
ASSERT(nRef >= 0);
|
||||||
|
@ -1070,6 +1133,18 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
|
||||||
taosRemoveFile(fname);
|
taosRemoveFile(fname);
|
||||||
taosMemoryFree(pSet->pSmaF);
|
taosMemoryFree(pSet->pSmaF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stt
|
||||||
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
nRef = atomic_sub_fetch_32(&pSet->aSttF[iStt]->nRef, 1);
|
||||||
|
ASSERT(nRef >= 0);
|
||||||
|
if (nRef == 0) {
|
||||||
|
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
|
||||||
|
taosRemoveFile(fname);
|
||||||
|
taosMemoryFree(pSet->aSttF[iStt]);
|
||||||
|
/* code */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pFS->aDFileSet);
|
taosArrayDestroy(pFS->aDFileSet);
|
||||||
|
|
|
@ -53,22 +53,22 @@ static int32_t tGetDataFile(uint8_t *p, SDataFile *pDataFile) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tPutLastFile(uint8_t *p, SLastFile *pLastFile) {
|
int32_t tPutSttFile(uint8_t *p, SSttFile *pSttFile) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
|
|
||||||
n += tPutI64v(p ? p + n : p, pLastFile->commitID);
|
n += tPutI64v(p ? p + n : p, pSttFile->commitID);
|
||||||
n += tPutI64v(p ? p + n : p, pLastFile->size);
|
n += tPutI64v(p ? p + n : p, pSttFile->size);
|
||||||
n += tPutI64v(p ? p + n : p, pLastFile->offset);
|
n += tPutI64v(p ? p + n : p, pSttFile->offset);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tGetLastFile(uint8_t *p, SLastFile *pLastFile) {
|
static int32_t tGetSttFile(uint8_t *p, SSttFile *pSttFile) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
|
|
||||||
n += tGetI64v(p + n, &pLastFile->commitID);
|
n += tGetI64v(p + n, &pSttFile->commitID);
|
||||||
n += tGetI64v(p + n, &pLastFile->size);
|
n += tGetI64v(p + n, &pSttFile->size);
|
||||||
n += tGetI64v(p + n, &pLastFile->offset);
|
n += tGetI64v(p + n, &pSttFile->offset);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,9 @@ void tsdbDataFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SDataFile *pDataF,
|
||||||
TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), fid, pDataF->commitID, ".data");
|
TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), fid, pDataF->commitID, ".data");
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbLastFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SLastFile *pLastF, char fname[]) {
|
void tsdbSttFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSttFile *pSttF, char fname[]) {
|
||||||
snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%df%dver%" PRId64 "%s", tfsGetDiskPath(pTsdb->pVnode->pTfs, did),
|
snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%df%dver%" PRId64 "%s", tfsGetDiskPath(pTsdb->pVnode->pTfs, did),
|
||||||
TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), fid, pLastF->commitID, ".last");
|
TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), fid, pSttF->commitID, ".stt");
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, char fname[]) {
|
void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, char fname[]) {
|
||||||
|
@ -148,7 +148,7 @@ int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ftruncate
|
// ftruncate
|
||||||
if (taosFtruncateFile(pFD, size) < 0) {
|
if (taosFtruncateFile(pFD, LOGIC_TO_FILE_SIZE(size, TSDB_DEFAULT_PAGE_SIZE)) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -194,9 +194,11 @@ int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet) {
|
||||||
n += tPutDataFile(p ? p + n : p, pSet->pDataF);
|
n += tPutDataFile(p ? p + n : p, pSet->pDataF);
|
||||||
n += tPutSmaFile(p ? p + n : p, pSet->pSmaF);
|
n += tPutSmaFile(p ? p + n : p, pSet->pSmaF);
|
||||||
|
|
||||||
// last
|
// stt
|
||||||
n += tPutU8(p ? p + n : p, 1); // for future compatibility
|
n += tPutU8(p ? p + n : p, pSet->nSttF);
|
||||||
n += tPutLastFile(p ? p + n : p, pSet->pLastF);
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
|
n += tPutSttFile(p ? p + n : p, pSet->aSttF[iStt]);
|
||||||
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -208,15 +210,40 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
||||||
n += tGetI32v(p + n, &pSet->diskId.id);
|
n += tGetI32v(p + n, &pSet->diskId.id);
|
||||||
n += tGetI32v(p + n, &pSet->fid);
|
n += tGetI32v(p + n, &pSet->fid);
|
||||||
|
|
||||||
// data
|
// head
|
||||||
|
pSet->pHeadF = (SHeadFile *)taosMemoryCalloc(1, sizeof(SHeadFile));
|
||||||
|
if (pSet->pHeadF == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pSet->pHeadF->nRef = 1;
|
||||||
n += tGetHeadFile(p + n, pSet->pHeadF);
|
n += tGetHeadFile(p + n, pSet->pHeadF);
|
||||||
|
|
||||||
|
// data
|
||||||
|
pSet->pDataF = (SDataFile *)taosMemoryCalloc(1, sizeof(SDataFile));
|
||||||
|
if (pSet->pDataF == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pSet->pDataF->nRef = 1;
|
||||||
n += tGetDataFile(p + n, pSet->pDataF);
|
n += tGetDataFile(p + n, pSet->pDataF);
|
||||||
|
|
||||||
|
// sma
|
||||||
|
pSet->pSmaF = (SSmaFile *)taosMemoryCalloc(1, sizeof(SSmaFile));
|
||||||
|
if (pSet->pSmaF == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pSet->pSmaF->nRef = 1;
|
||||||
n += tGetSmaFile(p + n, pSet->pSmaF);
|
n += tGetSmaFile(p + n, pSet->pSmaF);
|
||||||
|
|
||||||
// last
|
// stt
|
||||||
uint8_t nLast;
|
n += tGetU8(p + n, &pSet->nSttF);
|
||||||
n += tGetU8(p + n, &nLast);
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
n += tGetLastFile(p + n, pSet->pLastF);
|
pSet->aSttF[iStt] = (SSttFile *)taosMemoryCalloc(1, sizeof(SSttFile));
|
||||||
|
if (pSet->aSttF[iStt] == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pSet->aSttF[iStt]->nRef = 1;
|
||||||
|
n += tGetSttFile(p + n, pSet->aSttF[iStt]);
|
||||||
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,396 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tsdb.h"
|
||||||
|
|
||||||
|
// SLDataIter =================================================
|
||||||
|
struct SLDataIter {
|
||||||
|
SRBTreeNode node;
|
||||||
|
SSttBlk *pSttBlk;
|
||||||
|
SDataFReader *pReader;
|
||||||
|
int32_t iStt;
|
||||||
|
int8_t backward;
|
||||||
|
SArray *aSttBlk;
|
||||||
|
int32_t iSttBlk;
|
||||||
|
SBlockData bData[2];
|
||||||
|
int32_t loadIndex;
|
||||||
|
int32_t iRow;
|
||||||
|
SRowInfo rInfo;
|
||||||
|
uint64_t uid;
|
||||||
|
STimeWindow timeWindow;
|
||||||
|
SVersionRange verRange;
|
||||||
|
};
|
||||||
|
|
||||||
|
static SBlockData *getCurrentBlock(SLDataIter *pIter) { return &pIter->bData[pIter->loadIndex]; }
|
||||||
|
|
||||||
|
static SBlockData *getNextBlock(SLDataIter *pIter) {
|
||||||
|
pIter->loadIndex ^= 1;
|
||||||
|
return getCurrentBlock(pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
|
||||||
|
uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange) {
|
||||||
|
int32_t code = 0;
|
||||||
|
*pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
|
||||||
|
if (*pIter == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*pIter)->uid = uid;
|
||||||
|
(*pIter)->pReader = pReader;
|
||||||
|
(*pIter)->iStt = iStt;
|
||||||
|
(*pIter)->backward = backward;
|
||||||
|
(*pIter)->verRange = *pRange;
|
||||||
|
(*pIter)->timeWindow = *pTimeWindow;
|
||||||
|
(*pIter)->aSttBlk = taosArrayInit(0, sizeof(SSttBlk));
|
||||||
|
if ((*pIter)->aSttBlk == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tBlockDataCreate(&(*pIter)->bData[0]);
|
||||||
|
if (code) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tBlockDataCreate(&(*pIter)->bData[1]);
|
||||||
|
if (code) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tsdbReadSttBlk(pReader, iStt, (*pIter)->aSttBlk);
|
||||||
|
if (code) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = taosArrayGetSize((*pIter)->aSttBlk);
|
||||||
|
|
||||||
|
// find the start block
|
||||||
|
int32_t index = -1;
|
||||||
|
if (!backward) { // asc
|
||||||
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
|
SSttBlk *p = taosArrayGet((*pIter)->aSttBlk, i);
|
||||||
|
if (p->suid != suid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->minUid <= uid && p->maxUid >= uid) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // desc
|
||||||
|
for (int32_t i = size - 1; i >= 0; --i) {
|
||||||
|
SSttBlk *p = taosArrayGet((*pIter)->aSttBlk, i);
|
||||||
|
if (p->suid != suid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->minUid <= uid && p->maxUid >= uid) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(*pIter)->iSttBlk = index;
|
||||||
|
if (index != -1) {
|
||||||
|
(*pIter)->pSttBlk = taosArrayGet((*pIter)->aSttBlk, (*pIter)->iSttBlk);
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tLDataIterClose(SLDataIter *pIter) {
|
||||||
|
tBlockDataDestroy(&pIter->bData[0], 1);
|
||||||
|
tBlockDataDestroy(&pIter->bData[1], 1);
|
||||||
|
taosArrayDestroy(pIter->aSttBlk);
|
||||||
|
taosMemoryFree(pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tLDataIterNextBlock(SLDataIter *pIter) {
|
||||||
|
int32_t step = pIter->backward ? -1 : 1;
|
||||||
|
pIter->iSttBlk += step;
|
||||||
|
|
||||||
|
int32_t index = -1;
|
||||||
|
size_t size = taosArrayGetSize(pIter->aSttBlk);
|
||||||
|
for (int32_t i = pIter->iSttBlk; i < size && i >= 0; i += step) {
|
||||||
|
SSttBlk *p = taosArrayGet(pIter->aSttBlk, i);
|
||||||
|
if ((!pIter->backward) && p->minUid > pIter->uid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->backward && p->maxUid < pIter->uid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check uid firstly
|
||||||
|
if (p->minUid <= pIter->uid && p->maxUid >= pIter->uid) {
|
||||||
|
if ((!pIter->backward) && p->minKey > pIter->timeWindow.ekey) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->backward && p->maxKey < pIter->timeWindow.skey) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check time range secondly
|
||||||
|
if (p->minKey <= pIter->timeWindow.ekey && p->maxKey >= pIter->timeWindow.skey) {
|
||||||
|
if ((!pIter->backward) && p->minVer > pIter->verRange.maxVer) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->backward && p->maxVer < pIter->verRange.minVer) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->minVer <= pIter->verRange.maxVer && p->maxVer >= pIter->verRange.minVer) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == -1) {
|
||||||
|
pIter->pSttBlk = NULL;
|
||||||
|
} else {
|
||||||
|
pIter->pSttBlk = (SSttBlk *)taosArrayGet(pIter->aSttBlk, pIter->iSttBlk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void findNextValidRow(SLDataIter *pIter) {
|
||||||
|
int32_t step = pIter->backward ? -1 : 1;
|
||||||
|
|
||||||
|
bool hasVal = false;
|
||||||
|
int32_t i = pIter->iRow;
|
||||||
|
SBlockData *pBlockData = getCurrentBlock(pIter);
|
||||||
|
|
||||||
|
for (; i < pBlockData->nRow && i >= 0; i += step) {
|
||||||
|
if (pBlockData->aUid != NULL) {
|
||||||
|
if (!pIter->backward) {
|
||||||
|
if (pBlockData->aUid[i] < pIter->uid) {
|
||||||
|
continue;
|
||||||
|
} else if (pBlockData->aUid[i] > pIter->uid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (pBlockData->aUid[i] > pIter->uid) {
|
||||||
|
continue;
|
||||||
|
} else if (pBlockData->aUid[i] < pIter->uid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t ts = pBlockData->aTSKEY[i];
|
||||||
|
if (!pIter->backward) { // asc
|
||||||
|
if (ts > pIter->timeWindow.ekey) { // no more data
|
||||||
|
break;
|
||||||
|
} else if (ts < pIter->timeWindow.skey) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ts < pIter->timeWindow.skey) {
|
||||||
|
break;
|
||||||
|
} else if (ts > pIter->timeWindow.ekey) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t ver = pBlockData->aVersion[i];
|
||||||
|
if (ver < pIter->verRange.minVer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo opt handle desc case
|
||||||
|
if (ver > pIter->verRange.maxVer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasVal = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->iRow = (hasVal) ? i : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tLDataIterNextRow(SLDataIter *pIter) {
|
||||||
|
int32_t code = 0;
|
||||||
|
int32_t step = pIter->backward ? -1 : 1;
|
||||||
|
|
||||||
|
// no qualified last file block in current file, no need to fetch row
|
||||||
|
if (pIter->pSttBlk == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t iBlockL = pIter->iSttBlk;
|
||||||
|
SBlockData *pBlockData = getCurrentBlock(pIter);
|
||||||
|
|
||||||
|
if (pBlockData->nRow == 0 && pIter->pSttBlk != NULL) { // current block not loaded yet
|
||||||
|
pBlockData = getNextBlock(pIter);
|
||||||
|
code = tsdbReadSttBlock(pIter->pReader, pIter->iStt, pIter->pSttBlk, pBlockData);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->iRow = (pIter->backward) ? pBlockData->nRow : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->iRow += step;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
findNextValidRow(pIter);
|
||||||
|
|
||||||
|
if (pIter->iRow >= pBlockData->nRow || pIter->iRow < 0) {
|
||||||
|
tLDataIterNextBlock(pIter);
|
||||||
|
if (pIter->pSttBlk == NULL) { // no more data
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iBlockL != pIter->iSttBlk) {
|
||||||
|
pBlockData = getNextBlock(pIter);
|
||||||
|
code = tsdbReadSttBlock(pIter->pReader, pIter->iStt, pIter->pSttBlk, pBlockData);
|
||||||
|
if (code) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
pIter->iRow = pIter->backward ? (pBlockData->nRow - 1) : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->rInfo.suid = pBlockData->suid;
|
||||||
|
pIter->rInfo.uid = pBlockData->uid;
|
||||||
|
pIter->rInfo.row = tsdbRowFromBlockData(pBlockData, pIter->iRow);
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (code == TSDB_CODE_SUCCESS) && (pIter->pSttBlk != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
SRowInfo *tLDataIterGet(SLDataIter *pIter) { return &pIter->rInfo; }
|
||||||
|
|
||||||
|
// SMergeTree =================================================
|
||||||
|
static FORCE_INLINE int32_t tLDataIterCmprFn(const void *p1, const void *p2) {
|
||||||
|
SLDataIter *pIter1 = (SLDataIter *)(((uint8_t *)p1) - sizeof(SRBTreeNode));
|
||||||
|
SLDataIter *pIter2 = (SLDataIter *)(((uint8_t *)p2) - sizeof(SRBTreeNode));
|
||||||
|
|
||||||
|
TSDBKEY key1 = TSDBROW_KEY(&pIter1->rInfo.row);
|
||||||
|
TSDBKEY key2 = TSDBROW_KEY(&pIter2->rInfo.row);
|
||||||
|
|
||||||
|
if (key1.ts < key2.ts) {
|
||||||
|
return -1;
|
||||||
|
} else if (key1.ts > key2.ts) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (key1.version < key2.version) {
|
||||||
|
return -1;
|
||||||
|
} else if (key1.version > key2.version) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
|
||||||
|
STimeWindow *pTimeWindow, SVersionRange *pVerRange) {
|
||||||
|
pMTree->backward = backward;
|
||||||
|
pMTree->pIter = NULL;
|
||||||
|
pMTree->pIterList = taosArrayInit(4, POINTER_BYTES);
|
||||||
|
if (pMTree->pIterList == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn);
|
||||||
|
int32_t code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
struct SLDataIter *pIterList[TSDB_DEFAULT_STT_FILE] = {0};
|
||||||
|
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
|
||||||
|
code = tLDataIterOpen(&pIterList[i], pFReader, i, pMTree->backward, suid, uid, pTimeWindow, pVerRange);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasVal = tLDataIterNextRow(pIterList[i]);
|
||||||
|
if (hasVal) {
|
||||||
|
taosArrayPush(pMTree->pIterList, &pIterList[i]);
|
||||||
|
tMergeTreeAddIter(pMTree, pIterList[i]);
|
||||||
|
} else {
|
||||||
|
tLDataIterClose(pIterList[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
|
||||||
|
_end:
|
||||||
|
tMergeTreeClose(pMTree);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); }
|
||||||
|
|
||||||
|
bool tMergeTreeNext(SMergeTree *pMTree) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
if (pMTree->pIter) {
|
||||||
|
SLDataIter *pIter = pMTree->pIter;
|
||||||
|
|
||||||
|
bool hasVal = tLDataIterNextRow(pIter);
|
||||||
|
if (!hasVal) {
|
||||||
|
pMTree->pIter = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compare with min in RB Tree
|
||||||
|
pIter = (SLDataIter *)tRBTreeMin(&pMTree->rbt);
|
||||||
|
if (pMTree->pIter && pIter) {
|
||||||
|
int32_t c = pMTree->rbt.cmprFn(RBTREE_NODE_PAYLOAD(&pMTree->pIter->node), RBTREE_NODE_PAYLOAD(&pIter->node));
|
||||||
|
if (c > 0) {
|
||||||
|
tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pMTree->pIter);
|
||||||
|
pMTree->pIter = NULL;
|
||||||
|
} else {
|
||||||
|
ASSERT(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pMTree->pIter == NULL) {
|
||||||
|
pMTree->pIter = (SLDataIter *)tRBTreeMin(&pMTree->rbt);
|
||||||
|
if (pMTree->pIter) {
|
||||||
|
tRBTreeDrop(&pMTree->rbt, (SRBTreeNode *)pMTree->pIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pMTree->pIter != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSDBROW tMergeTreeGetRow(SMergeTree *pMTree) { return pMTree->pIter->rInfo.row; }
|
||||||
|
|
||||||
|
void tMergeTreeClose(SMergeTree *pMTree) {
|
||||||
|
size_t size = taosArrayGetSize(pMTree->pIterList);
|
||||||
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
|
SLDataIter *pIter = taosArrayGetP(pMTree->pIterList, i);
|
||||||
|
tLDataIterClose(pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
pMTree->pIterList = taosArrayDestroy(pMTree->pIterList);
|
||||||
|
pMTree->pIter = NULL;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -60,7 +60,7 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) {
|
||||||
if (expLevel < 0) {
|
if (expLevel < 0) {
|
||||||
taosMemoryFree(pSet->pHeadF);
|
taosMemoryFree(pSet->pHeadF);
|
||||||
taosMemoryFree(pSet->pDataF);
|
taosMemoryFree(pSet->pDataF);
|
||||||
taosMemoryFree(pSet->pLastF);
|
taosMemoryFree(pSet->aSttF[0]);
|
||||||
taosMemoryFree(pSet->pSmaF);
|
taosMemoryFree(pSet->pSmaF);
|
||||||
taosArrayRemove(fs.aDFileSet, iSet);
|
taosArrayRemove(fs.aDFileSet, iSet);
|
||||||
iSet--;
|
iSet--;
|
||||||
|
|
|
@ -27,13 +27,13 @@ struct STsdbSnapReader {
|
||||||
int32_t fid;
|
int32_t fid;
|
||||||
SDataFReader* pDataFReader;
|
SDataFReader* pDataFReader;
|
||||||
SArray* aBlockIdx; // SArray<SBlockIdx>
|
SArray* aBlockIdx; // SArray<SBlockIdx>
|
||||||
SArray* aBlockL; // SArray<SBlockL>
|
SArray* aSstBlk; // SArray<SSttBlk>
|
||||||
SBlockIdx* pBlockIdx;
|
SBlockIdx* pBlockIdx;
|
||||||
SBlockL* pBlockL;
|
SSttBlk* pSstBlk;
|
||||||
|
|
||||||
int32_t iBlockIdx;
|
int32_t iBlockIdx;
|
||||||
int32_t iBlockL;
|
int32_t iBlockL;
|
||||||
SMapData mBlock; // SMapData<SBlock>
|
SMapData mBlock; // SMapData<SDataBlk>
|
||||||
int32_t iBlock;
|
int32_t iBlock;
|
||||||
SBlockData oBlockData;
|
SBlockData oBlockData;
|
||||||
SBlockData nBlockData;
|
SBlockData nBlockData;
|
||||||
|
@ -64,7 +64,7 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||||
code = tsdbReadBlockIdx(pReader->pDataFReader, pReader->aBlockIdx);
|
code = tsdbReadBlockIdx(pReader->pDataFReader, pReader->aBlockIdx);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
code = tsdbReadBlockL(pReader->pDataFReader, pReader->aBlockL);
|
code = tsdbReadSttBlk(pReader->pDataFReader, 0, pReader->aSstBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// init
|
// init
|
||||||
|
@ -82,13 +82,13 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||||
|
|
||||||
pReader->iBlockL = 0;
|
pReader->iBlockL = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (pReader->iBlockL >= taosArrayGetSize(pReader->aBlockL)) {
|
if (pReader->iBlockL >= taosArrayGetSize(pReader->aSstBlk)) {
|
||||||
pReader->pBlockL = NULL;
|
pReader->pSstBlk = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pReader->pBlockL = (SBlockL*)taosArrayGet(pReader->aBlockL, pReader->iBlockL);
|
pReader->pSstBlk = (SSttBlk*)taosArrayGet(pReader->aSstBlk, pReader->iBlockL);
|
||||||
if (pReader->pBlockL->minVer <= pReader->ever && pReader->pBlockL->maxVer >= pReader->sver) {
|
if (pReader->pSstBlk->minVer <= pReader->ever && pReader->pSstBlk->maxVer >= pReader->sver) {
|
||||||
// TODO
|
// TODO
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (pReader->pBlockIdx && pReader->pBlockL) {
|
if (pReader->pBlockIdx && pReader->pSstBlk) {
|
||||||
TABLEID id = {.suid = pReader->pBlockL->suid, .uid = pReader->pBlockL->minUid};
|
TABLEID id = {.suid = pReader->pSstBlk->suid, .uid = pReader->pSstBlk->minUid};
|
||||||
|
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||||
// }
|
// }
|
||||||
} else if (pReader->pBlockIdx) {
|
} else if (pReader->pBlockIdx) {
|
||||||
while (pReader->iBlock < pReader->mBlock.nItem) {
|
while (pReader->iBlock < pReader->mBlock.nItem) {
|
||||||
SBlock block;
|
SDataBlk block;
|
||||||
tMapDataGetItemByIdx(&pReader->mBlock, pReader->iBlock, &block, tGetBlock);
|
tMapDataGetItemByIdx(&pReader->mBlock, pReader->iBlock, &block, tGetDataBlk);
|
||||||
|
|
||||||
if (block.minVer <= pReader->ever && block.maxVer >= pReader->sver) {
|
if (block.minVer <= pReader->ever && block.maxVer >= pReader->sver) {
|
||||||
// load data (todo)
|
// load data (todo)
|
||||||
|
@ -142,18 +142,18 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ppData) goto _exit;
|
if (*ppData) goto _exit;
|
||||||
} else if (pReader->pBlockL) {
|
} else if (pReader->pSstBlk) {
|
||||||
while (pReader->pBlockL) {
|
while (pReader->pSstBlk) {
|
||||||
if (pReader->pBlockL->minVer <= pReader->ever && pReader->pBlockL->maxVer >= pReader->sver) {
|
if (pReader->pSstBlk->minVer <= pReader->ever && pReader->pSstBlk->maxVer >= pReader->sver) {
|
||||||
// load data (todo)
|
// load data (todo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// next
|
// next
|
||||||
pReader->iBlockL++;
|
pReader->iBlockL++;
|
||||||
if (pReader->iBlockL < taosArrayGetSize(pReader->aBlockL)) {
|
if (pReader->iBlockL < taosArrayGetSize(pReader->aSstBlk)) {
|
||||||
pReader->pBlockL = (SBlockL*)taosArrayGetSize(pReader->aBlockL);
|
pReader->pSstBlk = (SSttBlk*)taosArrayGetSize(pReader->aSstBlk);
|
||||||
} else {
|
} else {
|
||||||
pReader->pBlockL = NULL;
|
pReader->pSstBlk = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ppData) goto _exit;
|
if (*ppData) goto _exit;
|
||||||
|
@ -298,8 +298,8 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
pReader->aBlockL = taosArrayInit(0, sizeof(SBlockL));
|
pReader->aSstBlk = taosArrayInit(0, sizeof(SSttBlk));
|
||||||
if (pReader->aBlockL == NULL) {
|
if (pReader->aSstBlk == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) {
|
||||||
if (pReader->pDataFReader) {
|
if (pReader->pDataFReader) {
|
||||||
tsdbDataFReaderClose(&pReader->pDataFReader);
|
tsdbDataFReaderClose(&pReader->pDataFReader);
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pReader->aBlockL);
|
taosArrayDestroy(pReader->aSstBlk);
|
||||||
taosArrayDestroy(pReader->aBlockIdx);
|
taosArrayDestroy(pReader->aBlockIdx);
|
||||||
tMapDataClear(&pReader->mBlock);
|
tMapDataClear(&pReader->mBlock);
|
||||||
tBlockDataDestroy(&pReader->oBlockData, 1);
|
tBlockDataDestroy(&pReader->oBlockData, 1);
|
||||||
|
@ -426,24 +426,24 @@ struct STsdbSnapWriter {
|
||||||
SArray* aBlockIdx; // SArray<SBlockIdx>
|
SArray* aBlockIdx; // SArray<SBlockIdx>
|
||||||
int32_t iBlockIdx;
|
int32_t iBlockIdx;
|
||||||
SBlockIdx* pBlockIdx;
|
SBlockIdx* pBlockIdx;
|
||||||
SMapData mBlock; // SMapData<SBlock>
|
SMapData mBlock; // SMapData<SDataBlk>
|
||||||
int32_t iBlock;
|
int32_t iBlock;
|
||||||
SBlockData* pBlockData;
|
SBlockData* pBlockData;
|
||||||
int32_t iRow;
|
int32_t iRow;
|
||||||
SBlockData bDataR;
|
SBlockData bDataR;
|
||||||
SArray* aBlockL; // SArray<SBlockL>
|
SArray* aSstBlk; // SArray<SSttBlk>
|
||||||
int32_t iBlockL;
|
int32_t iBlockL;
|
||||||
SBlockData lDataR;
|
SBlockData lDataR;
|
||||||
|
|
||||||
SDataFWriter* pDataFWriter;
|
SDataFWriter* pDataFWriter;
|
||||||
SBlockIdx* pBlockIdxW; // NULL when no committing table
|
SBlockIdx* pBlockIdxW; // NULL when no committing table
|
||||||
SBlock blockW;
|
SDataBlk blockW;
|
||||||
SBlockData bDataW;
|
SBlockData bDataW;
|
||||||
SBlockIdx blockIdxW;
|
SBlockIdx blockIdxW;
|
||||||
|
|
||||||
SMapData mBlockW; // SMapData<SBlock>
|
SMapData mBlockW; // SMapData<SDataBlk>
|
||||||
SArray* aBlockIdxW; // SArray<SBlockIdx>
|
SArray* aBlockIdxW; // SArray<SBlockIdx>
|
||||||
SArray* aBlockLW; // SArray<SBlockL>
|
SArray* aBlockLW; // SArray<SSttBlk>
|
||||||
|
|
||||||
// for del file
|
// for del file
|
||||||
SDelFReader* pDelFReader;
|
SDelFReader* pDelFReader;
|
||||||
|
@ -475,10 +475,10 @@ static int32_t tsdbSnapWriteTableDataEnd(STsdbSnapWriter* pWriter) {
|
||||||
// &pWriter->blockW, pWriter->cmprAlg);
|
// &pWriter->blockW, pWriter->cmprAlg);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
tBlockReset(&pWriter->blockW);
|
tDataBlkReset(&pWriter->blockW);
|
||||||
tBlockDataClear(&pWriter->bDataW);
|
tBlockDataClear(&pWriter->bDataW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,15 +499,15 @@ static int32_t tsdbSnapWriteTableDataEnd(STsdbSnapWriter* pWriter) {
|
||||||
// &pWriter->blockW, pWriter->cmprAlg);
|
// &pWriter->blockW, pWriter->cmprAlg);
|
||||||
// if (code) goto _err;
|
// if (code) goto _err;
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (pWriter->iBlock >= pWriter->mBlock.nItem) break;
|
if (pWriter->iBlock >= pWriter->mBlock.nItem) break;
|
||||||
|
|
||||||
SBlock block;
|
SDataBlk block;
|
||||||
tMapDataGetItemByIdx(&pWriter->mBlock, pWriter->iBlock, &block, tGetBlock);
|
tMapDataGetItemByIdx(&pWriter->mBlock, pWriter->iBlock, &block, tGetDataBlk);
|
||||||
|
|
||||||
// if (block.last) {
|
// if (block.last) {
|
||||||
// code = tsdbReadBlockData(pWriter->pDataFReader, pWriter->pBlockIdx, &block, &pWriter->bDataR, NULL, NULL);
|
// code = tsdbReadBlockData(pWriter->pDataFReader, pWriter->pBlockIdx, &block, &pWriter->bDataR, NULL, NULL);
|
||||||
|
@ -520,13 +520,13 @@ static int32_t tsdbSnapWriteTableDataEnd(STsdbSnapWriter* pWriter) {
|
||||||
// if (code) goto _err;
|
// if (code) goto _err;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &block, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &block, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
pWriter->iBlock++;
|
pWriter->iBlock++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBlock
|
// SDataBlk
|
||||||
// code = tsdbWriteBlock(pWriter->pDataFWriter, &pWriter->mBlockW, NULL, pWriter->pBlockIdxW);
|
// code = tsdbWriteBlock(pWriter->pDataFWriter, &pWriter->mBlockW, NULL, pWriter->pBlockIdxW);
|
||||||
// if (code) goto _err;
|
// if (code) goto _err;
|
||||||
|
|
||||||
|
@ -553,10 +553,10 @@ static int32_t tsdbSnapMoveWriteTableData(STsdbSnapWriter* pWriter, SBlockIdx* p
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
// SBlockData
|
// SBlockData
|
||||||
SBlock block;
|
SDataBlk block;
|
||||||
tMapDataReset(&pWriter->mBlockW);
|
tMapDataReset(&pWriter->mBlockW);
|
||||||
for (int32_t iBlock = 0; iBlock < pWriter->mBlock.nItem; iBlock++) {
|
for (int32_t iBlock = 0; iBlock < pWriter->mBlock.nItem; iBlock++) {
|
||||||
tMapDataGetItemByIdx(&pWriter->mBlock, iBlock, &block, tGetBlock);
|
tMapDataGetItemByIdx(&pWriter->mBlock, iBlock, &block, tGetDataBlk);
|
||||||
|
|
||||||
// if (block.last) {
|
// if (block.last) {
|
||||||
// code = tsdbReadBlockData(pWriter->pDataFReader, pBlockIdx, &block, &pWriter->bDataR, NULL, NULL);
|
// code = tsdbReadBlockData(pWriter->pDataFReader, pBlockIdx, &block, &pWriter->bDataR, NULL, NULL);
|
||||||
|
@ -570,11 +570,11 @@ static int32_t tsdbSnapMoveWriteTableData(STsdbSnapWriter* pWriter, SBlockIdx* p
|
||||||
// if (code) goto _err;
|
// if (code) goto _err;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &block, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &block, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBlock
|
// SDataBlk
|
||||||
SBlockIdx blockIdx = {.suid = pBlockIdx->suid, .uid = pBlockIdx->uid};
|
SBlockIdx blockIdx = {.suid = pBlockIdx->suid, .uid = pBlockIdx->uid};
|
||||||
code = tsdbWriteBlock(pWriter->pDataFWriter, &pWriter->mBlockW, &blockIdx);
|
code = tsdbWriteBlock(pWriter->pDataFWriter, &pWriter->mBlockW, &blockIdx);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
@ -642,10 +642,10 @@ static int32_t tsdbSnapWriteTableDataImpl(STsdbSnapWriter* pWriter) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (pWriter->iBlock >= pWriter->mBlock.nItem) break;
|
if (pWriter->iBlock >= pWriter->mBlock.nItem) break;
|
||||||
|
|
||||||
SBlock block;
|
SDataBlk block;
|
||||||
int32_t c;
|
int32_t c;
|
||||||
|
|
||||||
tMapDataGetItemByIdx(&pWriter->mBlock, pWriter->iBlock, &block, tGetBlock);
|
tMapDataGetItemByIdx(&pWriter->mBlock, pWriter->iBlock, &block, tGetDataBlk);
|
||||||
|
|
||||||
// if (block.last) {
|
// if (block.last) {
|
||||||
// pWriter->pBlockData = &pWriter->bDataR;
|
// pWriter->pBlockData = &pWriter->bDataR;
|
||||||
|
@ -668,14 +668,14 @@ static int32_t tsdbSnapWriteTableDataImpl(STsdbSnapWriter* pWriter) {
|
||||||
// &pWriter->blockW, pWriter->cmprAlg);
|
// &pWriter->blockW, pWriter->cmprAlg);
|
||||||
// if (code) goto _err;
|
// if (code) goto _err;
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
tBlockReset(&pWriter->blockW);
|
tDataBlkReset(&pWriter->blockW);
|
||||||
tBlockDataClear(&pWriter->bDataW);
|
tBlockDataClear(&pWriter->bDataW);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &block, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &block, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
pWriter->iBlock++;
|
pWriter->iBlock++;
|
||||||
|
@ -719,10 +719,10 @@ static int32_t tsdbSnapWriteTableDataImpl(STsdbSnapWriter* pWriter) {
|
||||||
// &pWriter->blockW, pWriter->cmprAlg);
|
// &pWriter->blockW, pWriter->cmprAlg);
|
||||||
// if (code) goto _err;
|
// if (code) goto _err;
|
||||||
|
|
||||||
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutBlock);
|
code = tMapDataPutItem(&pWriter->mBlockW, &pWriter->blockW, tPutDataBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
tBlockReset(&pWriter->blockW);
|
tDataBlkReset(&pWriter->blockW);
|
||||||
tBlockDataClear(&pWriter->bDataW);
|
tBlockDataClear(&pWriter->bDataW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ static int32_t tsdbSnapWriteTableData(STsdbSnapWriter* pWriter, TABLEID id) {
|
||||||
pWriter->pBlockIdxW->suid = id.suid;
|
pWriter->pBlockIdxW->suid = id.suid;
|
||||||
pWriter->pBlockIdxW->uid = id.uid;
|
pWriter->pBlockIdxW->uid = id.uid;
|
||||||
|
|
||||||
tBlockReset(&pWriter->blockW);
|
tDataBlkReset(&pWriter->blockW);
|
||||||
tBlockDataReset(&pWriter->bDataW);
|
tBlockDataReset(&pWriter->bDataW);
|
||||||
tMapDataReset(&pWriter->mBlockW);
|
tMapDataReset(&pWriter->mBlockW);
|
||||||
}
|
}
|
||||||
|
@ -845,7 +845,7 @@ static int32_t tsdbSnapWriteDataEnd(STsdbSnapWriter* pWriter) {
|
||||||
|
|
||||||
// write remain stuff
|
// write remain stuff
|
||||||
if (taosArrayGetSize(pWriter->aBlockLW) > 0) {
|
if (taosArrayGetSize(pWriter->aBlockLW) > 0) {
|
||||||
code = tsdbWriteBlockL(pWriter->pDataFWriter, pWriter->aBlockIdxW);
|
code = tsdbWriteSttBlk(pWriter->pDataFWriter, pWriter->aBlockIdxW);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,12 +911,12 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3
|
||||||
code = tsdbReadBlockIdx(pWriter->pDataFReader, pWriter->aBlockIdx);
|
code = tsdbReadBlockIdx(pWriter->pDataFReader, pWriter->aBlockIdx);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
code = tsdbReadBlockL(pWriter->pDataFReader, pWriter->aBlockL);
|
code = tsdbReadSttBlk(pWriter->pDataFReader, 0, pWriter->aSstBlk);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(pWriter->pDataFReader == NULL);
|
ASSERT(pWriter->pDataFReader == NULL);
|
||||||
taosArrayClear(pWriter->aBlockIdx);
|
taosArrayClear(pWriter->aBlockIdx);
|
||||||
taosArrayClear(pWriter->aBlockL);
|
taosArrayClear(pWriter->aSstBlk);
|
||||||
}
|
}
|
||||||
pWriter->iBlockIdx = 0;
|
pWriter->iBlockIdx = 0;
|
||||||
pWriter->pBlockIdx = NULL;
|
pWriter->pBlockIdx = NULL;
|
||||||
|
@ -931,23 +931,25 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3
|
||||||
// write
|
// write
|
||||||
SHeadFile fHead;
|
SHeadFile fHead;
|
||||||
SDataFile fData;
|
SDataFile fData;
|
||||||
SLastFile fLast;
|
SSttFile fLast;
|
||||||
SSmaFile fSma;
|
SSmaFile fSma;
|
||||||
SDFileSet wSet = {.pHeadF = &fHead, .pDataF = &fData, .pLastF = &fLast, .pSmaF = &fSma};
|
SDFileSet wSet = {.pHeadF = &fHead, .pDataF = &fData, .aSttF[0] = &fLast, .pSmaF = &fSma};
|
||||||
|
|
||||||
if (pSet) {
|
if (pSet) {
|
||||||
wSet.diskId = pSet->diskId;
|
wSet.diskId = pSet->diskId;
|
||||||
wSet.fid = fid;
|
wSet.fid = fid;
|
||||||
|
wSet.nSttF = 1;
|
||||||
fHead = (SHeadFile){.commitID = pWriter->commitID, .offset = 0, .size = 0};
|
fHead = (SHeadFile){.commitID = pWriter->commitID, .offset = 0, .size = 0};
|
||||||
fData = *pSet->pDataF;
|
fData = *pSet->pDataF;
|
||||||
fLast = (SLastFile){.commitID = pWriter->commitID, .size = 0};
|
fLast = (SSttFile){.commitID = pWriter->commitID, .size = 0};
|
||||||
fSma = *pSet->pSmaF;
|
fSma = *pSet->pSmaF;
|
||||||
} else {
|
} else {
|
||||||
wSet.diskId = (SDiskID){.level = 0, .id = 0};
|
wSet.diskId = (SDiskID){.level = 0, .id = 0};
|
||||||
wSet.fid = fid;
|
wSet.fid = fid;
|
||||||
|
wSet.nSttF = 1;
|
||||||
fHead = (SHeadFile){.commitID = pWriter->commitID, .offset = 0, .size = 0};
|
fHead = (SHeadFile){.commitID = pWriter->commitID, .offset = 0, .size = 0};
|
||||||
fData = (SDataFile){.commitID = pWriter->commitID, .size = 0};
|
fData = (SDataFile){.commitID = pWriter->commitID, .size = 0};
|
||||||
fLast = (SLastFile){.commitID = pWriter->commitID, .size = 0, .offset = 0};
|
fLast = (SSttFile){.commitID = pWriter->commitID, .size = 0, .offset = 0};
|
||||||
fSma = (SSmaFile){.commitID = pWriter->commitID, .size = 0};
|
fSma = (SSmaFile){.commitID = pWriter->commitID, .size = 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1145,8 +1147,8 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr
|
||||||
code = tBlockDataCreate(&pWriter->bDataR);
|
code = tBlockDataCreate(&pWriter->bDataR);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
pWriter->aBlockL = taosArrayInit(0, sizeof(SBlockL));
|
pWriter->aSstBlk = taosArrayInit(0, sizeof(SSttBlk));
|
||||||
if (pWriter->aBlockL == NULL) {
|
if (pWriter->aSstBlk == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1161,7 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr
|
||||||
code = tBlockDataCreate(&pWriter->bDataW);
|
code = tBlockDataCreate(&pWriter->bDataW);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
pWriter->aBlockLW = taosArrayInit(0, sizeof(SBlockL));
|
pWriter->aBlockLW = taosArrayInit(0, sizeof(SSttBlk));
|
||||||
if (pWriter->aBlockLW == NULL) {
|
if (pWriter->aBlockLW == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
|
|
|
@ -51,6 +51,22 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tMapDataCopy(SMapData *pFrom, SMapData *pTo) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
pTo->nItem = pFrom->nItem;
|
||||||
|
pTo->nData = pFrom->nData;
|
||||||
|
code = tRealloc((uint8_t **)&pTo->aOffset, sizeof(int32_t) * pFrom->nItem);
|
||||||
|
if (code) goto _exit;
|
||||||
|
code = tRealloc(&pTo->pData, pFrom->nData);
|
||||||
|
if (code) goto _exit;
|
||||||
|
memcpy(pTo->aOffset, pFrom->aOffset, sizeof(int32_t) * pFrom->nItem);
|
||||||
|
memcpy(pTo->pData, pFrom->pData, pFrom->nData);
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
|
int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItemFn)(uint8_t *, void *),
|
||||||
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem) {
|
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -198,7 +214,7 @@ int32_t tCmprBlockIdx(void const *lhs, void const *rhs) {
|
||||||
|
|
||||||
int32_t tCmprBlockL(void const *lhs, void const *rhs) {
|
int32_t tCmprBlockL(void const *lhs, void const *rhs) {
|
||||||
SBlockIdx *lBlockIdx = (SBlockIdx *)lhs;
|
SBlockIdx *lBlockIdx = (SBlockIdx *)lhs;
|
||||||
SBlockL *rBlockL = (SBlockL *)rhs;
|
SSttBlk *rBlockL = (SSttBlk *)rhs;
|
||||||
|
|
||||||
if (lBlockIdx->suid < rBlockL->suid) {
|
if (lBlockIdx->suid < rBlockL->suid) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -215,69 +231,69 @@ int32_t tCmprBlockL(void const *lhs, void const *rhs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBlock ======================================================
|
// SDataBlk ======================================================
|
||||||
void tBlockReset(SBlock *pBlock) {
|
void tDataBlkReset(SDataBlk *pDataBlk) {
|
||||||
*pBlock = (SBlock){.minKey = TSDBKEY_MAX, .maxKey = TSDBKEY_MIN, .minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
*pDataBlk = (SDataBlk){.minKey = TSDBKEY_MAX, .maxKey = TSDBKEY_MIN, .minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tPutBlock(uint8_t *p, void *ph) {
|
int32_t tPutDataBlk(uint8_t *p, void *ph) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
SBlock *pBlock = (SBlock *)ph;
|
SDataBlk *pDataBlk = (SDataBlk *)ph;
|
||||||
|
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->minKey.version);
|
n += tPutI64v(p ? p + n : p, pDataBlk->minKey.version);
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->minKey.ts);
|
n += tPutI64v(p ? p + n : p, pDataBlk->minKey.ts);
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->maxKey.version);
|
n += tPutI64v(p ? p + n : p, pDataBlk->maxKey.version);
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->maxKey.ts);
|
n += tPutI64v(p ? p + n : p, pDataBlk->maxKey.ts);
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->minVer);
|
n += tPutI64v(p ? p + n : p, pDataBlk->minVer);
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->maxVer);
|
n += tPutI64v(p ? p + n : p, pDataBlk->maxVer);
|
||||||
n += tPutI32v(p ? p + n : p, pBlock->nRow);
|
n += tPutI32v(p ? p + n : p, pDataBlk->nRow);
|
||||||
n += tPutI8(p ? p + n : p, pBlock->hasDup);
|
n += tPutI8(p ? p + n : p, pDataBlk->hasDup);
|
||||||
n += tPutI8(p ? p + n : p, pBlock->nSubBlock);
|
n += tPutI8(p ? p + n : p, pDataBlk->nSubBlock);
|
||||||
for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) {
|
for (int8_t iSubBlock = 0; iSubBlock < pDataBlk->nSubBlock; iSubBlock++) {
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].offset);
|
n += tPutI64v(p ? p + n : p, pDataBlk->aSubBlock[iSubBlock].offset);
|
||||||
n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szBlock);
|
n += tPutI32v(p ? p + n : p, pDataBlk->aSubBlock[iSubBlock].szBlock);
|
||||||
n += tPutI32v(p ? p + n : p, pBlock->aSubBlock[iSubBlock].szKey);
|
n += tPutI32v(p ? p + n : p, pDataBlk->aSubBlock[iSubBlock].szKey);
|
||||||
}
|
}
|
||||||
if (pBlock->nSubBlock == 1 && !pBlock->hasDup) {
|
if (pDataBlk->nSubBlock == 1 && !pDataBlk->hasDup) {
|
||||||
n += tPutI64v(p ? p + n : p, pBlock->smaInfo.offset);
|
n += tPutI64v(p ? p + n : p, pDataBlk->smaInfo.offset);
|
||||||
n += tPutI32v(p ? p + n : p, pBlock->smaInfo.size);
|
n += tPutI32v(p ? p + n : p, pDataBlk->smaInfo.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tGetBlock(uint8_t *p, void *ph) {
|
int32_t tGetDataBlk(uint8_t *p, void *ph) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
SBlock *pBlock = (SBlock *)ph;
|
SDataBlk *pDataBlk = (SDataBlk *)ph;
|
||||||
|
|
||||||
n += tGetI64v(p + n, &pBlock->minKey.version);
|
n += tGetI64v(p + n, &pDataBlk->minKey.version);
|
||||||
n += tGetI64v(p + n, &pBlock->minKey.ts);
|
n += tGetI64v(p + n, &pDataBlk->minKey.ts);
|
||||||
n += tGetI64v(p + n, &pBlock->maxKey.version);
|
n += tGetI64v(p + n, &pDataBlk->maxKey.version);
|
||||||
n += tGetI64v(p + n, &pBlock->maxKey.ts);
|
n += tGetI64v(p + n, &pDataBlk->maxKey.ts);
|
||||||
n += tGetI64v(p + n, &pBlock->minVer);
|
n += tGetI64v(p + n, &pDataBlk->minVer);
|
||||||
n += tGetI64v(p + n, &pBlock->maxVer);
|
n += tGetI64v(p + n, &pDataBlk->maxVer);
|
||||||
n += tGetI32v(p + n, &pBlock->nRow);
|
n += tGetI32v(p + n, &pDataBlk->nRow);
|
||||||
n += tGetI8(p + n, &pBlock->hasDup);
|
n += tGetI8(p + n, &pDataBlk->hasDup);
|
||||||
n += tGetI8(p + n, &pBlock->nSubBlock);
|
n += tGetI8(p + n, &pDataBlk->nSubBlock);
|
||||||
for (int8_t iSubBlock = 0; iSubBlock < pBlock->nSubBlock; iSubBlock++) {
|
for (int8_t iSubBlock = 0; iSubBlock < pDataBlk->nSubBlock; iSubBlock++) {
|
||||||
n += tGetI64v(p + n, &pBlock->aSubBlock[iSubBlock].offset);
|
n += tGetI64v(p + n, &pDataBlk->aSubBlock[iSubBlock].offset);
|
||||||
n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szBlock);
|
n += tGetI32v(p + n, &pDataBlk->aSubBlock[iSubBlock].szBlock);
|
||||||
n += tGetI32v(p + n, &pBlock->aSubBlock[iSubBlock].szKey);
|
n += tGetI32v(p + n, &pDataBlk->aSubBlock[iSubBlock].szKey);
|
||||||
}
|
}
|
||||||
if (pBlock->nSubBlock == 1 && !pBlock->hasDup) {
|
if (pDataBlk->nSubBlock == 1 && !pDataBlk->hasDup) {
|
||||||
n += tGetI64v(p + n, &pBlock->smaInfo.offset);
|
n += tGetI64v(p + n, &pDataBlk->smaInfo.offset);
|
||||||
n += tGetI32v(p + n, &pBlock->smaInfo.size);
|
n += tGetI32v(p + n, &pDataBlk->smaInfo.size);
|
||||||
} else {
|
} else {
|
||||||
pBlock->smaInfo.offset = 0;
|
pDataBlk->smaInfo.offset = 0;
|
||||||
pBlock->smaInfo.size = 0;
|
pDataBlk->smaInfo.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tBlockCmprFn(const void *p1, const void *p2) {
|
int32_t tDataBlkCmprFn(const void *p1, const void *p2) {
|
||||||
SBlock *pBlock1 = (SBlock *)p1;
|
SDataBlk *pBlock1 = (SDataBlk *)p1;
|
||||||
SBlock *pBlock2 = (SBlock *)p2;
|
SDataBlk *pBlock2 = (SDataBlk *)p2;
|
||||||
|
|
||||||
if (tsdbKeyCmprFn(&pBlock1->maxKey, &pBlock2->minKey) < 0) {
|
if (tsdbKeyCmprFn(&pBlock1->maxKey, &pBlock2->minKey) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -288,48 +304,48 @@ int32_t tBlockCmprFn(const void *p1, const void *p2) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tBlockHasSma(SBlock *pBlock) {
|
bool tDataBlkHasSma(SDataBlk *pDataBlk) {
|
||||||
if (pBlock->nSubBlock > 1) return false;
|
if (pDataBlk->nSubBlock > 1) return false;
|
||||||
if (pBlock->hasDup) return false;
|
if (pDataBlk->hasDup) return false;
|
||||||
|
|
||||||
return pBlock->smaInfo.size > 0;
|
return pDataBlk->smaInfo.size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBlockL ======================================================
|
// SSttBlk ======================================================
|
||||||
int32_t tPutBlockL(uint8_t *p, void *ph) {
|
int32_t tPutSttBlk(uint8_t *p, void *ph) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
SBlockL *pBlockL = (SBlockL *)ph;
|
SSttBlk *pSttBlk = (SSttBlk *)ph;
|
||||||
|
|
||||||
n += tPutI64(p ? p + n : p, pBlockL->suid);
|
n += tPutI64(p ? p + n : p, pSttBlk->suid);
|
||||||
n += tPutI64(p ? p + n : p, pBlockL->minUid);
|
n += tPutI64(p ? p + n : p, pSttBlk->minUid);
|
||||||
n += tPutI64(p ? p + n : p, pBlockL->maxUid);
|
n += tPutI64(p ? p + n : p, pSttBlk->maxUid);
|
||||||
n += tPutI64v(p ? p + n : p, pBlockL->minKey);
|
n += tPutI64v(p ? p + n : p, pSttBlk->minKey);
|
||||||
n += tPutI64v(p ? p + n : p, pBlockL->maxKey);
|
n += tPutI64v(p ? p + n : p, pSttBlk->maxKey);
|
||||||
n += tPutI64v(p ? p + n : p, pBlockL->minVer);
|
n += tPutI64v(p ? p + n : p, pSttBlk->minVer);
|
||||||
n += tPutI64v(p ? p + n : p, pBlockL->maxVer);
|
n += tPutI64v(p ? p + n : p, pSttBlk->maxVer);
|
||||||
n += tPutI32v(p ? p + n : p, pBlockL->nRow);
|
n += tPutI32v(p ? p + n : p, pSttBlk->nRow);
|
||||||
n += tPutI64v(p ? p + n : p, pBlockL->bInfo.offset);
|
n += tPutI64v(p ? p + n : p, pSttBlk->bInfo.offset);
|
||||||
n += tPutI32v(p ? p + n : p, pBlockL->bInfo.szBlock);
|
n += tPutI32v(p ? p + n : p, pSttBlk->bInfo.szBlock);
|
||||||
n += tPutI32v(p ? p + n : p, pBlockL->bInfo.szKey);
|
n += tPutI32v(p ? p + n : p, pSttBlk->bInfo.szKey);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tGetBlockL(uint8_t *p, void *ph) {
|
int32_t tGetSttBlk(uint8_t *p, void *ph) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
SBlockL *pBlockL = (SBlockL *)ph;
|
SSttBlk *pSttBlk = (SSttBlk *)ph;
|
||||||
|
|
||||||
n += tGetI64(p + n, &pBlockL->suid);
|
n += tGetI64(p + n, &pSttBlk->suid);
|
||||||
n += tGetI64(p + n, &pBlockL->minUid);
|
n += tGetI64(p + n, &pSttBlk->minUid);
|
||||||
n += tGetI64(p + n, &pBlockL->maxUid);
|
n += tGetI64(p + n, &pSttBlk->maxUid);
|
||||||
n += tGetI64v(p + n, &pBlockL->minKey);
|
n += tGetI64v(p + n, &pSttBlk->minKey);
|
||||||
n += tGetI64v(p + n, &pBlockL->maxKey);
|
n += tGetI64v(p + n, &pSttBlk->maxKey);
|
||||||
n += tGetI64v(p + n, &pBlockL->minVer);
|
n += tGetI64v(p + n, &pSttBlk->minVer);
|
||||||
n += tGetI64v(p + n, &pBlockL->maxVer);
|
n += tGetI64v(p + n, &pSttBlk->maxVer);
|
||||||
n += tGetI32v(p + n, &pBlockL->nRow);
|
n += tGetI32v(p + n, &pSttBlk->nRow);
|
||||||
n += tGetI64v(p + n, &pBlockL->bInfo.offset);
|
n += tGetI64v(p + n, &pSttBlk->bInfo.offset);
|
||||||
n += tGetI32v(p + n, &pBlockL->bInfo.szBlock);
|
n += tGetI32v(p + n, &pSttBlk->bInfo.szBlock);
|
||||||
n += tGetI32v(p + n, &pBlockL->bInfo.szKey);
|
n += tGetI32v(p + n, &pSttBlk->bInfo.szKey);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -1532,7 +1548,7 @@ int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut,
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
|
|
||||||
blockCol.offset = aBufN[0];
|
blockCol.offset = aBufN[0];
|
||||||
aBufN[0] = aBufN[0] + blockCol.szBitmap + blockCol.szOffset + blockCol.szValue + sizeof(TSCKSUM);
|
aBufN[0] = aBufN[0] + blockCol.szBitmap + blockCol.szOffset + blockCol.szValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tRealloc(&aBuf[1], hdr.szBlkCol + tPutBlockCol(NULL, &blockCol));
|
code = tRealloc(&aBuf[1], hdr.szBlkCol + tPutBlockCol(NULL, &blockCol));
|
||||||
|
@ -1540,15 +1556,8 @@ int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut,
|
||||||
hdr.szBlkCol += tPutBlockCol(aBuf[1] + hdr.szBlkCol, &blockCol);
|
hdr.szBlkCol += tPutBlockCol(aBuf[1] + hdr.szBlkCol, &blockCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
aBufN[1] = 0;
|
// SBlockCol
|
||||||
if (hdr.szBlkCol > 0) {
|
aBufN[1] = hdr.szBlkCol;
|
||||||
aBufN[1] = hdr.szBlkCol + sizeof(TSCKSUM);
|
|
||||||
|
|
||||||
code = tRealloc(&aBuf[1], aBufN[1]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
taosCalcChecksumAppend(0, aBuf[1], aBufN[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// uid + version + tskey
|
// uid + version + tskey
|
||||||
aBufN[2] = 0;
|
aBufN[2] = 0;
|
||||||
|
@ -1569,16 +1578,11 @@ int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut,
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
aBufN[2] += hdr.szKey;
|
aBufN[2] += hdr.szKey;
|
||||||
|
|
||||||
aBufN[2] += sizeof(TSCKSUM);
|
|
||||||
code = tRealloc(&aBuf[2], aBufN[2]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
// hdr
|
// hdr
|
||||||
aBufN[3] = tPutDiskDataHdr(NULL, &hdr);
|
aBufN[3] = tPutDiskDataHdr(NULL, &hdr);
|
||||||
code = tRealloc(&aBuf[3], aBufN[3]);
|
code = tRealloc(&aBuf[3], aBufN[3]);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
tPutDiskDataHdr(aBuf[3], &hdr);
|
tPutDiskDataHdr(aBuf[3], &hdr);
|
||||||
taosCalcChecksumAppend(taosCalcChecksum(0, aBuf[3], aBufN[3]), aBuf[2], aBufN[2]);
|
|
||||||
|
|
||||||
// aggragate
|
// aggragate
|
||||||
if (ppOut) {
|
if (ppOut) {
|
||||||
|
@ -1603,17 +1607,13 @@ _exit:
|
||||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]) {
|
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
tBlockDataClear(pBlockData);
|
tBlockDataReset(pBlockData);
|
||||||
|
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
SDiskDataHdr hdr = {0};
|
SDiskDataHdr hdr = {0};
|
||||||
|
|
||||||
// SDiskDataHdr
|
// SDiskDataHdr
|
||||||
n += tGetDiskDataHdr(pIn + n, &hdr);
|
n += tGetDiskDataHdr(pIn + n, &hdr);
|
||||||
if (!taosCheckChecksumWhole(pIn, n + hdr.szUid + hdr.szVer + hdr.szKey + sizeof(TSCKSUM))) {
|
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
ASSERT(hdr.delimiter == TSDB_FILE_DLMT);
|
ASSERT(hdr.delimiter == TSDB_FILE_DLMT);
|
||||||
|
|
||||||
pBlockData->suid = hdr.suid;
|
pBlockData->suid = hdr.suid;
|
||||||
|
@ -1641,7 +1641,7 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin
|
||||||
code = tsdbDecmprData(pIn + n, hdr.szKey, TSDB_DATA_TYPE_TIMESTAMP, hdr.cmprAlg, (uint8_t **)&pBlockData->aTSKEY,
|
code = tsdbDecmprData(pIn + n, hdr.szKey, TSDB_DATA_TYPE_TIMESTAMP, hdr.cmprAlg, (uint8_t **)&pBlockData->aTSKEY,
|
||||||
sizeof(TSKEY) * hdr.nRow, &aBuf[0]);
|
sizeof(TSKEY) * hdr.nRow, &aBuf[0]);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
n = n + hdr.szKey + sizeof(TSCKSUM);
|
n += hdr.szKey;
|
||||||
|
|
||||||
// loop to decode each column data
|
// loop to decode each column data
|
||||||
if (hdr.szBlkCol == 0) goto _exit;
|
if (hdr.szBlkCol == 0) goto _exit;
|
||||||
|
@ -1663,8 +1663,8 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code = tsdbDecmprColData(pIn + n + hdr.szBlkCol + sizeof(TSCKSUM) + blockCol.offset, &blockCol, hdr.cmprAlg,
|
code = tsdbDecmprColData(pIn + n + hdr.szBlkCol + blockCol.offset, &blockCol, hdr.cmprAlg, hdr.nRow, pColData,
|
||||||
hdr.nRow, pColData, &aBuf[0]);
|
&aBuf[0]);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2046,12 +2046,6 @@ int32_t tsdbCmprColData(SColData *pColData, int8_t cmprAlg, SBlockCol *pBlockCol
|
||||||
}
|
}
|
||||||
size += pBlockCol->szValue;
|
size += pBlockCol->szValue;
|
||||||
|
|
||||||
// checksum
|
|
||||||
size += sizeof(TSCKSUM);
|
|
||||||
code = tRealloc(ppOut, nOut + size);
|
|
||||||
if (code) goto _exit;
|
|
||||||
taosCalcChecksumAppend(0, *ppOut + nOut, size);
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2060,12 +2054,6 @@ int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, in
|
||||||
uint8_t **ppBuf) {
|
uint8_t **ppBuf) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
int32_t size = pBlockCol->szBitmap + pBlockCol->szOffset + pBlockCol->szValue + sizeof(TSCKSUM);
|
|
||||||
if (!taosCheckChecksumWhole(pIn, size)) {
|
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pColData->cid == pBlockCol->cid);
|
ASSERT(pColData->cid == pBlockCol->cid);
|
||||||
ASSERT(pColData->type == pBlockCol->type);
|
ASSERT(pColData->type == pBlockCol->type);
|
||||||
pColData->smaOn = pBlockCol->smaOn;
|
pColData->smaOn = pBlockCol->smaOn;
|
||||||
|
@ -2137,37 +2125,3 @@ int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, in
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadAndCheck(TdFilePtr pFD, int64_t offset, uint8_t **ppOut, int32_t size, int8_t toCheck) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
// alloc
|
|
||||||
code = tRealloc(ppOut, size);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
// seek
|
|
||||||
int64_t n = taosLSeekFile(pFD, offset, SEEK_SET);
|
|
||||||
if (n < 0) {
|
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read
|
|
||||||
n = taosReadFile(pFD, *ppOut, size);
|
|
||||||
if (n < 0) {
|
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _exit;
|
|
||||||
} else if (n < size) {
|
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check
|
|
||||||
if (toCheck && !taosCheckChecksumWhole(*ppOut, size)) {
|
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *
|
||||||
SSubmitBlkRsp r = {0};
|
SSubmitBlkRsp r = {0};
|
||||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
tGetSubmitMsgNext(&msgIter, &pBlock);
|
||||||
if (pBlock == NULL) break;
|
if (pBlock == NULL) break;
|
||||||
if (tsdbInsertTableData(pTsdb, version, &msgIter, pBlock, &r) < 0) {
|
if ((terrno = tsdbInsertTableData(pTsdb, version, &msgIter, pBlock, &r)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -368,6 +368,7 @@ _exit:
|
||||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
||||||
pLoad->vgId = TD_VID(pVnode);
|
pLoad->vgId = TD_VID(pVnode);
|
||||||
pLoad->syncState = syncGetMyRole(pVnode->sync);
|
pLoad->syncState = syncGetMyRole(pVnode->sync);
|
||||||
|
pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
|
||||||
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
||||||
pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);
|
pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);
|
||||||
pLoad->totalStorage = (int64_t)3 * 1073741824;
|
pLoad->totalStorage = (int64_t)3 * 1073741824;
|
||||||
|
|
|
@ -39,7 +39,7 @@ struct SVSnapReader {
|
||||||
SStreamStateReader *pStreamStateReader;
|
SStreamStateReader *pStreamStateReader;
|
||||||
// rsma
|
// rsma
|
||||||
int8_t rsmaDone;
|
int8_t rsmaDone;
|
||||||
SRsmaSnapReader *pRsmaReader;
|
SRSmaSnapReader *pRsmaReader;
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t vnodeSnapReaderOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapReader **ppReader) {
|
int32_t vnodeSnapReaderOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapReader **ppReader) {
|
||||||
|
@ -241,7 +241,7 @@ struct SVSnapWriter {
|
||||||
SStreamTaskWriter *pStreamTaskWriter;
|
SStreamTaskWriter *pStreamTaskWriter;
|
||||||
SStreamStateWriter *pStreamStateWriter;
|
SStreamStateWriter *pStreamStateWriter;
|
||||||
// rsma
|
// rsma
|
||||||
SRsmaSnapWriter *pRsmaSnapWriter;
|
SRSmaSnapWriter *pRsmaSnapWriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWriter **ppWriter) {
|
int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWriter **ppWriter) {
|
||||||
|
|
|
@ -534,7 +534,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pR
|
||||||
}
|
}
|
||||||
|
|
||||||
tqUpdateTbUidList(pVnode->pTq, tbUids, true);
|
tqUpdateTbUidList(pVnode->pTq, tbUids, true);
|
||||||
if (tdUpdateTbUidList(pVnode->pSma, pStore) < 0) {
|
if (tdUpdateTbUidList(pVnode->pSma, pStore, true) < 0) {
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
tdUidStoreFree(pStore);
|
tdUidStoreFree(pStore);
|
||||||
|
@ -692,6 +692,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq
|
||||||
SEncoder encoder = {0};
|
SEncoder encoder = {0};
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
SArray *tbUids = NULL;
|
SArray *tbUids = NULL;
|
||||||
|
STbUidStore *pStore = NULL;
|
||||||
|
|
||||||
pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
|
pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
|
||||||
pRsp->pCont = NULL;
|
pRsp->pCont = NULL;
|
||||||
|
@ -715,9 +716,10 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq
|
||||||
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
|
||||||
SVDropTbReq *pDropTbReq = req.pReqs + iReq;
|
SVDropTbReq *pDropTbReq = req.pReqs + iReq;
|
||||||
SVDropTbRsp dropTbRsp = {0};
|
SVDropTbRsp dropTbRsp = {0};
|
||||||
|
tb_uid_t tbUid = 0;
|
||||||
|
|
||||||
/* code */
|
/* code */
|
||||||
ret = metaDropTable(pVnode->pMeta, version, pDropTbReq, tbUids);
|
ret = metaDropTable(pVnode->pMeta, version, pDropTbReq, tbUids, &tbUid);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (pDropTbReq->igNotExists && terrno == TSDB_CODE_VND_TABLE_NOT_EXIST) {
|
if (pDropTbReq->igNotExists && terrno == TSDB_CODE_VND_TABLE_NOT_EXIST) {
|
||||||
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
||||||
|
@ -726,15 +728,18 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
||||||
|
if (tbUid > 0) tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(rsp.pArray, &dropTbRsp);
|
taosArrayPush(rsp.pArray, &dropTbRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
tqUpdateTbUidList(pVnode->pTq, tbUids, false);
|
tqUpdateTbUidList(pVnode->pTq, tbUids, false);
|
||||||
|
tdUpdateTbUidList(pVnode->pSma, pStore, false);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
taosArrayDestroy(tbUids);
|
taosArrayDestroy(tbUids);
|
||||||
|
tdUidStoreFree(pStore);
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret);
|
tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret);
|
||||||
pRsp->pCont = rpcMallocCont(pRsp->contLen);
|
pRsp->pCont = rpcMallocCont(pRsp->contLen);
|
||||||
|
|
|
@ -367,18 +367,22 @@ void ctgdShowDBCache(SCatalog* pCtg, SHashObj *dbHash) {
|
||||||
int32_t stbNum = dbCache->stbCache ? taosHashGetSize(dbCache->stbCache) : 0;
|
int32_t stbNum = dbCache->stbCache ? taosHashGetSize(dbCache->stbCache) : 0;
|
||||||
int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||||
int32_t hashMethod = -1;
|
int32_t hashMethod = -1;
|
||||||
|
int16_t hashPrefix = 0;
|
||||||
|
int16_t hashSuffix = 0;
|
||||||
int32_t vgNum = 0;
|
int32_t vgNum = 0;
|
||||||
|
|
||||||
if (dbCache->vgCache.vgInfo) {
|
if (dbCache->vgCache.vgInfo) {
|
||||||
vgVersion = dbCache->vgCache.vgInfo->vgVersion;
|
vgVersion = dbCache->vgCache.vgInfo->vgVersion;
|
||||||
hashMethod = dbCache->vgCache.vgInfo->hashMethod;
|
hashMethod = dbCache->vgCache.vgInfo->hashMethod;
|
||||||
|
hashPrefix = dbCache->vgCache.vgInfo->hashPrefix;
|
||||||
|
hashSuffix = dbCache->vgCache.vgInfo->hashSuffix;
|
||||||
if (dbCache->vgCache.vgInfo->vgHash) {
|
if (dbCache->vgCache.vgInfo->vgHash) {
|
||||||
vgNum = taosHashGetSize(dbCache->vgCache.vgInfo->vgHash);
|
vgNum = taosHashGetSize(dbCache->vgCache.vgInfo->vgHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgDebug("[%d] db [%.*s][0x%"PRIx64"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, vgNum:%d",
|
ctgDebug("[%d] db [%.*s][0x%"PRIx64"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d",
|
||||||
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted?"deleted":"", metaNum, stbNum, vgVersion, hashMethod, vgNum);
|
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted?"deleted":"", metaNum, stbNum, vgVersion, hashMethod, hashPrefix, hashSuffix, vgNum);
|
||||||
|
|
||||||
pIter = taosHashIterate(dbHash, pIter);
|
pIter = taosHashIterate(dbHash, pIter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -848,15 +848,11 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName
|
||||||
CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED);
|
CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
tableNameHashFp fp = NULL;
|
|
||||||
SVgroupInfo *vgInfo = NULL;
|
SVgroupInfo *vgInfo = NULL;
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetHashFunction(dbInfo->hashMethod, &fp));
|
|
||||||
|
|
||||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||||
tNameExtractFullName(pTableName, tbFullName);
|
tNameExtractFullName(pTableName, tbFullName);
|
||||||
|
|
||||||
uint32_t hashValue = (*fp)(tbFullName, (uint32_t)strlen(tbFullName));
|
uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, dbInfo->hashPrefix, dbInfo->hashSuffix);
|
||||||
|
|
||||||
void *pIter = taosHashIterate(dbInfo->vgHash, NULL);
|
void *pIter = taosHashIterate(dbInfo->vgHash, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
|
@ -919,11 +915,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
tableNameHashFp fp = NULL;
|
|
||||||
SVgroupInfo *vgInfo = NULL;
|
SVgroupInfo *vgInfo = NULL;
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetHashFunction(dbInfo->hashMethod, &fp));
|
|
||||||
|
|
||||||
int32_t tbNum = taosArrayGetSize(pNames);
|
int32_t tbNum = taosArrayGetSize(pNames);
|
||||||
|
|
||||||
if (1 == vgNum) {
|
if (1 == vgNum) {
|
||||||
|
@ -975,7 +967,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo
|
||||||
tbNameLen = offset + strlen(pName->tname);
|
tbNameLen = offset + strlen(pName->tname);
|
||||||
strcpy(tbFullName + offset, pName->tname);
|
strcpy(tbFullName + offset, pName->tname);
|
||||||
|
|
||||||
uint32_t hashValue = (*fp)(tbFullName, (uint32_t)tbNameLen);
|
uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, dbInfo->hashPrefix, dbInfo->hashSuffix);
|
||||||
|
|
||||||
SVgroupInfo **p = taosArraySearch(pVgList, &hashValue, ctgHashValueComp, TD_EQ);
|
SVgroupInfo **p = taosArraySearch(pVgList, &hashValue, ctgHashValueComp, TD_EQ);
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,8 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
|
||||||
ctgTestCurrentVgVersion = dbVgroup->vgVersion;
|
ctgTestCurrentVgVersion = dbVgroup->vgVersion;
|
||||||
|
|
||||||
dbVgroup->hashMethod = 0;
|
dbVgroup->hashMethod = 0;
|
||||||
|
dbVgroup->hashPrefix = 0;
|
||||||
|
dbVgroup->hashSuffix = 0;
|
||||||
dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
|
vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
|
||||||
|
|
|
@ -87,8 +87,6 @@ struct SqlFunctionCtx;
|
||||||
|
|
||||||
size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||||
void initResultRowInfo(SResultRowInfo* pResultRowInfo);
|
void initResultRowInfo(SResultRowInfo* pResultRowInfo);
|
||||||
|
|
||||||
void initResultRow(SResultRow* pResultRow);
|
|
||||||
void closeResultRow(SResultRow* pResultRow);
|
void closeResultRow(SResultRow* pResultRow);
|
||||||
|
|
||||||
struct SResultRowEntryInfo* getResultEntryInfo(const SResultRow* pRow, int32_t index, const int32_t* offset);
|
struct SResultRowEntryInfo* getResultEntryInfo(const SResultRow* pRow, int32_t index, const int32_t* offset);
|
||||||
|
|
|
@ -591,6 +591,24 @@ typedef struct SMergeAlignedIntervalAggOperatorInfo {
|
||||||
SNode* pCondition;
|
SNode* pCondition;
|
||||||
} SMergeAlignedIntervalAggOperatorInfo;
|
} SMergeAlignedIntervalAggOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SStreamIntervalOperatorInfo {
|
||||||
|
// SOptrBasicInfo should be first, SAggSupporter should be second for stream encode
|
||||||
|
SOptrBasicInfo binfo; // basic info
|
||||||
|
SAggSupporter aggSup; // aggregate supporter
|
||||||
|
SExprSupp scalarSupp; // supporter for perform scalar function
|
||||||
|
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||||
|
SInterval interval; // interval info
|
||||||
|
int32_t primaryTsIndex; // primary time stamp slot id from result of downstream operator.
|
||||||
|
STimeWindowAggSupp twAggSup;
|
||||||
|
bool invertible;
|
||||||
|
bool ignoreExpiredData;
|
||||||
|
SArray* pRecycledPages;
|
||||||
|
SArray* pDelWins; // SWinRes
|
||||||
|
int32_t delIndex;
|
||||||
|
SSDataBlock* pDelRes;
|
||||||
|
bool isFinal;
|
||||||
|
} SStreamIntervalOperatorInfo;
|
||||||
|
|
||||||
typedef struct SStreamFinalIntervalOperatorInfo {
|
typedef struct SStreamFinalIntervalOperatorInfo {
|
||||||
// SOptrBasicInfo should be first, SAggSupporter should be second for stream encode
|
// SOptrBasicInfo should be first, SAggSupporter should be second for stream encode
|
||||||
SOptrBasicInfo binfo; // basic info
|
SOptrBasicInfo binfo; // basic info
|
||||||
|
@ -909,8 +927,7 @@ void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLi
|
||||||
void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, int32_t offset,
|
void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, int32_t offset,
|
||||||
int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput);
|
int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput);
|
||||||
|
|
||||||
int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, int32_t numOfOutput, SArray* pColList,
|
int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart);
|
||||||
char** pNextStart);
|
|
||||||
void updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int32_t numOfRows, int32_t dataLen, int64_t startTs,
|
void updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int32_t numOfRows, int32_t dataLen, int64_t startTs,
|
||||||
SOperatorInfo* pOperator);
|
SOperatorInfo* pOperator);
|
||||||
|
|
||||||
|
@ -1004,6 +1021,8 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
||||||
SExecTaskInfo* pTaskInfo);
|
SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
|
SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
|
||||||
SExecTaskInfo* pTaskInfo, int32_t numOfChild);
|
SExecTaskInfo* pTaskInfo, int32_t numOfChild);
|
||||||
|
SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
|
SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
|
SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
|
||||||
SExecTaskInfo* pTaskInfo);
|
SExecTaskInfo* pTaskInfo);
|
||||||
|
|
|
@ -168,7 +168,9 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
|
||||||
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
||||||
memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf));
|
memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf));
|
||||||
taosFreeQitem(pBuf);
|
taosFreeQitem(pBuf);
|
||||||
*pLen = ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->dataLen;
|
|
||||||
|
SDataCacheEntry* pEntry = (SDataCacheEntry*)pDeleter->nextOutput.pData;
|
||||||
|
*pLen = pEntry->dataLen;
|
||||||
*pQueryEnd = pDeleter->queryEnd;
|
*pQueryEnd = pDeleter->queryEnd;
|
||||||
qDebug("got data len %" PRId64 ", row num %d in sink", *pLen, ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->numOfRows);
|
qDebug("got data len %" PRId64 ", row num %d in sink", *pLen, ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->numOfRows);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,8 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn
|
||||||
|
|
||||||
pBuf->useSize = sizeof(SDataCacheEntry);
|
pBuf->useSize = sizeof(SDataCacheEntry);
|
||||||
blockEncode(pInput->pData, pEntry->data, &pEntry->dataLen, numOfCols, pEntry->compressed);
|
blockEncode(pInput->pData, pEntry->data, &pEntry->dataLen, numOfCols, pEntry->compressed);
|
||||||
|
ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data+8));
|
||||||
|
ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data+8+4));
|
||||||
|
|
||||||
pBuf->useSize += pEntry->dataLen;
|
pBuf->useSize += pEntry->dataLen;
|
||||||
|
|
||||||
|
@ -170,7 +172,13 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
|
||||||
taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
|
taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
|
||||||
memcpy(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
|
memcpy(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
|
||||||
taosFreeQitem(pBuf);
|
taosFreeQitem(pBuf);
|
||||||
*pLen = ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->dataLen;
|
|
||||||
|
SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData;
|
||||||
|
*pLen = pEntry->dataLen;
|
||||||
|
|
||||||
|
ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data+8));
|
||||||
|
ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data+8+4));
|
||||||
|
|
||||||
*pQueryEnd = pDispatcher->queryEnd;
|
*pQueryEnd = pDispatcher->queryEnd;
|
||||||
qDebug("got data len %" PRId64 ", row num %d in sink", *pLen, ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows);
|
qDebug("got data len %" PRId64 ", row num %d in sink", *pLen, ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows);
|
||||||
}
|
}
|
||||||
|
@ -191,6 +199,9 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
||||||
pOutput->numOfCols = pEntry->numOfCols;
|
pOutput->numOfCols = pEntry->numOfCols;
|
||||||
pOutput->compressed = pEntry->compressed;
|
pOutput->compressed = pEntry->compressed;
|
||||||
|
|
||||||
|
ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data+8));
|
||||||
|
ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data+8+4));
|
||||||
|
|
||||||
atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
|
atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
|
||||||
atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
|
atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
|
||||||
|
|
||||||
|
|
|
@ -1302,7 +1302,6 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi
|
||||||
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
||||||
pCond->startVersion = -1;
|
pCond->startVersion = -1;
|
||||||
pCond->endVersion = -1;
|
pCond->endVersion = -1;
|
||||||
pCond->schemaVersion = -1;
|
|
||||||
// pCond->type = pTableScanNode->scanFlag;
|
// pCond->type = pTableScanNode->scanFlag;
|
||||||
|
|
||||||
int32_t j = 0;
|
int32_t j = 0;
|
||||||
|
|
|
@ -97,6 +97,8 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void streamInputBlockDataDestory(void* pBlock) { blockDataDestroy((SSDataBlock*)pBlock); }
|
||||||
|
|
||||||
void tdCleanupStreamInputDataBlock(qTaskInfo_t tinfo) {
|
void tdCleanupStreamInputDataBlock(qTaskInfo_t tinfo) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
if (!pTaskInfo || !pTaskInfo->pRoot || pTaskInfo->pRoot->numOfDownstream <= 0) {
|
if (!pTaskInfo || !pTaskInfo->pRoot || pTaskInfo->pRoot->numOfDownstream <= 0) {
|
||||||
|
@ -107,11 +109,7 @@ void tdCleanupStreamInputDataBlock(qTaskInfo_t tinfo) {
|
||||||
if (pOptrInfo->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pOptrInfo->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
SStreamScanInfo* pInfo = pOptrInfo->info;
|
SStreamScanInfo* pInfo = pOptrInfo->info;
|
||||||
if (pInfo->blockType == STREAM_INPUT__DATA_BLOCK) {
|
if (pInfo->blockType == STREAM_INPUT__DATA_BLOCK) {
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->pBlockLists); ++i) {
|
taosArrayClearP(pInfo->pBlockLists, streamInputBlockDataDestory);
|
||||||
SSDataBlock* p = *(SSDataBlock**)taosArrayGet(pInfo->pBlockLists, i);
|
|
||||||
taosArrayDestroy(p->pDataBlock);
|
|
||||||
taosMemoryFreeClear(p);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
@ -733,7 +731,6 @@ int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* s
|
||||||
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
||||||
pCond->startVersion = -1;
|
pCond->startVersion = -1;
|
||||||
pCond->endVersion = sContext->snapVersion;
|
pCond->endVersion = sContext->snapVersion;
|
||||||
pCond->schemaVersion = sContext->snapVersion;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCond->numOfCols; ++i) {
|
for (int32_t i = 0; i < pCond->numOfCols; ++i) {
|
||||||
pCond->colList[i].type = mtInfo.schema->pSchema[i].type;
|
pCond->colList[i].type = mtInfo.schema->pSchema[i].type;
|
||||||
|
|
|
@ -1866,13 +1866,11 @@ void updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int32_t numOfRows, int32_t
|
||||||
pOperator->resultInfo.totalRows += numOfRows;
|
pOperator->resultInfo.totalRows += numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, int32_t numOfOutput, SArray* pColList,
|
int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart) {
|
||||||
char** pNextStart) {
|
|
||||||
if (pColList == NULL) { // data from other sources
|
if (pColList == NULL) { // data from other sources
|
||||||
blockDataCleanup(pRes);
|
blockDataCleanup(pRes);
|
||||||
*pNextStart = (char*)blockDecode(pRes, pData);
|
*pNextStart = (char*)blockDecode(pRes, pData);
|
||||||
} else { // extract data according to pColList
|
} else { // extract data according to pColList
|
||||||
ASSERT(numOfOutput == taosArrayGetSize(pColList));
|
|
||||||
char* pStart = pData;
|
char* pStart = pData;
|
||||||
|
|
||||||
int32_t numOfCols = htonl(*(int32_t*)pStart);
|
int32_t numOfCols = htonl(*(int32_t*)pStart);
|
||||||
|
@ -1970,7 +1968,7 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
||||||
char* pStart = pRetrieveRsp->data;
|
char* pStart = pRetrieveRsp->data;
|
||||||
while (index++ < pRetrieveRsp->numOfBlocks) {
|
while (index++ < pRetrieveRsp->numOfBlocks) {
|
||||||
SSDataBlock* pb = createOneDataBlock(pExchangeInfo->pDummyBlock, false);
|
SSDataBlock* pb = createOneDataBlock(pExchangeInfo->pDummyBlock, false);
|
||||||
code = extractDataBlockFromFetchRsp(pb, pStart, pRetrieveRsp->numOfCols, NULL, &pStart);
|
code = extractDataBlockFromFetchRsp(pb, pStart, NULL, &pStart);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
taosMemoryFreeClear(pDataInfo->pRsp);
|
taosMemoryFreeClear(pDataInfo->pRsp);
|
||||||
goto _error;
|
goto _error;
|
||||||
|
@ -2095,7 +2093,7 @@ static int32_t seqLoadRemoteData(SOperatorInfo* pOperator) {
|
||||||
SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp;
|
SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp;
|
||||||
|
|
||||||
char* pStart = pRetrieveRsp->data;
|
char* pStart = pRetrieveRsp->data;
|
||||||
int32_t code = extractDataBlockFromFetchRsp(NULL, pStart, pRetrieveRsp->numOfCols, NULL, &pStart);
|
int32_t code = extractDataBlockFromFetchRsp(NULL, pStart, NULL, &pStart);
|
||||||
|
|
||||||
if (pRsp->completed == 1) {
|
if (pRsp->completed == 1) {
|
||||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, rowsOfSource:%" PRIu64
|
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, rowsOfSource:%" PRIu64
|
||||||
|
@ -3731,7 +3729,6 @@ static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pC
|
||||||
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
||||||
pCond->startVersion = -1;
|
pCond->startVersion = -1;
|
||||||
pCond->endVersion = -1;
|
pCond->endVersion = -1;
|
||||||
pCond->schemaVersion = -1;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -3916,7 +3913,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
pOptr = createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pAggNode->node.pConditions,
|
pOptr = createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pAggNode->node.pConditions,
|
||||||
pScalarExprInfo, numOfScalarExpr, pAggNode->mergeDataBlock, pTaskInfo);
|
pScalarExprInfo, numOfScalarExpr, pAggNode->mergeDataBlock, pTaskInfo);
|
||||||
}
|
}
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type || QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
|
||||||
SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
|
SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
|
||||||
|
|
||||||
SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num);
|
SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num);
|
||||||
|
@ -3941,6 +3938,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
pOptr = createIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, &as, pIntervalPhyNode,
|
pOptr = createIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, &as, pIntervalPhyNode,
|
||||||
pTaskInfo, isStream);
|
pTaskInfo, isStream);
|
||||||
|
|
||||||
|
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) {
|
||||||
|
pOptr = createStreamIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo);
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) {
|
||||||
SMergeAlignedIntervalPhysiNode* pIntervalPhyNode = (SMergeAlignedIntervalPhysiNode*)pPhyNode;
|
SMergeAlignedIntervalPhysiNode* pIntervalPhyNode = (SMergeAlignedIntervalPhysiNode*)pPhyNode;
|
||||||
pOptr = createMergeAlignedIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
|
pOptr = createMergeAlignedIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
|
||||||
|
|
|
@ -695,6 +695,7 @@ static void destroyTableScanOperatorInfo(void* param) {
|
||||||
cleanupQueryTableDataCond(&pTableScanInfo->cond);
|
cleanupQueryTableDataCond(&pTableScanInfo->cond);
|
||||||
|
|
||||||
tsdbReaderClose(pTableScanInfo->dataReader);
|
tsdbReaderClose(pTableScanInfo->dataReader);
|
||||||
|
pTableScanInfo->dataReader = NULL;
|
||||||
|
|
||||||
if (pTableScanInfo->pColMatchInfo != NULL) {
|
if (pTableScanInfo->pColMatchInfo != NULL) {
|
||||||
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
|
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
|
||||||
|
@ -2648,7 +2649,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* pStart = pRsp->data;
|
char* pStart = pRsp->data;
|
||||||
extractDataBlockFromFetchRsp(pInfo->pRes, pRsp->data, pOperator->exprSupp.numOfExprs, pInfo->scanCols, &pStart);
|
extractDataBlockFromFetchRsp(pInfo->pRes, pRsp->data, pInfo->scanCols, &pStart);
|
||||||
updateLoadRemoteInfo(&pInfo->loadInfo, pRsp->numOfRows, pRsp->compLen, startTs, pOperator);
|
updateLoadRemoteInfo(&pInfo->loadInfo, pRsp->numOfRows, pRsp->compLen, startTs, pOperator);
|
||||||
|
|
||||||
// todo log the filter info
|
// todo log the filter info
|
||||||
|
|
|
@ -622,7 +622,8 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num
|
||||||
if (pr->closed) {
|
if (pr->closed) {
|
||||||
ASSERT(isResultRowInterpolated(pr, RESULT_ROW_START_INTERP) &&
|
ASSERT(isResultRowInterpolated(pr, RESULT_ROW_START_INTERP) &&
|
||||||
isResultRowInterpolated(pr, RESULT_ROW_END_INTERP));
|
isResultRowInterpolated(pr, RESULT_ROW_END_INTERP));
|
||||||
tdListPopHead(pResultRowInfo->openWindow);
|
SListNode* pNode = tdListPopHead(pResultRowInfo->openWindow);
|
||||||
|
taosMemoryFree(pNode);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +652,8 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num
|
||||||
|
|
||||||
if (isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP)) {
|
if (isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP)) {
|
||||||
closeResultRow(pr);
|
closeResultRow(pr);
|
||||||
tdListPopHead(pResultRowInfo->openWindow);
|
SListNode* pNode = tdListPopHead(pResultRowInfo->openWindow);
|
||||||
|
taosMemoryFree(pNode);
|
||||||
} else { // the remains are can not be closed yet.
|
} else { // the remains are can not be closed yet.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -937,7 +939,7 @@ bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup) {
|
||||||
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup) { return isOverdue(pWin->ekey, pSup); }
|
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup) { return isOverdue(pWin->ekey, pSup); }
|
||||||
|
|
||||||
static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pBlock,
|
static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pBlock,
|
||||||
int32_t scanFlag, SHashObj* pUpdatedMap) {
|
int32_t scanFlag) {
|
||||||
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info;
|
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info;
|
||||||
|
|
||||||
SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo;
|
||||||
|
@ -953,21 +955,11 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
||||||
|
|
||||||
STimeWindow win =
|
STimeWindow win =
|
||||||
getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->inputOrder);
|
getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->inputOrder);
|
||||||
int32_t ret = TSDB_CODE_SUCCESS;
|
int32_t ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pSup->pCtx,
|
||||||
if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) &&
|
|
||||||
inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) {
|
|
||||||
ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pSup->pCtx,
|
|
||||||
numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
||||||
if (ret != TSDB_CODE_SUCCESS || pResult == NULL) {
|
if (ret != TSDB_CODE_SUCCESS || pResult == NULL) {
|
||||||
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM && pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
|
||||||
saveWinResultRow(pResult, tableGroupId, pUpdatedMap);
|
|
||||||
setResultBufPageDirty(pInfo->aggSup.pResultBuf, &pResultRowInfo->cur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TSKEY ekey = ascScan ? win.ekey : win.skey;
|
TSKEY ekey = ascScan ? win.ekey : win.skey;
|
||||||
int32_t forwardRows =
|
int32_t forwardRows =
|
||||||
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->inputOrder);
|
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->inputOrder);
|
||||||
|
@ -989,12 +981,9 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
||||||
doWindowBorderInterpolation(pInfo, pBlock, pResult, &win, startPos, forwardRows, pSup);
|
doWindowBorderInterpolation(pInfo, pBlock, pResult, &win, startPos, forwardRows, pSup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) &&
|
|
||||||
inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) {
|
|
||||||
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true);
|
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true);
|
||||||
doApplyFunctions(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, pBlock->info.rows,
|
doApplyFunctions(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, pBlock->info.rows,
|
||||||
numOfOutput);
|
numOfOutput);
|
||||||
}
|
|
||||||
|
|
||||||
doCloseWindow(pResultRowInfo, pInfo, pResult);
|
doCloseWindow(pResultRowInfo, pInfo, pResult);
|
||||||
|
|
||||||
|
@ -1005,13 +994,6 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
||||||
if (startPos < 0) {
|
if (startPos < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pInfo->ignoreExpiredData && isCloseWindow(&nextWin, &pInfo->twAggSup)) {
|
|
||||||
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
|
||||||
forwardRows =
|
|
||||||
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->inputOrder);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// null data, failed to allocate more memory buffer
|
// null data, failed to allocate more memory buffer
|
||||||
int32_t code = setTimeWindowOutputBuf(pResultRowInfo, &nextWin, (scanFlag == MAIN_SCAN), &pResult, tableGroupId,
|
int32_t code = setTimeWindowOutputBuf(pResultRowInfo, &nextWin, (scanFlag == MAIN_SCAN), &pResult, tableGroupId,
|
||||||
pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
||||||
|
@ -1019,11 +1001,6 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
||||||
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM && pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
|
||||||
saveWinResultRow(pResult, tableGroupId, pUpdatedMap);
|
|
||||||
setResultBufPageDirty(pInfo->aggSup.pResultBuf, &pResultRowInfo->cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
||||||
forwardRows =
|
forwardRows =
|
||||||
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->inputOrder);
|
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->inputOrder);
|
||||||
|
@ -1128,7 +1105,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->inputOrder, scanFlag, true);
|
setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->inputOrder, scanFlag, true);
|
||||||
blockDataUpdateTsWindow(pBlock, pInfo->primaryTsIndex);
|
blockDataUpdateTsWindow(pBlock, pInfo->primaryTsIndex);
|
||||||
|
|
||||||
hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, scanFlag, NULL);
|
hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, scanFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, pInfo->resultTsOrder);
|
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, pInfo->resultTsOrder);
|
||||||
|
@ -1579,141 +1556,6 @@ static void doBuildDeleteResult(SArray* pWins, int32_t* index, SSDataBlock* pBlo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|
||||||
SIntervalAggOperatorInfo* pInfo = pOperator->info;
|
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
||||||
|
|
||||||
pInfo->inputOrder = TSDB_ORDER_ASC;
|
|
||||||
SExprSupp* pSup = &pOperator->exprSupp;
|
|
||||||
|
|
||||||
if (pOperator->status == OP_EXEC_DONE) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
|
||||||
doBuildDeleteResult(pInfo->pDelWins, &pInfo->delIndex, pInfo->pDelRes);
|
|
||||||
if (pInfo->pDelRes->info.rows > 0) {
|
|
||||||
printDataBlock(pInfo->pDelRes, "single interval");
|
|
||||||
return pInfo->pDelRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
|
||||||
if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainResults(&pInfo->groupResInfo)) {
|
|
||||||
pOperator->status = OP_EXEC_DONE;
|
|
||||||
qDebug("===stream===single interval is done");
|
|
||||||
freeAllPages(pInfo->pRecycledPages, pInfo->aggSup.pResultBuf);
|
|
||||||
}
|
|
||||||
printDataBlock(pInfo->binfo.pRes, "single interval");
|
|
||||||
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
|
||||||
|
|
||||||
SArray* pUpdated = taosArrayInit(4, POINTER_BYTES); // SResKeyPos
|
|
||||||
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
|
||||||
SHashObj* pUpdatedMap = taosHashInit(1024, hashFn, false, HASH_NO_LOCK);
|
|
||||||
|
|
||||||
SStreamState* pState = pTaskInfo->streamInfo.pState;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
|
||||||
if (pBlock == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// qInfo("===stream===%ld", pBlock->info.version);
|
|
||||||
printDataBlock(pBlock, "single interval recv");
|
|
||||||
|
|
||||||
if (pBlock->info.type == STREAM_CLEAR) {
|
|
||||||
doClearWindows(&pInfo->aggSup, &pOperator->exprSupp, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock,
|
|
||||||
NULL);
|
|
||||||
qDebug("%s clear existed time window results for updates checked", GET_TASKID(pTaskInfo));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (pBlock->info.type == STREAM_DELETE_DATA) {
|
|
||||||
doDeleteSpecifyIntervalWindow(&pInfo->aggSup, pBlock, pInfo->pDelWins, &pInfo->interval, pUpdatedMap);
|
|
||||||
continue;
|
|
||||||
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
|
||||||
getAllIntervalWindow(pInfo->aggSup.pResultRowHashTable, pUpdatedMap);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pBlock->info.type == STREAM_NORMAL && pBlock->info.version != 0) {
|
|
||||||
// set input version
|
|
||||||
pTaskInfo->version = pBlock->info.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pInfo->scalarSupp.pExprInfo != NULL) {
|
|
||||||
SExprSupp* pExprSup = &pInfo->scalarSupp;
|
|
||||||
projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The timewindow that overlaps the timestamps of the input pBlock need to be recalculated and return to the
|
|
||||||
// caller. Note that all the time window are not close till now.
|
|
||||||
// the pDataBlock are always the same one, no need to call this again
|
|
||||||
setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->inputOrder, MAIN_SCAN, true);
|
|
||||||
if (pInfo->invertible) {
|
|
||||||
setInverFunction(pSup->pCtx, pOperator->exprSupp.numOfExprs, pBlock->info.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey);
|
|
||||||
hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, MAIN_SCAN, pUpdatedMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (pState) {
|
|
||||||
printf(">>>>>>>> stream read backend\n");
|
|
||||||
SWinKey key = {
|
|
||||||
.ts = 1,
|
|
||||||
.groupId = 2,
|
|
||||||
};
|
|
||||||
char* val = NULL;
|
|
||||||
int32_t sz;
|
|
||||||
if (streamStateGet(pState, &key, (void**)&val, &sz) < 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
printf("stream read %s %d\n", val, sz);
|
|
||||||
streamFreeVal(val);
|
|
||||||
|
|
||||||
SStreamStateCur* pCur = streamStateGetCur(pState, &key);
|
|
||||||
ASSERT(pCur);
|
|
||||||
while (streamStateCurNext(pState, pCur) == 0) {
|
|
||||||
SWinKey key1;
|
|
||||||
const void* val1;
|
|
||||||
if (streamStateGetKVByCur(pCur, &key1, &val1, &sz) < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
printf("stream iter key groupId:%d ts:%d, value %s %d\n", key1.groupId, key1.ts, val1, sz);
|
|
||||||
}
|
|
||||||
streamStateFreeCur(pCur);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pOperator->status = OP_RES_TO_RETURN;
|
|
||||||
closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, NULL, pUpdatedMap,
|
|
||||||
pInfo->pRecycledPages, pInfo->aggSup.pResultBuf);
|
|
||||||
|
|
||||||
void* pIte = NULL;
|
|
||||||
while ((pIte = taosHashIterate(pUpdatedMap, pIte)) != NULL) {
|
|
||||||
taosArrayPush(pUpdated, pIte);
|
|
||||||
}
|
|
||||||
taosArraySort(pUpdated, resultrowComparAsc);
|
|
||||||
|
|
||||||
finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pSup->rowEntryInfoOffset);
|
|
||||||
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
|
||||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
|
||||||
removeDeleteResults(pUpdatedMap, pInfo->pDelWins);
|
|
||||||
taosHashCleanup(pUpdatedMap);
|
|
||||||
doBuildDeleteResult(pInfo->pDelWins, &pInfo->delIndex, pInfo->pDelRes);
|
|
||||||
if (pInfo->pDelRes->info.rows > 0) {
|
|
||||||
printDataBlock(pInfo->pDelRes, "single interval");
|
|
||||||
return pInfo->pDelRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
|
||||||
printDataBlock(pInfo->binfo.pRes, "single interval");
|
|
||||||
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void destroyStateWindowOperatorInfo(void* param) {
|
static void destroyStateWindowOperatorInfo(void* param) {
|
||||||
SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*)param;
|
SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*)param;
|
||||||
cleanupBasicInfo(&pInfo->binfo);
|
cleanupBasicInfo(&pInfo->binfo);
|
||||||
|
@ -1731,6 +1573,10 @@ void destroyIntervalOperatorInfo(void* param) {
|
||||||
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)param;
|
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)param;
|
||||||
cleanupBasicInfo(&pInfo->binfo);
|
cleanupBasicInfo(&pInfo->binfo);
|
||||||
cleanupAggSup(&pInfo->aggSup);
|
cleanupAggSup(&pInfo->aggSup);
|
||||||
|
cleanupExprSupp(&pInfo->scalarSupp);
|
||||||
|
|
||||||
|
tdListFree(pInfo->binfo.resultRowInfo.openWindow);
|
||||||
|
|
||||||
pInfo->pRecycledPages = taosArrayDestroy(pInfo->pRecycledPages);
|
pInfo->pRecycledPages = taosArrayDestroy(pInfo->pRecycledPages);
|
||||||
pInfo->pInterpCols = taosArrayDestroy(pInfo->pInterpCols);
|
pInfo->pInterpCols = taosArrayDestroy(pInfo->pInterpCols);
|
||||||
taosArrayDestroyEx(pInfo->pPrevValues, freeItem);
|
taosArrayDestroyEx(pInfo->pPrevValues, freeItem);
|
||||||
|
@ -1919,7 +1765,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
||||||
pOperator->status = OP_NOT_OPENED;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
|
|
||||||
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, doStreamIntervalAgg, NULL,
|
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL,
|
||||||
destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||||
|
|
||||||
if (nodeType(pPhyNode) == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL) {
|
if (nodeType(pPhyNode) == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL) {
|
||||||
|
@ -5621,3 +5467,311 @@ _error:
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo,
|
||||||
|
SSDataBlock* pBlock, int32_t scanFlag, SHashObj* pUpdatedMap) {
|
||||||
|
SStreamIntervalOperatorInfo* pInfo = (SStreamIntervalOperatorInfo*)pOperatorInfo->info;
|
||||||
|
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo;
|
||||||
|
SExprSupp* pSup = &pOperatorInfo->exprSupp;
|
||||||
|
|
||||||
|
int32_t startPos = 0;
|
||||||
|
int32_t numOfOutput = pSup->numOfExprs;
|
||||||
|
SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||||
|
TSKEY* tsCols = (TSKEY*)pColDataInfo->pData;
|
||||||
|
uint64_t tableGroupId = pBlock->info.groupId;
|
||||||
|
bool ascScan = true;
|
||||||
|
TSKEY ts = getStartTsKey(&pBlock->info.window, tsCols);
|
||||||
|
SResultRow* pResult = NULL;
|
||||||
|
|
||||||
|
STimeWindow win =
|
||||||
|
getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, TSDB_ORDER_ASC);
|
||||||
|
int32_t ret = TSDB_CODE_SUCCESS;
|
||||||
|
if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) &&
|
||||||
|
inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) {
|
||||||
|
ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pSup->pCtx,
|
||||||
|
numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS || pResult == NULL) {
|
||||||
|
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||||
|
saveWinResultRow(pResult, tableGroupId, pUpdatedMap);
|
||||||
|
setResultBufPageDirty(pInfo->aggSup.pResultBuf, &pResultRowInfo->cur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TSKEY ekey = ascScan ? win.ekey : win.skey;
|
||||||
|
int32_t forwardRows =
|
||||||
|
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||||
|
ASSERT(forwardRows > 0);
|
||||||
|
|
||||||
|
if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) &&
|
||||||
|
inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) {
|
||||||
|
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true);
|
||||||
|
doApplyFunctions(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, pBlock->info.rows,
|
||||||
|
numOfOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
STimeWindow nextWin = win;
|
||||||
|
while (1) {
|
||||||
|
int32_t prevEndPos = forwardRows - 1 + startPos;
|
||||||
|
startPos = getNextQualifiedWindow(&pInfo->interval, &nextWin, &pBlock->info, tsCols, prevEndPos, TSDB_ORDER_ASC);
|
||||||
|
if (startPos < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pInfo->ignoreExpiredData && isCloseWindow(&nextWin, &pInfo->twAggSup)) {
|
||||||
|
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
||||||
|
forwardRows =
|
||||||
|
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// null data, failed to allocate more memory buffer
|
||||||
|
int32_t code = setTimeWindowOutputBuf(pResultRowInfo, &nextWin, (scanFlag == MAIN_SCAN), &pResult, tableGroupId,
|
||||||
|
pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
|
||||||
|
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||||
|
saveWinResultRow(pResult, tableGroupId, pUpdatedMap);
|
||||||
|
setResultBufPageDirty(pInfo->aggSup.pResultBuf, &pResultRowInfo->cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
||||||
|
forwardRows =
|
||||||
|
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||||
|
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
|
||||||
|
doApplyFunctions(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, pBlock->info.rows,
|
||||||
|
numOfOutput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
|
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
int64_t maxTs = INT64_MIN;
|
||||||
|
SExprSupp* pSup = &pOperator->exprSupp;
|
||||||
|
|
||||||
|
if (pOperator->status == OP_EXEC_DONE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||||
|
doBuildDeleteResult(pInfo->pDelWins, &pInfo->delIndex, pInfo->pDelRes);
|
||||||
|
if (pInfo->pDelRes->info.rows > 0) {
|
||||||
|
printDataBlock(pInfo->pDelRes, "single interval");
|
||||||
|
return pInfo->pDelRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||||
|
if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainResults(&pInfo->groupResInfo)) {
|
||||||
|
pOperator->status = OP_EXEC_DONE;
|
||||||
|
qDebug("===stream===single interval is done");
|
||||||
|
freeAllPages(pInfo->pRecycledPages, pInfo->aggSup.pResultBuf);
|
||||||
|
}
|
||||||
|
printDataBlock(pInfo->binfo.pRes, "single interval");
|
||||||
|
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||||
|
|
||||||
|
SArray* pUpdated = taosArrayInit(4, POINTER_BYTES); // SResKeyPos
|
||||||
|
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||||
|
SHashObj* pUpdatedMap = taosHashInit(1024, hashFn, false, HASH_NO_LOCK);
|
||||||
|
|
||||||
|
SStreamState* pState = pTaskInfo->streamInfo.pState;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||||
|
if (pBlock == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printDataBlock(pBlock, "single interval recv");
|
||||||
|
|
||||||
|
if (pBlock->info.type == STREAM_CLEAR) {
|
||||||
|
doClearWindows(&pInfo->aggSup, &pOperator->exprSupp, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock,
|
||||||
|
NULL);
|
||||||
|
qDebug("%s clear existed time window results for updates checked", GET_TASKID(pTaskInfo));
|
||||||
|
continue;
|
||||||
|
} else if (pBlock->info.type == STREAM_DELETE_DATA) {
|
||||||
|
doDeleteSpecifyIntervalWindow(&pInfo->aggSup, pBlock, pInfo->pDelWins, &pInfo->interval, pUpdatedMap);
|
||||||
|
continue;
|
||||||
|
} else if (pBlock->info.type == STREAM_GET_ALL) {
|
||||||
|
getAllIntervalWindow(pInfo->aggSup.pResultRowHashTable, pUpdatedMap);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pBlock->info.type == STREAM_NORMAL && pBlock->info.version != 0) {
|
||||||
|
// set input version
|
||||||
|
pTaskInfo->version = pBlock->info.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pInfo->scalarSupp.pExprInfo != NULL) {
|
||||||
|
SExprSupp* pExprSup = &pInfo->scalarSupp;
|
||||||
|
projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The timewindow that overlaps the timestamps of the input pBlock need to be recalculated and return to the
|
||||||
|
// caller. Note that all the time window are not close till now.
|
||||||
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
|
setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true);
|
||||||
|
if (pInfo->invertible) {
|
||||||
|
setInverFunction(pSup->pCtx, pOperator->exprSupp.numOfExprs, pBlock->info.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
maxTs = TMAX(maxTs, pBlock->info.window.ekey);
|
||||||
|
doStreamIntervalAggImpl(pOperator, &pInfo->binfo.resultRowInfo, pBlock, MAIN_SCAN, pUpdatedMap);
|
||||||
|
}
|
||||||
|
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (pState) {
|
||||||
|
printf(">>>>>>>> stream read backend\n");
|
||||||
|
SWinKey key = {
|
||||||
|
.ts = 1,
|
||||||
|
.groupId = 2,
|
||||||
|
};
|
||||||
|
char* val = NULL;
|
||||||
|
int32_t sz;
|
||||||
|
if (streamStateGet(pState, &key, (void**)&val, &sz) < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
printf("stream read %s %d\n", val, sz);
|
||||||
|
streamFreeVal(val);
|
||||||
|
|
||||||
|
SStreamStateCur* pCur = streamStateGetCur(pState, &key);
|
||||||
|
ASSERT(pCur);
|
||||||
|
while (streamStateCurNext(pState, pCur) == 0) {
|
||||||
|
SWinKey key1;
|
||||||
|
const void* val1;
|
||||||
|
if (streamStateGetKVByCur(pCur, &key1, &val1, &sz) < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("stream iter key groupId:%d ts:%d, value %s %d\n", key1.groupId, key1.ts, val1, sz);
|
||||||
|
}
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pOperator->status = OP_RES_TO_RETURN;
|
||||||
|
closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, NULL, pUpdatedMap,
|
||||||
|
pInfo->pRecycledPages, pInfo->aggSup.pResultBuf);
|
||||||
|
|
||||||
|
void* pIte = NULL;
|
||||||
|
while ((pIte = taosHashIterate(pUpdatedMap, pIte)) != NULL) {
|
||||||
|
taosArrayPush(pUpdated, pIte);
|
||||||
|
}
|
||||||
|
taosArraySort(pUpdated, resultrowComparAsc);
|
||||||
|
|
||||||
|
finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pSup->rowEntryInfoOffset);
|
||||||
|
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||||
|
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||||
|
removeDeleteResults(pUpdatedMap, pInfo->pDelWins);
|
||||||
|
taosHashCleanup(pUpdatedMap);
|
||||||
|
doBuildDeleteResult(pInfo->pDelWins, &pInfo->delIndex, pInfo->pDelRes);
|
||||||
|
if (pInfo->pDelRes->info.rows > 0) {
|
||||||
|
printDataBlock(pInfo->pDelRes, "single interval");
|
||||||
|
return pInfo->pDelRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||||
|
printDataBlock(pInfo->binfo.pRes, "single interval");
|
||||||
|
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyStreamIntervalOperatorInfo(void* param) {
|
||||||
|
SStreamIntervalOperatorInfo* pInfo = (SStreamIntervalOperatorInfo*)param;
|
||||||
|
cleanupBasicInfo(&pInfo->binfo);
|
||||||
|
cleanupAggSup(&pInfo->aggSup);
|
||||||
|
pInfo->pRecycledPages = taosArrayDestroy(pInfo->pRecycledPages);
|
||||||
|
|
||||||
|
pInfo->pDelWins = taosArrayDestroy(pInfo->pDelWins);
|
||||||
|
pInfo->pDelRes = blockDataDestroy(pInfo->pDelRes);
|
||||||
|
|
||||||
|
cleanupGroupResInfo(&pInfo->groupResInfo);
|
||||||
|
colDataDestroy(&pInfo->twAggSup.timeWindowData);
|
||||||
|
taosMemoryFreeClear(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
|
||||||
|
SExecTaskInfo* pTaskInfo) {
|
||||||
|
SStreamIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamIntervalOperatorInfo));
|
||||||
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
SStreamIntervalPhysiNode* pIntervalPhyNode = (SStreamIntervalPhysiNode*)pPhyNode;
|
||||||
|
|
||||||
|
int32_t numOfCols = 0;
|
||||||
|
SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &numOfCols);
|
||||||
|
ASSERT(numOfCols > 0);
|
||||||
|
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||||
|
SInterval interval = {.interval = pIntervalPhyNode->interval,
|
||||||
|
.sliding = pIntervalPhyNode->sliding,
|
||||||
|
.intervalUnit = pIntervalPhyNode->intervalUnit,
|
||||||
|
.slidingUnit = pIntervalPhyNode->slidingUnit,
|
||||||
|
.offset = pIntervalPhyNode->offset,
|
||||||
|
.precision = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->node.resType.precision, };
|
||||||
|
STimeWindowAggSupp twAggSupp = {.waterMark = pIntervalPhyNode->window.watermark,
|
||||||
|
.calTrigger = pIntervalPhyNode->window.triggerType,
|
||||||
|
.maxTs = INT64_MIN, };
|
||||||
|
ASSERT(twAggSupp.calTrigger != STREAM_TRIGGER_MAX_DELAY);
|
||||||
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
pInfo->interval = interval;
|
||||||
|
pInfo->twAggSup = twAggSupp;
|
||||||
|
pInfo->ignoreExpiredData = pIntervalPhyNode->window.igExpired;
|
||||||
|
pInfo->isFinal = false;
|
||||||
|
|
||||||
|
if (pIntervalPhyNode->window.pExprs != NULL) {
|
||||||
|
int32_t numOfScalar = 0;
|
||||||
|
SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar);
|
||||||
|
int32_t code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;;
|
||||||
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
|
SExprSupp* pSup = &pOperator->exprSupp;
|
||||||
|
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
||||||
|
int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
initBasicInfo(&pInfo->binfo, pResBlock);
|
||||||
|
initStreamFunciton(pSup->pCtx, pSup->numOfExprs);
|
||||||
|
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
||||||
|
|
||||||
|
pInfo->invertible = allInvertible(pSup->pCtx, numOfCols);
|
||||||
|
pInfo->invertible = false; // Todo(liuyao): Dependent TSDB API
|
||||||
|
pInfo->pRecycledPages = taosArrayInit(4, sizeof(int32_t));
|
||||||
|
pInfo->pDelWins = taosArrayInit(4, sizeof(SWinKey));
|
||||||
|
pInfo->delIndex = 0;
|
||||||
|
pInfo->pDelRes = createSpecialDataBlock(STREAM_DELETE_RESULT);
|
||||||
|
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
|
|
||||||
|
pOperator->name = "StreamIntervalOperator";
|
||||||
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL;
|
||||||
|
pOperator->blocking = true;
|
||||||
|
pOperator->status = OP_NOT_OPENED;
|
||||||
|
pOperator->info = pInfo;
|
||||||
|
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamIntervalAgg, NULL, NULL,
|
||||||
|
destroyStreamIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||||
|
|
||||||
|
initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, pInfo->twAggSup.waterMark);
|
||||||
|
code = appendDownstream(pOperator, &downstream, 1);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pOperator;
|
||||||
|
|
||||||
|
_error:
|
||||||
|
destroyStreamIntervalOperatorInfo(pInfo);
|
||||||
|
taosMemoryFreeClear(pOperator);
|
||||||
|
pTaskInfo->code = code;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -227,9 +227,9 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPageInfo* pPgInfo = *(SPageInfo**)taosArrayGet(pSource->pageIdList, pSource->pageIndex);
|
int32_t* pPgId = taosArrayGet(pSource->pageIdList, pSource->pageIndex);
|
||||||
|
|
||||||
void* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo));
|
void* pPage = getBufPage(pHandle->pBuf, *pPgId);
|
||||||
code = blockDataFromBuf(pSource->src.pBlock, pPage);
|
code = blockDataFromBuf(pSource->src.pBlock, pPage);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -302,9 +302,9 @@ static int32_t adjustMergeTreeForNextTuple(SSortSource *pSource, SMultiwayMergeT
|
||||||
pSource->pageIndex = -1;
|
pSource->pageIndex = -1;
|
||||||
pSource->src.pBlock = blockDataDestroy(pSource->src.pBlock);
|
pSource->src.pBlock = blockDataDestroy(pSource->src.pBlock);
|
||||||
} else {
|
} else {
|
||||||
SPageInfo* pPgInfo = *(SPageInfo**)taosArrayGet(pSource->pageIdList, pSource->pageIndex);
|
int32_t* pPgId = taosArrayGet(pSource->pageIdList, pSource->pageIndex);
|
||||||
|
|
||||||
void* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo));
|
void* pPage = getBufPage(pHandle->pBuf, *pPgId);
|
||||||
int32_t code = blockDataFromBuf(pSource->src.pBlock, pPage);
|
int32_t code = blockDataFromBuf(pSource->src.pBlock, pPage);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -510,6 +510,7 @@ int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo)
|
||||||
SVnodeLoad *pLoad = taosArrayGet(pInfo->pVloads, i);
|
SVnodeLoad *pLoad = taosArrayGet(pInfo->pVloads, i);
|
||||||
if (tEncodeI32(&encoder, pLoad->vgId) < 0) return -1;
|
if (tEncodeI32(&encoder, pLoad->vgId) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pLoad->syncState) < 0) return -1;
|
if (tEncodeI32(&encoder, pLoad->syncState) < 0) return -1;
|
||||||
|
if (tEncodeI64(&encoder, pLoad->cacheUsage) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pLoad->numOfTables) < 0) return -1;
|
if (tEncodeI64(&encoder, pLoad->numOfTables) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pLoad->numOfTimeSeries) < 0) return -1;
|
if (tEncodeI64(&encoder, pLoad->numOfTimeSeries) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pLoad->totalStorage) < 0) return -1;
|
if (tEncodeI64(&encoder, pLoad->totalStorage) < 0) return -1;
|
||||||
|
@ -544,6 +545,7 @@ int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInf
|
||||||
SVnodeLoad load = {0};
|
SVnodeLoad load = {0};
|
||||||
if (tDecodeI32(&decoder, &load.vgId) < 0) return -1;
|
if (tDecodeI32(&decoder, &load.vgId) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &load.syncState) < 0) return -1;
|
if (tDecodeI32(&decoder, &load.syncState) < 0) return -1;
|
||||||
|
if (tDecodeI64(&decoder, &load.cacheUsage) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &load.numOfTables) < 0) return -1;
|
if (tDecodeI64(&decoder, &load.numOfTables) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &load.numOfTimeSeries) < 0) return -1;
|
if (tDecodeI64(&decoder, &load.numOfTimeSeries) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &load.totalStorage) < 0) return -1;
|
if (tDecodeI64(&decoder, &load.totalStorage) < 0) return -1;
|
||||||
|
@ -594,7 +596,6 @@ int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInf
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
|
int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
|
||||||
SEncoder encoder = {0};
|
SEncoder encoder = {0};
|
||||||
tEncoderInit(&encoder, buf, bufLen);
|
tEncoderInit(&encoder, buf, bufLen);
|
||||||
|
@ -639,5 +640,3 @@ int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
|
||||||
|
|
||||||
pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
|
pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
|
||||||
pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
|
pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
|
||||||
|
pOut->dbVgroup->hashPrefix = usedbRsp->hashPrefix;
|
||||||
|
pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
|
||||||
|
|
||||||
qDebug("Got %d vgroup for db %s", usedbRsp->vgNum, usedbRsp->db);
|
qDebug("Got %d vgroup for db %s", usedbRsp->vgNum, usedbRsp->db);
|
||||||
|
|
||||||
|
|
|
@ -287,10 +287,10 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) {
|
||||||
STransCtxVal* sVal = (STransCtxVal*)iter;
|
STransCtxVal* sVal = (STransCtxVal*)iter;
|
||||||
key = taosHashGetKey(sVal, &klen);
|
key = taosHashGetKey(sVal, &klen);
|
||||||
|
|
||||||
STransCtxVal* dVal = taosHashGet(dst->args, key, klen);
|
// STransCtxVal* dVal = taosHashGet(dst->args, key, klen);
|
||||||
if (dVal) {
|
// if (dVal) {
|
||||||
dst->freeFunc(dVal->val);
|
// dst->freeFunc(dVal->val);
|
||||||
}
|
// }
|
||||||
taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal));
|
taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal));
|
||||||
iter = taosHashIterate(src->args, iter);
|
iter = taosHashIterate(src->args, iter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,6 +618,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_REMOVE_EXISTS, "Rsma remove exists"
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_FETCH_MSG_MSSED_UP, "Rsma fetch msg is messed up")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_FETCH_MSG_MSSED_UP, "Rsma fetch msg is messed up")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_EMPTY_INFO, "Rsma info is empty")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_EMPTY_INFO, "Rsma info is empty")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_SCHEMA, "Rsma invalid schema")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_SCHEMA, "Rsma invalid schema")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_REGEX_MATCH, "Rsma regex match")
|
||||||
|
|
||||||
//index
|
//index
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_REBUILDING, "Index is rebuilding")
|
TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_REBUILDING, "Index is rebuilding")
|
||||||
|
|
|
@ -13,179 +13,297 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "trbtree.h"
|
||||||
|
|
||||||
typedef int32_t (*tRBTreeCmprFn)(void *, void *);
|
static void tRBTreeRotateLeft(SRBTree *pTree, SRBTreeNode *x) {
|
||||||
|
SRBTreeNode *y = x->right;
|
||||||
typedef struct SRBTree SRBTree;
|
x->right = y->left;
|
||||||
typedef struct SRBTreeNode SRBTreeNode;
|
if (y->left != pTree->NIL) {
|
||||||
typedef struct SRBTreeIter SRBTreeIter;
|
y->left->parent = x;
|
||||||
|
|
||||||
struct SRBTreeNode {
|
|
||||||
enum { RED, BLACK } color;
|
|
||||||
SRBTreeNode *parent;
|
|
||||||
SRBTreeNode *left;
|
|
||||||
SRBTreeNode *right;
|
|
||||||
uint8_t payload[];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SRBTree {
|
|
||||||
tRBTreeCmprFn cmprFn;
|
|
||||||
SRBTreeNode *root;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SRBTreeIter {
|
|
||||||
SRBTree *pTree;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define RBTREE_NODE_COLOR(N) ((N) ? (N)->color : BLACK)
|
|
||||||
|
|
||||||
// APIs ================================================
|
|
||||||
static void tRBTreeRotateLeft(SRBTree *pTree, SRBTreeNode *pNode) {
|
|
||||||
SRBTreeNode *right = pNode->right;
|
|
||||||
|
|
||||||
pNode->right = right->left;
|
|
||||||
if (pNode->right) {
|
|
||||||
pNode->right->parent = pNode;
|
|
||||||
}
|
}
|
||||||
|
y->parent = x->parent;
|
||||||
right->parent = pNode->parent;
|
if (x->parent == pTree->NIL) {
|
||||||
if (pNode->parent == NULL) {
|
pTree->root = y;
|
||||||
pTree->root = right;
|
} else if (x == x->parent->left) {
|
||||||
} else if (pNode == pNode->parent->left) {
|
x->parent->left = y;
|
||||||
pNode->parent->left = right;
|
|
||||||
} else {
|
} else {
|
||||||
pNode->parent->right = right;
|
x->parent->right = y;
|
||||||
}
|
}
|
||||||
|
y->left = x;
|
||||||
right->left = pNode;
|
x->parent = y;
|
||||||
pNode->parent = right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tRBTreeRotateRight(SRBTree *pTree, SRBTreeNode *pNode) {
|
static void tRBTreeRotateRight(SRBTree *pTree, SRBTreeNode *x) {
|
||||||
SRBTreeNode *left = pNode->left;
|
SRBTreeNode *y = x->left;
|
||||||
|
x->left = y->right;
|
||||||
pNode->left = left->right;
|
if (y->right != pTree->NIL) {
|
||||||
if (pNode->left) {
|
y->right->parent = x;
|
||||||
pNode->left->parent = pNode;
|
|
||||||
}
|
}
|
||||||
|
y->parent = x->parent;
|
||||||
left->parent = pNode->parent;
|
if (x->parent == pTree->NIL) {
|
||||||
if (pNode->parent == NULL) {
|
pTree->root = y;
|
||||||
pTree->root = left;
|
} else if (x == x->parent->right) {
|
||||||
} else if (pNode == pNode->parent->left) {
|
x->parent->right = y;
|
||||||
pNode->parent->left = left;
|
|
||||||
} else {
|
} else {
|
||||||
pNode->parent->right = left;
|
x->parent->left = y;
|
||||||
}
|
}
|
||||||
|
y->right = x;
|
||||||
left->right = pNode;
|
x->parent = y;
|
||||||
pNode->parent = left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define tRBTreeCreate(compare) \
|
static void tRBTreePutFix(SRBTree *pTree, SRBTreeNode *z) {
|
||||||
(SRBTree) { .cmprFn = (compare), .root = NULL }
|
while (z->parent->color == RED) {
|
||||||
|
if (z->parent == z->parent->parent->left) { // z.parent is the left child
|
||||||
|
|
||||||
SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) {
|
SRBTreeNode *y = z->parent->parent->right; // uncle of z
|
||||||
pNew->left = NULL;
|
|
||||||
pNew->right = NULL;
|
|
||||||
pNew->color = RED;
|
|
||||||
|
|
||||||
// insert
|
if (y->color == RED) { // case 1
|
||||||
if (pTree->root == NULL) {
|
z->parent->color = BLACK;
|
||||||
pNew->parent = NULL;
|
y->color = BLACK;
|
||||||
pTree->root = pNew;
|
z->parent->parent->color = RED;
|
||||||
} else {
|
z = z->parent->parent;
|
||||||
SRBTreeNode *pNode = pTree->root;
|
} else { // case2 or case3
|
||||||
while (true) {
|
if (z == z->parent->right) { // case2
|
||||||
ASSERT(pNode);
|
z = z->parent; // marked z.parent as new z
|
||||||
|
tRBTreeRotateLeft(pTree, z);
|
||||||
int32_t c = pTree->cmprFn(pNew->payload, pNode->payload);
|
|
||||||
if (c < 0) {
|
|
||||||
if (pNode->left) {
|
|
||||||
pNode = pNode->left;
|
|
||||||
} else {
|
|
||||||
pNew->parent = pNode;
|
|
||||||
pNode->left = pNew;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if (c > 0) {
|
// case3
|
||||||
if (pNode->right) {
|
z->parent->color = BLACK; // made parent black
|
||||||
|
z->parent->parent->color = RED; // made parent red
|
||||||
|
tRBTreeRotateRight(pTree, z->parent->parent);
|
||||||
|
}
|
||||||
|
} else { // z.parent is the right child
|
||||||
|
SRBTreeNode *y = z->parent->parent->left; // uncle of z
|
||||||
|
|
||||||
|
if (y->color == RED) {
|
||||||
|
z->parent->color = BLACK;
|
||||||
|
y->color = BLACK;
|
||||||
|
z->parent->parent->color = RED;
|
||||||
|
z = z->parent->parent;
|
||||||
|
} else {
|
||||||
|
if (z == z->parent->left) {
|
||||||
|
z = z->parent; // marked z.parent as new z
|
||||||
|
tRBTreeRotateRight(pTree, z);
|
||||||
|
}
|
||||||
|
z->parent->color = BLACK; // made parent black
|
||||||
|
z->parent->parent->color = RED; // made parent red
|
||||||
|
tRBTreeRotateLeft(pTree, z->parent->parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pTree->root->color = BLACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tRBTreeTransplant(SRBTree *pTree, SRBTreeNode *u, SRBTreeNode *v) {
|
||||||
|
if (u->parent == pTree->NIL)
|
||||||
|
pTree->root = v;
|
||||||
|
else if (u == u->parent->left)
|
||||||
|
u->parent->left = v;
|
||||||
|
else
|
||||||
|
u->parent->right = v;
|
||||||
|
v->parent = u->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tRBTreeDropFix(SRBTree *pTree, SRBTreeNode *x) {
|
||||||
|
while (x != pTree->root && x->color == BLACK) {
|
||||||
|
if (x == x->parent->left) {
|
||||||
|
SRBTreeNode *w = x->parent->right;
|
||||||
|
if (w->color == RED) {
|
||||||
|
w->color = BLACK;
|
||||||
|
x->parent->color = RED;
|
||||||
|
tRBTreeRotateLeft(pTree, x->parent);
|
||||||
|
w = x->parent->right;
|
||||||
|
}
|
||||||
|
if (w->left->color == BLACK && w->right->color == BLACK) {
|
||||||
|
w->color = RED;
|
||||||
|
x = x->parent;
|
||||||
|
} else {
|
||||||
|
if (w->right->color == BLACK) {
|
||||||
|
w->left->color = BLACK;
|
||||||
|
w->color = RED;
|
||||||
|
tRBTreeRotateRight(pTree, w);
|
||||||
|
w = x->parent->right;
|
||||||
|
}
|
||||||
|
w->color = x->parent->color;
|
||||||
|
x->parent->color = BLACK;
|
||||||
|
w->right->color = BLACK;
|
||||||
|
tRBTreeRotateLeft(pTree, x->parent);
|
||||||
|
x = pTree->root;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SRBTreeNode *w = x->parent->left;
|
||||||
|
if (w->color == RED) {
|
||||||
|
w->color = BLACK;
|
||||||
|
x->parent->color = RED;
|
||||||
|
tRBTreeRotateRight(pTree, x->parent);
|
||||||
|
w = x->parent->left;
|
||||||
|
}
|
||||||
|
if (w->right->color == BLACK && w->left->color == BLACK) {
|
||||||
|
w->color = RED;
|
||||||
|
x = x->parent;
|
||||||
|
} else {
|
||||||
|
if (w->left->color == BLACK) {
|
||||||
|
w->right->color = BLACK;
|
||||||
|
w->color = RED;
|
||||||
|
tRBTreeRotateLeft(pTree, w);
|
||||||
|
w = x->parent->left;
|
||||||
|
}
|
||||||
|
w->color = x->parent->color;
|
||||||
|
x->parent->color = BLACK;
|
||||||
|
w->left->color = BLACK;
|
||||||
|
tRBTreeRotateRight(pTree, x->parent);
|
||||||
|
x = pTree->root;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x->color = BLACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRBTreeNode *tRBTreeSuccessor(SRBTree *pTree, SRBTreeNode *pNode) {
|
||||||
|
if (pNode->right != pTree->NIL) {
|
||||||
pNode = pNode->right;
|
pNode = pNode->right;
|
||||||
} else {
|
while (pNode->left != pTree->NIL) {
|
||||||
pNew->parent = pNode;
|
pNode = pNode->left;
|
||||||
pNode->right = pNew;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
while (true) {
|
||||||
|
if (pNode->parent == pTree->NIL || pNode == pNode->parent->left) {
|
||||||
|
pNode = pNode->parent;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
pNode = pNode->parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRBTreeNode *tRBTreePredecessor(SRBTree *pTree, SRBTreeNode *pNode) {
|
||||||
|
if (pNode->left != pTree->NIL) {
|
||||||
|
pNode = pNode->left;
|
||||||
|
while (pNode->right != pTree->NIL) {
|
||||||
|
pNode = pNode->right;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (true) {
|
||||||
|
if (pNode->parent == pTree->NIL || pNode == pNode->parent->right) {
|
||||||
|
pNode = pNode->parent;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
pNode = pNode->parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tRBTreeCreate(SRBTree *pTree, tRBTreeCmprFn cmprFn) {
|
||||||
|
pTree->cmprFn = cmprFn;
|
||||||
|
pTree->n = 0;
|
||||||
|
pTree->NIL = &pTree->NILNODE;
|
||||||
|
pTree->NIL->color = BLACK;
|
||||||
|
pTree->NIL->parent = NULL;
|
||||||
|
pTree->NIL->left = NULL;
|
||||||
|
pTree->NIL->right = NULL;
|
||||||
|
pTree->root = pTree->NIL;
|
||||||
|
pTree->min = pTree->NIL;
|
||||||
|
pTree->max = pTree->NIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *z) {
|
||||||
|
SRBTreeNode *y = pTree->NIL; // variable for the parent of the added node
|
||||||
|
SRBTreeNode *temp = pTree->root;
|
||||||
|
|
||||||
|
while (temp != pTree->NIL) {
|
||||||
|
y = temp;
|
||||||
|
|
||||||
|
int32_t c = pTree->cmprFn(RBTREE_NODE_PAYLOAD(z), RBTREE_NODE_PAYLOAD(temp));
|
||||||
|
if (c < 0) {
|
||||||
|
temp = temp->left;
|
||||||
|
} else if (c > 0) {
|
||||||
|
temp = temp->right;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
z->parent = y;
|
||||||
|
|
||||||
|
if (y == pTree->NIL) {
|
||||||
|
pTree->root = z;
|
||||||
|
} else if (pTree->cmprFn(RBTREE_NODE_PAYLOAD(z), RBTREE_NODE_PAYLOAD(y)) < 0) {
|
||||||
|
y->left = z;
|
||||||
|
} else {
|
||||||
|
y->right = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
z->color = RED;
|
||||||
|
z->left = pTree->NIL;
|
||||||
|
z->right = pTree->NIL;
|
||||||
|
|
||||||
|
tRBTreePutFix(pTree, z);
|
||||||
|
|
||||||
|
// update min/max node
|
||||||
|
if (pTree->min == pTree->NIL || pTree->cmprFn(RBTREE_NODE_PAYLOAD(pTree->min), RBTREE_NODE_PAYLOAD(z)) > 0) {
|
||||||
|
pTree->min = z;
|
||||||
|
}
|
||||||
|
if (pTree->max == pTree->NIL || pTree->cmprFn(RBTREE_NODE_PAYLOAD(pTree->max), RBTREE_NODE_PAYLOAD(z)) < 0) {
|
||||||
|
pTree->max = z;
|
||||||
|
}
|
||||||
|
pTree->n++;
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tRBTreeDrop(SRBTree *pTree, SRBTreeNode *z) {
|
||||||
|
SRBTreeNode *y = z;
|
||||||
|
SRBTreeNode *x;
|
||||||
|
ECOLOR y_orignal_color = y->color;
|
||||||
|
|
||||||
|
// update min/max node
|
||||||
|
if (pTree->min == z) {
|
||||||
|
pTree->min = tRBTreeSuccessor(pTree, pTree->min);
|
||||||
|
}
|
||||||
|
if (pTree->max == z) {
|
||||||
|
pTree->max = tRBTreePredecessor(pTree, pTree->max);
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop impl
|
||||||
|
if (z->left == pTree->NIL) {
|
||||||
|
x = z->right;
|
||||||
|
tRBTreeTransplant(pTree, z, z->right);
|
||||||
|
} else if (z->right == pTree->NIL) {
|
||||||
|
x = z->left;
|
||||||
|
tRBTreeTransplant(pTree, z, z->left);
|
||||||
|
} else {
|
||||||
|
y = tRBTreeSuccessor(pTree, z);
|
||||||
|
y_orignal_color = y->color;
|
||||||
|
x = y->right;
|
||||||
|
if (y->parent == z) {
|
||||||
|
x->parent = z;
|
||||||
|
} else {
|
||||||
|
tRBTreeTransplant(pTree, y, y->right);
|
||||||
|
y->right = z->right;
|
||||||
|
y->right->parent = y;
|
||||||
|
}
|
||||||
|
tRBTreeTransplant(pTree, z, y);
|
||||||
|
y->left = z->left;
|
||||||
|
y->left->parent = y;
|
||||||
|
y->color = z->color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix
|
// fix
|
||||||
SRBTreeNode *pNode = pNew;
|
if (y_orignal_color == BLACK) {
|
||||||
while (pNode->parent && pNode->parent->color == RED) {
|
tRBTreeDropFix(pTree, x);
|
||||||
SRBTreeNode *p = pNode->parent;
|
|
||||||
SRBTreeNode *g = p->parent;
|
|
||||||
|
|
||||||
if (p == g->left) {
|
|
||||||
SRBTreeNode *u = g->right;
|
|
||||||
|
|
||||||
if (RBTREE_NODE_COLOR(u) == RED) {
|
|
||||||
p->color = BLACK;
|
|
||||||
u->color = BLACK;
|
|
||||||
g->color = RED;
|
|
||||||
pNode = g;
|
|
||||||
} else {
|
|
||||||
if (pNode == p->right) {
|
|
||||||
pNode = p;
|
|
||||||
tRBTreeRotateLeft(pTree, pNode);
|
|
||||||
}
|
}
|
||||||
pNode->parent->color = BLACK;
|
pTree->n--;
|
||||||
pNode->parent->parent->color = RED;
|
|
||||||
tRBTreeRotateRight(pTree, pNode->parent->parent);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SRBTreeNode *u = g->left;
|
|
||||||
|
|
||||||
if (RBTREE_NODE_COLOR(u) == RED) {
|
|
||||||
p->color = BLACK;
|
|
||||||
u->color = BLACK;
|
|
||||||
g->color = RED;
|
|
||||||
} else {
|
|
||||||
if (pNode == p->left) {
|
|
||||||
pNode = p;
|
|
||||||
tRBTreeRotateRight(pTree, pNode);
|
|
||||||
}
|
|
||||||
pNode->parent->color = BLACK;
|
|
||||||
pNode->parent->parent->color = RED;
|
|
||||||
tRBTreeRotateLeft(pTree, pNode->parent->parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pTree->root->color = BLACK;
|
|
||||||
return pNew;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SRBTreeNode *tRBTreeDrop(SRBTree *pTree, void *pKey) {
|
SRBTreeNode *tRBTreeDropByKey(SRBTree *pTree, void *pKey) {
|
||||||
SRBTreeNode *pNode = pTree->root;
|
SRBTreeNode *pNode = tRBTreeGet(pTree, pKey);
|
||||||
|
|
||||||
while (pNode) {
|
|
||||||
int32_t c = pTree->cmprFn(pKey, pNode->payload);
|
|
||||||
|
|
||||||
if (c < 0) {
|
|
||||||
pNode = pNode->left;
|
|
||||||
} else if (c > 0) {
|
|
||||||
pNode = pNode->right;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pNode) {
|
if (pNode) {
|
||||||
// TODO
|
tRBTreeDrop(pTree, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNode;
|
return pNode;
|
||||||
|
@ -194,8 +312,8 @@ SRBTreeNode *tRBTreeDrop(SRBTree *pTree, void *pKey) {
|
||||||
SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey) {
|
SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey) {
|
||||||
SRBTreeNode *pNode = pTree->root;
|
SRBTreeNode *pNode = pTree->root;
|
||||||
|
|
||||||
while (pNode) {
|
while (pNode != pTree->NIL) {
|
||||||
int32_t c = pTree->cmprFn(pKey, pNode->payload);
|
int32_t c = pTree->cmprFn(pKey, RBTREE_NODE_PAYLOAD(pNode));
|
||||||
|
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
pNode = pNode->left;
|
pNode = pNode->left;
|
||||||
|
@ -206,5 +324,23 @@ SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNode;
|
return (pNode == pTree->NIL) ? NULL : pNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SRBTreeIter ================================================
|
||||||
|
SRBTreeNode *tRBTreeIterNext(SRBTreeIter *pIter) {
|
||||||
|
SRBTreeNode *pNode = pIter->pNode;
|
||||||
|
|
||||||
|
if (pIter->pNode != pIter->pTree->NIL) {
|
||||||
|
if (pIter->asc) {
|
||||||
|
// ascend
|
||||||
|
pIter->pNode = tRBTreeSuccessor(pIter->pTree, pIter->pNode);
|
||||||
|
} else {
|
||||||
|
// descend
|
||||||
|
pIter->pNode = tRBTreePredecessor(pIter->pTree, pIter->pNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return (pNode == pIter->pTree->NIL) ? NULL : pNode;
|
||||||
}
|
}
|
|
@ -76,3 +76,11 @@ add_test(
|
||||||
NAME taosbsearchTest
|
NAME taosbsearchTest
|
||||||
COMMAND taosbsearchTest
|
COMMAND taosbsearchTest
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# trbtreeTest
|
||||||
|
add_executable(rbtreeTest "trbtreeTest.cpp")
|
||||||
|
target_link_libraries(rbtreeTest os util gtest_main)
|
||||||
|
add_test(
|
||||||
|
NAME rbtreeTest
|
||||||
|
COMMAND rbtreeTest
|
||||||
|
)
|
|
@ -0,0 +1,40 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "trbtree.h"
|
||||||
|
|
||||||
|
static int32_t tCmprInteger(const void *p1, const void *p2) {
|
||||||
|
if (*(int *)p1 < *(int *)p2) {
|
||||||
|
return -1;
|
||||||
|
} else if (*(int *)p1 > *(int *)p2) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(trbtreeTest, rbtree_test1) {
|
||||||
|
#if 0
|
||||||
|
SRBTree rt;
|
||||||
|
tRBTreeCreate(&rt, tCmprInteger);
|
||||||
|
int a[] = {1, 3, 4, 2, 7, 5, 8};
|
||||||
|
|
||||||
|
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) {
|
||||||
|
SRBTreeNode *pNode = (SRBTreeNode *)taosMemoryMalloc(sizeof(*pNode) + sizeof(int));
|
||||||
|
*(int *)pNode->payload = a[i];
|
||||||
|
|
||||||
|
tRBTreePut(&rt, pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
SRBTreeIter rti = tRBTreeIterCreate(&rt, 1);
|
||||||
|
SRBTreeNode *pNode = tRBTreeIterNext(&rti);
|
||||||
|
int la = 0;
|
||||||
|
while (pNode) {
|
||||||
|
GTEST_ASSERT_GT(*(int *)pNode->payload, la);
|
||||||
|
la = *(int *)pNode->payload;
|
||||||
|
// printf("%d\n", la);
|
||||||
|
pNode = tRBTreeIterNext(&rti);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -128,6 +128,7 @@ if $rows != 5 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data00 != $rowNum then
|
if $data00 != $rowNum then
|
||||||
|
print expect $rowNum , actual: $data00
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data10 != $rowNum then
|
if $data10 != $rowNum then
|
||||||
|
|
|
@ -588,4 +588,38 @@ if $data00 != 5 then
|
||||||
goto loop3
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
#max,min selectivity
|
||||||
|
sql create database test3 vgroups 1;
|
||||||
|
sql use test3;
|
||||||
|
sql create stable st(ts timestamp, a int, b int , c int) tags(ta int,tb int,tc int);
|
||||||
|
sql create table ts1 using st tags(1,1,1);
|
||||||
|
sql create stream stream_t3 trigger at_once into streamtST3 as select ts, min(a) c6, a, b, c, ta, tb, tc from ts1 interval(10s) ;
|
||||||
|
|
||||||
|
sql insert into ts1 values(1648791211000,1,2,3);
|
||||||
|
sleep 50
|
||||||
|
sql insert into ts1 values(1648791222001,2,2,3);
|
||||||
|
sleep 50
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop3:
|
||||||
|
sql select * from streamtST3;
|
||||||
|
|
||||||
|
sleep 300
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
# row 0
|
||||||
|
if $data02 != 1 then
|
||||||
|
print =====data02=$data02
|
||||||
|
goto loop3
|
||||||
|
endi
|
||||||
|
|
||||||
|
# row 1
|
||||||
|
if $data12 != 2 then
|
||||||
|
print =====data12=$data12
|
||||||
|
goto loop3
|
||||||
|
endi
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
|
@ -198,7 +198,7 @@ endi
|
||||||
sql select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5, avg(d) from st interval(10s);
|
sql select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5, avg(d) from st interval(10s);
|
||||||
|
|
||||||
|
|
||||||
sql create database test1 vgroups 1;
|
sql create database test1 vgroups 4;
|
||||||
sql use test1;
|
sql use test1;
|
||||||
sql create stable st(ts timestamp, a int, b int , c int) tags(ta int,tb int,tc int);
|
sql create stable st(ts timestamp, a int, b int , c int) tags(ta int,tb int,tc int);
|
||||||
sql create table ts1 using st tags(1,1,1);
|
sql create table ts1 using st tags(1,1,1);
|
||||||
|
@ -232,4 +232,43 @@ if $data11 != 2 then
|
||||||
goto loop2
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
#max,min selectivity
|
||||||
|
sql create database test3 vgroups 4;
|
||||||
|
sql use test3;
|
||||||
|
sql create stable st(ts timestamp, a int, b int , c int) tags(ta int,tb int,tc int);
|
||||||
|
sql create table ts1 using st tags(1,1,1);
|
||||||
|
sql create table ts2 using st tags(2,2,2);
|
||||||
|
sql create stream stream_t3 trigger at_once into streamtST3 as select ts, min(a) c6, a, b, c, ta, tb, tc from st interval(10s) ;
|
||||||
|
|
||||||
|
sql insert into ts1 values(1648791211000,1,2,3);
|
||||||
|
sleep 50
|
||||||
|
sql insert into ts1 values(1648791222001,2,2,3);
|
||||||
|
sleep 50
|
||||||
|
sql insert into ts2 values(1648791211000,1,2,3);
|
||||||
|
sleep 50
|
||||||
|
sql insert into ts2 values(1648791222001,2,2,3);
|
||||||
|
sleep 50
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop3:
|
||||||
|
sql select * from streamtST3;
|
||||||
|
|
||||||
|
sleep 300
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
# row 0
|
||||||
|
if $data02 != 1 then
|
||||||
|
print =====data02=$data02
|
||||||
|
goto loop3
|
||||||
|
endi
|
||||||
|
|
||||||
|
# row 1
|
||||||
|
if $data12 != 2 then
|
||||||
|
print =====data12=$data12
|
||||||
|
goto loop3
|
||||||
|
endi
|
||||||
|
|
||||||
system sh/stop_dnodes.sh
|
system sh/stop_dnodes.sh
|
||||||
|
|
|
@ -24,7 +24,7 @@ sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop0:
|
loop0:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -48,7 +48,7 @@ sql insert into t1 values(1648791213000,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop1:
|
loop1:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -71,7 +71,7 @@ sql insert into t1 values(1648791213000,2,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop2:
|
loop2:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -97,7 +97,7 @@ sql insert into t1 values(1648791213002,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop3:
|
loop3:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -134,7 +134,7 @@ sql insert into t1 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (16
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop4:
|
loop4:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -208,7 +208,7 @@ sql insert into t1 values(1648791213001,1,2,3,2.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop5:
|
loop5:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt1 order by c1, c4, c2, c3;
|
sql select * from streamt1 order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -229,7 +229,7 @@ sql insert into t1 values(1648791213001,1,1,6,2.0) (1648791223002,1,1,7,2.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop6:
|
loop6:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from streamt1 order by c1, c4, c2, c3;
|
sql select * from streamt1 order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -294,7 +294,7 @@ sql insert into t2 values(1648791213000,NULL,NULL,NULL,NULL);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop7:
|
loop7:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -318,7 +318,7 @@ sql insert into t2 values(1648791213000,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop8:
|
loop8:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -342,7 +342,7 @@ sql insert into t2 values(1648791213000,2,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop9:
|
loop9:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -372,7 +372,7 @@ sql insert into t2 values(1648791213002,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop10:
|
loop10:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -414,7 +414,7 @@ sql insert into t2 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (16
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop11:
|
loop11:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -492,7 +492,7 @@ sql insert into t4 values(1648791213000,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop13:
|
loop13:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt4 order by c1, c2, c3;
|
sql select * from test.streamt4 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
@ -534,7 +534,7 @@ sql insert into t1 values(1648791213000,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop14:
|
loop14:
|
||||||
sleep 100
|
sleep 50
|
||||||
sql select * from test.streamt4 order by c1, c2, c3;
|
sql select * from test.streamt4 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
|
|
|
@ -24,11 +24,11 @@ sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop0:
|
loop0:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -45,12 +45,14 @@ endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop1:
|
loop1:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -66,12 +68,14 @@ endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,2,2,3,1.0);
|
sql insert into t1 values(1648791213000,2,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop2:
|
loop2:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -90,12 +94,14 @@ sql insert into t1 values(1648791213001,2,2,3,1.0);
|
||||||
sql insert into t1 values(1648791213002,2,2,3,1.0);
|
sql insert into t1 values(1648791213002,2,2,3,1.0);
|
||||||
sql insert into t1 values(1648791213002,1,2,3,1.0);
|
sql insert into t1 values(1648791213002,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop3:
|
loop3:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -125,12 +131,14 @@ sql insert into t1 values(1648791223002,3,2,3,1.0);
|
||||||
sql insert into t1 values(1648791223003,3,2,3,1.0);
|
sql insert into t1 values(1648791223003,3,2,3,1.0);
|
||||||
sql insert into t1 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0);
|
sql insert into t1 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop4:
|
loop4:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -199,11 +207,11 @@ sql insert into t1 values(1648791213001,1,2,3,2.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop5:
|
loop5:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt1 order by c1, c4, c2, c3;
|
sql select * from streamt1 order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -217,12 +225,14 @@ sql insert into t1 values(1648791223001,1,2,5,2.0);
|
||||||
sql insert into t1 values(1648791223002,1,2,5,2.0);
|
sql insert into t1 values(1648791223002,1,2,5,2.0);
|
||||||
sql insert into t1 values(1648791213001,1,1,6,2.0) (1648791223002,1,1,7,2.0);
|
sql insert into t1 values(1648791213001,1,1,6,2.0) (1648791223002,1,1,7,2.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop6:
|
loop6:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from streamt1 order by c1, c4, c2, c3;
|
sql select * from streamt1 order by c1, c4, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -282,11 +292,11 @@ sql insert into t2 values(1648791213000,NULL,NULL,NULL,NULL);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop7:
|
loop7:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -303,12 +313,14 @@ endi
|
||||||
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
||||||
sql insert into t2 values(1648791213000,1,2,3,1.0);
|
sql insert into t2 values(1648791213000,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop8:
|
loop8:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -324,12 +336,15 @@ endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,2,2,3,1.0);
|
sql insert into t1 values(1648791213000,2,2,3,1.0);
|
||||||
sql insert into t2 values(1648791213000,2,2,3,1.0);
|
sql insert into t2 values(1648791213000,2,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop9:
|
loop9:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -352,12 +367,14 @@ sql insert into t2 values(1648791213001,2,2,3,1.0);
|
||||||
sql insert into t2 values(1648791213002,2,2,3,1.0);
|
sql insert into t2 values(1648791213002,2,2,3,1.0);
|
||||||
sql insert into t2 values(1648791213002,1,2,3,1.0);
|
sql insert into t2 values(1648791213002,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop10:
|
loop10:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -373,7 +390,7 @@ endi
|
||||||
|
|
||||||
if $data11 != 2 thenloop4
|
if $data11 != 2 thenloop4
|
||||||
print =====data11=$data11
|
print =====data11=$data11
|
||||||
goto loop3
|
goto loop10
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 1 then
|
if $data12 != 1 then
|
||||||
|
@ -392,12 +409,14 @@ sql insert into t2 values(1648791223002,3,2,3,1.0);
|
||||||
sql insert into t2 values(1648791223003,3,2,3,1.0);
|
sql insert into t2 values(1648791223003,3,2,3,1.0);
|
||||||
sql insert into t2 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0);
|
sql insert into t2 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop11:
|
loop11:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt2 order by c1, c2, c3;
|
sql select * from test.streamt2 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -470,17 +489,17 @@ sql insert into t4 values(1648791213000,1,2,3,1.0);
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop13:
|
loop13:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt4 order by c1, c2, c3;
|
sql select * from test.streamt4 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $rows != 2 then
|
if $rows != 2 then
|
||||||
print =====rows=$rows
|
print =====rows=$rows
|
||||||
goto loop14
|
goto loop13
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != 1 then
|
if $data01 != 1 then
|
||||||
|
@ -495,12 +514,12 @@ endi
|
||||||
|
|
||||||
if $data11 != 3 then
|
if $data11 != 3 then
|
||||||
print =====data11=$data11
|
print =====data11=$data11
|
||||||
goto loop11
|
goto loop13
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 2 then
|
if $data12 != 2 then
|
||||||
print =====data12=$data12
|
print =====data12=$data12
|
||||||
goto loop11
|
goto loop13
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t4 values(1648791213000,2,2,3,1.0);
|
sql insert into t4 values(1648791213000,2,2,3,1.0);
|
||||||
|
@ -509,12 +528,14 @@ sql insert into t1 values(1648791233000,2,2,3,1.0);
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop14:
|
loop14:
|
||||||
sleep 300
|
sleep 50
|
||||||
sql select * from test.streamt4 order by c1, c2, c3;
|
sql select * from test.streamt4 order by c1, c2, c3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,1,1,3,1.0);
|
sql insert into t1 values(1648791213000,1,1,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop1:
|
loop1:
|
||||||
sleep 300
|
sleep 300
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
@ -61,6 +63,8 @@ endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,2,1,3,1.0);
|
sql insert into t1 values(1648791213000,2,1,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop2:
|
loop2:
|
||||||
sleep 300
|
sleep 300
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
@ -85,6 +89,8 @@ sql insert into t1 values(1648791213001,2,1,3,1.0);
|
||||||
sql insert into t1 values(1648791213002,2,1,3,1.0);
|
sql insert into t1 values(1648791213002,2,1,3,1.0);
|
||||||
sql insert into t1 values(1648791213002,1,1,3,1.0);
|
sql insert into t1 values(1648791213002,1,1,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop3:
|
loop3:
|
||||||
sleep 300
|
sleep 300
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
@ -120,6 +126,8 @@ sql insert into t1 values(1648791223002,3,2,3,1.0);
|
||||||
sql insert into t1 values(1648791223003,3,2,3,1.0);
|
sql insert into t1 values(1648791223003,3,2,3,1.0);
|
||||||
sql insert into t1 values(1648791213001,1,1,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0);
|
sql insert into t1 values(1648791213001,1,1,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop4:
|
loop4:
|
||||||
sleep 300
|
sleep 300
|
||||||
sql select * from streamt order by c1, c4, c2, c3;
|
sql select * from streamt order by c1, c4, c2, c3;
|
||||||
|
@ -212,6 +220,8 @@ sql insert into t1 values(1648791223001,1,2,2,5);
|
||||||
sql insert into t1 values(1648791223002,1,2,2,6);
|
sql insert into t1 values(1648791223002,1,2,2,6);
|
||||||
sql insert into t1 values(1648791213001,1,1,1,7) (1648791223002,1,1,2,8);
|
sql insert into t1 values(1648791213001,1,1,1,7) (1648791223002,1,1,2,8);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
loop6:
|
loop6:
|
||||||
sleep 300
|
sleep 300
|
||||||
sql select * from streamt1 order by c1, c4, c2, c3;
|
sql select * from streamt1 order by c1, c4, c2, c3;
|
||||||
|
|
|
@ -156,8 +156,8 @@ python3 ./test.py -f 2-query/sin.py
|
||||||
python3 ./test.py -f 2-query/sin.py -R
|
python3 ./test.py -f 2-query/sin.py -R
|
||||||
python3 ./test.py -f 2-query/smaTest.py
|
python3 ./test.py -f 2-query/smaTest.py
|
||||||
python3 ./test.py -f 2-query/smaTest.py -R
|
python3 ./test.py -f 2-query/smaTest.py -R
|
||||||
python3 ./test.py -f 2-query/sml.py
|
#python3 ./test.py -f 2-query/sml.py
|
||||||
python3 ./test.py -f 2-query/sml.py -R
|
#python3 ./test.py -f 2-query/sml.py -R
|
||||||
python3 ./test.py -f 2-query/spread.py
|
python3 ./test.py -f 2-query/spread.py
|
||||||
python3 ./test.py -f 2-query/spread.py -R
|
python3 ./test.py -f 2-query/spread.py -R
|
||||||
python3 ./test.py -f 2-query/sqrt.py
|
python3 ./test.py -f 2-query/sqrt.py
|
||||||
|
@ -512,6 +512,6 @@ python3 ./test.py -f 2-query/count_partition.py -Q 3
|
||||||
python3 ./test.py -f 2-query/max_partition.py -Q 3
|
python3 ./test.py -f 2-query/max_partition.py -Q 3
|
||||||
python3 ./test.py -f 2-query/last_row.py -Q 3
|
python3 ./test.py -f 2-query/last_row.py -Q 3
|
||||||
python3 ./test.py -f 2-query/tsbsQuery.py -Q 3
|
python3 ./test.py -f 2-query/tsbsQuery.py -Q 3
|
||||||
python3 ./test.py -f 2-query/sml.py -Q 3
|
#python3 ./test.py -f 2-query/sml.py -Q 3
|
||||||
python3 ./test.py -f 2-query/interp.py -Q 3
|
python3 ./test.py -f 2-query/interp.py -Q 3
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ int smlProcess_telnet_Test() {
|
||||||
int smlProcess_json1_Test() {
|
int smlProcess_json1_Test() {
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
|
||||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(taos, "use sml_db");
|
pRes = taos_query(taos, "use sml_db");
|
||||||
|
@ -112,7 +112,7 @@ int smlProcess_json1_Test() {
|
||||||
" },"
|
" },"
|
||||||
" {"
|
" {"
|
||||||
" \"metric\": \"sys.cpu.nice\","
|
" \"metric\": \"sys.cpu.nice\","
|
||||||
" \"timestamp\": 1346846400,"
|
" \"timestamp\": 1662344042,"
|
||||||
" \"value\": 9,"
|
" \"value\": 9,"
|
||||||
" \"tags\": {"
|
" \"tags\": {"
|
||||||
" \"host\": \"web02\","
|
" \"host\": \"web02\","
|
||||||
|
@ -141,7 +141,7 @@ int smlProcess_json2_Test() {
|
||||||
"{"
|
"{"
|
||||||
" \"metric\": \"meter_current0\","
|
" \"metric\": \"meter_current0\","
|
||||||
" \"timestamp\": {"
|
" \"timestamp\": {"
|
||||||
" \"value\" : 1346846400,"
|
" \"value\" : 1662344042,"
|
||||||
" \"type\" : \"s\""
|
" \"type\" : \"s\""
|
||||||
" },"
|
" },"
|
||||||
" \"value\": {"
|
" \"value\": {"
|
||||||
|
@ -181,7 +181,7 @@ int smlProcess_json3_Test() {
|
||||||
"{"
|
"{"
|
||||||
" \"metric\": \"meter_current1\","
|
" \"metric\": \"meter_current1\","
|
||||||
" \"timestamp\": {"
|
" \"timestamp\": {"
|
||||||
" \"value\" : 1346846400,"
|
" \"value\" : 1662344042,"
|
||||||
" \"type\" : \"s\""
|
" \"type\" : \"s\""
|
||||||
" },"
|
" },"
|
||||||
" \"value\": {"
|
" \"value\": {"
|
||||||
|
@ -249,7 +249,7 @@ int smlProcess_json4_Test() {
|
||||||
"{"
|
"{"
|
||||||
" \"metric\": \"meter_current2\","
|
" \"metric\": \"meter_current2\","
|
||||||
" \"timestamp\": {"
|
" \"timestamp\": {"
|
||||||
" \"value\" : 1346846500000,"
|
" \"value\" : 1662344042000,"
|
||||||
" \"type\" : \"ms\""
|
" \"type\" : \"ms\""
|
||||||
" },"
|
" },"
|
||||||
" \"value\": \"ni\","
|
" \"value\": \"ni\","
|
||||||
|
|
Loading…
Reference in New Issue