Merge branch 'feature/compressData' of https://github.com/taosdata/TDengine into feature/compressData
This commit is contained in:
commit
bdbe9b042c
|
@ -19,6 +19,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "talgo.h"
|
#include "talgo.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
#include "tbuffer.h"
|
||||||
#include "tencode.h"
|
#include "tencode.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
@ -27,10 +28,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct SBuffer SBuffer;
|
|
||||||
typedef struct SSchema SSchema;
|
typedef struct SSchema SSchema;
|
||||||
typedef struct SSchemaExt SSchemaExt;
|
|
||||||
typedef struct SSchema2 SSchema2;
|
typedef struct SSchema2 SSchema2;
|
||||||
|
typedef struct SSchemaExt SSchemaExt;
|
||||||
typedef struct STColumn STColumn;
|
typedef struct STColumn STColumn;
|
||||||
typedef struct STSchema STSchema;
|
typedef struct STSchema STSchema;
|
||||||
typedef struct SValue SValue;
|
typedef struct SValue SValue;
|
||||||
|
@ -41,6 +41,9 @@ typedef struct STagVal STagVal;
|
||||||
typedef struct STag STag;
|
typedef struct STag STag;
|
||||||
typedef struct SColData SColData;
|
typedef struct SColData SColData;
|
||||||
|
|
||||||
|
typedef struct SRowKey SRowKey;
|
||||||
|
typedef struct SValueColumn SValueColumn;
|
||||||
|
|
||||||
#define HAS_NONE ((uint8_t)0x1)
|
#define HAS_NONE ((uint8_t)0x1)
|
||||||
#define HAS_NULL ((uint8_t)0x2)
|
#define HAS_NULL ((uint8_t)0x2)
|
||||||
#define HAS_VALUE ((uint8_t)0x4)
|
#define HAS_VALUE ((uint8_t)0x4)
|
||||||
|
@ -79,32 +82,42 @@ const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b001111
|
||||||
} while (0)
|
} while (0)
|
||||||
#define GET_BIT2(p, i) (((p)[DIV_4(i)] >> MOD_4_TIME_2(i)) & THREE)
|
#define GET_BIT2(p, i) (((p)[DIV_4(i)] >> MOD_4_TIME_2(i)) & THREE)
|
||||||
|
|
||||||
// SBuffer ================================
|
|
||||||
struct SBuffer {
|
|
||||||
int64_t nBuf;
|
|
||||||
uint8_t *pBuf;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define tBufferCreate() \
|
|
||||||
(SBuffer) { .nBuf = 0, .pBuf = NULL }
|
|
||||||
void tBufferDestroy(SBuffer *pBuffer);
|
|
||||||
int32_t tBufferInit(SBuffer *pBuffer, int64_t size);
|
|
||||||
int32_t tBufferPut(SBuffer *pBuffer, const void *pData, int64_t nData);
|
|
||||||
int32_t tBufferReserve(SBuffer *pBuffer, int64_t nData, void **ppData);
|
|
||||||
|
|
||||||
// SColVal ================================
|
// SColVal ================================
|
||||||
#define CV_FLAG_VALUE ((int8_t)0x0)
|
#define CV_FLAG_VALUE ((int8_t)0x0)
|
||||||
#define CV_FLAG_NONE ((int8_t)0x1)
|
#define CV_FLAG_NONE ((int8_t)0x1)
|
||||||
#define CV_FLAG_NULL ((int8_t)0x2)
|
#define CV_FLAG_NULL ((int8_t)0x2)
|
||||||
|
|
||||||
#define COL_VAL_NONE(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .flag = CV_FLAG_NONE})
|
#define COL_VAL_NONE(CID, TYPE) ((SColVal){.cid = (CID), .flag = CV_FLAG_NONE, .value = {.type = (TYPE)}})
|
||||||
#define COL_VAL_NULL(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .flag = CV_FLAG_NULL})
|
#define COL_VAL_NULL(CID, TYPE) ((SColVal){.cid = (CID), .flag = CV_FLAG_NULL, .value = {.type = (TYPE)}})
|
||||||
#define COL_VAL_VALUE(CID, TYPE, V) ((SColVal){.cid = (CID), .type = (TYPE), .value = (V)})
|
#define COL_VAL_VALUE(CID, V) ((SColVal){.cid = (CID), .flag = CV_FLAG_VALUE, .value = (V)})
|
||||||
|
|
||||||
#define COL_VAL_IS_NONE(CV) ((CV)->flag == CV_FLAG_NONE)
|
#define COL_VAL_IS_NONE(CV) ((CV)->flag == CV_FLAG_NONE)
|
||||||
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
|
#define COL_VAL_IS_NULL(CV) ((CV)->flag == CV_FLAG_NULL)
|
||||||
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
|
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
|
||||||
|
|
||||||
|
// SValueColumn ================================
|
||||||
|
typedef struct {
|
||||||
|
int8_t cmprAlg; // filled by caller
|
||||||
|
int8_t type;
|
||||||
|
int32_t dataOriginalSize;
|
||||||
|
int32_t dataCompressedSize;
|
||||||
|
int32_t offsetOriginalSize;
|
||||||
|
int32_t offsetCompressedSize;
|
||||||
|
} SValueColumnCompressInfo;
|
||||||
|
|
||||||
|
int32_t tValueColumnInit(SValueColumn *valCol);
|
||||||
|
int32_t tValueColumnDestroy(SValueColumn *valCol);
|
||||||
|
int32_t tValueColumnClear(SValueColumn *valCol);
|
||||||
|
int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value);
|
||||||
|
int32_t tValueColumnUpdate(SValueColumn *valCol, int32_t idx, const SValue *value);
|
||||||
|
int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value);
|
||||||
|
int32_t tValueColumnCompress(SValueColumn *valCol, SValueColumnCompressInfo *info, SBuffer *output, SBuffer *assist);
|
||||||
|
int32_t tValueColumnDecompress(void *input, const SValueColumnCompressInfo *compressInfo, SValueColumn *valCol,
|
||||||
|
SBuffer *buffer);
|
||||||
|
int32_t tValueColumnCompressInfoEncode(const SValueColumnCompressInfo *compressInfo, SBuffer *buffer);
|
||||||
|
int32_t tValueColumnCompressInfoDecode(SBufferReader *reader, SValueColumnCompressInfo *compressInfo);
|
||||||
|
int32_t tValueCompare(const SValue *tv1, const SValue *tv2);
|
||||||
|
|
||||||
// SRow ================================
|
// SRow ================================
|
||||||
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
||||||
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||||
|
@ -112,6 +125,8 @@ void tRowDestroy(SRow *pRow);
|
||||||
int32_t tRowSort(SArray *aRowP);
|
int32_t tRowSort(SArray *aRowP);
|
||||||
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
|
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
|
||||||
int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag);
|
int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag);
|
||||||
|
void tRowGetKey(SRow *pRow, SRowKey *key);
|
||||||
|
int32_t tRowKeyCompare(const void *p1, const void *p2);
|
||||||
|
|
||||||
// SRowIter ================================
|
// SRowIter ================================
|
||||||
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
|
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
|
||||||
|
@ -133,9 +148,25 @@ void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remov
|
||||||
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf);
|
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf);
|
||||||
|
|
||||||
// SColData ================================
|
// SColData ================================
|
||||||
|
typedef struct {
|
||||||
|
int8_t cmprAlg; // filled by caller
|
||||||
|
int8_t columnFlag;
|
||||||
|
int8_t flag;
|
||||||
|
int8_t dataType;
|
||||||
|
int16_t columnId;
|
||||||
|
int32_t numOfData;
|
||||||
|
int32_t bitmapOriginalSize;
|
||||||
|
int32_t bitmapCompressedSize;
|
||||||
|
int32_t offsetOriginalSize;
|
||||||
|
int32_t offsetCompressedSize;
|
||||||
|
int32_t dataOriginalSize;
|
||||||
|
int32_t dataCompressedSize;
|
||||||
|
} SColDataCompressInfo;
|
||||||
|
|
||||||
typedef void *(*xMallocFn)(void *, int32_t);
|
typedef void *(*xMallocFn)(void *, int32_t);
|
||||||
|
|
||||||
void tColDataDestroy(void *ph);
|
void tColDataDestroy(void *ph);
|
||||||
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn);
|
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t cflag);
|
||||||
void tColDataClear(SColData *pColData);
|
void tColDataClear(SColData *pColData);
|
||||||
void tColDataDeepClear(SColData *pColData);
|
void tColDataDeepClear(SColData *pColData);
|
||||||
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
|
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
|
||||||
|
@ -143,8 +174,12 @@ int32_t tColDataUpdateValue(SColData *pColData, SColVal *pColVal, bool forward);
|
||||||
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
|
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
|
||||||
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
|
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
|
||||||
int32_t tColDataCopy(SColData *pColDataFrom, SColData *pColData, xMallocFn xMalloc, void *arg);
|
int32_t tColDataCopy(SColData *pColDataFrom, SColData *pColData, xMallocFn xMalloc, void *arg);
|
||||||
|
|
||||||
extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull);
|
extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull);
|
||||||
|
|
||||||
|
int32_t tColDataCompress(SColData *colData, SColDataCompressInfo *info, SBuffer *output, SBuffer *assist);
|
||||||
|
int32_t tColDataDecompress(void *input, SColDataCompressInfo *info, SColData *colData, SBuffer *assist);
|
||||||
|
|
||||||
// for stmt bind
|
// for stmt bind
|
||||||
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen);
|
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen);
|
||||||
void tColDataSortMerge(SArray *colDataArr);
|
void tColDataSortMerge(SArray *colDataArr);
|
||||||
|
@ -173,28 +208,47 @@ struct STSchema {
|
||||||
STColumn columns[];
|
STColumn columns[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1. Tuple format:
|
||||||
|
* SRow + [(type, offset) * numOfPKs +] [bit map +] fix-length data + [var-length data]
|
||||||
|
*
|
||||||
|
* 2. K-V format:
|
||||||
|
* SRow + [(type, offset) * numOfPKs +] offset array + ([-]cid [+ data]) * numColsNotNone
|
||||||
|
*/
|
||||||
struct SRow {
|
struct SRow {
|
||||||
uint8_t flag;
|
uint8_t flag;
|
||||||
uint8_t rsv;
|
uint8_t numOfPKs;
|
||||||
uint16_t sver;
|
uint16_t sver;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
TSKEY ts;
|
TSKEY ts;
|
||||||
uint8_t data[];
|
uint8_t data[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int8_t type;
|
||||||
|
uint32_t offset;
|
||||||
|
} SPrimaryKeyIndex;
|
||||||
|
|
||||||
struct SValue {
|
struct SValue {
|
||||||
|
int8_t type;
|
||||||
union {
|
union {
|
||||||
int64_t val;
|
int64_t val;
|
||||||
struct {
|
struct {
|
||||||
uint32_t nData;
|
|
||||||
uint8_t *pData;
|
uint8_t *pData;
|
||||||
|
uint32_t nData;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define TD_MAX_PK_COLS 2
|
||||||
|
struct SRowKey {
|
||||||
|
TSKEY ts;
|
||||||
|
uint8_t numOfPKs;
|
||||||
|
SValue pks[TD_MAX_PK_COLS];
|
||||||
|
};
|
||||||
|
|
||||||
struct SColVal {
|
struct SColVal {
|
||||||
int16_t cid;
|
int16_t cid;
|
||||||
int8_t type;
|
|
||||||
int8_t flag;
|
int8_t flag;
|
||||||
SValue value;
|
SValue value;
|
||||||
};
|
};
|
||||||
|
@ -202,7 +256,7 @@ struct SColVal {
|
||||||
struct SColData {
|
struct SColData {
|
||||||
int16_t cid;
|
int16_t cid;
|
||||||
int8_t type;
|
int8_t type;
|
||||||
int8_t smaOn;
|
int8_t cflag;
|
||||||
int32_t numOfNone; // # of none
|
int32_t numOfNone; // # of none
|
||||||
int32_t numOfNull; // # of null
|
int32_t numOfNull; // # of null
|
||||||
int32_t numOfValue; // # of vale
|
int32_t numOfValue; // # of vale
|
||||||
|
@ -274,6 +328,36 @@ STSchema *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version);
|
||||||
pTSchema = NULL; \
|
pTSchema = NULL; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
const STColumn *tTSchemaSearchColumn(const STSchema *pTSchema, int16_t cid);
|
||||||
|
|
||||||
|
struct SValueColumn {
|
||||||
|
int8_t type;
|
||||||
|
uint32_t numOfValues;
|
||||||
|
SBuffer data;
|
||||||
|
SBuffer offsets;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int8_t dataType; // filled by caller
|
||||||
|
int8_t cmprAlg; // filled by caller
|
||||||
|
int32_t originalSize; // filled by caller
|
||||||
|
int32_t compressedSize;
|
||||||
|
} SCompressInfo;
|
||||||
|
|
||||||
|
int32_t tCompressData(void *input, // input
|
||||||
|
SCompressInfo *info, // compress info
|
||||||
|
void *output, // output
|
||||||
|
int32_t outputSize, // output size
|
||||||
|
SBuffer *buffer // assistant buffer provided by caller, can be NULL
|
||||||
|
);
|
||||||
|
int32_t tDecompressData(void *input, // input
|
||||||
|
const SCompressInfo *info, // compress info
|
||||||
|
void *output, // output
|
||||||
|
int32_t outputSize, // output size
|
||||||
|
SBuffer *buffer // assistant buffer provided by caller, can be NULL
|
||||||
|
);
|
||||||
|
int32_t tCompressDataToBuffer(void *input, SCompressInfo *info, SBuffer *output, SBuffer *assist);
|
||||||
|
int32_t tDecompressDataToBuffer(void *input, SCompressInfo *info, SBuffer *output, SBuffer *assist);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -622,6 +622,7 @@ void tFreeSSubmitRsp(SSubmitRsp* pRsp);
|
||||||
|
|
||||||
#define COL_SMA_ON ((int8_t)0x1)
|
#define COL_SMA_ON ((int8_t)0x1)
|
||||||
#define COL_IDX_ON ((int8_t)0x2)
|
#define COL_IDX_ON ((int8_t)0x2)
|
||||||
|
#define COL_IS_KEY ((int8_t)0x4)
|
||||||
#define COL_SET_NULL ((int8_t)0x10)
|
#define COL_SET_NULL ((int8_t)0x10)
|
||||||
#define COL_SET_VAL ((int8_t)0x20)
|
#define COL_SET_VAL ((int8_t)0x20)
|
||||||
#define COL_IS_SYSINFO ((int8_t)0x40)
|
#define COL_IS_SYSINFO ((int8_t)0x40)
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#ifndef _TD_COMMON_TOKEN_H_
|
#ifndef _TD_COMMON_TOKEN_H_
|
||||||
#define _TD_COMMON_TOKEN_H_
|
#define _TD_COMMON_TOKEN_H_
|
||||||
|
|
||||||
|
|
||||||
#define TK_OR 1
|
#define TK_OR 1
|
||||||
#define TK_AND 2
|
#define TK_AND 2
|
||||||
#define TK_UNION 3
|
#define TK_UNION 3
|
||||||
|
@ -367,9 +366,10 @@
|
||||||
#define TK_VALUES 348
|
#define TK_VALUES 348
|
||||||
#define TK_VARIABLE 349
|
#define TK_VARIABLE 349
|
||||||
#define TK_WAL 350
|
#define TK_WAL 350
|
||||||
#define TK_ENCODE 351
|
#define TK_PRIMARY 351
|
||||||
#define TK_COMPRESS 352
|
#define TK_ENCODE 352
|
||||||
#define TK_LEVEL 353
|
#define TK_COMPRESS 353
|
||||||
|
#define TK_LEVEL 354
|
||||||
|
|
||||||
#define TK_NK_SPACE 600
|
#define TK_NK_SPACE 600
|
||||||
#define TK_NK_COMMENT 601
|
#define TK_NK_COMMENT 601
|
||||||
|
|
|
@ -171,6 +171,7 @@ typedef struct SColumnOptions {
|
||||||
char encode[TSDB_CL_COMPRESS_OPTION_LEN];
|
char encode[TSDB_CL_COMPRESS_OPTION_LEN];
|
||||||
char compress[TSDB_CL_COMPRESS_OPTION_LEN];
|
char compress[TSDB_CL_COMPRESS_OPTION_LEN];
|
||||||
char compressLevel[TSDB_CL_COMPRESS_OPTION_LEN];
|
char compressLevel[TSDB_CL_COMPRESS_OPTION_LEN];
|
||||||
|
bool bPrimaryKey;
|
||||||
} SColumnOptions;
|
} SColumnOptions;
|
||||||
typedef struct SColumnDefNode {
|
typedef struct SColumnDefNode {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
|
@ -179,6 +180,7 @@ typedef struct SColumnDefNode {
|
||||||
char comments[TSDB_TB_COMMENT_LEN];
|
char comments[TSDB_TB_COMMENT_LEN];
|
||||||
SColumnOptions* pOptions;
|
SColumnOptions* pOptions;
|
||||||
bool sma;
|
bool sma;
|
||||||
|
bool is_pk;
|
||||||
} SColumnDefNode;
|
} SColumnDefNode;
|
||||||
|
|
||||||
typedef struct SCreateTableStmt {
|
typedef struct SCreateTableStmt {
|
||||||
|
|
|
@ -761,6 +761,8 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE TAOS_DEF_ERROR_CODE(0, 0x266E)
|
#define TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE TAOS_DEF_ERROR_CODE(0, 0x266E)
|
||||||
#define TSDB_CODE_PAR_ORDERBY_AMBIGUOUS TAOS_DEF_ERROR_CODE(0, 0x266F)
|
#define TSDB_CODE_PAR_ORDERBY_AMBIGUOUS TAOS_DEF_ERROR_CODE(0, 0x266F)
|
||||||
#define TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT TAOS_DEF_ERROR_CODE(0, 0x2670)
|
#define TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT TAOS_DEF_ERROR_CODE(0, 0x2670)
|
||||||
|
#define TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY TAOS_DEF_ERROR_CODE(0, 0x2671)
|
||||||
|
#define TSDB_CODE_PAR_SECOND_COL_PK TAOS_DEF_ERROR_CODE(0, 0x2672)
|
||||||
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x26FF)
|
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x26FF)
|
||||||
|
|
||||||
//planner
|
//planner
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* 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 "os.h"
|
||||||
|
|
||||||
|
#ifndef __TD_BUFFER_H__
|
||||||
|
#define __TD_BUFFER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct SBuffer SBuffer;
|
||||||
|
typedef struct SBufferReader SBufferReader;
|
||||||
|
|
||||||
|
// SBuffer
|
||||||
|
#define BUFFER_INITIALIZER ((SBuffer){0, 0, NULL})
|
||||||
|
static int32_t tBufferInit(SBuffer *buffer);
|
||||||
|
static int32_t tBufferDestroy(SBuffer *buffer);
|
||||||
|
static int32_t tBufferClear(SBuffer *buffer);
|
||||||
|
static int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capacity);
|
||||||
|
static int32_t tBufferPut(SBuffer *buffer, const void *data, uint32_t size);
|
||||||
|
static int32_t tBufferPutAt(SBuffer *buffer, uint32_t offset, const void *data, uint32_t size);
|
||||||
|
static int32_t tBufferPutI8(SBuffer *buffer, int8_t value);
|
||||||
|
static int32_t tBufferPutI16(SBuffer *buffer, int16_t value);
|
||||||
|
static int32_t tBufferPutI32(SBuffer *buffer, int32_t value);
|
||||||
|
static int32_t tBufferPutI64(SBuffer *buffer, int64_t value);
|
||||||
|
static int32_t tBufferPutU8(SBuffer *buffer, uint8_t value);
|
||||||
|
static int32_t tBufferPutU16(SBuffer *buffer, uint16_t value);
|
||||||
|
static int32_t tBufferPutU32(SBuffer *buffer, uint32_t value);
|
||||||
|
static int32_t tBufferPutU64(SBuffer *buffer, uint64_t value);
|
||||||
|
static int32_t tBufferPutI16v(SBuffer *buffer, int16_t value);
|
||||||
|
static int32_t tBufferPutI32v(SBuffer *buffer, int32_t value);
|
||||||
|
static int32_t tBufferPutI64v(SBuffer *buffer, int64_t value);
|
||||||
|
static int32_t tBufferPutU16v(SBuffer *buffer, uint16_t value);
|
||||||
|
static int32_t tBufferPutU32v(SBuffer *buffer, uint32_t value);
|
||||||
|
static int32_t tBufferPutU64v(SBuffer *buffer, uint64_t value);
|
||||||
|
static int32_t tBufferPutBinary(SBuffer *buffer, const void *data, uint32_t size);
|
||||||
|
static int32_t tBufferPutCStr(SBuffer *buffer, const char *str);
|
||||||
|
static int32_t tBufferPutF32(SBuffer *buffer, float value);
|
||||||
|
static int32_t tBufferPutF64(SBuffer *buffer, double value);
|
||||||
|
|
||||||
|
#define tBufferGetSize(buffer) ((buffer)->size)
|
||||||
|
#define tBufferGetCapacity(buffer) ((buffer)->capacity)
|
||||||
|
#define tBufferGetData(buffer) ((buffer)->data)
|
||||||
|
#define tBufferGetDataAt(buffer, offset) ((char *)(buffer)->data + (offset))
|
||||||
|
#define tBufferGetDataEnd(buffer) ((char *)(buffer)->data + (buffer)->size)
|
||||||
|
|
||||||
|
// SBufferReader
|
||||||
|
#define BUFFER_READER_INITIALIZER(offset, buffer) ((SBufferReader){offset, buffer})
|
||||||
|
#define BR_PTR(br) tBufferGetDataAt((br)->buffer, (br)->offset)
|
||||||
|
#define tBufferReaderDestroy(reader) ((void)0)
|
||||||
|
#define tBufferReaderGetOffset(reader) ((reader)->offset)
|
||||||
|
static int32_t tBufferGet(SBufferReader *reader, uint32_t size, void *data);
|
||||||
|
static int32_t tBufferReaderInit(SBufferReader *reader, uint32_t offset, SBuffer *buffer);
|
||||||
|
static int32_t tBufferGetI8(SBufferReader *reader, int8_t *value);
|
||||||
|
static int32_t tBufferGetI16(SBufferReader *reader, int16_t *value);
|
||||||
|
static int32_t tBufferGetI32(SBufferReader *reader, int32_t *value);
|
||||||
|
static int32_t tBufferGetI64(SBufferReader *reader, int64_t *value);
|
||||||
|
static int32_t tBufferGetU8(SBufferReader *reader, uint8_t *value);
|
||||||
|
static int32_t tBufferGetU16(SBufferReader *reader, uint16_t *value);
|
||||||
|
static int32_t tBufferGetU32(SBufferReader *reader, uint32_t *value);
|
||||||
|
static int32_t tBufferGetU64(SBufferReader *reader, uint64_t *value);
|
||||||
|
static int32_t tBufferGetI16v(SBufferReader *reader, int16_t *value);
|
||||||
|
static int32_t tBufferGetI32v(SBufferReader *reader, int32_t *value);
|
||||||
|
static int32_t tBufferGetI64v(SBufferReader *reader, int64_t *value);
|
||||||
|
static int32_t tBufferGetU16v(SBufferReader *reader, uint16_t *value);
|
||||||
|
static int32_t tBufferGetU32v(SBufferReader *reader, uint32_t *value);
|
||||||
|
static int32_t tBufferGetU64v(SBufferReader *reader, uint64_t *value);
|
||||||
|
static int32_t tBufferGetBinary(SBufferReader *reader, const void **data, uint32_t *size);
|
||||||
|
static int32_t tBufferGetCStr(SBufferReader *reader, const char **str);
|
||||||
|
static int32_t tBufferGetF32(SBufferReader *reader, float *value);
|
||||||
|
static int32_t tBufferGetF64(SBufferReader *reader, double *value);
|
||||||
|
|
||||||
|
#include "tbuffer.inc"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*__TD_BUFFER_H__*/
|
|
@ -0,0 +1,346 @@
|
||||||
|
/*
|
||||||
|
* 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 "taoserror.h"
|
||||||
|
#include "tcoding.h"
|
||||||
|
|
||||||
|
struct SBuffer {
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t capacity;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SBufferReader {
|
||||||
|
uint32_t offset;
|
||||||
|
SBuffer *buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
// SBuffer
|
||||||
|
static FORCE_INLINE int32_t tBufferInit(SBuffer *buffer) {
|
||||||
|
buffer->size = 0;
|
||||||
|
buffer->capacity = 0;
|
||||||
|
buffer->data = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferDestroy(SBuffer *buffer) {
|
||||||
|
buffer->size = 0;
|
||||||
|
buffer->capacity = 0;
|
||||||
|
if (buffer->data) {
|
||||||
|
taosMemoryFree(buffer->data);
|
||||||
|
buffer->data = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferClear(SBuffer *buffer) {
|
||||||
|
buffer->size = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capacity) {
|
||||||
|
if (buffer->capacity < capacity) {
|
||||||
|
uint32_t newCapacity = (buffer->capacity > 0) ? (buffer->capacity << 1) : 1024;
|
||||||
|
while (newCapacity < capacity) {
|
||||||
|
newCapacity <<= 1;
|
||||||
|
}
|
||||||
|
void *newData = taosMemoryRealloc(buffer->data, newCapacity);
|
||||||
|
if (newData == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
buffer->data = newData;
|
||||||
|
buffer->capacity = newCapacity;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPut(SBuffer *buffer, const void *data, uint32_t size) {
|
||||||
|
int32_t code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||||
|
if (code) return code;
|
||||||
|
memcpy((char *)buffer->data + buffer->size, data, size);
|
||||||
|
buffer->size += size;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferPutAt(SBuffer *buffer, uint32_t offset, const void *data, uint32_t size) {
|
||||||
|
if (offset + size > buffer->size) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
memcpy((char *)buffer->data + offset, data, size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI8(SBuffer *buffer, int8_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI16(SBuffer *buffer, int16_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI32(SBuffer *buffer, int32_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI64(SBuffer *buffer, int64_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU8(SBuffer *buffer, uint8_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU16(SBuffer *buffer, uint16_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU32(SBuffer *buffer, uint32_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU64(SBuffer *buffer, uint64_t value) {
|
||||||
|
return tBufferPut(buffer, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU16v(SBuffer *buffer, uint16_t value) { return tBufferPutU64v(buffer, value); }
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU32v(SBuffer *buffer, uint32_t value) { return tBufferPutU64v(buffer, value); }
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutU64v(SBuffer *buffer, uint64_t value) {
|
||||||
|
int32_t code;
|
||||||
|
while (value >= 0x80) {
|
||||||
|
code = tBufferPutU8(buffer, (value & 0x7F) | 0x80);
|
||||||
|
if (code) return code;
|
||||||
|
value >>= 7;
|
||||||
|
}
|
||||||
|
return tBufferPutU8(buffer, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI16v(SBuffer *buffer, int16_t value) {
|
||||||
|
return tBufferPutU64v(buffer, ZIGZAGE(int16_t, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI32v(SBuffer *buffer, int32_t value) {
|
||||||
|
return tBufferPutU64v(buffer, ZIGZAGE(int32_t, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutI64v(SBuffer *buffer, int64_t value) {
|
||||||
|
return tBufferPutU64v(buffer, ZIGZAGE(int64_t, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutBinary(SBuffer *buffer, const void *data, uint32_t size) {
|
||||||
|
int32_t code = tBufferPutU32v(buffer, size);
|
||||||
|
if (code) return code;
|
||||||
|
return tBufferPut(buffer, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutCStr(SBuffer *buffer, const char *str) {
|
||||||
|
return tBufferPutBinary(buffer, str, str ? strlen(str) + 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutF32(SBuffer *buffer, float value) {
|
||||||
|
union {
|
||||||
|
float f;
|
||||||
|
uint32_t u;
|
||||||
|
} u;
|
||||||
|
u.f = value;
|
||||||
|
return tBufferPutU32(buffer, u.u);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferPutF64(SBuffer *buffer, double value) {
|
||||||
|
union {
|
||||||
|
double f;
|
||||||
|
uint64_t u;
|
||||||
|
} u;
|
||||||
|
u.f = value;
|
||||||
|
return tBufferPutU64(buffer, u.u);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reader
|
||||||
|
// SBufferReader
|
||||||
|
static int32_t tBufferReaderInit(SBufferReader *reader, uint32_t offset, SBuffer *buffer) {
|
||||||
|
reader->offset = offset;
|
||||||
|
reader->buffer = buffer;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tBufferGet(SBufferReader *reader, uint32_t size, void *data) {
|
||||||
|
if (reader->offset < 0 || reader->offset + size > reader->buffer->size) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
if (data) {
|
||||||
|
memcpy(data, BR_PTR(reader), size);
|
||||||
|
}
|
||||||
|
reader->offset += size;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetI8(SBufferReader *reader, int8_t *value) { return tBufferGet(reader, sizeof(*value), value); }
|
||||||
|
|
||||||
|
static int32_t tBufferGetI16(SBufferReader *reader, int16_t *value) {
|
||||||
|
return tBufferGet(reader, sizeof(*value), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetI32(SBufferReader *reader, int32_t *value) {
|
||||||
|
return tBufferGet(reader, sizeof(*value), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetI64(SBufferReader *reader, int64_t *value) {
|
||||||
|
return tBufferGet(reader, sizeof(*value), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetU8(SBufferReader *reader, uint8_t *value) { return tBufferGet(reader, sizeof(*value), value); }
|
||||||
|
|
||||||
|
static int32_t tBufferGetU16(SBufferReader *reader, uint16_t *value) {
|
||||||
|
return tBufferGet(reader, sizeof(*value), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetU32(SBufferReader *reader, uint32_t *value) {
|
||||||
|
return tBufferGet(reader, sizeof(*value), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetU64(SBufferReader *reader, uint64_t *value) {
|
||||||
|
return tBufferGet(reader, sizeof(*value), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetU64v(SBufferReader *reader, uint64_t *value) {
|
||||||
|
uint8_t byte;
|
||||||
|
int32_t code;
|
||||||
|
uint64_t u64 = 0;
|
||||||
|
|
||||||
|
for (int32_t i = 0;; i++) {
|
||||||
|
code = tBufferGetU8(reader, &byte);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
u64 |= (((uint64_t)(byte & 0x7F)) << (i * 7));
|
||||||
|
|
||||||
|
if (byte < 0x80) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
*value = u64;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetU16v(SBufferReader *reader, uint16_t *value) {
|
||||||
|
uint64_t u64;
|
||||||
|
int32_t code = tBufferGetU64v(reader, &u64);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = (uint16_t)u64;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetU32v(SBufferReader *reader, uint32_t *value) {
|
||||||
|
uint64_t u64;
|
||||||
|
int32_t code = tBufferGetU64v(reader, &u64);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = (uint32_t)u64;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetI16v(SBufferReader *reader, int16_t *value) {
|
||||||
|
uint16_t u16;
|
||||||
|
int32_t code = tBufferGetU16v(reader, &u16);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = ZIGZAGD(int16_t, u16);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetI32v(SBufferReader *reader, int32_t *value) {
|
||||||
|
uint32_t u32;
|
||||||
|
int32_t code = tBufferGetU32v(reader, &u32);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = ZIGZAGD(int32_t, u32);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetI64v(SBufferReader *reader, int64_t *value) {
|
||||||
|
uint64_t u64;
|
||||||
|
int32_t code = tBufferGetU64v(reader, &u64);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = ZIGZAGD(int64_t, u64);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetBinary(SBufferReader *reader, const void **data, uint32_t *size) {
|
||||||
|
uint32_t tmpSize;
|
||||||
|
int32_t code;
|
||||||
|
|
||||||
|
// size
|
||||||
|
code = tBufferGetU32v(reader, &tmpSize);
|
||||||
|
if (code) return code;
|
||||||
|
if (size) {
|
||||||
|
*size = tmpSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// data
|
||||||
|
if (tmpSize > 0) {
|
||||||
|
if (reader->offset + tmpSize > reader->buffer->size) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
if (data) {
|
||||||
|
*data = BR_PTR(reader);
|
||||||
|
}
|
||||||
|
reader->offset += tmpSize;
|
||||||
|
} else if (data) {
|
||||||
|
*data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetCStr(SBufferReader *reader, const char **str) {
|
||||||
|
return tBufferGetBinary(reader, (const void **)str, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetF32(SBufferReader *reader, float *value) {
|
||||||
|
union {
|
||||||
|
float f;
|
||||||
|
uint32_t u;
|
||||||
|
} u;
|
||||||
|
int32_t code = tBufferGetU32(reader, &u.u);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = u.f;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tBufferGetF64(SBufferReader *reader, double *value) {
|
||||||
|
union {
|
||||||
|
double f;
|
||||||
|
uint64_t u;
|
||||||
|
} u;
|
||||||
|
int32_t code = tBufferGetU64(reader, &u.u);
|
||||||
|
if (code) return code;
|
||||||
|
if (value) {
|
||||||
|
*value = u.f;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -266,7 +266,8 @@ void colDataSetNItemsNull(SColumnInfoData* pColumnInfoData, uint32_t currentRow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t colDataCopyAndReassign(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, uint32_t numOfRows) {
|
int32_t colDataCopyAndReassign(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData,
|
||||||
|
uint32_t numOfRows) {
|
||||||
int32_t code = colDataSetVal(pColumnInfoData, currentRow, pData, false);
|
int32_t code = colDataSetVal(pColumnInfoData, currentRow, pData, false);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -281,8 +282,8 @@ int32_t colDataCopyAndReassign(SColumnInfoData* pColumnInfoData, uint32_t curren
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t colDataCopyNItems(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData,
|
int32_t colDataCopyNItems(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, uint32_t numOfRows,
|
||||||
uint32_t numOfRows, bool isNull) {
|
bool isNull) {
|
||||||
int32_t len = pColumnInfoData->info.bytes;
|
int32_t len = pColumnInfoData->info.bytes;
|
||||||
if (isNull) {
|
if (isNull) {
|
||||||
colDataSetNItemsNull(pColumnInfoData, currentRow, numOfRows);
|
colDataSetNItemsNull(pColumnInfoData, currentRow, numOfRows);
|
||||||
|
@ -868,8 +869,8 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock) {
|
||||||
size_t blockDataGetSerialMetaSize(uint32_t numOfCols) {
|
size_t blockDataGetSerialMetaSize(uint32_t numOfCols) {
|
||||||
// | version | total length | total rows | blankFull | total columns | flag seg| block group id | column schema
|
// | version | total length | total rows | blankFull | total columns | flag seg| block group id | column schema
|
||||||
// | each column length |
|
// | each column length |
|
||||||
return sizeof(int32_t) + sizeof(int32_t) + sizeof(int32_t) + sizeof(bool) + sizeof(int32_t) + sizeof(int32_t) + sizeof(uint64_t) +
|
return sizeof(int32_t) + sizeof(int32_t) + sizeof(int32_t) + sizeof(bool) + sizeof(int32_t) + sizeof(int32_t) +
|
||||||
numOfCols * (sizeof(int8_t) + sizeof(int32_t)) + numOfCols * sizeof(int32_t);
|
sizeof(uint64_t) + numOfCols * (sizeof(int8_t) + sizeof(int32_t)) + numOfCols * sizeof(int32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
||||||
|
@ -1878,10 +1879,10 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf,
|
||||||
int32_t rows = pDataBlock->info.rows;
|
int32_t rows = pDataBlock->info.rows;
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
len += snprintf(dumpBuf + len, size - len,
|
len += snprintf(dumpBuf + len, size - len,
|
||||||
"%s===stream===%s|block type %d|child id %d|group id:%" PRIu64 "|uid:%" PRId64
|
"%s===stream===%s|block type %d|child id %d|group id:%" PRIu64 "|uid:%" PRId64 "|rows:%" PRId64
|
||||||
"|rows:%" PRId64 "|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "|tbl:%s\n",
|
"|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "|tbl:%s\n",
|
||||||
taskIdStr, flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.id.groupId,
|
taskIdStr, flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId,
|
||||||
pDataBlock->info.id.uid, pDataBlock->info.rows, pDataBlock->info.version,
|
pDataBlock->info.id.groupId, pDataBlock->info.id.uid, pDataBlock->info.rows, pDataBlock->info.version,
|
||||||
pDataBlock->info.calWin.skey, pDataBlock->info.calWin.ekey, pDataBlock->info.parTbName);
|
pDataBlock->info.calWin.skey, pDataBlock->info.calWin.ekey, pDataBlock->info.parTbName);
|
||||||
if (len >= size - 1) return dumpBuf;
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
|
||||||
|
@ -2039,13 +2040,13 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat
|
||||||
if (!isStartKey) {
|
if (!isStartKey) {
|
||||||
isStartKey = true;
|
isStartKey = true;
|
||||||
ASSERT(PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId);
|
ASSERT(PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId);
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, (SValue){.val = *(TSKEY*)var});
|
SColVal cv = COL_VAL_VALUE(pCol->colId, ((SValue){.type = pCol->type, .val = *(TSKEY*)var}));
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
} else if (colDataIsNull_s(pColInfoData, j)) {
|
} else if (colDataIsNull_s(pColInfoData, j)) {
|
||||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
} else {
|
} else {
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, (SValue){.val = *(int64_t*)var});
|
SColVal cv = COL_VAL_VALUE(pCol->colId, ((SValue){.type = pCol->type, .val = *(int64_t*)var}));
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2058,8 +2059,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
} else {
|
} else {
|
||||||
void* data = colDataGetVarData(pColInfoData, j);
|
void* data = colDataGetVarData(pColInfoData, j);
|
||||||
SValue sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
SValue sv = (SValue){
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
.type = pCol->type, .nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
||||||
|
SColVal cv = COL_VAL_VALUE(pCol->colId, sv);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2077,7 +2079,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat
|
||||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type); // should use pCol->type
|
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type); // should use pCol->type
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
} else {
|
} else {
|
||||||
SValue sv;
|
SValue sv = {.type = pCol->type};
|
||||||
if (pCol->type == pColInfoData->info.type) {
|
if (pCol->type == pColInfoData->info.type) {
|
||||||
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2105,7 +2107,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat
|
||||||
}
|
}
|
||||||
memcpy(&sv.val, tv, tDataTypes[pCol->type].bytes);
|
memcpy(&sv.val, tv, tDataTypes[pCol->type].bytes);
|
||||||
}
|
}
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pColInfoData->info.type, sv);
|
SColVal cv = COL_VAL_VALUE(pCol->colId, sv);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -573,8 +573,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
||||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||||
if (tEncodeU32(&encoder, pField->compress) < 0) return -1;
|
if (tEncodeU32(&encoder, pField->compress) < 0) return -1;
|
||||||
// XSDEBUG
|
|
||||||
printf("column: %s, compress: %0x.\n", pField->name, pField->compress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pReq->numOfTags; ++i) {
|
for (int32_t i = 0; i < pReq->numOfTags; ++i) {
|
||||||
|
|
|
@ -1106,7 +1106,7 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
|
||||||
*pColVal = COL_VAL_NULL(pTColumn->colId, pTColumn->type);
|
*pColVal = COL_VAL_NULL(pTColumn->colId, pTColumn->type);
|
||||||
} else {
|
} else {
|
||||||
pColVal->cid = pTColumn->colId;
|
pColVal->cid = pTColumn->colId;
|
||||||
pColVal->type = pTColumn->type;
|
pColVal->value.type = pTColumn->type;
|
||||||
pColVal->flag = CV_FLAG_VALUE;
|
pColVal->flag = CV_FLAG_VALUE;
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||||
|
|
|
@ -143,73 +143,73 @@ static int32_t genTestData(const char **data, int16_t nCols, SArray **pArray) {
|
||||||
}
|
}
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
colVal.type = TSDB_DATA_TYPE_TIMESTAMP;
|
colVal.value.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
sscanf(data[i], "%" PRIi64, &colVal.value.val);
|
sscanf(data[i], "%" PRIi64, &colVal.value.val);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
colVal.type = TSDB_DATA_TYPE_INT;
|
colVal.value.type = TSDB_DATA_TYPE_INT;
|
||||||
sscanf(data[i], "%" PRIi32, (int32_t *)&colVal.value.val);
|
sscanf(data[i], "%" PRIi32, (int32_t *)&colVal.value.val);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
colVal.type = TSDB_DATA_TYPE_BIGINT;
|
colVal.value.type = TSDB_DATA_TYPE_BIGINT;
|
||||||
sscanf(data[i], "%" PRIi64, &colVal.value.val);
|
sscanf(data[i], "%" PRIi64, &colVal.value.val);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
colVal.type = TSDB_DATA_TYPE_FLOAT;
|
colVal.value.type = TSDB_DATA_TYPE_FLOAT;
|
||||||
sscanf(data[i], "%f", (float *)&colVal.value.val);
|
sscanf(data[i], "%f", (float *)&colVal.value.val);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
colVal.type = TSDB_DATA_TYPE_DOUBLE;
|
colVal.value.type = TSDB_DATA_TYPE_DOUBLE;
|
||||||
sscanf(data[i], "%lf", (double *)&colVal.value.val);
|
sscanf(data[i], "%lf", (double *)&colVal.value.val);
|
||||||
break;
|
break;
|
||||||
case 5: {
|
case 5: {
|
||||||
colVal.type = TSDB_DATA_TYPE_BINARY;
|
colVal.value.type = TSDB_DATA_TYPE_BINARY;
|
||||||
int16_t dataLen = strlen(data[i]) + 1;
|
int16_t dataLen = strlen(data[i]) + 1;
|
||||||
colVal.value.nData = dataLen < 10 ? dataLen : 10;
|
colVal.value.nData = dataLen < 10 ? dataLen : 10;
|
||||||
colVal.value.pData = (uint8_t *)data[i];
|
colVal.value.pData = (uint8_t *)data[i];
|
||||||
} break;
|
} break;
|
||||||
case 6: {
|
case 6: {
|
||||||
colVal.type = TSDB_DATA_TYPE_NCHAR;
|
colVal.value.type = TSDB_DATA_TYPE_NCHAR;
|
||||||
int16_t dataLen = strlen(data[i]) + 1;
|
int16_t dataLen = strlen(data[i]) + 1;
|
||||||
colVal.value.nData = dataLen < 40 ? dataLen : 40;
|
colVal.value.nData = dataLen < 40 ? dataLen : 40;
|
||||||
colVal.value.pData = (uint8_t *)data[i]; // just for test, not real nchar
|
colVal.value.pData = (uint8_t *)data[i]; // just for test, not real nchar
|
||||||
} break;
|
} break;
|
||||||
case 7: {
|
case 7: {
|
||||||
colVal.type = TSDB_DATA_TYPE_TINYINT;
|
colVal.value.type = TSDB_DATA_TYPE_TINYINT;
|
||||||
int32_t d8;
|
int32_t d8;
|
||||||
sscanf(data[i], "%" PRId32, &d8);
|
sscanf(data[i], "%" PRId32, &d8);
|
||||||
colVal.value.val = (int8_t)d8;
|
colVal.value.val = (int8_t)d8;
|
||||||
}
|
}
|
||||||
case 8: {
|
case 8: {
|
||||||
colVal.type = TSDB_DATA_TYPE_SMALLINT;
|
colVal.value.type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
int32_t d16;
|
int32_t d16;
|
||||||
sscanf(data[i], "%" PRId32, &d16);
|
sscanf(data[i], "%" PRId32, &d16);
|
||||||
colVal.value.val = (int16_t)d16;
|
colVal.value.val = (int16_t)d16;
|
||||||
} break;
|
} break;
|
||||||
case 9: {
|
case 9: {
|
||||||
colVal.type = TSDB_DATA_TYPE_BOOL;
|
colVal.value.type = TSDB_DATA_TYPE_BOOL;
|
||||||
int32_t d8;
|
int32_t d8;
|
||||||
sscanf(data[i], "%" PRId32, &d8);
|
sscanf(data[i], "%" PRId32, &d8);
|
||||||
colVal.value.val = (int8_t)d8;
|
colVal.value.val = (int8_t)d8;
|
||||||
} break;
|
} break;
|
||||||
case 10: {
|
case 10: {
|
||||||
colVal.type = TSDB_DATA_TYPE_UTINYINT;
|
colVal.value.type = TSDB_DATA_TYPE_UTINYINT;
|
||||||
uint32_t u8;
|
uint32_t u8;
|
||||||
sscanf(data[i], "%" PRId32, &u8);
|
sscanf(data[i], "%" PRId32, &u8);
|
||||||
colVal.value.val = (uint8_t)u8;
|
colVal.value.val = (uint8_t)u8;
|
||||||
} break;
|
} break;
|
||||||
case 11: {
|
case 11: {
|
||||||
colVal.type = TSDB_DATA_TYPE_USMALLINT;
|
colVal.value.type = TSDB_DATA_TYPE_USMALLINT;
|
||||||
uint32_t u16;
|
uint32_t u16;
|
||||||
sscanf(data[i], "%" PRId32, &u16);
|
sscanf(data[i], "%" PRId32, &u16);
|
||||||
colVal.value.val = (uint16_t)u16;
|
colVal.value.val = (uint16_t)u16;
|
||||||
} break;
|
} break;
|
||||||
case 12: {
|
case 12: {
|
||||||
colVal.type = TSDB_DATA_TYPE_UINT;
|
colVal.value.type = TSDB_DATA_TYPE_UINT;
|
||||||
sscanf(data[i], "%" PRIu32, (uint32_t *)&colVal.value.val);
|
sscanf(data[i], "%" PRIu32, (uint32_t *)&colVal.value.val);
|
||||||
} break;
|
} break;
|
||||||
case 13: {
|
case 13: {
|
||||||
colVal.type = TSDB_DATA_TYPE_UBIGINT;
|
colVal.value.type = TSDB_DATA_TYPE_UBIGINT;
|
||||||
sscanf(data[i], "%" PRIu64, (uint64_t *)&colVal.value.val);
|
sscanf(data[i], "%" PRIu64, (uint64_t *)&colVal.value.val);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
|
@ -430,7 +430,7 @@ static void checkTSRow(const char **data, STSRow *row, STSchema *pTSchema) {
|
||||||
}
|
}
|
||||||
|
|
||||||
colVal.cid = pCol->colId;
|
colVal.cid = pCol->colId;
|
||||||
colVal.type = pCol->type;
|
colVal.value.type = pCol->type;
|
||||||
if (tdValTypeIsNone(cv.valType)) {
|
if (tdValTypeIsNone(cv.valType)) {
|
||||||
colVal.flag = CV_FLAG_NONE;
|
colVal.flag = CV_FLAG_NONE;
|
||||||
} else if (tdValTypeIsNull(cv.valType)) {
|
} else if (tdValTypeIsNull(cv.valType)) {
|
||||||
|
|
|
@ -1137,10 +1137,6 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo xsdebug
|
|
||||||
// terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
|
||||||
// goto _OVER;
|
|
||||||
|
|
||||||
mInfo("stb:%s, start to create", createReq.name);
|
mInfo("stb:%s, start to create", createReq.name);
|
||||||
if (mndCheckCreateStbReq(&createReq) != 0) {
|
if (mndCheckCreateStbReq(&createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
|
|
@ -75,6 +75,7 @@ typedef struct SBlkInfo SBlkInfo;
|
||||||
typedef struct STsdbDataIter2 STsdbDataIter2;
|
typedef struct STsdbDataIter2 STsdbDataIter2;
|
||||||
typedef struct STsdbFilterInfo STsdbFilterInfo;
|
typedef struct STsdbFilterInfo STsdbFilterInfo;
|
||||||
typedef struct STFileSystem STFileSystem;
|
typedef struct STFileSystem STFileSystem;
|
||||||
|
typedef struct STsdbRowKey STsdbRowKey;
|
||||||
|
|
||||||
#define TSDBROW_ROW_FMT ((int8_t)0x0)
|
#define TSDBROW_ROW_FMT ((int8_t)0x0)
|
||||||
#define TSDBROW_COL_FMT ((int8_t)0x1)
|
#define TSDBROW_COL_FMT ((int8_t)0x1)
|
||||||
|
@ -120,7 +121,10 @@ static FORCE_INLINE int64_t tsdbLogicToFileSize(int64_t lSize, int32_t szPage) {
|
||||||
((TSDBROW){.type = TSDBROW_COL_FMT, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
|
((TSDBROW){.type = TSDBROW_COL_FMT, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
|
||||||
|
|
||||||
void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||||
int32_t tsdbRowCmprFn(const void *p1, const void *p2);
|
int32_t tsdbRowCompare(const void *p1, const void *p2);
|
||||||
|
int32_t tsdbRowCompareWithoutVersion(const void *p1, const void *p2);
|
||||||
|
int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2);
|
||||||
|
void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key);
|
||||||
// STSDBRowIter
|
// STSDBRowIter
|
||||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||||
void tsdbRowClose(STSDBRowIter *pIter);
|
void tsdbRowClose(STSDBRowIter *pIter);
|
||||||
|
@ -139,8 +143,8 @@ int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
||||||
#define MIN_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) < 0) ? (KEY1) : (KEY2))
|
#define MIN_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) < 0) ? (KEY1) : (KEY2))
|
||||||
#define MAX_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) > 0) ? (KEY1) : (KEY2))
|
#define MAX_TSDBKEY(KEY1, KEY2) ((tsdbKeyCmprFn(&(KEY1), &(KEY2)) > 0) ? (KEY1) : (KEY2))
|
||||||
// SBlockCol
|
// SBlockCol
|
||||||
int32_t tPutBlockCol(uint8_t *p, void *ph);
|
int32_t tPutBlockCol(SBuffer *buffer, const SBlockCol *pBlockCol);
|
||||||
int32_t tGetBlockCol(uint8_t *p, void *ph);
|
int32_t tGetBlockCol(SBufferReader *br, SBlockCol *pBlockCol);
|
||||||
int32_t tBlockColCmprFn(const void *p1, const void *p2);
|
int32_t tBlockColCmprFn(const void *p1, const void *p2);
|
||||||
// SDataBlk
|
// SDataBlk
|
||||||
void tDataBlkReset(SDataBlk *pBlock);
|
void tDataBlkReset(SDataBlk *pBlock);
|
||||||
|
@ -172,13 +176,17 @@ int32_t tBlockDataUpdateRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
|
||||||
int32_t tBlockDataTryUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, int64_t uid);
|
int32_t tBlockDataTryUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, int64_t uid);
|
||||||
int32_t tBlockDataUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
|
int32_t tBlockDataUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
|
||||||
void tBlockDataClear(SBlockData *pBlockData);
|
void tBlockDataClear(SBlockData *pBlockData);
|
||||||
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData);
|
int32_t tBlockDataCompress(SBlockData *bData, int8_t cmprAlg, SBuffer *buffers, SBuffer *assist);
|
||||||
int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[],
|
int32_t tBlockDataDecompress(SBufferReader *br, SBlockData *blockData, SBuffer *assist);
|
||||||
int32_t aBufN[]);
|
int32_t tBlockDataDecompressKeyPart(const SDiskDataHdr *hdr, SBufferReader *br, SBlockData *blockData, SBuffer *assist);
|
||||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]);
|
int32_t tBlockDataDecompressColData(const SDiskDataHdr *hdr, const SBlockCol *blockCol, SBufferReader *br,
|
||||||
|
SBlockData *blockData, SBuffer *assist);
|
||||||
|
|
||||||
|
SColData *tBlockDataGetColData(SBlockData *pBlockData, int16_t cid);
|
||||||
|
int32_t tBlockDataAddColData(SBlockData *pBlockData, int16_t cid, int8_t type, int8_t cflag, SColData **ppColData);
|
||||||
// SDiskDataHdr
|
// SDiskDataHdr
|
||||||
int32_t tPutDiskDataHdr(uint8_t *p, const SDiskDataHdr *pHdr);
|
int32_t tPutDiskDataHdr(SBuffer *buffer, const SDiskDataHdr *pHdr);
|
||||||
int32_t tGetDiskDataHdr(uint8_t *p, void *ph);
|
int32_t tGetDiskDataHdr(SBufferReader *br, SDiskDataHdr *pHdr);
|
||||||
// SDelIdx
|
// SDelIdx
|
||||||
int32_t tPutDelIdx(uint8_t *p, void *ph);
|
int32_t tPutDelIdx(uint8_t *p, void *ph);
|
||||||
int32_t tGetDelIdx(uint8_t *p, void *ph);
|
int32_t tGetDelIdx(uint8_t *p, void *ph);
|
||||||
|
@ -204,16 +212,8 @@ int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision);
|
||||||
void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey);
|
void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey);
|
||||||
int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t nowSec);
|
int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t nowSec);
|
||||||
int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline);
|
int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline);
|
||||||
int32_t tPutColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg);
|
int32_t tPutColumnDataAgg(SBuffer *buffer, SColumnDataAgg *pColAgg);
|
||||||
int32_t tGetColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg);
|
int32_t tGetColumnDataAgg(SBufferReader *br, SColumnDataAgg *pColAgg);
|
||||||
int32_t tsdbCmprData(uint8_t *pIn, int32_t szIn, int8_t type, int8_t cmprAlg, uint8_t **ppOut, int32_t nOut,
|
|
||||||
int32_t *szOut, uint8_t **ppBuf);
|
|
||||||
int32_t tsdbDecmprData(uint8_t *pIn, int32_t szIn, int8_t type, int8_t cmprAlg, uint8_t **ppOut, int32_t szOut,
|
|
||||||
uint8_t **ppBuf);
|
|
||||||
int32_t tsdbCmprColData(SColData *pColData, int8_t cmprAlg, SBlockCol *pBlockCol, uint8_t **ppOut, int32_t nOut,
|
|
||||||
uint8_t **ppBuf);
|
|
||||||
int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, int32_t nVal, SColData *pColData,
|
|
||||||
uint8_t **ppBuf);
|
|
||||||
int32_t tRowInfoCmprFn(const void *p1, const void *p2);
|
int32_t tRowInfoCmprFn(const void *p1, const void *p2);
|
||||||
// tsdbMemTable ==============================================================================================
|
// tsdbMemTable ==============================================================================================
|
||||||
// SMemTable
|
// SMemTable
|
||||||
|
@ -224,9 +224,9 @@ int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode);
|
||||||
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive);
|
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive);
|
||||||
SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable);
|
SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable);
|
||||||
// STbDataIter
|
// STbDataIter
|
||||||
int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter);
|
int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter);
|
||||||
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
||||||
void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter);
|
void tsdbTbDataIterOpen(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter *pIter);
|
||||||
bool tsdbTbDataIterNext(STbDataIter *pIter);
|
bool tsdbTbDataIterNext(STbDataIter *pIter);
|
||||||
void tsdbMemTableCountRows(SMemTable *pMemTable, SSHashObj *pTableMap, int64_t *rowsNum);
|
void tsdbMemTableCountRows(SMemTable *pMemTable, SSHashObj *pTableMap, int64_t *rowsNum);
|
||||||
|
|
||||||
|
@ -264,11 +264,6 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader);
|
||||||
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
|
||||||
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk);
|
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk);
|
||||||
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
|
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
|
||||||
int32_t tsdbReadBlockSma(SDataFReader *pReader, SDataBlk *pBlock, SArray *aColumnDataAgg);
|
|
||||||
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pBlock, SBlockData *pBlockData);
|
|
||||||
int32_t tsdbReadDataBlockEx(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData *pBlockData);
|
|
||||||
int32_t tsdbReadSttBlock(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk, SBlockData *pBlockData);
|
|
||||||
int32_t tsdbReadSttBlockEx(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk, SBlockData *pBlockData);
|
|
||||||
// SDelFReader
|
// SDelFReader
|
||||||
int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb);
|
int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb);
|
||||||
int32_t tsdbDelFReaderClose(SDelFReader **ppReader);
|
int32_t tsdbDelFReaderClose(SDelFReader **ppReader);
|
||||||
|
@ -289,14 +284,6 @@ typedef struct {
|
||||||
|
|
||||||
int32_t tsdbMerge(void *arg);
|
int32_t tsdbMerge(void *arg);
|
||||||
|
|
||||||
// tsdbDiskData ==============================================================================================
|
|
||||||
int32_t tDiskDataBuilderCreate(SDiskDataBuilder **ppBuilder);
|
|
||||||
void *tDiskDataBuilderDestroy(SDiskDataBuilder *pBuilder);
|
|
||||||
int32_t tDiskDataBuilderInit(SDiskDataBuilder *pBuilder, STSchema *pTSchema, TABLEID *pId, uint8_t cmprAlg,
|
|
||||||
uint8_t calcSma);
|
|
||||||
int32_t tDiskDataBuilderClear(SDiskDataBuilder *pBuilder);
|
|
||||||
int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTSchema, TABLEID *pId);
|
|
||||||
int32_t tGnrtDiskData(SDiskDataBuilder *pBuilder, const SDiskData **ppDiskData, const SBlkInfo **ppBlkInfo);
|
|
||||||
// tsdbDataIter.c ==============================================================================================
|
// tsdbDataIter.c ==============================================================================================
|
||||||
#define TSDB_MEM_TABLE_DATA_ITER 0
|
#define TSDB_MEM_TABLE_DATA_ITER 0
|
||||||
#define TSDB_DATA_FILE_DATA_ITER 1
|
#define TSDB_DATA_FILE_DATA_ITER 1
|
||||||
|
@ -375,15 +362,6 @@ struct TSDBKEY {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SMemSkipListNode SMemSkipListNode;
|
typedef struct SMemSkipListNode SMemSkipListNode;
|
||||||
struct SMemSkipListNode {
|
|
||||||
int8_t level;
|
|
||||||
int8_t flag; // TSDBROW_ROW_FMT for row format, TSDBROW_COL_FMT for col format
|
|
||||||
int32_t iRow;
|
|
||||||
int64_t version;
|
|
||||||
void *pData;
|
|
||||||
SMemSkipListNode *forwards[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct SMemSkipList {
|
typedef struct SMemSkipList {
|
||||||
int64_t size;
|
int64_t size;
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
|
@ -437,6 +415,17 @@ struct TSDBROW {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SMemSkipListNode {
|
||||||
|
int8_t level;
|
||||||
|
TSDBROW row;
|
||||||
|
SMemSkipListNode *forwards[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct STsdbRowKey {
|
||||||
|
SRowKey key;
|
||||||
|
int64_t version;
|
||||||
|
};
|
||||||
|
|
||||||
struct SBlockIdx {
|
struct SBlockIdx {
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
|
@ -454,7 +443,7 @@ struct SMapData {
|
||||||
struct SBlockCol {
|
struct SBlockCol {
|
||||||
int16_t cid;
|
int16_t cid;
|
||||||
int8_t type;
|
int8_t type;
|
||||||
int8_t smaOn;
|
int8_t cflag;
|
||||||
int8_t flag; // HAS_NONE|HAS_NULL|HAS_VALUE
|
int8_t flag; // HAS_NONE|HAS_NULL|HAS_VALUE
|
||||||
int32_t szOrigin; // original column value size (only save for variant data type)
|
int32_t szOrigin; // original column value size (only save for variant data type)
|
||||||
int32_t szBitmap; // bitmap size, 0 only for flag == HAS_VAL
|
int32_t szBitmap; // bitmap size, 0 only for flag == HAS_VAL
|
||||||
|
@ -562,6 +551,10 @@ struct SDiskDataHdr {
|
||||||
int32_t szBlkCol;
|
int32_t szBlkCol;
|
||||||
int32_t nRow;
|
int32_t nRow;
|
||||||
int8_t cmprAlg;
|
int8_t cmprAlg;
|
||||||
|
|
||||||
|
// fmtVer == 1
|
||||||
|
int8_t numOfPKs;
|
||||||
|
SBlockCol primaryBlockCols[TD_MAX_PK_COLS];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SDelFile {
|
struct SDelFile {
|
||||||
|
@ -942,34 +935,7 @@ static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
||||||
// #define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
// #define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
||||||
// #define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
// #define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
||||||
|
|
||||||
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
|
TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter);
|
||||||
if (pIter == NULL) return NULL;
|
|
||||||
|
|
||||||
if (pIter->pRow) {
|
|
||||||
return pIter->pRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pIter->backward) {
|
|
||||||
if (pIter->pNode == pIter->pTbData->sl.pHead) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pIter->pNode == pIter->pTbData->sl.pTail) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pIter->pRow = &pIter->row;
|
|
||||||
if (pIter->pNode->flag == TSDBROW_ROW_FMT) {
|
|
||||||
pIter->row = tsdbRowFromTSRow(pIter->pNode->version, pIter->pNode->pData);
|
|
||||||
} else if (pIter->pNode->flag == TSDBROW_COL_FMT) {
|
|
||||||
pIter->row = tsdbRowFromBlockData(pIter->pNode->pData, pIter->pNode->iRow);
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pIter->pRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
|
|
|
@ -578,7 +578,7 @@ static int32_t buildResSDataBlock(SSDataBlock* pBlock, SSchemaWrapper* pSchema,
|
||||||
static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SColVal* pColVal) {
|
static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SColVal* pColVal) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
if (IS_STR_DATA_TYPE(pColVal->type)) {
|
if (IS_STR_DATA_TYPE(pColVal->value.type)) {
|
||||||
char val[65535 + 2] = {0};
|
char val[65535 + 2] = {0};
|
||||||
if (COL_VAL_IS_VALUE(pColVal)) {
|
if (COL_VAL_IS_VALUE(pColVal)) {
|
||||||
if (pColVal->value.pData != NULL) {
|
if (pColVal->value.pData != NULL) {
|
||||||
|
|
|
@ -567,13 +567,14 @@ int32_t doConvertRows(SSubmitTbData* pTableData, const STSchema* pTSchema, SSDat
|
||||||
void* colData = colDataGetData(pColData, j);
|
void* colData = colDataGetData(pColData, j);
|
||||||
if (IS_STR_DATA_TYPE(pCol->type)) {
|
if (IS_STR_DATA_TYPE(pCol->type)) {
|
||||||
// address copy, no value
|
// address copy, no value
|
||||||
SValue sv = (SValue){.nData = varDataLen(colData), .pData = (uint8_t*)varDataVal(colData)};
|
SValue sv =
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
(SValue){.type = pCol->type, .nData = varDataLen(colData), .pData = (uint8_t*)varDataVal(colData)};
|
||||||
|
SColVal cv = COL_VAL_VALUE(pCol->colId, sv);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
} else {
|
} else {
|
||||||
SValue sv;
|
SValue sv = {.type = pCol->type};
|
||||||
memcpy(&sv.val, colData, tDataTypes[pCol->type].bytes);
|
memcpy(&sv.val, colData, tDataTypes[pCol->type].bytes);
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
SColVal cv = COL_VAL_VALUE(pCol->colId, sv);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
dataIndex++;
|
dataIndex++;
|
||||||
|
|
|
@ -329,7 +329,7 @@ static SLastCol *tsdbCacheDeserialize(char const *value) {
|
||||||
|
|
||||||
SLastCol *pLastCol = (SLastCol *)value;
|
SLastCol *pLastCol = (SLastCol *)value;
|
||||||
SColVal *pColVal = &pLastCol->colVal;
|
SColVal *pColVal = &pLastCol->colVal;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
if (pColVal->value.nData > 0) {
|
if (pColVal->value.nData > 0) {
|
||||||
pColVal->value.pData = (char *)value + sizeof(*pLastCol);
|
pColVal->value.pData = (char *)value + sizeof(*pLastCol);
|
||||||
} else {
|
} else {
|
||||||
|
@ -343,13 +343,13 @@ static SLastCol *tsdbCacheDeserialize(char const *value) {
|
||||||
static void tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size) {
|
static void tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size) {
|
||||||
SColVal *pColVal = &pLastCol->colVal;
|
SColVal *pColVal = &pLastCol->colVal;
|
||||||
size_t length = sizeof(*pLastCol);
|
size_t length = sizeof(*pLastCol);
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
length += pColVal->value.nData;
|
length += pColVal->value.nData;
|
||||||
}
|
}
|
||||||
*value = taosMemoryMalloc(length);
|
*value = taosMemoryMalloc(length);
|
||||||
|
|
||||||
*(SLastCol *)(*value) = *pLastCol;
|
*(SLastCol *)(*value) = *pLastCol;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
uint8_t *pVal = pColVal->value.pData;
|
uint8_t *pVal = pColVal->value.pData;
|
||||||
SColVal *pDColVal = &((SLastCol *)(*value))->colVal;
|
SColVal *pDColVal = &((SLastCol *)(*value))->colVal;
|
||||||
pDColVal->value.pData = *value + sizeof(*pLastCol);
|
pDColVal->value.pData = *value + sizeof(*pLastCol);
|
||||||
|
@ -434,7 +434,7 @@ int32_t tsdbCacheCommit(STsdb *pTsdb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reallocVarData(SColVal *pColVal) {
|
static void reallocVarData(SColVal *pColVal) {
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
uint8_t *pVal = pColVal->value.pData;
|
uint8_t *pVal = pColVal->value.pData;
|
||||||
if (pColVal->value.nData > 0) {
|
if (pColVal->value.nData > 0) {
|
||||||
pColVal->value.pData = taosMemoryMalloc(pColVal->value.nData);
|
pColVal->value.pData = taosMemoryMalloc(pColVal->value.nData);
|
||||||
|
@ -452,7 +452,7 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud
|
||||||
tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud);
|
tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.type) /* && pLastCol->colVal.value.nData > 0*/) {
|
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type) /* && pLastCol->colVal.value.nData > 0*/) {
|
||||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ static int32_t tsdbCacheNewTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, i
|
||||||
|
|
||||||
reallocVarData(&pLastCol->colVal);
|
reallocVarData(&pLastCol->colVal);
|
||||||
size_t charge = sizeof(*pLastCol);
|
size_t charge = sizeof(*pLastCol);
|
||||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) {
|
||||||
charge += pLastCol->colVal.value.nData;
|
charge += pLastCol->colVal.value.nData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,12 +839,12 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
|
||||||
if (pLastCol->ts <= keyTs) {
|
if (pLastCol->ts <= keyTs) {
|
||||||
uint8_t *pVal = NULL;
|
uint8_t *pVal = NULL;
|
||||||
int nData = pLastCol->colVal.value.nData;
|
int nData = pLastCol->colVal.value.nData;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
pVal = pLastCol->colVal.value.pData;
|
pVal = pLastCol->colVal.value.pData;
|
||||||
}
|
}
|
||||||
pLastCol->ts = keyTs;
|
pLastCol->ts = keyTs;
|
||||||
pLastCol->colVal = *pColVal;
|
pLastCol->colVal = *pColVal;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
if (nData < pColVal->value.nData) {
|
if (nData < pColVal->value.nData) {
|
||||||
taosMemoryFree(pVal);
|
taosMemoryFree(pVal);
|
||||||
pLastCol->colVal.value.pData = taosMemoryCalloc(1, pColVal->value.nData);
|
pLastCol->colVal.value.pData = taosMemoryCalloc(1, pColVal->value.nData);
|
||||||
|
@ -878,12 +878,12 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
|
||||||
if (pLastCol->ts <= keyTs) {
|
if (pLastCol->ts <= keyTs) {
|
||||||
uint8_t *pVal = NULL;
|
uint8_t *pVal = NULL;
|
||||||
int nData = pLastCol->colVal.value.nData;
|
int nData = pLastCol->colVal.value.nData;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
pVal = pLastCol->colVal.value.pData;
|
pVal = pLastCol->colVal.value.pData;
|
||||||
}
|
}
|
||||||
pLastCol->ts = keyTs;
|
pLastCol->ts = keyTs;
|
||||||
pLastCol->colVal = *pColVal;
|
pLastCol->colVal = *pColVal;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
if (nData < pColVal->value.nData) {
|
if (nData < pColVal->value.nData) {
|
||||||
taosMemoryFree(pVal);
|
taosMemoryFree(pVal);
|
||||||
pLastCol->colVal.value.pData = taosMemoryCalloc(1, pColVal->value.nData);
|
pLastCol->colVal.value.pData = taosMemoryCalloc(1, pColVal->value.nData);
|
||||||
|
@ -962,7 +962,7 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
|
||||||
|
|
||||||
reallocVarData(&pLastCol->colVal);
|
reallocVarData(&pLastCol->colVal);
|
||||||
size_t charge = sizeof(*pLastCol);
|
size_t charge = sizeof(*pLastCol);
|
||||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) {
|
||||||
charge += pLastCol->colVal.value.nData;
|
charge += pLastCol->colVal.value.nData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -994,7 +994,7 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
|
||||||
|
|
||||||
reallocVarData(&pLastCol->colVal);
|
reallocVarData(&pLastCol->colVal);
|
||||||
size_t charge = sizeof(*pLastCol);
|
size_t charge = sizeof(*pLastCol);
|
||||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) {
|
||||||
charge += pLastCol->colVal.value.nData;
|
charge += pLastCol->colVal.value.nData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1310,7 +1310,7 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
|
|
||||||
reallocVarData(&pLastCol->colVal);
|
reallocVarData(&pLastCol->colVal);
|
||||||
size_t charge = sizeof(*pLastCol);
|
size_t charge = sizeof(*pLastCol);
|
||||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) {
|
||||||
charge += pLastCol->colVal.value.nData;
|
charge += pLastCol->colVal.value.nData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1394,7 +1394,7 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA
|
||||||
|
|
||||||
reallocVarData(&pLastCol->colVal);
|
reallocVarData(&pLastCol->colVal);
|
||||||
size_t charge = sizeof(*pLastCol);
|
size_t charge = sizeof(*pLastCol);
|
||||||
if (IS_VAR_DATA_TYPE(pLastCol->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pLastCol->colVal.value.type)) {
|
||||||
charge += pLastCol->colVal.value.nData;
|
charge += pLastCol->colVal.value.nData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2175,7 +2175,7 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea
|
||||||
|
|
||||||
STombRecord record = {0};
|
STombRecord record = {0};
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
for (int32_t k = 0; k < TARRAY2_SIZE(block.suid); ++k) {
|
for (int32_t k = 0; k < TOMB_BLOCK_SIZE(&block); ++k) {
|
||||||
code = tTombBlockGet(&block, k, &record);
|
code = tTombBlockGet(&block, k, &record);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
finished = true;
|
finished = true;
|
||||||
|
@ -2551,7 +2551,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->iBrinRecord = BRIN_BLOCK_SIZE(&state->brinBlock) - 1;
|
state->iBrinRecord = state->brinBlock.numOfRecords - 1;
|
||||||
state->state = SFSNEXTROW_BRINBLOCK;
|
state->state = SFSNEXTROW_BRINBLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3185,14 +3185,14 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
||||||
if (slotIds[iCol] == 0) {
|
if (slotIds[iCol] == 0) {
|
||||||
STColumn *pTColumn = &pTSchema->columns[0];
|
STColumn *pTColumn = &pTSchema->columns[0];
|
||||||
|
|
||||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = rowTs});
|
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||||
taosArraySet(pColArray, 0, &(SLastCol){.ts = rowTs, .colVal = *pColVal});
|
taosArraySet(pColArray, 0, &(SLastCol){.ts = rowTs, .colVal = *pColVal});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||||
|
|
||||||
*pCol = (SLastCol){.ts = rowTs, .colVal = *pColVal};
|
*pCol = (SLastCol){.ts = rowTs, .colVal = *pColVal};
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type) /*&& pColVal->value.nData > 0*/) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||||
if (pColVal->value.nData > 0) {
|
if (pColVal->value.nData > 0) {
|
||||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||||
if (pCol->colVal.value.pData == NULL) {
|
if (pCol->colVal.value.pData == NULL) {
|
||||||
|
@ -3242,7 +3242,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
||||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||||
if (!COL_VAL_IS_VALUE(tColVal) && COL_VAL_IS_VALUE(pColVal)) {
|
if (!COL_VAL_IS_VALUE(tColVal) && COL_VAL_IS_VALUE(pColVal)) {
|
||||||
SLastCol lastCol = {.ts = rowTs, .colVal = *pColVal};
|
SLastCol lastCol = {.ts = rowTs, .colVal = *pColVal};
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type) /* && pColVal->value.nData > 0 */) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type) /* && pColVal->value.nData > 0 */) {
|
||||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol);
|
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol);
|
||||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||||
|
|
||||||
|
@ -3364,14 +3364,14 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
||||||
if (slotIds[iCol] == 0) {
|
if (slotIds[iCol] == 0) {
|
||||||
STColumn *pTColumn = &pTSchema->columns[0];
|
STColumn *pTColumn = &pTSchema->columns[0];
|
||||||
|
|
||||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = rowTs});
|
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||||
taosArraySet(pColArray, 0, &(SLastCol){.ts = rowTs, .colVal = *pColVal});
|
taosArraySet(pColArray, 0, &(SLastCol){.ts = rowTs, .colVal = *pColVal});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||||
|
|
||||||
*pCol = (SLastCol){.ts = rowTs, .colVal = *pColVal};
|
*pCol = (SLastCol){.ts = rowTs, .colVal = *pColVal};
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type) /*&& pColVal->value.nData > 0*/) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||||
if (pColVal->value.nData > 0) {
|
if (pColVal->value.nData > 0) {
|
||||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||||
if (pCol->colVal.value.pData == NULL) {
|
if (pCol->colVal.value.pData == NULL) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ static void saveOneRowForLastRaw(SLastCol* pColVal, SCacheRowsReader* pReader, c
|
||||||
SColVal* pVal = &pColVal->colVal;
|
SColVal* pVal = &pColVal->colVal;
|
||||||
|
|
||||||
// allNullRow = false;
|
// allNullRow = false;
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
||||||
if (!COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
if (!COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
||||||
colDataSetNULL(pColInfoData, numOfRows);
|
colDataSetNULL(pColInfoData, numOfRows);
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,7 +60,6 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p
|
||||||
// bool allNullRow = true;
|
// bool allNullRow = true;
|
||||||
|
|
||||||
if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) {
|
if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) {
|
||||||
|
|
||||||
uint64_t ts = TSKEY_MIN;
|
uint64_t ts = TSKEY_MIN;
|
||||||
SFirstLastRes* p = NULL;
|
SFirstLastRes* p = NULL;
|
||||||
col_id_t colId = -1;
|
col_id_t colId = -1;
|
||||||
|
@ -98,13 +97,13 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p
|
||||||
p->isNull = !COL_VAL_IS_VALUE(&pColVal->colVal);
|
p->isNull = !COL_VAL_IS_VALUE(&pColVal->colVal);
|
||||||
// allNullRow = p->isNull & allNullRow;
|
// allNullRow = p->isNull & allNullRow;
|
||||||
if (!p->isNull) {
|
if (!p->isNull) {
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
||||||
varDataSetLen(p->buf, pColVal->colVal.value.nData);
|
varDataSetLen(p->buf, pColVal->colVal.value.nData);
|
||||||
|
|
||||||
memcpy(varDataVal(p->buf), pColVal->colVal.value.pData, pColVal->colVal.value.nData);
|
memcpy(varDataVal(p->buf), pColVal->colVal.value.pData, pColVal->colVal.value.nData);
|
||||||
p->bytes = pColVal->colVal.value.nData + VARSTR_HEADER_SIZE; // binary needs to plus the header size
|
p->bytes = pColVal->colVal.value.nData + VARSTR_HEADER_SIZE; // binary needs to plus the header size
|
||||||
} else {
|
} else {
|
||||||
memcpy(p->buf, &pColVal->colVal.value, pReader->pSchema->columns[slotId].bytes);
|
memcpy(p->buf, &pColVal->colVal.value.val, pReader->pSchema->columns[slotId].bytes);
|
||||||
p->bytes = pReader->pSchema->columns[slotId].bytes;
|
p->bytes = pReader->pSchema->columns[slotId].bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +314,7 @@ void* tsdbCacherowsReaderClose(void* pReader) {
|
||||||
|
|
||||||
static void freeItem(void* pItem) {
|
static void freeItem(void* pItem) {
|
||||||
SLastCol* pCol = (SLastCol*)pItem;
|
SLastCol* pCol = (SLastCol*)pItem;
|
||||||
if (IS_VAR_DATA_TYPE(pCol->colVal.type) && pCol->colVal.value.pData) {
|
if (IS_VAR_DATA_TYPE(pCol->colVal.value.type) && pCol->colVal.value.pData) {
|
||||||
taosMemoryFree(pCol->colVal.value.pData);
|
taosMemoryFree(pCol->colVal.value.pData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -390,12 +389,12 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
||||||
for (int32_t i = 0; i < pr->numOfCols; ++i) {
|
for (int32_t i = 0; i < pr->numOfCols; ++i) {
|
||||||
int32_t slotId = slotIds[i];
|
int32_t slotId = slotIds[i];
|
||||||
if (slotId == -1) {
|
if (slotId == -1) {
|
||||||
SLastCol p = {.ts = INT64_MIN, .colVal.type = TSDB_DATA_TYPE_BOOL, .colVal.flag = CV_FLAG_NULL};
|
SLastCol p = {.ts = INT64_MIN, .colVal.value.type = TSDB_DATA_TYPE_BOOL, .colVal.flag = CV_FLAG_NULL};
|
||||||
taosArrayPush(pLastCols, &p);
|
taosArrayPush(pLastCols, &p);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct STColumn* pCol = &pr->pSchema->columns[slotId];
|
struct STColumn* pCol = &pr->pSchema->columns[slotId];
|
||||||
SLastCol p = {.ts = INT64_MIN, .colVal.type = pCol->type, .colVal.flag = CV_FLAG_NULL};
|
SLastCol p = {.ts = INT64_MIN, .colVal.value.type = pCol->type, .colVal.flag = CV_FLAG_NULL};
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||||
p.colVal.value.pData = taosMemoryCalloc(pCol->bytes, sizeof(char));
|
p.colVal.value.pData = taosMemoryCalloc(pCol->bytes, sizeof(char));
|
||||||
|
@ -447,7 +446,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
||||||
singleTableLastTs = pColVal->ts;
|
singleTableLastTs = pColVal->ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_VAR_DATA_TYPE(pColVal->colVal.type)) {
|
if (!IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) {
|
||||||
p->colVal = pColVal->colVal;
|
p->colVal = pColVal->colVal;
|
||||||
} else {
|
} else {
|
||||||
if (COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
if (COL_VAL_IS_VALUE(&pColVal->colVal)) {
|
||||||
|
@ -455,7 +454,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
||||||
}
|
}
|
||||||
|
|
||||||
p->colVal.value.nData = pColVal->colVal.value.nData;
|
p->colVal.value.nData = pColVal->colVal.value.nData;
|
||||||
p->colVal.type = pColVal->colVal.type;
|
p->colVal.value.type = pColVal->colVal.value.type;
|
||||||
p->colVal.flag = pColVal->colVal.flag;
|
p->colVal.flag = pColVal->colVal.flag;
|
||||||
p->colVal.cid = pColVal->colVal.cid;
|
p->colVal.cid = pColVal->colVal.cid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ int32_t tRowInfoCmprFn(const void *p1, const void *p2) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tsdbRowCmprFn(&pInfo1->row, &pInfo2->row);
|
return tsdbRowCompare(&pInfo1->row, &pInfo2->row);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbBegin(STsdb *pTsdb) {
|
int32_t tsdbBegin(STsdb *pTsdb) {
|
||||||
|
|
|
@ -300,8 +300,11 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) {
|
||||||
// mem data iter
|
// mem data iter
|
||||||
config.type = TSDB_ITER_TYPE_MEMT;
|
config.type = TSDB_ITER_TYPE_MEMT;
|
||||||
config.memt = committer->tsdb->imem;
|
config.memt = committer->tsdb->imem;
|
||||||
config.from->ts = committer->ctx->minKey;
|
|
||||||
config.from->version = VERSION_MIN;
|
config.from->version = VERSION_MIN;
|
||||||
|
config.from->key = (SRowKey){
|
||||||
|
.ts = committer->ctx->minKey,
|
||||||
|
.numOfPKs = 0, // TODO: support multiple primary keys
|
||||||
|
};
|
||||||
|
|
||||||
code = tsdbIterOpen(&config, &iter);
|
code = tsdbIterOpen(&config, &iter);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,18 +25,16 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef TARRAY2(SBlockIdx) TBlockIdxArray;
|
|
||||||
typedef TARRAY2(SDataBlk) TDataBlkArray;
|
|
||||||
typedef TARRAY2(SColumnDataAgg) TColumnDataAggArray;
|
typedef TARRAY2(SColumnDataAgg) TColumnDataAggArray;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SFDataPtr brinBlkPtr[1];
|
SFDataPtr brinBlkPtr[1];
|
||||||
SFDataPtr rsrvd[2];
|
char rsrvd[32];
|
||||||
} SHeadFooter;
|
} SHeadFooter;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SFDataPtr tombBlkPtr[1];
|
SFDataPtr tombBlkPtr[1];
|
||||||
SFDataPtr rsrvd[2];
|
char rsrvd[32];
|
||||||
} STombFooter;
|
} STombFooter;
|
||||||
|
|
||||||
// SDataFileReader =============================================
|
// SDataFileReader =============================================
|
||||||
|
@ -48,7 +46,7 @@ typedef struct SDataFileReaderConfig {
|
||||||
bool exist;
|
bool exist;
|
||||||
STFile file;
|
STFile file;
|
||||||
} files[TSDB_FTYPE_MAX];
|
} files[TSDB_FTYPE_MAX];
|
||||||
uint8_t **bufArr;
|
SBuffer *buffers;
|
||||||
} SDataFileReaderConfig;
|
} SDataFileReaderConfig;
|
||||||
|
|
||||||
int32_t tsdbDataFileReaderOpen(const char *fname[/* TSDB_FTYPE_MAX */], const SDataFileReaderConfig *config,
|
int32_t tsdbDataFileReaderOpen(const char *fname[/* TSDB_FTYPE_MAX */], const SDataFileReaderConfig *config,
|
||||||
|
@ -86,7 +84,7 @@ typedef struct SDataFileWriterConfig {
|
||||||
SSkmInfo *skmTb;
|
SSkmInfo *skmTb;
|
||||||
SSkmInfo *skmRow;
|
SSkmInfo *skmRow;
|
||||||
SHashObj *pColCmpr;
|
SHashObj *pColCmpr;
|
||||||
uint8_t **bufArr;
|
SBuffer *buffers;
|
||||||
} SDataFileWriterConfig;
|
} SDataFileWriterConfig;
|
||||||
|
|
||||||
int32_t tsdbDataFileWriterOpen(const SDataFileWriterConfig *config, SDataFileWriter **writer);
|
int32_t tsdbDataFileWriterOpen(const SDataFileWriterConfig *config, SDataFileWriter **writer);
|
||||||
|
@ -98,14 +96,14 @@ int32_t tsdbDataFileFlush(SDataFileWriter *writer);
|
||||||
|
|
||||||
// head
|
// head
|
||||||
int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, int8_t cmprAlg, int64_t *fileSize,
|
int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, int8_t cmprAlg, int64_t *fileSize,
|
||||||
TBrinBlkArray *brinBlkArray, uint8_t **bufArr, SVersionRange *range);
|
TBrinBlkArray *brinBlkArray, SBuffer *buffers, SVersionRange *range);
|
||||||
int32_t tsdbFileWriteBrinBlk(STsdbFD *fd, TBrinBlkArray *brinBlkArray, SFDataPtr *ptr, int64_t *fileSize);
|
int32_t tsdbFileWriteBrinBlk(STsdbFD *fd, TBrinBlkArray *brinBlkArray, SFDataPtr *ptr, int64_t *fileSize);
|
||||||
int32_t tsdbFileWriteHeadFooter(STsdbFD *fd, int64_t *fileSize, const SHeadFooter *footer);
|
int32_t tsdbFileWriteHeadFooter(STsdbFD *fd, int64_t *fileSize, const SHeadFooter *footer);
|
||||||
|
|
||||||
// tomb
|
// tomb
|
||||||
int32_t tsdbDataFileWriteTombRecord(SDataFileWriter *writer, const STombRecord *record);
|
int32_t tsdbDataFileWriteTombRecord(SDataFileWriter *writer, const STombRecord *record);
|
||||||
int32_t tsdbFileWriteTombBlock(STsdbFD *fd, STombBlock *tombBlock, int8_t cmprAlg, int64_t *fileSize,
|
int32_t tsdbFileWriteTombBlock(STsdbFD *fd, STombBlock *tombBlock, int8_t cmprAlg, int64_t *fileSize,
|
||||||
TTombBlkArray *tombBlkArray, uint8_t **bufArr, SVersionRange *range);
|
TTombBlkArray *tombBlkArray, SBuffer *buffers, SVersionRange *range);
|
||||||
int32_t tsdbFileWriteTombBlk(STsdbFD *fd, const TTombBlkArray *tombBlkArray, SFDataPtr *ptr, int64_t *fileSize);
|
int32_t tsdbFileWriteTombBlk(STsdbFD *fd, const TTombBlkArray *tombBlkArray, SFDataPtr *ptr, int64_t *fileSize);
|
||||||
int32_t tsdbFileWriteTombFooter(STsdbFD *fd, const STombFooter *footer, int64_t *fileSize);
|
int32_t tsdbFileWriteTombFooter(STsdbFD *fd, const STombFooter *footer, int64_t *fileSize);
|
||||||
|
|
||||||
|
|
|
@ -1,477 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "tsdb.h"
|
|
||||||
#include "vnodeInt.h"
|
|
||||||
|
|
||||||
#ifdef BUILD_NO_CALL
|
|
||||||
// STsdbDataIter2
|
|
||||||
/* open */
|
|
||||||
int32_t tsdbOpenDataFileDataIter(SDataFReader* pReader, STsdbDataIter2** ppIter) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
// create handle
|
|
||||||
STsdbDataIter2* pIter = (STsdbDataIter2*)taosMemoryCalloc(1, sizeof(*pIter));
|
|
||||||
if (pIter == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
pIter->type = TSDB_DATA_FILE_DATA_ITER;
|
|
||||||
pIter->dIter.pReader = pReader;
|
|
||||||
if ((pIter->dIter.aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx))) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tBlockDataCreate(&pIter->dIter.bData);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
pIter->dIter.iBlockIdx = 0;
|
|
||||||
pIter->dIter.iDataBlk = 0;
|
|
||||||
pIter->dIter.iRow = 0;
|
|
||||||
|
|
||||||
// read data
|
|
||||||
code = tsdbReadBlockIdx(pReader, pIter->dIter.aBlockIdx);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
if (taosArrayGetSize(pIter->dIter.aBlockIdx) == 0) goto _clear;
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
if (pIter) {
|
|
||||||
_clear:
|
|
||||||
tBlockDataDestroy(&pIter->dIter.bData);
|
|
||||||
taosArrayDestroy(pIter->dIter.aBlockIdx);
|
|
||||||
taosMemoryFree(pIter);
|
|
||||||
pIter = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*ppIter = pIter;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbOpenSttFileDataIter(SDataFReader* pReader, int32_t iStt, STsdbDataIter2** ppIter) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
// create handle
|
|
||||||
STsdbDataIter2* pIter = (STsdbDataIter2*)taosMemoryCalloc(1, sizeof(*pIter));
|
|
||||||
if (pIter == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
pIter->type = TSDB_STT_FILE_DATA_ITER;
|
|
||||||
pIter->sIter.pReader = pReader;
|
|
||||||
pIter->sIter.iStt = iStt;
|
|
||||||
pIter->sIter.aSttBlk = taosArrayInit(0, sizeof(SSttBlk));
|
|
||||||
if (pIter->sIter.aSttBlk == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tBlockDataCreate(&pIter->sIter.bData);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
pIter->sIter.iSttBlk = 0;
|
|
||||||
pIter->sIter.iRow = 0;
|
|
||||||
|
|
||||||
// read data
|
|
||||||
code = tsdbReadSttBlk(pReader, iStt, pIter->sIter.aSttBlk);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
if (taosArrayGetSize(pIter->sIter.aSttBlk) == 0) goto _clear;
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
if (pIter) {
|
|
||||||
_clear:
|
|
||||||
taosArrayDestroy(pIter->sIter.aSttBlk);
|
|
||||||
tBlockDataDestroy(&pIter->sIter.bData);
|
|
||||||
taosMemoryFree(pIter);
|
|
||||||
pIter = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*ppIter = pIter;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbOpenTombFileDataIter(SDelFReader* pReader, STsdbDataIter2** ppIter) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
STsdbDataIter2* pIter = (STsdbDataIter2*)taosMemoryCalloc(1, sizeof(*pIter));
|
|
||||||
if (pIter == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
pIter->type = TSDB_TOMB_FILE_DATA_ITER;
|
|
||||||
|
|
||||||
pIter->tIter.pReader = pReader;
|
|
||||||
if ((pIter->tIter.aDelIdx = taosArrayInit(0, sizeof(SDelIdx))) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
if ((pIter->tIter.aDelData = taosArrayInit(0, sizeof(SDelData))) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbReadDelIdx(pReader, pIter->tIter.aDelIdx);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
if (taosArrayGetSize(pIter->tIter.aDelIdx) == 0) goto _clear;
|
|
||||||
|
|
||||||
pIter->tIter.iDelIdx = 0;
|
|
||||||
pIter->tIter.iDelData = 0;
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
if (pIter) {
|
|
||||||
_clear:
|
|
||||||
taosArrayDestroy(pIter->tIter.aDelIdx);
|
|
||||||
taosArrayDestroy(pIter->tIter.aDelData);
|
|
||||||
taosMemoryFree(pIter);
|
|
||||||
pIter = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*ppIter = pIter;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* close */
|
|
||||||
static void tsdbCloseDataFileDataIter(STsdbDataIter2* pIter) {
|
|
||||||
tBlockDataDestroy(&pIter->dIter.bData);
|
|
||||||
tMapDataClear(&pIter->dIter.mDataBlk);
|
|
||||||
taosArrayDestroy(pIter->dIter.aBlockIdx);
|
|
||||||
taosMemoryFree(pIter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tsdbCloseSttFileDataIter(STsdbDataIter2* pIter) {
|
|
||||||
tBlockDataDestroy(&pIter->sIter.bData);
|
|
||||||
taosArrayDestroy(pIter->sIter.aSttBlk);
|
|
||||||
taosMemoryFree(pIter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tsdbCloseTombFileDataIter(STsdbDataIter2* pIter) {
|
|
||||||
taosArrayDestroy(pIter->tIter.aDelData);
|
|
||||||
taosArrayDestroy(pIter->tIter.aDelIdx);
|
|
||||||
taosMemoryFree(pIter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tsdbCloseDataIter2(STsdbDataIter2* pIter) {
|
|
||||||
if (pIter->type == TSDB_MEM_TABLE_DATA_ITER) {
|
|
||||||
ASSERT(0);
|
|
||||||
} else if (pIter->type == TSDB_DATA_FILE_DATA_ITER) {
|
|
||||||
tsdbCloseDataFileDataIter(pIter);
|
|
||||||
} else if (pIter->type == TSDB_STT_FILE_DATA_ITER) {
|
|
||||||
tsdbCloseSttFileDataIter(pIter);
|
|
||||||
} else if (pIter->type == TSDB_TOMB_FILE_DATA_ITER) {
|
|
||||||
tsdbCloseTombFileDataIter(pIter);
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cmpr */
|
|
||||||
int32_t tsdbDataIterCmprFn(const SRBTreeNode* pNode1, const SRBTreeNode* pNode2) {
|
|
||||||
STsdbDataIter2* pIter1 = TSDB_RBTN_TO_DATA_ITER(pNode1);
|
|
||||||
STsdbDataIter2* pIter2 = TSDB_RBTN_TO_DATA_ITER(pNode2);
|
|
||||||
return tRowInfoCmprFn(&pIter1->rowInfo, &pIter2->rowInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* seek */
|
|
||||||
|
|
||||||
/* iter next */
|
|
||||||
static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* pFilterInfo) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
while (pIter->dIter.iRow < pIter->dIter.bData.nRow) {
|
|
||||||
if (pFilterInfo) {
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
|
|
||||||
if (pIter->dIter.bData.aVersion[pIter->dIter.iRow] < pFilterInfo->sver ||
|
|
||||||
pIter->dIter.bData.aVersion[pIter->dIter.iRow] > pFilterInfo->ever) {
|
|
||||||
pIter->dIter.iRow++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pIter->rowInfo.suid == pIter->dIter.bData.suid);
|
|
||||||
ASSERT(pIter->rowInfo.uid == pIter->dIter.bData.uid);
|
|
||||||
pIter->rowInfo.row = tsdbRowFromBlockData(&pIter->dIter.bData, pIter->dIter.iRow);
|
|
||||||
pIter->dIter.iRow++;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
while (pIter->dIter.iDataBlk < pIter->dIter.mDataBlk.nItem) {
|
|
||||||
SDataBlk dataBlk;
|
|
||||||
tMapDataGetItemByIdx(&pIter->dIter.mDataBlk, pIter->dIter.iDataBlk, &dataBlk, tGetDataBlk);
|
|
||||||
|
|
||||||
// filter
|
|
||||||
if (pFilterInfo) {
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
|
|
||||||
if (pFilterInfo->sver > dataBlk.maxVer || pFilterInfo->ever < dataBlk.minVer) {
|
|
||||||
pIter->dIter.iDataBlk++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbReadDataBlockEx(pIter->dIter.pReader, &dataBlk, &pIter->dIter.bData);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
pIter->dIter.iDataBlk++;
|
|
||||||
pIter->dIter.iRow = 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pIter->dIter.iRow < pIter->dIter.bData.nRow) break;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (pIter->dIter.iBlockIdx < taosArrayGetSize(pIter->dIter.aBlockIdx)) {
|
|
||||||
SBlockIdx* pBlockIdx = taosArrayGet(pIter->dIter.aBlockIdx, pIter->dIter.iBlockIdx);
|
|
||||||
|
|
||||||
if (pFilterInfo) {
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
|
|
||||||
int32_t c = tTABLEIDCmprFn(pBlockIdx, &pFilterInfo->tbid);
|
|
||||||
if (c == 0) {
|
|
||||||
pIter->dIter.iBlockIdx++;
|
|
||||||
continue;
|
|
||||||
} else if (c < 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) {
|
|
||||||
SMetaInfo info;
|
|
||||||
if (metaGetInfo(pIter->dIter.pReader->pTsdb->pVnode->pMeta, pBlockIdx->uid, &info, NULL)) {
|
|
||||||
pIter->dIter.iBlockIdx++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbReadDataBlk(pIter->dIter.pReader, pBlockIdx, &pIter->dIter.mDataBlk);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
pIter->rowInfo.suid = pBlockIdx->suid;
|
|
||||||
pIter->rowInfo.uid = pBlockIdx->uid;
|
|
||||||
|
|
||||||
pIter->dIter.iBlockIdx++;
|
|
||||||
pIter->dIter.iDataBlk = 0;
|
|
||||||
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
pIter->rowInfo = (SRowInfo){0};
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tsdbSttFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* pFilterInfo) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
while (pIter->sIter.iRow < pIter->sIter.bData.nRow) {
|
|
||||||
if (pFilterInfo) {
|
|
||||||
int64_t uid = pIter->sIter.bData.uid ? pIter->sIter.bData.uid : pIter->sIter.bData.aUid[pIter->sIter.iRow];
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
|
|
||||||
if (pFilterInfo->tbid.uid == uid) {
|
|
||||||
pIter->sIter.iRow++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) {
|
|
||||||
if (pIter->rowInfo.uid != uid) {
|
|
||||||
SMetaInfo info;
|
|
||||||
if (metaGetInfo(pIter->sIter.pReader->pTsdb->pVnode->pMeta, uid, &info, NULL)) {
|
|
||||||
pIter->sIter.iRow++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
|
|
||||||
if (pFilterInfo->sver > pIter->sIter.bData.aVersion[pIter->sIter.iRow] ||
|
|
||||||
pFilterInfo->ever < pIter->sIter.bData.aVersion[pIter->sIter.iRow]) {
|
|
||||||
pIter->sIter.iRow++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pIter->rowInfo.suid = pIter->sIter.bData.suid;
|
|
||||||
pIter->rowInfo.uid = pIter->sIter.bData.uid ? pIter->sIter.bData.uid : pIter->sIter.bData.aUid[pIter->sIter.iRow];
|
|
||||||
pIter->rowInfo.row = tsdbRowFromBlockData(&pIter->sIter.bData, pIter->sIter.iRow);
|
|
||||||
pIter->sIter.iRow++;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (pIter->sIter.iSttBlk < taosArrayGetSize(pIter->sIter.aSttBlk)) {
|
|
||||||
SSttBlk* pSttBlk = taosArrayGet(pIter->sIter.aSttBlk, pIter->sIter.iSttBlk);
|
|
||||||
|
|
||||||
if (pFilterInfo) {
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
|
|
||||||
if (pSttBlk->suid == pFilterInfo->tbid.suid && pSttBlk->minUid == pFilterInfo->tbid.uid &&
|
|
||||||
pSttBlk->maxUid == pFilterInfo->tbid.uid) {
|
|
||||||
pIter->sIter.iSttBlk++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
|
|
||||||
if (pFilterInfo->sver > pSttBlk->maxVer || pFilterInfo->ever < pSttBlk->minVer) {
|
|
||||||
pIter->sIter.iSttBlk++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbReadSttBlockEx(pIter->sIter.pReader, pIter->sIter.iStt, pSttBlk, &pIter->sIter.bData);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
pIter->sIter.iRow = 0;
|
|
||||||
pIter->sIter.iSttBlk++;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
pIter->rowInfo = (SRowInfo){0};
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tsdbTombFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* pFilterInfo) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
while (pIter->tIter.iDelData < taosArrayGetSize(pIter->tIter.aDelData)) {
|
|
||||||
SDelData* pDelData = taosArrayGet(pIter->tIter.aDelData, pIter->tIter.iDelData);
|
|
||||||
|
|
||||||
if (pFilterInfo) {
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
|
|
||||||
if (pFilterInfo->sver > pDelData->version || pFilterInfo->ever < pDelData->version) {
|
|
||||||
pIter->tIter.iDelData++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pIter->delInfo.delData = *pDelData;
|
|
||||||
pIter->tIter.iDelData++;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (pIter->tIter.iDelIdx < taosArrayGetSize(pIter->tIter.aDelIdx)) {
|
|
||||||
SDelIdx* pDelIdx = taosArrayGet(pIter->tIter.aDelIdx, pIter->tIter.iDelIdx);
|
|
||||||
|
|
||||||
if (pFilterInfo) {
|
|
||||||
if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) {
|
|
||||||
SMetaInfo info;
|
|
||||||
if (metaGetInfo(pIter->dIter.pReader->pTsdb->pVnode->pMeta, pDelIdx->uid, &info, NULL)) {
|
|
||||||
pIter->tIter.iDelIdx++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbReadDelDatav1(pIter->tIter.pReader, pDelIdx, pIter->tIter.aDelData, INT64_MAX);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
pIter->delInfo.suid = pDelIdx->suid;
|
|
||||||
pIter->delInfo.uid = pDelIdx->uid;
|
|
||||||
pIter->tIter.iDelData = 0;
|
|
||||||
pIter->tIter.iDelIdx++;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
pIter->delInfo = (SDelInfo){0};
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbDataIterNext2(STsdbDataIter2* pIter, STsdbFilterInfo* pFilterInfo) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
if (pIter->type == TSDB_MEM_TABLE_DATA_ITER) {
|
|
||||||
ASSERT(0);
|
|
||||||
return code;
|
|
||||||
} else if (pIter->type == TSDB_DATA_FILE_DATA_ITER) {
|
|
||||||
return tsdbDataFileDataIterNext(pIter, pFilterInfo);
|
|
||||||
} else if (pIter->type == TSDB_STT_FILE_DATA_ITER) {
|
|
||||||
return tsdbSttFileDataIterNext(pIter, pFilterInfo);
|
|
||||||
} else if (pIter->type == TSDB_TOMB_FILE_DATA_ITER) {
|
|
||||||
return tsdbTombFileDataIterNext(pIter, pFilterInfo);
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* get */
|
|
||||||
|
|
||||||
// STsdbFSetIter
|
|
||||||
typedef struct STsdbFSetDataIter {
|
|
||||||
STsdb* pTsdb;
|
|
||||||
int32_t flags;
|
|
||||||
|
|
||||||
/* tombstone */
|
|
||||||
SDelFReader* pDelFReader;
|
|
||||||
SArray* aDelIdx; // SArray<SDelIdx>
|
|
||||||
SArray* aDelData; // SArray<SDelData>
|
|
||||||
SArray* aSkeyLine; // SArray<TABLEID>
|
|
||||||
int32_t iDelIdx;
|
|
||||||
int32_t iSkyLine;
|
|
||||||
|
|
||||||
/* time-series data */
|
|
||||||
SDataFReader* pReader;
|
|
||||||
STsdbDataIter2* iterList;
|
|
||||||
STsdbDataIter2* pIter;
|
|
||||||
SRBTree rbt;
|
|
||||||
} STsdbFSetDataIter;
|
|
|
@ -35,6 +35,7 @@ extern int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbF
|
||||||
extern void tsdbCloseFile(STsdbFD **ppFD);
|
extern void tsdbCloseFile(STsdbFD **ppFD);
|
||||||
extern int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size);
|
extern int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size);
|
||||||
extern int32_t tsdbReadFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint);
|
extern int32_t tsdbReadFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint);
|
||||||
|
extern int32_t tsdbReadFileToBuffer(STsdbFD *pFD, int64_t offset, int64_t size, SBuffer *buffer, int64_t szHint);
|
||||||
extern int32_t tsdbFsyncFile(STsdbFD *pFD);
|
extern int32_t tsdbFsyncFile(STsdbFD *pFD);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,697 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "tsdb.h"
|
|
||||||
|
|
||||||
typedef struct SDiskColBuilder SDiskColBuilder;
|
|
||||||
|
|
||||||
struct SDiskColBuilder {
|
|
||||||
int16_t cid;
|
|
||||||
int8_t type;
|
|
||||||
uint8_t cmprAlg;
|
|
||||||
uint8_t calcSma;
|
|
||||||
int8_t flag;
|
|
||||||
int32_t nVal;
|
|
||||||
uint8_t *pBitMap;
|
|
||||||
int32_t offset;
|
|
||||||
SCompressor *pOffC;
|
|
||||||
SCompressor *pValC;
|
|
||||||
SColumnDataAgg sma;
|
|
||||||
uint8_t minSet;
|
|
||||||
uint8_t maxSet;
|
|
||||||
uint8_t *aBuf[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
// SDiskData ================================================
|
|
||||||
static int32_t tDiskDataDestroy(SDiskData *pDiskData) {
|
|
||||||
int32_t code = 0;
|
|
||||||
pDiskData->aDiskCol = taosArrayDestroy(pDiskData->aDiskCol);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDiskColBuilder ================================================
|
|
||||||
#define tDiskColBuilderCreate() \
|
|
||||||
(SDiskColBuilder) { 0 }
|
|
||||||
|
|
||||||
static int32_t tDiskColBuilderDestroy(SDiskColBuilder *pBuilder) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
tFree(pBuilder->pBitMap);
|
|
||||||
if (pBuilder->pOffC) tCompressorDestroy(pBuilder->pOffC);
|
|
||||||
if (pBuilder->pValC) tCompressorDestroy(pBuilder->pValC);
|
|
||||||
for (int32_t iBuf = 0; iBuf < sizeof(pBuilder->aBuf) / sizeof(pBuilder->aBuf[0]); iBuf++) {
|
|
||||||
tFree(pBuilder->aBuf[iBuf]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tDiskColBuilderInit(SDiskColBuilder *pBuilder, int16_t cid, int8_t type, uint8_t cmprAlg,
|
|
||||||
uint8_t calcSma) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pBuilder->cid = cid;
|
|
||||||
pBuilder->type = type;
|
|
||||||
pBuilder->cmprAlg = cmprAlg;
|
|
||||||
pBuilder->calcSma = IS_VAR_DATA_TYPE(type) ? 0 : calcSma;
|
|
||||||
pBuilder->flag = 0;
|
|
||||||
pBuilder->nVal = 0;
|
|
||||||
pBuilder->offset = 0;
|
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(type)) {
|
|
||||||
if (pBuilder->pOffC == NULL && (code = tCompressorCreate(&pBuilder->pOffC))) return code;
|
|
||||||
code = tCompressStart(pBuilder->pOffC, TSDB_DATA_TYPE_INT, cmprAlg);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pBuilder->pValC == NULL && (code = tCompressorCreate(&pBuilder->pValC))) return code;
|
|
||||||
code = tCompressStart(pBuilder->pValC, type, cmprAlg);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
if (pBuilder->calcSma) {
|
|
||||||
pBuilder->sma = (SColumnDataAgg){.colId = cid};
|
|
||||||
pBuilder->minSet = 0;
|
|
||||||
pBuilder->maxSet = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tGnrtDiskCol(SDiskColBuilder *pBuilder, SDiskCol *pDiskCol) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
ASSERT(pBuilder->flag && pBuilder->flag != HAS_NONE);
|
|
||||||
|
|
||||||
*pDiskCol = (SDiskCol){(SBlockCol){.cid = pBuilder->cid,
|
|
||||||
.type = pBuilder->type,
|
|
||||||
.smaOn = pBuilder->calcSma,
|
|
||||||
.flag = pBuilder->flag,
|
|
||||||
.szOrigin = 0,
|
|
||||||
.szBitmap = 0,
|
|
||||||
.szOffset = 0,
|
|
||||||
.szValue = 0,
|
|
||||||
.offset = 0},
|
|
||||||
.pBit = NULL, .pOff = NULL, .pVal = NULL, .agg = pBuilder->sma};
|
|
||||||
|
|
||||||
if (pBuilder->flag == HAS_NULL) return code;
|
|
||||||
|
|
||||||
// BITMAP
|
|
||||||
if (pBuilder->flag != HAS_VALUE) {
|
|
||||||
int32_t nBit;
|
|
||||||
if (pBuilder->flag == (HAS_VALUE | HAS_NULL | HAS_NONE)) {
|
|
||||||
nBit = BIT2_SIZE(pBuilder->nVal);
|
|
||||||
} else {
|
|
||||||
nBit = BIT1_SIZE(pBuilder->nVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->aBuf[0], nBit + COMP_OVERFLOW_BYTES);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->aBuf[1], nBit + COMP_OVERFLOW_BYTES);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
pDiskCol->bCol.szBitmap =
|
|
||||||
tsCompressTinyint(pBuilder->pBitMap, nBit, nBit, pBuilder->aBuf[0], nBit + COMP_OVERFLOW_BYTES,
|
|
||||||
pBuilder->cmprAlg, pBuilder->aBuf[1], nBit + COMP_OVERFLOW_BYTES);
|
|
||||||
pDiskCol->pBit = pBuilder->aBuf[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// OFFSET
|
|
||||||
if (IS_VAR_DATA_TYPE(pBuilder->type)) {
|
|
||||||
code = tCompressEnd(pBuilder->pOffC, &pDiskCol->pOff, &pDiskCol->bCol.szOffset, NULL);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// VALUE
|
|
||||||
if (pBuilder->flag != (HAS_NULL | HAS_NONE)) {
|
|
||||||
code = tCompressEnd(pBuilder->pValC, &pDiskCol->pVal, &pDiskCol->bCol.szValue, &pDiskCol->bCol.szOrigin);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tDiskColPutValue(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
|
||||||
code = tCompress(pBuilder->pOffC, &pBuilder->offset, sizeof(int32_t));
|
|
||||||
if (code) return code;
|
|
||||||
pBuilder->offset += pColVal->value.nData;
|
|
||||||
|
|
||||||
code = tCompress(pBuilder->pValC, pColVal->value.pData, pColVal->value.nData);
|
|
||||||
if (code) return code;
|
|
||||||
} else {
|
|
||||||
code = tCompress(pBuilder->pValC, &pColVal->value.val, tDataTypes[pColVal->type].bytes);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal00(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
pBuilder->flag = HAS_VALUE;
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal01(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
pBuilder->flag = HAS_NONE;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal02(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
pBuilder->flag = HAS_NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal10(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
// bit map
|
|
||||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
memset(pBuilder->pBitMap, 0, nBit);
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
// value
|
|
||||||
pBuilder->flag |= HAS_VALUE;
|
|
||||||
|
|
||||||
SColVal cv = COL_VAL_VALUE(pColVal->cid, pColVal->type, (SValue){0});
|
|
||||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
|
||||||
code = tDiskColPutValue(pBuilder, &cv);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal12(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
memset(pBuilder->pBitMap, 0, nBit);
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_NULL;
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal20(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_VALUE;
|
|
||||||
|
|
||||||
memset(pBuilder->pBitMap, 0, nBit);
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
SColVal cv = COL_VAL_VALUE(pColVal->cid, pColVal->type, (SValue){0});
|
|
||||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
|
||||||
code = tDiskColPutValue(pBuilder, &cv);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal21(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_NONE;
|
|
||||||
|
|
||||||
memset(pBuilder->pBitMap, 255, nBit);
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal30(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_VALUE;
|
|
||||||
|
|
||||||
uint8_t *pBitMap = NULL;
|
|
||||||
code = tRealloc(&pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
|
||||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pBuilder->pBitMap, iVal));
|
|
||||||
}
|
|
||||||
SET_BIT2(pBitMap, pBuilder->nVal, 2);
|
|
||||||
|
|
||||||
tFree(pBuilder->pBitMap);
|
|
||||||
pBuilder->pBitMap = pBitMap;
|
|
||||||
|
|
||||||
SColVal cv = COL_VAL_VALUE(pColVal->cid, pColVal->type, (SValue){0});
|
|
||||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
|
||||||
code = tDiskColPutValue(pBuilder, &cv);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal31(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal32(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal40(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal41(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_NONE;
|
|
||||||
|
|
||||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
memset(pBuilder->pBitMap, 255, nBit);
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal42(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_NULL;
|
|
||||||
|
|
||||||
int32_t nBit = BIT1_SIZE(pBuilder->nVal + 1);
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, nBit);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
memset(pBuilder->pBitMap, 255, nBit);
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal50(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal51(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal52(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_NULL;
|
|
||||||
|
|
||||||
uint8_t *pBitMap = NULL;
|
|
||||||
code = tRealloc(&pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
|
||||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pBuilder->pBitMap, iVal) ? 2 : 0);
|
|
||||||
}
|
|
||||||
SET_BIT2(pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
tFree(pBuilder->pBitMap);
|
|
||||||
pBuilder->pBitMap = pBitMap;
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal60(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal61(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pBuilder->flag |= HAS_NONE;
|
|
||||||
|
|
||||||
uint8_t *pBitMap = NULL;
|
|
||||||
code = tRealloc(&pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
for (int32_t iVal = 0; iVal < pBuilder->nVal; iVal++) {
|
|
||||||
SET_BIT2(pBitMap, iVal, GET_BIT1(pBuilder->pBitMap, iVal) ? 2 : 1);
|
|
||||||
}
|
|
||||||
SET_BIT2(pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
tFree(pBuilder->pBitMap);
|
|
||||||
pBuilder->pBitMap = pBitMap;
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal62(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT1_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT1(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal70(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT2(pBuilder->pBitMap, pBuilder->nVal, 2);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal71(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT2(pBuilder->pBitMap, pBuilder->nVal, 0);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t tDiskColAddVal72(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tRealloc(&pBuilder->pBitMap, BIT2_SIZE(pBuilder->nVal + 1));
|
|
||||||
if (code) return code;
|
|
||||||
SET_BIT2(pBuilder->pBitMap, pBuilder->nVal, 1);
|
|
||||||
|
|
||||||
return tDiskColPutValue(pBuilder, pColVal);
|
|
||||||
}
|
|
||||||
static int32_t (*tDiskColAddValImpl[8][3])(SDiskColBuilder *pBuilder, SColVal *pColVal) = {
|
|
||||||
{tDiskColAddVal00, tDiskColAddVal01, tDiskColAddVal02}, // 0
|
|
||||||
{tDiskColAddVal10, NULL, tDiskColAddVal12}, // HAS_NONE
|
|
||||||
{tDiskColAddVal20, tDiskColAddVal21, NULL}, // HAS_NULL
|
|
||||||
{tDiskColAddVal30, tDiskColAddVal31, tDiskColAddVal32}, // HAS_NULL|HAS_NONE
|
|
||||||
{tDiskColAddVal40, tDiskColAddVal41, tDiskColAddVal42}, // HAS_VALUE
|
|
||||||
{tDiskColAddVal50, tDiskColAddVal51, tDiskColAddVal52}, // HAS_VALUE|HAS_NONE
|
|
||||||
{tDiskColAddVal60, tDiskColAddVal61, tDiskColAddVal62}, // HAS_VALUE|HAS_NULL
|
|
||||||
{tDiskColAddVal70, tDiskColAddVal71, tDiskColAddVal72} // HAS_VALUE|HAS_NULL|HAS_NONE
|
|
||||||
};
|
|
||||||
// extern void (*tSmaUpdateImpl[])(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet);
|
|
||||||
static int32_t tDiskColAddVal(SDiskColBuilder *pBuilder, SColVal *pColVal) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
if (pBuilder->calcSma) {
|
|
||||||
if (COL_VAL_IS_VALUE(pColVal)) {
|
|
||||||
// tSmaUpdateImpl[pBuilder->type](&pBuilder->sma, pColVal, &pBuilder->minSet, &pBuilder->maxSet);
|
|
||||||
} else {
|
|
||||||
pBuilder->sma.numOfNull++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tDiskColAddValImpl[pBuilder->flag][pColVal->flag]) {
|
|
||||||
code = tDiskColAddValImpl[pBuilder->flag][pColVal->flag](pBuilder, pColVal);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
pBuilder->nVal++;
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDiskDataBuilder ================================================
|
|
||||||
int32_t tDiskDataBuilderCreate(SDiskDataBuilder **ppBuilder) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
*ppBuilder = (SDiskDataBuilder *)taosMemoryCalloc(1, sizeof(SDiskDataBuilder));
|
|
||||||
if (*ppBuilder == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *tDiskDataBuilderDestroy(SDiskDataBuilder *pBuilder) {
|
|
||||||
if (pBuilder == NULL) return NULL;
|
|
||||||
|
|
||||||
if (pBuilder->pUidC) tCompressorDestroy(pBuilder->pUidC);
|
|
||||||
if (pBuilder->pVerC) tCompressorDestroy(pBuilder->pVerC);
|
|
||||||
if (pBuilder->pKeyC) tCompressorDestroy(pBuilder->pKeyC);
|
|
||||||
|
|
||||||
if (pBuilder->aBuilder) {
|
|
||||||
for (int32_t iBuilder = 0; iBuilder < taosArrayGetSize(pBuilder->aBuilder); iBuilder++) {
|
|
||||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
|
|
||||||
tDiskColBuilderDestroy(pDCBuilder);
|
|
||||||
}
|
|
||||||
taosArrayDestroy(pBuilder->aBuilder);
|
|
||||||
}
|
|
||||||
for (int32_t iBuf = 0; iBuf < sizeof(pBuilder->aBuf) / sizeof(pBuilder->aBuf[0]); iBuf++) {
|
|
||||||
tFree(pBuilder->aBuf[iBuf]);
|
|
||||||
}
|
|
||||||
tDiskDataDestroy(&pBuilder->dd);
|
|
||||||
taosMemoryFree(pBuilder);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tDiskDataBuilderInit(SDiskDataBuilder *pBuilder, STSchema *pTSchema, TABLEID *pId, uint8_t cmprAlg,
|
|
||||||
uint8_t calcSma) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
ASSERT(pId->suid || pId->uid);
|
|
||||||
|
|
||||||
pBuilder->suid = pId->suid;
|
|
||||||
pBuilder->uid = pId->uid;
|
|
||||||
pBuilder->nRow = 0;
|
|
||||||
pBuilder->cmprAlg = cmprAlg;
|
|
||||||
pBuilder->calcSma = calcSma;
|
|
||||||
pBuilder->bi = (SBlkInfo){.minUid = INT64_MAX,
|
|
||||||
.maxUid = INT64_MIN,
|
|
||||||
.minKey = TSKEY_MAX,
|
|
||||||
.maxKey = TSKEY_MIN,
|
|
||||||
.minVer = VERSION_MAX,
|
|
||||||
.maxVer = VERSION_MIN,
|
|
||||||
.minTKey = TSDBKEY_MAX,
|
|
||||||
.maxTKey = TSDBKEY_MIN};
|
|
||||||
|
|
||||||
if (pBuilder->pUidC == NULL && (code = tCompressorCreate(&pBuilder->pUidC))) return code;
|
|
||||||
code = tCompressStart(pBuilder->pUidC, TSDB_DATA_TYPE_BIGINT, cmprAlg);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
if (pBuilder->pVerC == NULL && (code = tCompressorCreate(&pBuilder->pVerC))) return code;
|
|
||||||
code = tCompressStart(pBuilder->pVerC, TSDB_DATA_TYPE_BIGINT, cmprAlg);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
if (pBuilder->pKeyC == NULL && (code = tCompressorCreate(&pBuilder->pKeyC))) return code;
|
|
||||||
code = tCompressStart(pBuilder->pKeyC, TSDB_DATA_TYPE_TIMESTAMP, cmprAlg);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
if (pBuilder->aBuilder == NULL) {
|
|
||||||
pBuilder->aBuilder = taosArrayInit(pTSchema->numOfCols - 1, sizeof(SDiskColBuilder));
|
|
||||||
if (pBuilder->aBuilder == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pBuilder->nBuilder = 0;
|
|
||||||
for (int32_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) {
|
|
||||||
STColumn *pTColumn = &pTSchema->columns[iCol];
|
|
||||||
|
|
||||||
if (pBuilder->nBuilder >= taosArrayGetSize(pBuilder->aBuilder)) {
|
|
||||||
SDiskColBuilder dc = tDiskColBuilderCreate();
|
|
||||||
if (taosArrayPush(pBuilder->aBuilder, &dc) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, pBuilder->nBuilder);
|
|
||||||
|
|
||||||
code = tDiskColBuilderInit(pDCBuilder, pTColumn->colId, pTColumn->type, cmprAlg,
|
|
||||||
(calcSma && (pTColumn->flags & COL_SMA_ON)));
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
pBuilder->nBuilder++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tDiskDataBuilderClear(SDiskDataBuilder *pBuilder) {
|
|
||||||
int32_t code = 0;
|
|
||||||
pBuilder->suid = 0;
|
|
||||||
pBuilder->uid = 0;
|
|
||||||
pBuilder->nRow = 0;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTSchema, TABLEID *pId) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
ASSERT(pBuilder->suid || pBuilder->uid);
|
|
||||||
ASSERT(pId->suid == pBuilder->suid);
|
|
||||||
|
|
||||||
TSDBKEY kRow = TSDBROW_KEY(pRow);
|
|
||||||
if (tsdbKeyCmprFn(&pBuilder->bi.minTKey, &kRow) > 0) pBuilder->bi.minTKey = kRow;
|
|
||||||
if (tsdbKeyCmprFn(&pBuilder->bi.maxTKey, &kRow) < 0) pBuilder->bi.maxTKey = kRow;
|
|
||||||
|
|
||||||
// uid
|
|
||||||
if (pBuilder->uid && pBuilder->uid != pId->uid) {
|
|
||||||
ASSERT(pBuilder->suid);
|
|
||||||
for (int32_t iRow = 0; iRow < pBuilder->nRow; iRow++) {
|
|
||||||
code = tCompress(pBuilder->pUidC, &pBuilder->uid, sizeof(int64_t));
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
pBuilder->uid = 0;
|
|
||||||
}
|
|
||||||
if (pBuilder->uid == 0) {
|
|
||||||
code = tCompress(pBuilder->pUidC, &pId->uid, sizeof(int64_t));
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
if (pBuilder->bi.minUid > pId->uid) pBuilder->bi.minUid = pId->uid;
|
|
||||||
if (pBuilder->bi.maxUid < pId->uid) pBuilder->bi.maxUid = pId->uid;
|
|
||||||
|
|
||||||
// version
|
|
||||||
code = tCompress(pBuilder->pVerC, &kRow.version, sizeof(int64_t));
|
|
||||||
if (code) return code;
|
|
||||||
if (pBuilder->bi.minVer > kRow.version) pBuilder->bi.minVer = kRow.version;
|
|
||||||
if (pBuilder->bi.maxVer < kRow.version) pBuilder->bi.maxVer = kRow.version;
|
|
||||||
|
|
||||||
// TSKEY
|
|
||||||
code = tCompress(pBuilder->pKeyC, &kRow.ts, sizeof(int64_t));
|
|
||||||
if (code) return code;
|
|
||||||
if (pBuilder->bi.minKey > kRow.ts) pBuilder->bi.minKey = kRow.ts;
|
|
||||||
if (pBuilder->bi.maxKey < kRow.ts) pBuilder->bi.maxKey = kRow.ts;
|
|
||||||
|
|
||||||
STSDBRowIter iter = {0};
|
|
||||||
tsdbRowIterOpen(&iter, pRow, pTSchema);
|
|
||||||
|
|
||||||
SColVal *pColVal = tsdbRowIterNext(&iter);
|
|
||||||
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
|
|
||||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
|
|
||||||
|
|
||||||
while (pColVal && pColVal->cid < pDCBuilder->cid) {
|
|
||||||
pColVal = tsdbRowIterNext(&iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pColVal && pColVal->cid == pDCBuilder->cid) {
|
|
||||||
code = tDiskColAddVal(pDCBuilder, pColVal);
|
|
||||||
if (code) return code;
|
|
||||||
pColVal = tsdbRowIterNext(&iter);
|
|
||||||
} else {
|
|
||||||
code = tDiskColAddVal(pDCBuilder, &COL_VAL_NONE(pDCBuilder->cid, pDCBuilder->type));
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pBuilder->nRow++;
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tGnrtDiskData(SDiskDataBuilder *pBuilder, const SDiskData **ppDiskData, const SBlkInfo **ppBlkInfo) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
ASSERT(pBuilder->nRow);
|
|
||||||
|
|
||||||
*ppDiskData = NULL;
|
|
||||||
*ppBlkInfo = NULL;
|
|
||||||
|
|
||||||
SDiskData *pDiskData = &pBuilder->dd;
|
|
||||||
// reset SDiskData
|
|
||||||
pDiskData->hdr = (SDiskDataHdr){.delimiter = TSDB_FILE_DLMT,
|
|
||||||
.fmtVer = 0,
|
|
||||||
.suid = pBuilder->suid,
|
|
||||||
.uid = pBuilder->uid,
|
|
||||||
.szUid = 0,
|
|
||||||
.szVer = 0,
|
|
||||||
.szKey = 0,
|
|
||||||
.szBlkCol = 0,
|
|
||||||
.nRow = pBuilder->nRow,
|
|
||||||
.cmprAlg = pBuilder->cmprAlg};
|
|
||||||
pDiskData->pUid = NULL;
|
|
||||||
pDiskData->pVer = NULL;
|
|
||||||
pDiskData->pKey = NULL;
|
|
||||||
|
|
||||||
// UID
|
|
||||||
if (pBuilder->uid == 0) {
|
|
||||||
code = tCompressEnd(pBuilder->pUidC, &pDiskData->pUid, &pDiskData->hdr.szUid, NULL);
|
|
||||||
if (code) return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// VERSION
|
|
||||||
code = tCompressEnd(pBuilder->pVerC, &pDiskData->pVer, &pDiskData->hdr.szVer, NULL);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
// TSKEY
|
|
||||||
code = tCompressEnd(pBuilder->pKeyC, &pDiskData->pKey, &pDiskData->hdr.szKey, NULL);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
// aDiskCol
|
|
||||||
if (pDiskData->aDiskCol) {
|
|
||||||
taosArrayClear(pDiskData->aDiskCol);
|
|
||||||
} else {
|
|
||||||
pDiskData->aDiskCol = taosArrayInit(pBuilder->nBuilder, sizeof(SDiskCol));
|
|
||||||
if (pDiskData->aDiskCol == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t offset = 0;
|
|
||||||
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
|
|
||||||
SDiskColBuilder *pDCBuilder = (SDiskColBuilder *)taosArrayGet(pBuilder->aBuilder, iBuilder);
|
|
||||||
|
|
||||||
if (pDCBuilder->flag == HAS_NONE) continue;
|
|
||||||
|
|
||||||
SDiskCol dCol;
|
|
||||||
|
|
||||||
code = tGnrtDiskCol(pDCBuilder, &dCol);
|
|
||||||
if (code) return code;
|
|
||||||
|
|
||||||
dCol.bCol.offset = offset;
|
|
||||||
offset = offset + dCol.bCol.szBitmap + dCol.bCol.szOffset + dCol.bCol.szValue;
|
|
||||||
|
|
||||||
if (taosArrayPush(pDiskData->aDiskCol, &dCol) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
pDiskData->hdr.szBlkCol += tPutBlockCol(NULL, &dCol.bCol);
|
|
||||||
}
|
|
||||||
|
|
||||||
*ppDiskData = pDiskData;
|
|
||||||
*ppBlkInfo = &pBuilder->bi;
|
|
||||||
return code;
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ struct SFSetWriter {
|
||||||
|
|
||||||
SSkmInfo skmTb[1];
|
SSkmInfo skmTb[1];
|
||||||
SSkmInfo skmRow[1];
|
SSkmInfo skmRow[1];
|
||||||
uint8_t *bufArr[10];
|
SBuffer buffers[10];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
TABLEID tbid[1];
|
TABLEID tbid[1];
|
||||||
|
@ -152,7 +152,7 @@ int32_t tsdbFSetWriterOpen(SFSetWriterConfig *config, SFSetWriter **writer) {
|
||||||
.compactVersion = config->compactVersion,
|
.compactVersion = config->compactVersion,
|
||||||
.skmTb = writer[0]->skmTb,
|
.skmTb = writer[0]->skmTb,
|
||||||
.skmRow = writer[0]->skmRow,
|
.skmRow = writer[0]->skmRow,
|
||||||
.bufArr = writer[0]->bufArr,
|
.buffers = writer[0]->buffers,
|
||||||
};
|
};
|
||||||
for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||||
dataWriterConfig.files[ftype].exist = config->files[ftype].exist;
|
dataWriterConfig.files[ftype].exist = config->files[ftype].exist;
|
||||||
|
@ -176,7 +176,8 @@ int32_t tsdbFSetWriterOpen(SFSetWriterConfig *config, SFSetWriter **writer) {
|
||||||
.level = config->level,
|
.level = config->level,
|
||||||
.skmTb = writer[0]->skmTb,
|
.skmTb = writer[0]->skmTb,
|
||||||
.skmRow = writer[0]->skmRow,
|
.skmRow = writer[0]->skmRow,
|
||||||
.bufArr = writer[0]->bufArr,
|
.buffers = writer[0]->buffers,
|
||||||
|
|
||||||
};
|
};
|
||||||
code = tsdbSttFileWriterOpen(&sttWriterConfig, &writer[0]->sttWriter);
|
code = tsdbSttFileWriterOpen(&sttWriterConfig, &writer[0]->sttWriter);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
@ -212,8 +213,8 @@ int32_t tsdbFSetWriterClose(SFSetWriter **writer, bool abort, TFileOpArray *fopA
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->blockData); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->blockData); i++) {
|
||||||
tBlockDataDestroy(&writer[0]->blockData[i]);
|
tBlockDataDestroy(&writer[0]->blockData[i]);
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->bufArr); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->buffers); i++) {
|
||||||
tFree(writer[0]->bufArr[i]);
|
tBufferDestroy(&writer[0]->buffers[i]);
|
||||||
}
|
}
|
||||||
tDestroyTSchema(writer[0]->skmRow->pTSchema);
|
tDestroyTSchema(writer[0]->skmRow->pTSchema);
|
||||||
tDestroyTSchema(writer[0]->skmTb->pTSchema);
|
tDestroyTSchema(writer[0]->skmTb->pTSchema);
|
||||||
|
@ -248,10 +249,11 @@ int32_t tsdbFSetWriteRow(SFSetWriter *writer, SRowInfo *row) {
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBKEY key = TSDBROW_KEY(&row->row);
|
if (TSDBROW_VERSION(&row->row) <= writer->config->compactVersion //
|
||||||
if (key.version <= writer->config->compactVersion //
|
|
||||||
&& writer->blockData[writer->blockDataIdx].nRow > 0 //
|
&& writer->blockData[writer->blockDataIdx].nRow > 0 //
|
||||||
&& key.ts == writer->blockData[writer->blockDataIdx].aTSKEY[writer->blockData[writer->blockDataIdx].nRow - 1]) {
|
&& tsdbRowCompareWithoutVersion(&row->row,
|
||||||
|
&tsdbRowFromBlockData(&writer->blockData[writer->blockDataIdx],
|
||||||
|
writer->blockData[writer->blockDataIdx].nRow - 1)) == 0) {
|
||||||
code = tBlockDataUpdateRow(&writer->blockData[writer->blockDataIdx], &row->row, writer->skmRow->pTSchema);
|
code = tBlockDataUpdateRow(&writer->blockData[writer->blockDataIdx], &row->row, writer->skmRow->pTSchema);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct STsdbIter {
|
||||||
} dataData[1];
|
} dataData[1];
|
||||||
struct {
|
struct {
|
||||||
SMemTable *memt;
|
SMemTable *memt;
|
||||||
TSDBKEY from[1];
|
STsdbRowKey from[1];
|
||||||
SRBTreeIter iter[1];
|
SRBTreeIter iter[1];
|
||||||
STbData *tbData;
|
STbData *tbData;
|
||||||
STbDataIter tbIter[1];
|
STbDataIter tbIter[1];
|
||||||
|
@ -147,12 +147,11 @@ static int32_t tsdbDataIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBrinBlock
|
// SBrinBlock
|
||||||
if (iter->dataData->brinBlockIdx >= BRIN_BLOCK_SIZE(iter->dataData->brinBlock)) {
|
if (iter->dataData->brinBlockIdx >= iter->dataData->brinBlock->numOfRecords) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; iter->dataData->brinBlockIdx < BRIN_BLOCK_SIZE(iter->dataData->brinBlock);
|
for (; iter->dataData->brinBlockIdx < iter->dataData->brinBlock->numOfRecords; iter->dataData->brinBlockIdx++) {
|
||||||
iter->dataData->brinBlockIdx++) {
|
|
||||||
SBrinRecord record[1];
|
SBrinRecord record[1];
|
||||||
tBrinBlockGet(iter->dataData->brinBlock, iter->dataData->brinBlockIdx, record);
|
tBrinBlockGet(iter->dataData->brinBlock, iter->dataData->brinBlockIdx, record);
|
||||||
|
|
||||||
|
@ -255,9 +254,7 @@ _exit:
|
||||||
static int32_t tsdbDataTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
static int32_t tsdbDataTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
||||||
while (!iter->noMoreData) {
|
while (!iter->noMoreData) {
|
||||||
for (; iter->dataTomb->tombBlockIdx < TOMB_BLOCK_SIZE(iter->dataTomb->tombBlock); iter->dataTomb->tombBlockIdx++) {
|
for (; iter->dataTomb->tombBlockIdx < TOMB_BLOCK_SIZE(iter->dataTomb->tombBlock); iter->dataTomb->tombBlockIdx++) {
|
||||||
iter->record->suid = TARRAY2_GET(iter->dataTomb->tombBlock->suid, iter->dataTomb->tombBlockIdx);
|
tTombBlockGet(iter->dataTomb->tombBlock, iter->dataTomb->tombBlockIdx, iter->record);
|
||||||
iter->record->uid = TARRAY2_GET(iter->dataTomb->tombBlock->uid, iter->dataTomb->tombBlockIdx);
|
|
||||||
iter->record->version = TARRAY2_GET(iter->dataTomb->tombBlock->version, iter->dataTomb->tombBlockIdx);
|
|
||||||
|
|
||||||
if (iter->filterByVersion && (iter->record->version < iter->range[0] || iter->record->version > iter->range[1])) {
|
if (iter->filterByVersion && (iter->record->version < iter->range[0] || iter->record->version > iter->range[1])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -266,9 +263,6 @@ static int32_t tsdbDataTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
||||||
if (tbid && iter->record->suid == tbid->suid && iter->record->uid == tbid->uid) {
|
if (tbid && iter->record->suid == tbid->suid && iter->record->uid == tbid->uid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter->record->skey = TARRAY2_GET(iter->dataTomb->tombBlock->skey, iter->dataTomb->tombBlockIdx);
|
|
||||||
iter->record->ekey = TARRAY2_GET(iter->dataTomb->tombBlock->ekey, iter->dataTomb->tombBlockIdx);
|
|
||||||
iter->dataTomb->tombBlockIdx++;
|
iter->dataTomb->tombBlockIdx++;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
@ -445,9 +439,7 @@ static int32_t tsdbMemTableIterClose(STsdbIter *iter) { return 0; }
|
||||||
static int32_t tsdbSttTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
static int32_t tsdbSttTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
||||||
while (!iter->noMoreData) {
|
while (!iter->noMoreData) {
|
||||||
for (; iter->sttTomb->tombBlockIdx < TOMB_BLOCK_SIZE(iter->sttTomb->tombBlock); iter->sttTomb->tombBlockIdx++) {
|
for (; iter->sttTomb->tombBlockIdx < TOMB_BLOCK_SIZE(iter->sttTomb->tombBlock); iter->sttTomb->tombBlockIdx++) {
|
||||||
iter->record->suid = TARRAY2_GET(iter->sttTomb->tombBlock->suid, iter->sttTomb->tombBlockIdx);
|
tTombBlockGet(iter->sttTomb->tombBlock, iter->sttTomb->tombBlockIdx, iter->record);
|
||||||
iter->record->uid = TARRAY2_GET(iter->sttTomb->tombBlock->uid, iter->sttTomb->tombBlockIdx);
|
|
||||||
iter->record->version = TARRAY2_GET(iter->sttTomb->tombBlock->version, iter->sttTomb->tombBlockIdx);
|
|
||||||
|
|
||||||
if (iter->filterByVersion && (iter->record->version < iter->range[0] || iter->record->version > iter->range[1])) {
|
if (iter->filterByVersion && (iter->record->version < iter->range[0] || iter->record->version > iter->range[1])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -457,8 +449,6 @@ static int32_t tsdbSttTombIterNext(STsdbIter *iter, const TABLEID *tbid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter->record->skey = TARRAY2_GET(iter->sttTomb->tombBlock->skey, iter->sttTomb->tombBlockIdx);
|
|
||||||
iter->record->ekey = TARRAY2_GET(iter->sttTomb->tombBlock->ekey, iter->sttTomb->tombBlockIdx);
|
|
||||||
iter->sttTomb->tombBlockIdx++;
|
iter->sttTomb->tombBlockIdx++;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ typedef struct {
|
||||||
SDataFileReader *dataReader; // TSDB_ITER_TYPE_DATA || TSDB_ITER_TYPE_DATA_TOMB
|
SDataFileReader *dataReader; // TSDB_ITER_TYPE_DATA || TSDB_ITER_TYPE_DATA_TOMB
|
||||||
struct {
|
struct {
|
||||||
SMemTable *memt; // TSDB_ITER_TYPE_MEMT_TOMB
|
SMemTable *memt; // TSDB_ITER_TYPE_MEMT_TOMB
|
||||||
TSDBKEY from[1];
|
STsdbRowKey from[1];
|
||||||
}; // TSDB_ITER_TYPE_MEMT
|
}; // TSDB_ITER_TYPE_MEMT
|
||||||
};
|
};
|
||||||
bool filterByVersion;
|
bool filterByVersion;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#define SL_MOVE_BACKWARD 0x1
|
#define SL_MOVE_BACKWARD 0x1
|
||||||
#define SL_MOVE_FROM_POS 0x2
|
#define SL_MOVE_FROM_POS 0x2
|
||||||
|
|
||||||
static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags);
|
static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, STsdbRowKey *pKey, int32_t flags);
|
||||||
static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData);
|
static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData);
|
||||||
static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||||
SSubmitTbData *pSubmitTbData, int32_t *affectedRows);
|
SSubmitTbData *pSubmitTbData, int32_t *affectedRows);
|
||||||
|
@ -219,7 +219,7 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter) {
|
int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
(*ppIter) = (STbDataIter *)taosMemoryCalloc(1, sizeof(STbDataIter));
|
(*ppIter) = (STbDataIter *)taosMemoryCalloc(1, sizeof(STbDataIter));
|
||||||
|
@ -241,7 +241,7 @@ void *tsdbTbDataIterDestroy(STbDataIter *pIter) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter) {
|
void tsdbTbDataIterOpen(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter *pIter) {
|
||||||
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
||||||
SMemSkipListNode *pHead;
|
SMemSkipListNode *pHead;
|
||||||
SMemSkipListNode *pTail;
|
SMemSkipListNode *pTail;
|
||||||
|
@ -433,10 +433,10 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags) {
|
static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, STsdbRowKey *pKey, int32_t flags) {
|
||||||
SMemSkipListNode *px;
|
SMemSkipListNode *px;
|
||||||
SMemSkipListNode *pn;
|
SMemSkipListNode *pn;
|
||||||
TSDBKEY tKey = {0};
|
STsdbRowKey tKey;
|
||||||
int32_t backward = flags & SL_MOVE_BACKWARD;
|
int32_t backward = flags & SL_MOVE_BACKWARD;
|
||||||
int32_t fromPos = flags & SL_MOVE_FROM_POS;
|
int32_t fromPos = flags & SL_MOVE_FROM_POS;
|
||||||
|
|
||||||
|
@ -455,15 +455,9 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
||||||
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||||
pn = SL_GET_NODE_BACKWARD(px, iLevel);
|
pn = SL_GET_NODE_BACKWARD(px, iLevel);
|
||||||
while (pn != pTbData->sl.pHead) {
|
while (pn != pTbData->sl.pHead) {
|
||||||
if (pn->flag == TSDBROW_ROW_FMT) {
|
tsdbRowGetKey(&pn->row, &tKey);
|
||||||
tKey.version = pn->version;
|
|
||||||
tKey.ts = ((SRow *)pn->pData)->ts;
|
|
||||||
} else if (pn->flag == TSDBROW_COL_FMT) {
|
|
||||||
tKey.version = ((SBlockData *)pn->pData)->aVersion[pn->iRow];
|
|
||||||
tKey.ts = ((SBlockData *)pn->pData)->aTSKEY[pn->iRow];
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t c = tsdbKeyCmprFn(&tKey, pKey);
|
int32_t c = tsdbRowKeyCmpr(&tKey, pKey);
|
||||||
if (c <= 0) {
|
if (c <= 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -490,15 +484,9 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
||||||
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||||
pn = SL_GET_NODE_FORWARD(px, iLevel);
|
pn = SL_GET_NODE_FORWARD(px, iLevel);
|
||||||
while (pn != pTbData->sl.pTail) {
|
while (pn != pTbData->sl.pTail) {
|
||||||
if (pn->flag == TSDBROW_ROW_FMT) {
|
tsdbRowGetKey(&pn->row, &tKey);
|
||||||
tKey.version = pn->version;
|
|
||||||
tKey.ts = ((SRow *)pn->pData)->ts;
|
|
||||||
} else if (pn->flag == TSDBROW_COL_FMT) {
|
|
||||||
tKey.version = ((SBlockData *)pn->pData)->aVersion[pn->iRow];
|
|
||||||
tKey.ts = ((SBlockData *)pn->pData)->aTSKEY[pn->iRow];
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t c = tsdbKeyCmprFn(&tKey, pKey);
|
int32_t c = tsdbRowKeyCmpr(&tKey, pKey);
|
||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -547,16 +535,10 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode->level = level;
|
pNode->level = level;
|
||||||
pNode->flag = pRow->type;
|
pNode->row = *pRow;
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
pNode->version = pRow->version;
|
pNode->row.pTSRow = (SRow *)((char *)pNode + nSize);
|
||||||
pNode->pData = (char *)pNode + nSize;
|
memcpy(pNode->row.pTSRow, pRow->pTSRow, pRow->pTSRow->len);
|
||||||
memcpy(pNode->pData, pRow->pTSRow, pRow->pTSRow->len);
|
|
||||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
|
||||||
pNode->iRow = pRow->iRow;
|
|
||||||
pNode->pData = pRow->pBlockData;
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set node
|
// set node
|
||||||
|
@ -656,13 +638,14 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
// loop to add each row to the skiplist
|
// loop to add each row to the skiplist
|
||||||
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
||||||
TSDBROW tRow = tsdbRowFromBlockData(pBlockData, 0);
|
TSDBROW tRow = tsdbRowFromBlockData(pBlockData, 0);
|
||||||
TSDBKEY key = {.version = version, .ts = pBlockData->aTSKEY[0]};
|
STsdbRowKey key;
|
||||||
TSDBROW lRow; // last row
|
TSDBROW lRow; // last row
|
||||||
|
|
||||||
// first row
|
// first row
|
||||||
|
tsdbRowGetKey(&tRow, &key);
|
||||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
||||||
if ((code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 0))) goto _exit;
|
if ((code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 0))) goto _exit;
|
||||||
pTbData->minKey = TMIN(pTbData->minKey, key.ts);
|
pTbData->minKey = TMIN(pTbData->minKey, key.key.ts);
|
||||||
lRow = tRow;
|
lRow = tRow;
|
||||||
|
|
||||||
// remain row
|
// remain row
|
||||||
|
@ -673,7 +656,7 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tRow.iRow < pBlockData->nRow) {
|
while (tRow.iRow < pBlockData->nRow) {
|
||||||
key.ts = pBlockData->aTSKEY[tRow.iRow];
|
tsdbRowGetKey(&tRow, &key);
|
||||||
|
|
||||||
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
||||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||||
|
@ -686,8 +669,8 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.ts >= pTbData->maxKey) {
|
if (key.key.ts >= pTbData->maxKey) {
|
||||||
pTbData->maxKey = key.ts;
|
pTbData->maxKey = key.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) {
|
if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) {
|
||||||
|
@ -711,7 +694,7 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
|
|
||||||
int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
|
int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
|
||||||
SRow **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
|
SRow **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
|
||||||
TSDBKEY key = {.version = version};
|
STsdbRowKey key;
|
||||||
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
||||||
TSDBROW tRow = {.type = TSDBROW_ROW_FMT, .version = version};
|
TSDBROW tRow = {.type = TSDBROW_ROW_FMT, .version = version};
|
||||||
int32_t iRow = 0;
|
int32_t iRow = 0;
|
||||||
|
@ -719,13 +702,13 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
|
|
||||||
// backward put first data
|
// backward put first data
|
||||||
tRow.pTSRow = aRow[iRow++];
|
tRow.pTSRow = aRow[iRow++];
|
||||||
key.ts = tRow.pTSRow->ts;
|
tsdbRowGetKey(&tRow, &key);
|
||||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
||||||
code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 0);
|
code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 0);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
lRow = tRow;
|
lRow = tRow;
|
||||||
|
|
||||||
pTbData->minKey = TMIN(pTbData->minKey, key.ts);
|
pTbData->minKey = TMIN(pTbData->minKey, key.key.ts);
|
||||||
|
|
||||||
// forward put rest data
|
// forward put rest data
|
||||||
if (iRow < nRow) {
|
if (iRow < nRow) {
|
||||||
|
@ -735,7 +718,7 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
|
|
||||||
while (iRow < nRow) {
|
while (iRow < nRow) {
|
||||||
tRow.pTSRow = aRow[iRow];
|
tRow.pTSRow = aRow[iRow];
|
||||||
key.ts = tRow.pTSRow->ts;
|
tsdbRowGetKey(&tRow, &key);
|
||||||
|
|
||||||
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
||||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||||
|
@ -750,8 +733,8 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.ts >= pTbData->maxKey) {
|
if (key.key.ts >= pTbData->maxKey) {
|
||||||
pTbData->maxKey = key.ts;
|
pTbData->maxKey = key.key.ts;
|
||||||
}
|
}
|
||||||
if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) {
|
if (!TSDB_CACHE_NO(pMemTable->pTsdb->pVnode->config)) {
|
||||||
tsdbCacheUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, &lRow);
|
tsdbCacheUpdate(pMemTable->pTsdb, pTbData->suid, pTbData->uid, &lRow);
|
||||||
|
@ -833,3 +816,26 @@ SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable) {
|
||||||
_exit:
|
_exit:
|
||||||
return aTbDataP;
|
return aTbDataP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
|
||||||
|
if (pIter == NULL) return NULL;
|
||||||
|
|
||||||
|
if (pIter->pRow) {
|
||||||
|
return pIter->pRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->backward) {
|
||||||
|
if (pIter->pNode == pIter->pTbData->sl.pHead) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (pIter->pNode == pIter->pTbData->sl.pTail) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->pRow = &pIter->row;
|
||||||
|
pIter->row = pIter->pNode->row;
|
||||||
|
|
||||||
|
return pIter->pRow;
|
||||||
|
}
|
|
@ -15,10 +15,10 @@
|
||||||
|
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsdbFSet2.h"
|
#include "tsdbFSet2.h"
|
||||||
#include "tsdbUtil2.h"
|
|
||||||
#include "tsdbMerge.h"
|
#include "tsdbMerge.h"
|
||||||
#include "tsdbReadUtil.h"
|
#include "tsdbReadUtil.h"
|
||||||
#include "tsdbSttFileRW.h"
|
#include "tsdbSttFileRW.h"
|
||||||
|
#include "tsdbUtil2.h"
|
||||||
|
|
||||||
static void tLDataIterClose2(SLDataIter *pIter);
|
static void tLDataIterClose2(SLDataIter *pIter);
|
||||||
|
|
||||||
|
@ -350,8 +350,8 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
|
||||||
tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block);
|
tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block);
|
||||||
|
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
int32_t rows = TARRAY2_SIZE(block.suid);
|
int32_t rows = block.numOfRecords;
|
||||||
while (i < rows && block.suid->data[i] != suid) {
|
while (i < rows && ((int64_t *)block.suids.data)[i] != suid) {
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,16 +365,24 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStatisBlkArray->data[k].maxTbid.suid == suid) {
|
if (pStatisBlkArray->data[k].maxTbid.suid == suid) {
|
||||||
taosArrayAddBatch(pBlockLoadInfo->info.pUid, &block.uid->data[i], rows - i);
|
taosArrayAddBatch(pBlockLoadInfo->info.pUid, tBufferGetDataAt(&block.suids, i * sizeof(int64_t)), rows - i);
|
||||||
taosArrayAddBatch(pBlockLoadInfo->info.pFirstKey, &block.firstKey->data[i], rows - i);
|
taosArrayAddBatch(pBlockLoadInfo->info.pFirstKey,
|
||||||
taosArrayAddBatch(pBlockLoadInfo->info.pLastKey, &block.lastKey->data[i], rows - i);
|
tBufferGetDataAt(&block.firstKeyTimestamps, i * sizeof(int64_t)), rows - i);
|
||||||
taosArrayAddBatch(pBlockLoadInfo->info.pCount, &block.count->data[i], rows - i);
|
taosArrayAddBatch(pBlockLoadInfo->info.pLastKey,
|
||||||
|
tBufferGetDataAt(&block.lastKeyTimestamps, i * sizeof(int64_t)), rows - i);
|
||||||
|
taosArrayAddBatch(pBlockLoadInfo->info.pCount, tBufferGetDataAt(&block.counts, i * sizeof(int64_t)), rows - i);
|
||||||
} else {
|
} else {
|
||||||
while (i < rows && block.suid->data[i] == suid) {
|
STbStatisRecord record;
|
||||||
taosArrayPush(pBlockLoadInfo->info.pUid, &block.uid->data[i]);
|
while (i < rows) {
|
||||||
taosArrayPush(pBlockLoadInfo->info.pFirstKey, &block.firstKey->data[i]);
|
tStatisBlockGet(&block, i, &record);
|
||||||
taosArrayPush(pBlockLoadInfo->info.pLastKey, &block.lastKey->data[i]);
|
if (record.suid != suid) {
|
||||||
taosArrayPush(pBlockLoadInfo->info.pCount, &block.count->data[i]);
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayPush(pBlockLoadInfo->info.pUid, &record.uid);
|
||||||
|
taosArrayPush(pBlockLoadInfo->info.pFirstKey, &record.firstKey.ts);
|
||||||
|
taosArrayPush(pBlockLoadInfo->info.pLastKey, &record.lastKey.ts);
|
||||||
|
taosArrayPush(pBlockLoadInfo->info.pCount, &record.count);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,6 +419,7 @@ static int32_t doLoadSttFilesBlk(SSttBlockLoadInfo *pBlockLoadInfo, SLDataIter *
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
// load stt statistics block for all stt-blocks, to decide if the data of queried table exists in current stt file
|
// load stt statistics block for all stt-blocks, to decide if the data of queried table exists in current stt file
|
||||||
TStatisBlkArray *pStatisBlkArray = NULL;
|
TStatisBlkArray *pStatisBlkArray = NULL;
|
||||||
code = tsdbSttFileReadStatisBlk(pIter->pReader, (const TStatisBlkArray **)&pStatisBlkArray);
|
code = tsdbSttFileReadStatisBlk(pIter->pReader, (const TStatisBlkArray **)&pStatisBlkArray);
|
||||||
|
@ -425,6 +434,7 @@ static int32_t doLoadSttFilesBlk(SSttBlockLoadInfo *pBlockLoadInfo, SLDataIter *
|
||||||
tsdbError("failed to load stt statistics block data, code:%s, %s", tstrerror(code), idStr);
|
tsdbError("failed to load stt statistics block data, code:%s, %s", tstrerror(code), idStr);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
code = loadTombFn(pReader1, pIter->pReader, pIter->pBlockLoadInfo);
|
code = loadTombFn(pReader1, pIter->pReader, pIter->pBlockLoadInfo);
|
||||||
|
|
||||||
|
@ -796,7 +806,8 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF
|
||||||
int64_t numOfRows = 0;
|
int64_t numOfRows = 0;
|
||||||
|
|
||||||
int64_t cid = pSttLevel->fobjArr->data[i]->f->cid;
|
int64_t cid = pSttLevel->fobjArr->data[i]->f->cid;
|
||||||
code = tLDataIterOpen2(pIter, pSttFileReader, cid, pMTree->backward, pConf, pLoadInfo, &w, &numOfRows, pMTree->idStr);
|
code = tLDataIterOpen2(pIter, pSttFileReader, cid, pMTree->backward, pConf, pLoadInfo, &w, &numOfRows,
|
||||||
|
pMTree->idStr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ static TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbRe
|
||||||
static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader);
|
static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader);
|
||||||
static int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts,
|
static int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts,
|
||||||
SRowMerger* pMerger, SVersionRange* pVerRange, const char* id);
|
SRowMerger* pMerger, SVersionRange* pVerRange, const char* id);
|
||||||
static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, STsdbReader* pReader);
|
static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, STsdbRowKey* pKey, SArray* pDelList,
|
||||||
|
STsdbReader* pReader);
|
||||||
static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow,
|
static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow,
|
||||||
STableBlockScanInfo* pScanInfo);
|
STableBlockScanInfo* pScanInfo);
|
||||||
static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData,
|
static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData,
|
||||||
|
@ -79,6 +80,32 @@ static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWi
|
||||||
|
|
||||||
static void resetPreFilesetMemTableListIndex(SReaderStatus* pStatus);
|
static void resetPreFilesetMemTableListIndex(SReaderStatus* pStatus);
|
||||||
|
|
||||||
|
static int32_t pkComp(STsdbReader* pReader, TSDBROW* p1, TSDBROW* p2) {
|
||||||
|
STsdbRowKey k1 = {0}, k2 = {0};
|
||||||
|
|
||||||
|
if (pReader->pkComparFn == NULL) {
|
||||||
|
ASSERT(TSDBROW_TS(p1) != TSDBROW_TS(p2));
|
||||||
|
ASSERT(pReader->pkChecked);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbRowGetKey(p1, &k1);
|
||||||
|
tsdbRowGetKey(p2, &k2);
|
||||||
|
return pReader->pkComparFn(&k1.key.pks[0].val, &k2.key.pks[0].val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t pkComp1(STsdbReader* pReader, STsdbRowKey* p1, TSDBROW* p2) {
|
||||||
|
if (pReader->pkComparFn == NULL) {
|
||||||
|
ASSERT(p1->key.ts != TSDBROW_TS(p2));
|
||||||
|
ASSERT(pReader->pkChecked);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STsdbRowKey k2 = {0};
|
||||||
|
tsdbRowGetKey(p2, &k2);
|
||||||
|
return pReader->pkComparFn(&p1->key.pks[0].val, &k2.key.pks[0].val);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pCols, const int32_t* pSlotIdList,
|
static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pCols, const int32_t* pSlotIdList,
|
||||||
int32_t numOfCols) {
|
int32_t numOfCols) {
|
||||||
pSupInfo->smaValid = true;
|
pSupInfo->smaValid = true;
|
||||||
|
@ -591,7 +618,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. time range check
|
// 1. time range check
|
||||||
if (pRecord->firstKey > w.ekey || pRecord->lastKey < w.skey) {
|
if (pRecord->firstKey.key.ts > w.ekey || pRecord->lastKey.key.ts < w.skey) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,11 +636,11 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pScanInfo->filesetWindow.skey > pRecord->firstKey) {
|
if (pScanInfo->filesetWindow.skey > pRecord->firstKey.key.ts) {
|
||||||
pScanInfo->filesetWindow.skey = pRecord->firstKey;
|
pScanInfo->filesetWindow.skey = pRecord->firstKey.key.ts;
|
||||||
}
|
}
|
||||||
if (pScanInfo->filesetWindow.ekey < pRecord->lastKey) {
|
if (pScanInfo->filesetWindow.ekey < pRecord->lastKey.key.ts) {
|
||||||
pScanInfo->filesetWindow.ekey = pRecord->lastKey;
|
pScanInfo->filesetWindow.ekey = pRecord->lastKey.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlockNum->numOfBlocks += 1;
|
pBlockNum->numOfBlocks += 1;
|
||||||
|
@ -653,7 +680,7 @@ static void setBlockAllDumped(SFileBlockDumpInfo* pDumpInfo, int64_t maxKey, int
|
||||||
|
|
||||||
static int32_t doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int32_t colIndex, SColVal* pColVal,
|
static int32_t doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int32_t colIndex, SColVal* pColVal,
|
||||||
SBlockLoadSuppInfo* pSup) {
|
SBlockLoadSuppInfo* pSup) {
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
if (!COL_VAL_IS_VALUE(pColVal)) {
|
if (!COL_VAL_IS_VALUE(pColVal)) {
|
||||||
colDataSetNULL(pColInfoData, rowIndex);
|
colDataSetNULL(pColInfoData, rowIndex);
|
||||||
} else {
|
} else {
|
||||||
|
@ -671,7 +698,7 @@ static int32_t doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int
|
||||||
colDataSetVal(pColInfoData, rowIndex, pSup->buildBuf[colIndex], false);
|
colDataSetVal(pColInfoData, rowIndex, pSup->buildBuf[colIndex], false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
colDataSetVal(pColInfoData, rowIndex, (const char*)&pColVal->value, !COL_VAL_IS_VALUE(pColVal));
|
colDataSetVal(pColInfoData, rowIndex, (const char*)&pColVal->value.val, !COL_VAL_IS_VALUE(pColVal));
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -745,9 +772,9 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData
|
||||||
int32_t endPos = -1;
|
int32_t endPos = -1;
|
||||||
bool asc = ASCENDING_TRAVERSE(pReader->info.order);
|
bool asc = ASCENDING_TRAVERSE(pReader->info.order);
|
||||||
|
|
||||||
if (asc && pReader->info.window.ekey >= pRecord->lastKey) {
|
if (asc && pReader->info.window.ekey >= pRecord->lastKey.key.ts) {
|
||||||
endPos = pRecord->numRow - 1;
|
endPos = pRecord->numRow - 1;
|
||||||
} else if (!asc && pReader->info.window.skey <= pRecord->firstKey) {
|
} else if (!asc && pReader->info.window.skey <= pRecord->firstKey.key.ts) {
|
||||||
endPos = 0;
|
endPos = 0;
|
||||||
} else {
|
} else {
|
||||||
int64_t key = asc ? pReader->info.window.ekey : pReader->info.window.skey;
|
int64_t key = asc ? pReader->info.window.ekey : pReader->info.window.skey;
|
||||||
|
@ -890,8 +917,12 @@ static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo
|
||||||
|
|
||||||
static void blockInfoToRecord(SBrinRecord* record, SFileDataBlockInfo* pBlockInfo) {
|
static void blockInfoToRecord(SBrinRecord* record, SFileDataBlockInfo* pBlockInfo) {
|
||||||
record->uid = pBlockInfo->uid;
|
record->uid = pBlockInfo->uid;
|
||||||
record->firstKey = pBlockInfo->firstKey;
|
record->firstKey = (STsdbRowKey){
|
||||||
record->lastKey = pBlockInfo->lastKey;
|
.key = {.ts = pBlockInfo->firstKey, .numOfPKs = 0},
|
||||||
|
};
|
||||||
|
record->lastKey = (STsdbRowKey){
|
||||||
|
.key = {.ts = pBlockInfo->lastKey, .numOfPKs = 0},
|
||||||
|
};
|
||||||
record->minVer = pBlockInfo->minVer;
|
record->minVer = pBlockInfo->minVer;
|
||||||
record->maxVer = pBlockInfo->maxVer;
|
record->maxVer = pBlockInfo->maxVer;
|
||||||
record->blockOffset = pBlockInfo->blockOffset;
|
record->blockOffset = pBlockInfo->blockOffset;
|
||||||
|
@ -934,9 +965,10 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
|
||||||
|
|
||||||
// row index of dump info remain the initial position, let's find the appropriate start position.
|
// row index of dump info remain the initial position, let's find the appropriate start position.
|
||||||
if ((pDumpInfo->rowIndex == 0 && asc) || (pDumpInfo->rowIndex == pRecord->numRow - 1 && (!asc))) {
|
if ((pDumpInfo->rowIndex == 0 && asc) || (pDumpInfo->rowIndex == pRecord->numRow - 1 && (!asc))) {
|
||||||
if (asc && pReader->info.window.skey <= pRecord->firstKey && pReader->info.verRange.minVer <= pRecord->minVer) {
|
if (asc && pReader->info.window.skey <= pRecord->firstKey.key.ts &&
|
||||||
|
pReader->info.verRange.minVer <= pRecord->minVer) {
|
||||||
// pDumpInfo->rowIndex = 0;
|
// pDumpInfo->rowIndex = 0;
|
||||||
} else if (!asc && pReader->info.window.ekey >= pRecord->lastKey &&
|
} else if (!asc && pReader->info.window.ekey >= pRecord->lastKey.key.ts &&
|
||||||
pReader->info.verRange.maxVer >= pRecord->maxVer) {
|
pReader->info.verRange.maxVer >= pRecord->maxVer) {
|
||||||
// pDumpInfo->rowIndex = pRecord->numRow - 1;
|
// pDumpInfo->rowIndex = pRecord->numRow - 1;
|
||||||
} else { // find the appropriate the start position in current block, and set it to be the current rowIndex
|
} else { // find the appropriate the start position in current block, and set it to be the current rowIndex
|
||||||
|
@ -949,8 +981,8 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
|
||||||
tsdbError(
|
tsdbError(
|
||||||
"%p failed to locate the start position in current block, global index:%d, table index:%d, brange:%" PRId64
|
"%p failed to locate the start position in current block, global index:%d, table index:%d, brange:%" PRId64
|
||||||
"-%" PRId64 ", minVer:%" PRId64 ", maxVer:%" PRId64 " %s",
|
"-%" PRId64 ", minVer:%" PRId64 ", maxVer:%" PRId64 " %s",
|
||||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey, pRecord->lastKey, pRecord->minVer,
|
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey.key.ts, pRecord->lastKey.key.ts,
|
||||||
pRecord->maxVer, pReader->idStr);
|
pRecord->minVer, pRecord->maxVer, pReader->idStr);
|
||||||
return TSDB_CODE_INVALID_PARA;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1059,7 +1091,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
|
||||||
setBlockAllDumped(pDumpInfo, ts, pReader->info.order);
|
setBlockAllDumped(pDumpInfo, ts, pReader->info.order);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int64_t ts = asc ? pRecord->lastKey : pRecord->firstKey;
|
int64_t ts = asc ? pRecord->lastKey.key.ts : pRecord->firstKey.key.ts;
|
||||||
setBlockAllDumped(pDumpInfo, ts, pReader->info.order);
|
setBlockAllDumped(pDumpInfo, ts, pReader->info.order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1069,8 +1101,8 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
|
||||||
int32_t unDumpedRows = asc ? pRecord->numRow - pDumpInfo->rowIndex : pDumpInfo->rowIndex + 1;
|
int32_t unDumpedRows = asc ? pRecord->numRow - pDumpInfo->rowIndex : pDumpInfo->rowIndex + 1;
|
||||||
tsdbDebug("%p copy file block to sdatablock, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
|
tsdbDebug("%p copy file block to sdatablock, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
|
||||||
", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", uid:%" PRIu64 " elapsed time:%.2f ms, %s",
|
", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", uid:%" PRIu64 " elapsed time:%.2f ms, %s",
|
||||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey, pRecord->lastKey, dumpedRows,
|
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey.key.ts, pRecord->lastKey.key.ts,
|
||||||
unDumpedRows, pRecord->minVer, pRecord->maxVer, pBlockInfo->uid, elapsedTime, pReader->idStr);
|
dumpedRows, unDumpedRows, pRecord->minVer, pRecord->maxVer, pBlockInfo->uid, elapsedTime, pReader->idStr);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1123,8 +1155,8 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
tsdbError("%p error occurs in loading file block, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
|
tsdbError("%p error occurs in loading file block, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
|
||||||
", rows:%d, code:%s %s",
|
", rows:%d, code:%s %s",
|
||||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlockInfo->firstKey,
|
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlockInfo->firstKey, pBlockInfo->lastKey,
|
||||||
pBlockInfo->lastKey, pBlockInfo->numRow, tstrerror(code), pReader->idStr);
|
pBlockInfo->numRow, tstrerror(code), pReader->idStr);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1132,8 +1164,8 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
|
||||||
|
|
||||||
tsdbDebug("%p load file block into buffer, global index:%d, index in table block list:%d, brange:%" PRId64 "-%" PRId64
|
tsdbDebug("%p load file block into buffer, global index:%d, index in table block list:%d, brange:%" PRId64 "-%" PRId64
|
||||||
", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
|
", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
|
||||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey, pRecord->lastKey, pRecord->numRow,
|
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey.key.ts, pRecord->lastKey.key.ts,
|
||||||
pRecord->minVer, pRecord->maxVer, elapsedTime, pReader->idStr);
|
pRecord->numRow, pRecord->minVer, pRecord->maxVer, elapsedTime, pReader->idStr);
|
||||||
|
|
||||||
pReader->cost.blockLoadTime += elapsedTime;
|
pReader->cost.blockLoadTime += elapsedTime;
|
||||||
pDumpInfo->allDumped = false;
|
pDumpInfo->allDumped = false;
|
||||||
|
@ -1236,9 +1268,9 @@ static int32_t setFileBlockActiveInBlockIter(STsdbReader* pReader, SDataBlockIte
|
||||||
static bool overlapWithNeighborBlock2(SFileDataBlockInfo* pBlock, SBrinRecord* pRec, int32_t order) {
|
static bool overlapWithNeighborBlock2(SFileDataBlockInfo* pBlock, SBrinRecord* pRec, int32_t order) {
|
||||||
// it is the last block in current file, no chance to overlap with neighbor blocks.
|
// it is the last block in current file, no chance to overlap with neighbor blocks.
|
||||||
if (ASCENDING_TRAVERSE(order)) {
|
if (ASCENDING_TRAVERSE(order)) {
|
||||||
return pBlock->lastKey == pRec->firstKey;
|
return pBlock->lastKey == pRec->firstKey.key.ts;
|
||||||
} else {
|
} else {
|
||||||
return pBlock->firstKey == pRec->lastKey;
|
return pBlock->firstKey == pRec->lastKey.key.ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,8 +1298,8 @@ static bool bufferDataInFileBlockGap(TSDBKEY keyInBuf, SFileDataBlockInfo* pBloc
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool keyOverlapFileBlock(TSDBKEY key, SFileDataBlockInfo* pBlock, SVersionRange* pVerRange) {
|
static bool keyOverlapFileBlock(TSDBKEY key, SFileDataBlockInfo* pBlock, SVersionRange* pVerRange) {
|
||||||
return (key.ts >= pBlock->firstKey && key.ts <= pBlock->lastKey) &&
|
return (key.ts >= pBlock->firstKey && key.ts <= pBlock->lastKey) && (pBlock->maxVer >= pVerRange->minVer) &&
|
||||||
(pBlock->maxVer >= pVerRange->minVer) && (pBlock->minVer <= pVerRange->maxVer);
|
(pBlock->minVer <= pVerRange->maxVer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pBlockInfo,
|
static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pBlockInfo,
|
||||||
|
@ -1292,8 +1324,7 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo*
|
||||||
ASSERT(pScanInfo->sttKeyInfo.status != STT_FILE_READER_UNINIT);
|
ASSERT(pScanInfo->sttKeyInfo.status != STT_FILE_READER_UNINIT);
|
||||||
if (pScanInfo->sttKeyInfo.status == STT_FILE_HAS_DATA) {
|
if (pScanInfo->sttKeyInfo.status == STT_FILE_HAS_DATA) {
|
||||||
int64_t nextProcKeyInStt = pScanInfo->sttKeyInfo.nextProcKey;
|
int64_t nextProcKeyInStt = pScanInfo->sttKeyInfo.nextProcKey;
|
||||||
pInfo->overlapWithSttBlock =
|
pInfo->overlapWithSttBlock = !(pBlockInfo->lastKey < nextProcKeyInStt || pBlockInfo->firstKey > nextProcKeyInStt);
|
||||||
!(pBlockInfo->lastKey < nextProcKeyInStt || pBlockInfo->firstKey > nextProcKeyInStt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->moreThanCapcity = pBlockInfo->numRow > pReader->resBlockInfo.capacity;
|
pInfo->moreThanCapcity = pBlockInfo->numRow > pReader->resBlockInfo.capacity;
|
||||||
|
@ -1500,7 +1531,9 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
tsLast = getCurrentKeyInSttBlock(pSttBlockReader);
|
tsLast = getCurrentKeyInSttBlock(pSttBlockReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
STsdbRowKey k;
|
||||||
|
tsdbRowGetKey(pRow, &k);
|
||||||
|
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
|
|
||||||
// merge is not initialized yet, due to the fact that the pReader->info.pSchema is not initialized
|
// merge is not initialized yet, due to the fact that the pReader->info.pSchema is not initialized
|
||||||
|
@ -1519,8 +1552,8 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
minKey = tsLast;
|
minKey = tsLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey > k.ts) {
|
if (minKey > k.key.ts) {
|
||||||
minKey = k.ts;
|
minKey = k.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey > key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
if (minKey > key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
||||||
|
@ -1532,8 +1565,8 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
minKey = tsLast;
|
minKey = tsLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey < k.ts) {
|
if (minKey < k.key.ts) {
|
||||||
minKey = k.ts;
|
minKey = k.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey < key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
if (minKey < key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
||||||
|
@ -1561,7 +1594,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->info.verRange, pReader->idStr);
|
doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->info.verRange, pReader->idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.key.ts) {
|
||||||
STSchema* pTSchema = NULL;
|
STSchema* pTSchema = NULL;
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
|
@ -1575,13 +1608,13 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.key.ts) {
|
||||||
STSchema* pTSchema = NULL;
|
STSchema* pTSchema = NULL;
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
|
@ -1595,7 +1628,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS || pMerger->pTSchema == NULL) {
|
if (code != TSDB_CODE_SUCCESS || pMerger->pTSchema == NULL) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1743,8 +1776,9 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
int64_t key = hasDataInFileBlock(pBlockData, pDumpInfo) ? pBlockData->aTSKEY[pDumpInfo->rowIndex] : INT64_MIN;
|
int64_t key = hasDataInFileBlock(pBlockData, pDumpInfo) ? pBlockData->aTSKEY[pDumpInfo->rowIndex] : INT64_MIN;
|
||||||
|
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
STsdbRowKey k, ik;
|
||||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
tsdbRowGetKey(pRow, &k);
|
||||||
|
tsdbRowGetKey(piRow, &ik);
|
||||||
|
|
||||||
STSchema* pSchema = NULL;
|
STSchema* pSchema = NULL;
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
|
@ -1774,12 +1808,12 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
int64_t minKey = 0;
|
int64_t minKey = 0;
|
||||||
if (ASCENDING_TRAVERSE(pReader->info.order)) {
|
if (ASCENDING_TRAVERSE(pReader->info.order)) {
|
||||||
minKey = INT64_MAX; // let's find the minimum
|
minKey = INT64_MAX; // let's find the minimum
|
||||||
if (minKey > k.ts) {
|
if (minKey > k.key.ts) {
|
||||||
minKey = k.ts;
|
minKey = k.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey > ik.ts) {
|
if (minKey > ik.key.ts) {
|
||||||
minKey = ik.ts;
|
minKey = ik.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey > key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
if (minKey > key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
||||||
|
@ -1791,12 +1825,12 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
minKey = INT64_MIN; // let find the maximum ts value
|
minKey = INT64_MIN; // let find the maximum ts value
|
||||||
if (minKey < k.ts) {
|
if (minKey < k.key.ts) {
|
||||||
minKey = k.ts;
|
minKey = k.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey < ik.ts) {
|
if (minKey < ik.key.ts) {
|
||||||
minKey = ik.ts;
|
minKey = ik.key.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey < key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
if (minKey < key && hasDataInFileBlock(pBlockData, pDumpInfo)) {
|
||||||
|
@ -1831,49 +1865,49 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->info.verRange, pReader->idStr);
|
doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->info.verRange, pReader->idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey == ik.ts) {
|
if (minKey == ik.key.ts) {
|
||||||
code = tsdbRowMergerAdd(pMerger, piRow, piSchema);
|
code = tsdbRowMergerAdd(pMerger, piRow, piSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, &ik, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.key.ts) {
|
||||||
code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
|
code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.key.ts) {
|
||||||
code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
|
code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minKey == ik.ts) {
|
if (minKey == ik.key.ts) {
|
||||||
code = tsdbRowMergerAdd(pMerger, piRow, piSchema);
|
code = tsdbRowMergerAdd(pMerger, piRow, piSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, &ik, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1912,7 +1946,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doInitMemDataIter(STsdbReader* pReader, STbData** pData, STableBlockScanInfo* pBlockScanInfo, TSDBKEY* pKey,
|
int32_t doInitMemDataIter(STsdbReader* pReader, STbData** pData, STableBlockScanInfo* pBlockScanInfo, STsdbRowKey* pKey,
|
||||||
SMemTable* pMem, SIterInfo* pIter, const char* type) {
|
SMemTable* pMem, SIterInfo* pIter, const char* type) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t backward = (!ASCENDING_TRAVERSE(pReader->info.order));
|
int32_t backward = (!ASCENDING_TRAVERSE(pReader->info.order));
|
||||||
|
@ -1928,8 +1962,8 @@ int32_t doInitMemDataIter(STsdbReader* pReader, STbData** pData, STableBlockScan
|
||||||
|
|
||||||
tsdbDebug("%p uid:%" PRIu64 ", check data in %s from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64
|
tsdbDebug("%p uid:%" PRIu64 ", check data in %s from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64
|
||||||
"-%" PRId64 " %s",
|
"-%" PRId64 " %s",
|
||||||
pReader, pBlockScanInfo->uid, type, pKey->ts, pReader->info.order, (*pData)->minKey, (*pData)->maxKey,
|
pReader, pBlockScanInfo->uid, type, pKey->key.ts, pReader->info.order, (*pData)->minKey,
|
||||||
pReader->idStr);
|
(*pData)->maxKey, pReader->idStr);
|
||||||
} else {
|
} else {
|
||||||
tsdbError("%p uid:%" PRIu64 ", failed to create iterator for %s, code:%s, %s", pReader, pBlockScanInfo->uid,
|
tsdbError("%p uid:%" PRIu64 ", failed to create iterator for %s, code:%s, %s", pReader, pBlockScanInfo->uid,
|
||||||
type, tstrerror(code), pReader->idStr);
|
type, tstrerror(code), pReader->idStr);
|
||||||
|
@ -1949,11 +1983,19 @@ static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbRea
|
||||||
}
|
}
|
||||||
|
|
||||||
STbData* d = NULL;
|
STbData* d = NULL;
|
||||||
TSDBKEY startKey = {0};
|
STsdbRowKey startKey = {0};
|
||||||
if (ASCENDING_TRAVERSE(pReader->info.order)) {
|
if (ASCENDING_TRAVERSE(pReader->info.order)) {
|
||||||
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastProcKey + 1, .version = pReader->info.verRange.minVer};
|
startKey = (STsdbRowKey){.version = pReader->info.verRange.minVer,
|
||||||
|
.key = {
|
||||||
|
.ts = pBlockScanInfo->lastProcKey + 1,
|
||||||
|
.numOfPKs = 0, // TODO: change here if multi-key is supported
|
||||||
|
}};
|
||||||
} else {
|
} else {
|
||||||
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastProcKey - 1, .version = pReader->info.verRange.maxVer};
|
startKey = (STsdbRowKey){.version = pReader->info.verRange.maxVer,
|
||||||
|
.key = {
|
||||||
|
.ts = pBlockScanInfo->lastProcKey - 1,
|
||||||
|
.numOfPKs = 0, // TODO: change here if multi-key is supported
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code =
|
int32_t code =
|
||||||
|
@ -2001,8 +2043,8 @@ static bool isValidFileBlockRow(SBlockData* pBlockData, int32_t rowIndex, STable
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockScanInfo->delSkyline != NULL && TARRAY_SIZE(pBlockScanInfo->delSkyline) > 0) {
|
if (pBlockScanInfo->delSkyline != NULL && TARRAY_SIZE(pBlockScanInfo->delSkyline) > 0) {
|
||||||
bool dropped = hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, ts, ver,
|
bool dropped = hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, ts, ver, pInfo->order,
|
||||||
pInfo->order, &pInfo->verRange);
|
&pInfo->verRange);
|
||||||
if (dropped) {
|
if (dropped) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2069,7 +2111,7 @@ static bool initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScan
|
||||||
initMemDataIterator(pScanInfo, pReader);
|
initMemDataIterator(pScanInfo, pReader);
|
||||||
initDelSkylineIterator(pScanInfo, pReader->info.order, &pReader->cost);
|
initDelSkylineIterator(pScanInfo, pReader->info.order, &pReader->cost);
|
||||||
|
|
||||||
if (conf.rspRows) {
|
if (0 /*conf.rspRows*/) {
|
||||||
pScanInfo->cleanSttBlocks =
|
pScanInfo->cleanSttBlocks =
|
||||||
isCleanSttBlock(info.pTimeWindowList, &pReader->info.window, pScanInfo, pReader->info.order);
|
isCleanSttBlock(info.pTimeWindowList, &pReader->info.window, pScanInfo, pReader->info.order);
|
||||||
|
|
||||||
|
@ -2675,7 +2717,8 @@ static void buildCleanBlockFromDataFiles(STsdbReader* pReader, STableBlockScanIn
|
||||||
|
|
||||||
// update the last key for the corresponding table
|
// update the last key for the corresponding table
|
||||||
pScanInfo->lastProcKey = asc ? pInfo->window.ekey : pInfo->window.skey;
|
pScanInfo->lastProcKey = asc ? pInfo->window.ekey : pInfo->window.skey;
|
||||||
tsdbDebug("%p uid:%" PRIu64 " clean file block retrieved from file, global index:%d, "
|
tsdbDebug("%p uid:%" PRIu64
|
||||||
|
" clean file block retrieved from file, global index:%d, "
|
||||||
"table index:%d, rows:%d, brange:%" PRId64 "-%" PRId64 ", %s",
|
"table index:%d, rows:%d, brange:%" PRId64 "-%" PRId64 ", %s",
|
||||||
pReader, pScanInfo->uid, blockIndex, pBlockInfo->tbBlockIdx, pBlockInfo->numRow, pBlockInfo->firstKey,
|
pReader, pScanInfo->uid, blockIndex, pBlockInfo->tbBlockIdx, pBlockInfo->numRow, pBlockInfo->firstKey,
|
||||||
pBlockInfo->lastKey, pReader->idStr);
|
pBlockInfo->lastKey, pReader->idStr);
|
||||||
|
@ -3327,9 +3370,18 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW* pRow = tsdbTbDataIterGet(pIter->iter);
|
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
|
||||||
int32_t order = pReader->info.order;
|
int32_t order = pReader->info.order;
|
||||||
|
TSDBROW* pRow = tsdbTbDataIterGet(pIter->iter);
|
||||||
|
|
||||||
|
if (!pReader->pkChecked) {
|
||||||
|
STsdbRowKey k;
|
||||||
|
tsdbRowGetKey(pRow, &k);
|
||||||
|
|
||||||
|
pReader->pkComparFn = getComparFunc(k.key.pks[0].type, 0);
|
||||||
|
pReader->pkChecked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
if (outOfTimeWindow(key.ts, &pReader->info.window)) {
|
if (outOfTimeWindow(key.ts, &pReader->info.window)) {
|
||||||
pIter->hasVal = false;
|
pIter->hasVal = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3374,7 +3426,7 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, STsdbReader* pReader) {
|
int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, STsdbRowKey *pCurKey, SArray* pDelList, STsdbReader* pReader) {
|
||||||
SRowMerger* pMerger = &pReader->status.merger;
|
SRowMerger* pMerger = &pReader->status.merger;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -3390,8 +3442,11 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDe
|
||||||
}
|
}
|
||||||
|
|
||||||
// ts is not identical, quit
|
// ts is not identical, quit
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
if (TSDBROW_TS(pRow) != pCurKey->key.ts) {
|
||||||
if (k.ts != ts) {
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pkComp1(pReader, pCurKey, pRow) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3512,6 +3567,9 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
TSDBROW* pNextRow = NULL;
|
TSDBROW* pNextRow = NULL;
|
||||||
TSDBROW current = *pRow;
|
TSDBROW current = *pRow;
|
||||||
|
|
||||||
|
STsdbRowKey curKey = {0};
|
||||||
|
tsdbRowGetKey(¤t, &curKey);
|
||||||
|
|
||||||
{ // if the timestamp of the next valid row has a different ts, return current row directly
|
{ // if the timestamp of the next valid row has a different ts, return current row directly
|
||||||
pIter->hasVal = tsdbTbDataIterNext(pIter->iter);
|
pIter->hasVal = tsdbTbDataIterNext(pIter->iter);
|
||||||
|
|
||||||
|
@ -3527,7 +3585,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDBROW_TS(¤t) != TSDBROW_TS(pNextRow)) {
|
if (TSDBROW_TS(¤t) != TSDBROW_TS(pNextRow) || (pkComp1(pReader, &curKey, pNextRow) != 0)) {
|
||||||
*pResRow = current;
|
*pResRow = current;
|
||||||
*freeTSRow = false;
|
*freeTSRow = false;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -3565,7 +3623,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, pReader);
|
code = doMergeRowsInBuf(pIter, uid, &curKey, pDelList, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3586,8 +3644,9 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
SRow** pTSRow) {
|
SRow** pTSRow) {
|
||||||
SRowMerger* pMerger = &pReader->status.merger;
|
SRowMerger* pMerger = &pReader->status.merger;
|
||||||
|
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
STsdbRowKey k, ik;
|
||||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
tsdbRowGetKey(pRow, &k);
|
||||||
|
tsdbRowGetKey(piRow, &ik);
|
||||||
|
|
||||||
STSchema* pSchema = NULL;
|
STSchema* pSchema = NULL;
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
|
@ -3611,13 +3670,13 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, &ik, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMergerAdd(&pReader->status.merger, pRow, pSchema);
|
tsdbRowMergerAdd(&pReader->status.merger, pRow, pSchema);
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3628,13 +3687,13 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMergerAdd(&pReader->status.merger, piRow, piSchema);
|
tsdbRowMergerAdd(&pReader->status.merger, piRow, piSchema);
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
|
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, &ik, pBlockScanInfo->delSkyline, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3673,7 +3732,7 @@ static int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbRea
|
||||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
TSDBKEY ik = TSDBROW_KEY(piRow);
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (ik.ts != k.ts) {
|
if (ik.ts != k.ts || (pkComp(pReader, pRow, piRow) != 0)) {
|
||||||
if (((ik.ts < k.ts) && asc) || ((ik.ts > k.ts) && (!asc))) { // ik.ts < k.ts
|
if (((ik.ts < k.ts) && asc) || ((ik.ts > k.ts) && (!asc))) { // ik.ts < k.ts
|
||||||
code = doMergeMemTableMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, pResRow, pReader, freeTSRow);
|
code = doMergeMemTableMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, pResRow, pReader, freeTSRow);
|
||||||
} else if (((k.ts < ik.ts) && asc) || ((k.ts > ik.ts) && (!asc))) {
|
} else if (((k.ts < ik.ts) && asc) || ((k.ts > ik.ts) && (!asc))) {
|
||||||
|
@ -3692,8 +3751,7 @@ static int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbRea
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockScanInfo->iter.hasVal && pRow != NULL) {
|
if (pBlockScanInfo->iter.hasVal && pRow != NULL) {
|
||||||
return doMergeMemTableMultiRows(pRow, pBlockScanInfo->uid, &pBlockScanInfo->iter, pDelList, pResRow, pReader,
|
return doMergeMemTableMultiRows(pRow, uid, &pBlockScanInfo->iter, pDelList, pResRow, pReader, freeTSRow);
|
||||||
freeTSRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockScanInfo->iiter.hasVal && piRow != NULL) {
|
if (pBlockScanInfo->iiter.hasVal && piRow != NULL) {
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tsdbReadUtil.h"
|
#include "tsdbReadUtil.h"
|
||||||
#include "osDef.h"
|
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsdbDataFileRW.h"
|
#include "tsdbDataFileRW.h"
|
||||||
#include "tsdbFS2.h"
|
#include "tsdbFS2.h"
|
||||||
|
@ -281,7 +280,7 @@ void initBrinRecordIter(SBrinRecordIter* pIter, SDataFileReader* pReader, SArray
|
||||||
}
|
}
|
||||||
|
|
||||||
SBrinRecord* getNextBrinRecord(SBrinRecordIter* pIter) {
|
SBrinRecord* getNextBrinRecord(SBrinRecordIter* pIter) {
|
||||||
if (pIter->blockIndex == -1 || (pIter->recordIndex + 1) >= TARRAY2_SIZE(pIter->block.numRow)) {
|
if (pIter->blockIndex == -1 || (pIter->recordIndex + 1) >= pIter->block.numOfRecords) {
|
||||||
pIter->blockIndex += 1;
|
pIter->blockIndex += 1;
|
||||||
if (pIter->blockIndex >= taosArrayGetSize(pIter->pBrinBlockList)) {
|
if (pIter->blockIndex >= taosArrayGetSize(pIter->pBrinBlockList)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -358,8 +357,8 @@ static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, v
|
||||||
|
|
||||||
static void recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record) {
|
static void recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record) {
|
||||||
pBlockInfo->uid = record->uid;
|
pBlockInfo->uid = record->uid;
|
||||||
pBlockInfo->firstKey = record->firstKey;
|
pBlockInfo->firstKey = record->firstKey.key.ts;
|
||||||
pBlockInfo->lastKey = record->lastKey;
|
pBlockInfo->lastKey = record->lastKey.key.ts;
|
||||||
pBlockInfo->minVer = record->minVer;
|
pBlockInfo->minVer = record->minVer;
|
||||||
pBlockInfo->maxVer = record->maxVer;
|
pBlockInfo->maxVer = record->maxVer;
|
||||||
pBlockInfo->blockOffset = record->blockOffset;
|
pBlockInfo->blockOffset = record->blockOffset;
|
||||||
|
@ -529,7 +528,7 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_
|
||||||
pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData));
|
pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t k = 0; k < TARRAY2_SIZE(pBlock->suid); ++k) {
|
for (int32_t k = 0; k < pBlock->numOfRecords; ++k) {
|
||||||
code = tTombBlockGet(pBlock, k, &record);
|
code = tTombBlockGet(pBlock, k, &record);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
*pRet = BLK_CHECK_QUIT;
|
*pRet = BLK_CHECK_QUIT;
|
||||||
|
@ -722,11 +721,11 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo
|
||||||
pBlockLoadInfo->cost.statisElapsedTime += el;
|
pBlockLoadInfo->cost.statisElapsedTime += el;
|
||||||
|
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
while (index < TARRAY2_SIZE(pStatisBlock->suid) && pStatisBlock->suid->data[index] < suid) {
|
while (index < pStatisBlock->numOfRecords && ((int64_t*)pStatisBlock->suids.data)[index] < suid) {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= TARRAY2_SIZE(pStatisBlock->suid)) {
|
if (index >= pStatisBlock->numOfRecords) {
|
||||||
tStatisBlockDestroy(pStatisBlock);
|
tStatisBlockDestroy(pStatisBlock);
|
||||||
taosMemoryFreeClear(pStatisBlock);
|
taosMemoryFreeClear(pStatisBlock);
|
||||||
return num;
|
return num;
|
||||||
|
@ -744,14 +743,14 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo
|
||||||
|
|
||||||
uint64_t uid = pUidList[uidIndex];
|
uint64_t uid = pUidList[uidIndex];
|
||||||
|
|
||||||
if (pStatisBlock->uid->data[j] == uid) {
|
if (((int64_t*)pStatisBlock->uids.data)[j] == uid) {
|
||||||
num += pStatisBlock->count->data[j];
|
num += ((int64_t*)pStatisBlock->counts.data)[j];
|
||||||
uidIndex += 1;
|
uidIndex += 1;
|
||||||
j += 1;
|
j += 1;
|
||||||
loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->suid->size, &i, &j);
|
loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j);
|
||||||
} else if (pStatisBlock->uid->data[j] < uid) {
|
} else if (((int64_t*)pStatisBlock->uids.data)[j] < uid) {
|
||||||
j += 1;
|
j += 1;
|
||||||
loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->suid->size, &i, &j);
|
loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j);
|
||||||
} else {
|
} else {
|
||||||
uidIndex += 1;
|
uidIndex += 1;
|
||||||
}
|
}
|
||||||
|
@ -962,15 +961,15 @@ static bool doCheckDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const S
|
||||||
|
|
||||||
for (int32_t i = startIndex; i < num; i += 1) {
|
for (int32_t i = startIndex; i < num; i += 1) {
|
||||||
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
||||||
if (p->ts >= pRecord->firstKey && p->ts <= pRecord->lastKey) {
|
if (p->ts >= pRecord->firstKey.key.ts && p->ts <= pRecord->lastKey.key.ts) {
|
||||||
if (p->version >= pRecord->minVer) {
|
if (p->version >= pRecord->minVer) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (p->ts < pRecord->firstKey) { // p->ts < pBlock->minKey.ts
|
} else if (p->ts < pRecord->firstKey.key.ts) { // p->ts < pBlock->minKey.ts
|
||||||
if (p->version >= pRecord->minVer) {
|
if (p->version >= pRecord->minVer) {
|
||||||
if (i < num - 1) {
|
if (i < num - 1) {
|
||||||
TSDBKEY* pnext = taosArrayGet(pBlockScanInfo->delSkyline, i + 1);
|
TSDBKEY* pnext = taosArrayGet(pBlockScanInfo->delSkyline, i + 1);
|
||||||
if (pnext->ts >= pRecord->firstKey) {
|
if (pnext->ts >= pRecord->firstKey.key.ts) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else { // it must be the last point
|
} else { // it must be the last point
|
||||||
|
@ -991,12 +990,12 @@ static bool doCheckDatablockOverlapWithoutVersion(STableBlockScanInfo* pBlockSca
|
||||||
|
|
||||||
for (int32_t i = startIndex; i < num; i += 1) {
|
for (int32_t i = startIndex; i < num; i += 1) {
|
||||||
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
||||||
if (p->ts >= pRecord->firstKey && p->ts <= pRecord->lastKey) {
|
if (p->ts >= pRecord->firstKey.key.ts && p->ts <= pRecord->lastKey.key.ts) {
|
||||||
return true;
|
return true;
|
||||||
} else if (p->ts < pRecord->firstKey) { // p->ts < pBlock->minKey.ts
|
} else if (p->ts < pRecord->firstKey.key.ts) { // p->ts < pBlock->minKey.ts
|
||||||
if (i < num - 1) {
|
if (i < num - 1) {
|
||||||
TSDBKEY* pnext = taosArrayGet(pBlockScanInfo->delSkyline, i + 1);
|
TSDBKEY* pnext = taosArrayGet(pBlockScanInfo->delSkyline, i + 1);
|
||||||
if (pnext->ts >= pRecord->firstKey) {
|
if (pnext->ts >= pRecord->firstKey.key.ts) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1016,7 +1015,7 @@ bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SBrinRecor
|
||||||
// ts is not overlap
|
// ts is not overlap
|
||||||
TSDBKEY* pFirst = taosArrayGet(pBlockScanInfo->delSkyline, 0);
|
TSDBKEY* pFirst = taosArrayGet(pBlockScanInfo->delSkyline, 0);
|
||||||
TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline);
|
TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline);
|
||||||
if (pRecord->firstKey > pLast->ts || pRecord->lastKey < pFirst->ts) {
|
if (pRecord->firstKey.key.ts > pLast->ts || pRecord->lastKey.key.ts < pFirst->ts) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1027,10 +1026,10 @@ bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SBrinRecor
|
||||||
int32_t index = pBlockScanInfo->fileDelIndex;
|
int32_t index = pBlockScanInfo->fileDelIndex;
|
||||||
while (1) {
|
while (1) {
|
||||||
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, index);
|
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, index);
|
||||||
if (p->ts > pRecord->firstKey && index > 0) {
|
if (p->ts > pRecord->firstKey.key.ts && index > 0) {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
} else { // find the first point that is smaller than the minKey.ts of dataBlock.
|
} else { // find the first point that is smaller than the minKey.ts of dataBlock.
|
||||||
if (p->ts == pRecord->firstKey && p->version < pRecord->maxVer && index > 0) {
|
if (p->ts == pRecord->firstKey.key.ts && p->version < pRecord->maxVer && index > 0) {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1049,7 +1048,7 @@ bool overlapWithDelSkylineWithoutVer(STableBlockScanInfo* pBlockScanInfo, const
|
||||||
// ts is not overlap
|
// ts is not overlap
|
||||||
TSDBKEY* pFirst = taosArrayGet(pBlockScanInfo->delSkyline, 0);
|
TSDBKEY* pFirst = taosArrayGet(pBlockScanInfo->delSkyline, 0);
|
||||||
TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline);
|
TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline);
|
||||||
if (pRecord->firstKey > pLast->ts || pRecord->lastKey < pFirst->ts) {
|
if (pRecord->firstKey.key.ts > pLast->ts || pRecord->lastKey.key.ts < pFirst->ts) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,10 +1059,10 @@ bool overlapWithDelSkylineWithoutVer(STableBlockScanInfo* pBlockScanInfo, const
|
||||||
int32_t index = pBlockScanInfo->fileDelIndex;
|
int32_t index = pBlockScanInfo->fileDelIndex;
|
||||||
while (1) {
|
while (1) {
|
||||||
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, index);
|
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, index);
|
||||||
if (p->ts > pRecord->firstKey && index > 0) {
|
if (p->ts > pRecord->firstKey.key.ts && index > 0) {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
} else { // find the first point that is smaller than the minKey.ts of dataBlock.
|
} else { // find the first point that is smaller than the minKey.ts of dataBlock.
|
||||||
if (p->ts == pRecord->firstKey && index > 0) {
|
if (p->ts == pRecord->firstKey.key.ts && index > 0) {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -267,6 +267,8 @@ struct STsdbReader {
|
||||||
bool bFilesetDelimited; // duration by duration output
|
bool bFilesetDelimited; // duration by duration output
|
||||||
TsdReaderNotifyCbFn notifyFn;
|
TsdReaderNotifyCbFn notifyFn;
|
||||||
void* notifyParam;
|
void* notifyParam;
|
||||||
|
__compar_fn_t pkComparFn;
|
||||||
|
bool pkChecked;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SBrinRecordIter {
|
typedef struct SBrinRecordIter {
|
||||||
|
|
|
@ -414,6 +414,18 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tsdbReadFileToBuffer(STsdbFD *pFD, int64_t offset, int64_t size, SBuffer *buffer, int64_t szHint) {
|
||||||
|
int32_t code;
|
||||||
|
|
||||||
|
code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||||
|
if (code) return code;
|
||||||
|
code = tsdbReadFile(pFD, offset, (uint8_t *)tBufferGetDataEnd(buffer), size, szHint);
|
||||||
|
if (code) return code;
|
||||||
|
buffer->size += size;
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tsdbFsyncFile(STsdbFD *pFD) {
|
int32_t tsdbFsyncFile(STsdbFD *pFD) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
@ -620,235 +632,6 @@ _err:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbReadBlockSma(SDataFReader *pReader, SDataBlk *pDataBlk, SArray *aColumnDataAgg) {
|
|
||||||
int32_t code = 0;
|
|
||||||
SSmaInfo *pSmaInfo = &pDataBlk->smaInfo;
|
|
||||||
|
|
||||||
ASSERT(pSmaInfo->size > 0);
|
|
||||||
|
|
||||||
taosArrayClear(aColumnDataAgg);
|
|
||||||
|
|
||||||
// alloc
|
|
||||||
code = tRealloc(&pReader->aBuf[0], pSmaInfo->size);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
// read
|
|
||||||
code = tsdbReadFile(pReader->pSmaFD, pSmaInfo->offset, pReader->aBuf[0], pSmaInfo->size, 0);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
// decode
|
|
||||||
int32_t n = 0;
|
|
||||||
while (n < pSmaInfo->size) {
|
|
||||||
SColumnDataAgg sma;
|
|
||||||
n += tGetColumnDataAgg(pReader->aBuf[0] + n, &sma);
|
|
||||||
|
|
||||||
if (taosArrayPush(aColumnDataAgg, &sma) == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ASSERT(n == pSmaInfo->size);
|
|
||||||
return code;
|
|
||||||
|
|
||||||
_err:
|
|
||||||
tsdbError("vgId:%d, tsdb read block sma failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tsdbReadBlockDataImpl(SDataFReader *pReader, SBlockInfo *pBlkInfo, SBlockData *pBlockData,
|
|
||||||
int32_t iStt) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
tBlockDataClear(pBlockData);
|
|
||||||
|
|
||||||
STsdbFD *pFD = (iStt < 0) ? pReader->pDataFD : pReader->aSttFD[iStt];
|
|
||||||
|
|
||||||
// uid + version + tskey
|
|
||||||
code = tRealloc(&pReader->aBuf[0], pBlkInfo->szKey);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
code = tsdbReadFile(pFD, pBlkInfo->offset, pReader->aBuf[0], pBlkInfo->szKey, 0);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
SDiskDataHdr hdr;
|
|
||||||
uint8_t *p = pReader->aBuf[0] + tGetDiskDataHdr(pReader->aBuf[0], &hdr);
|
|
||||||
|
|
||||||
ASSERT(hdr.delimiter == TSDB_FILE_DLMT);
|
|
||||||
ASSERT(pBlockData->suid == hdr.suid);
|
|
||||||
|
|
||||||
pBlockData->uid = hdr.uid;
|
|
||||||
pBlockData->nRow = hdr.nRow;
|
|
||||||
|
|
||||||
// uid
|
|
||||||
if (hdr.uid == 0) {
|
|
||||||
ASSERT(hdr.szUid);
|
|
||||||
code = tsdbDecmprData(p, hdr.szUid, TSDB_DATA_TYPE_BIGINT, hdr.cmprAlg, (uint8_t **)&pBlockData->aUid,
|
|
||||||
sizeof(int64_t) * hdr.nRow, &pReader->aBuf[1]);
|
|
||||||
if (code) goto _err;
|
|
||||||
} else {
|
|
||||||
ASSERT(!hdr.szUid);
|
|
||||||
}
|
|
||||||
p += hdr.szUid;
|
|
||||||
|
|
||||||
// version
|
|
||||||
code = tsdbDecmprData(p, hdr.szVer, TSDB_DATA_TYPE_BIGINT, hdr.cmprAlg, (uint8_t **)&pBlockData->aVersion,
|
|
||||||
sizeof(int64_t) * hdr.nRow, &pReader->aBuf[1]);
|
|
||||||
if (code) goto _err;
|
|
||||||
p += hdr.szVer;
|
|
||||||
|
|
||||||
// TSKEY
|
|
||||||
code = tsdbDecmprData(p, hdr.szKey, TSDB_DATA_TYPE_TIMESTAMP, hdr.cmprAlg, (uint8_t **)&pBlockData->aTSKEY,
|
|
||||||
sizeof(TSKEY) * hdr.nRow, &pReader->aBuf[1]);
|
|
||||||
if (code) goto _err;
|
|
||||||
p += hdr.szKey;
|
|
||||||
|
|
||||||
ASSERT(p - pReader->aBuf[0] == pBlkInfo->szKey);
|
|
||||||
|
|
||||||
// read and decode columns
|
|
||||||
if (pBlockData->nColData == 0) goto _exit;
|
|
||||||
|
|
||||||
if (hdr.szBlkCol > 0) {
|
|
||||||
int64_t offset = pBlkInfo->offset + pBlkInfo->szKey;
|
|
||||||
|
|
||||||
code = tRealloc(&pReader->aBuf[0], hdr.szBlkCol);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
code = tsdbReadFile(pFD, offset, pReader->aBuf[0], hdr.szBlkCol, 0);
|
|
||||||
if (code) goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
SBlockCol blockCol = {.cid = 0};
|
|
||||||
SBlockCol *pBlockCol = &blockCol;
|
|
||||||
int32_t n = 0;
|
|
||||||
|
|
||||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
|
||||||
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData);
|
|
||||||
|
|
||||||
while (pBlockCol && pBlockCol->cid < pColData->cid) {
|
|
||||||
if (n < hdr.szBlkCol) {
|
|
||||||
n += tGetBlockCol(pReader->aBuf[0] + n, pBlockCol);
|
|
||||||
} else {
|
|
||||||
ASSERT(n == hdr.szBlkCol);
|
|
||||||
pBlockCol = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pBlockCol == NULL || pBlockCol->cid > pColData->cid) {
|
|
||||||
// add a lot of NONE
|
|
||||||
for (int32_t iRow = 0; iRow < hdr.nRow; iRow++) {
|
|
||||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
|
||||||
if (code) goto _err;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ASSERT(pBlockCol->type == pColData->type);
|
|
||||||
ASSERT(pBlockCol->flag && pBlockCol->flag != HAS_NONE);
|
|
||||||
|
|
||||||
if (pBlockCol->flag == HAS_NULL) {
|
|
||||||
// add a lot of NULL
|
|
||||||
for (int32_t iRow = 0; iRow < hdr.nRow; iRow++) {
|
|
||||||
code = tColDataAppendValue(pColData, &COL_VAL_NULL(pBlockCol->cid, pBlockCol->type));
|
|
||||||
if (code) goto _err;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// decode from binary
|
|
||||||
int64_t offset = pBlkInfo->offset + pBlkInfo->szKey + hdr.szBlkCol + pBlockCol->offset;
|
|
||||||
int32_t size = pBlockCol->szBitmap + pBlockCol->szOffset + pBlockCol->szValue;
|
|
||||||
|
|
||||||
code = tRealloc(&pReader->aBuf[1], size);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
code = tsdbReadFile(pFD, offset, pReader->aBuf[1], size, 0);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
code = tsdbDecmprColData(pReader->aBuf[1], pBlockCol, hdr.cmprAlg, hdr.nRow, pColData, &pReader->aBuf[2]);
|
|
||||||
if (code) goto _err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
return code;
|
|
||||||
|
|
||||||
_err:
|
|
||||||
tsdbError("vgId:%d, tsdb read block data impl failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbReadDataBlockEx(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData *pBlockData) {
|
|
||||||
int32_t code = 0;
|
|
||||||
SBlockInfo *pBlockInfo = &pDataBlk->aSubBlock[0];
|
|
||||||
|
|
||||||
// alloc
|
|
||||||
code = tRealloc(&pReader->aBuf[0], pBlockInfo->szBlock);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
// read
|
|
||||||
code = tsdbReadFile(pReader->pDataFD, pBlockInfo->offset, pReader->aBuf[0], pBlockInfo->szBlock, 0);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
// decmpr
|
|
||||||
code = tDecmprBlockData(pReader->aBuf[0], pBlockInfo->szBlock, pBlockData, &pReader->aBuf[1]);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
return code;
|
|
||||||
|
|
||||||
_err:
|
|
||||||
tsdbError("vgId:%d, tsdb read data block ex failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData *pBlockData) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
code = tsdbReadBlockDataImpl(pReader, &pDataBlk->aSubBlock[0], pBlockData, -1);
|
|
||||||
if (code) goto _err;
|
|
||||||
|
|
||||||
ASSERT(pDataBlk->nSubBlock == 1);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
|
|
||||||
_err:
|
|
||||||
tsdbError("vgId:%d, tsdb read data block failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code));
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbReadSttBlock(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk, SBlockData *pBlockData) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
code = tsdbReadBlockDataImpl(pReader, &pSttBlk->bInfo, pBlockData, iStt);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pReader->pTsdb->pVnode), __func__, lino, tstrerror(code));
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbReadSttBlockEx(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk, SBlockData *pBlockData) {
|
|
||||||
int32_t code = 0;
|
|
||||||
int32_t lino = 0;
|
|
||||||
|
|
||||||
// alloc
|
|
||||||
code = tRealloc(&pReader->aBuf[0], pSttBlk->bInfo.szBlock);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
// read
|
|
||||||
code = tsdbReadFile(pReader->aSttFD[iStt], pSttBlk->bInfo.offset, pReader->aBuf[0], pSttBlk->bInfo.szBlock, 0);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
// decmpr
|
|
||||||
code = tDecmprBlockData(pReader->aBuf[0], pSttBlk->bInfo.szBlock, pBlockData, &pReader->aBuf[1]);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pReader->pTsdb->pVnode), __func__, lino, tstrerror(code));
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDelFReader ====================================================
|
// SDelFReader ====================================================
|
||||||
struct SDelFReader {
|
struct SDelFReader {
|
||||||
STsdb *pTsdb;
|
STsdb *pTsdb;
|
||||||
|
|
|
@ -29,7 +29,7 @@ struct STsdbSnapReader {
|
||||||
int64_t ever;
|
int64_t ever;
|
||||||
int8_t type;
|
int8_t type;
|
||||||
|
|
||||||
uint8_t* aBuf[5];
|
SBuffer buffers[10];
|
||||||
SSkmInfo skmTb[1];
|
SSkmInfo skmTb[1];
|
||||||
|
|
||||||
TFileSetRangeArray* fsrArr;
|
TFileSetRangeArray* fsrArr;
|
||||||
|
@ -68,7 +68,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) {
|
||||||
SDataFileReaderConfig config = {
|
SDataFileReaderConfig config = {
|
||||||
.tsdb = reader->tsdb,
|
.tsdb = reader->tsdb,
|
||||||
.szPage = reader->tsdb->pVnode->config.tsdbPageSize,
|
.szPage = reader->tsdb->pVnode->config.tsdbPageSize,
|
||||||
.bufArr = reader->aBuf,
|
.buffers = reader->buffers,
|
||||||
};
|
};
|
||||||
bool hasDataFile = false;
|
bool hasDataFile = false;
|
||||||
for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX; ftype++) {
|
for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX; ftype++) {
|
||||||
|
@ -94,7 +94,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) {
|
||||||
.tsdb = reader->tsdb,
|
.tsdb = reader->tsdb,
|
||||||
.szPage = reader->tsdb->pVnode->config.tsdbPageSize,
|
.szPage = reader->tsdb->pVnode->config.tsdbPageSize,
|
||||||
.file = fobj->f[0],
|
.file = fobj->f[0],
|
||||||
.bufArr = reader->aBuf,
|
.buffers = reader->buffers,
|
||||||
};
|
};
|
||||||
|
|
||||||
code = tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader);
|
code = tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader);
|
||||||
|
@ -247,11 +247,14 @@ static int32_t tsdbSnapCmprData(STsdbSnapReader* reader, uint8_t** data) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
int32_t aBufN[5] = {0};
|
code = tBlockDataCompress(reader->blockData, NO_COMPRESSION, reader->buffers, reader->buffers + 4);
|
||||||
code = tCmprBlockData(reader->blockData, NO_COMPRESSION, NULL, NULL, reader->aBuf, aBufN);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
// TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
int32_t size = aBufN[0] + aBufN[1] + aBufN[2] + aBufN[3];
|
int32_t size = 0;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
size += reader->buffers[i].size;
|
||||||
|
}
|
||||||
*data = taosMemoryMalloc(sizeof(SSnapDataHdr) + size);
|
*data = taosMemoryMalloc(sizeof(SSnapDataHdr) + size);
|
||||||
if (*data == NULL) {
|
if (*data == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -259,16 +262,13 @@ static int32_t tsdbSnapCmprData(STsdbSnapReader* reader, uint8_t** data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSnapDataHdr* pHdr = (SSnapDataHdr*)*data;
|
SSnapDataHdr* pHdr = (SSnapDataHdr*)*data;
|
||||||
|
uint8_t* pBuf = pHdr->data;
|
||||||
|
|
||||||
pHdr->type = reader->type;
|
pHdr->type = reader->type;
|
||||||
pHdr->size = size;
|
pHdr->size = size;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
memcpy(pHdr->data, reader->aBuf[3], aBufN[3]);
|
memcpy(pBuf, reader->buffers[i].data, reader->buffers[i].size);
|
||||||
memcpy(pHdr->data + aBufN[3], reader->aBuf[2], aBufN[2]);
|
pBuf += reader->buffers[i].size;
|
||||||
if (aBufN[1]) {
|
|
||||||
memcpy(pHdr->data + aBufN[3] + aBufN[2], reader->aBuf[1], aBufN[1]);
|
|
||||||
}
|
|
||||||
if (aBufN[0]) {
|
|
||||||
memcpy(pHdr->data + aBufN[3] + aBufN[2] + aBufN[1], reader->aBuf[0], aBufN[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -355,8 +355,8 @@ static int32_t tsdbSnapCmprTombData(STsdbSnapReader* reader, uint8_t** data) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(reader->tombBlock->dataArr); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(reader->tombBlock->buffers); i++) {
|
||||||
size += TARRAY2_DATA_LEN(reader->tombBlock->dataArr + i);
|
size += reader->tombBlock->buffers[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[0] = taosMemoryMalloc(size + sizeof(SSnapDataHdr));
|
data[0] = taosMemoryMalloc(size + sizeof(SSnapDataHdr));
|
||||||
|
@ -370,9 +370,9 @@ static int32_t tsdbSnapCmprTombData(STsdbSnapReader* reader, uint8_t** data) {
|
||||||
hdr->size = size;
|
hdr->size = size;
|
||||||
|
|
||||||
uint8_t* tdata = hdr->data;
|
uint8_t* tdata = hdr->data;
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(reader->tombBlock->dataArr); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(reader->tombBlock->buffers); i++) {
|
||||||
memcpy(tdata, TARRAY2_DATA(reader->tombBlock->dataArr + i), TARRAY2_DATA_LEN(reader->tombBlock->dataArr + i));
|
memcpy(tdata, reader->tombBlock->buffers[i].data, reader->tombBlock->buffers[i].size);
|
||||||
tdata += TARRAY2_DATA_LEN(reader->tombBlock->dataArr + i);
|
tdata += reader->tombBlock->buffers[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -475,8 +475,8 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) {
|
||||||
tsdbFSDestroyRefRangedSnapshot(&reader[0]->fsrArr);
|
tsdbFSDestroyRefRangedSnapshot(&reader[0]->fsrArr);
|
||||||
tDestroyTSchema(reader[0]->skmTb->pTSchema);
|
tDestroyTSchema(reader[0]->skmTb->pTSchema);
|
||||||
|
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->aBuf); ++i) {
|
for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->buffers); ++i) {
|
||||||
tFree(reader[0]->aBuf[i]);
|
tBufferDestroy(reader[0]->buffers + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(reader[0]);
|
taosMemoryFree(reader[0]);
|
||||||
|
@ -554,7 +554,7 @@ struct STsdbSnapWriter {
|
||||||
int32_t szPage;
|
int32_t szPage;
|
||||||
int64_t compactVersion;
|
int64_t compactVersion;
|
||||||
int64_t now;
|
int64_t now;
|
||||||
uint8_t* aBuf[5];
|
SBuffer buffers[10];
|
||||||
|
|
||||||
TFileSetArray* fsetArr;
|
TFileSetArray* fsetArr;
|
||||||
TFileOpArray fopArr[1];
|
TFileOpArray fopArr[1];
|
||||||
|
@ -632,7 +632,7 @@ static int32_t tsdbSnapWriteFileSetOpenReader(STsdbSnapWriter* writer) {
|
||||||
// open data reader
|
// open data reader
|
||||||
SDataFileReaderConfig dataFileReaderConfig = {
|
SDataFileReaderConfig dataFileReaderConfig = {
|
||||||
.tsdb = writer->tsdb,
|
.tsdb = writer->tsdb,
|
||||||
.bufArr = writer->aBuf,
|
.buffers = writer->buffers,
|
||||||
.szPage = writer->szPage,
|
.szPage = writer->szPage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ static int32_t tsdbSnapWriteFileSetOpenReader(STsdbSnapWriter* writer) {
|
||||||
SSttFileReaderConfig sttFileReaderConfig = {
|
SSttFileReaderConfig sttFileReaderConfig = {
|
||||||
.tsdb = writer->tsdb,
|
.tsdb = writer->tsdb,
|
||||||
.szPage = writer->szPage,
|
.szPage = writer->szPage,
|
||||||
.bufArr = writer->aBuf,
|
.buffers = writer->buffers,
|
||||||
.file = fobj->f[0],
|
.file = fobj->f[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -939,7 +939,14 @@ static int32_t tsdbSnapWriteTimeSeriesData(STsdbSnapWriter* writer, SSnapDataHdr
|
||||||
|
|
||||||
SBlockData blockData[1] = {0};
|
SBlockData blockData[1] = {0};
|
||||||
|
|
||||||
code = tDecmprBlockData(hdr->data, hdr->size - sizeof(*hdr), blockData, writer->aBuf);
|
SBuffer buffer = {
|
||||||
|
.capacity = hdr->size,
|
||||||
|
.data = hdr->data,
|
||||||
|
.size = hdr->size,
|
||||||
|
};
|
||||||
|
SBufferReader br = BUFFER_READER_INITIALIZER(0, &buffer);
|
||||||
|
|
||||||
|
code = tBlockDataDecompress(&br, blockData, &writer->buffers[0]);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
int32_t fid = tsdbKeyFid(blockData->aTSKEY[0], writer->minutes, writer->precision);
|
int32_t fid = tsdbKeyFid(blockData->aTSKEY[0], writer->minutes, writer->precision);
|
||||||
|
@ -977,15 +984,19 @@ static int32_t tsdbSnapWriteDecmprTombBlock(SSnapDataHdr* hdr, STombBlock* tombB
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
|
tTombBlockClear(tombBlock);
|
||||||
|
|
||||||
int64_t size = hdr->size;
|
int64_t size = hdr->size;
|
||||||
ASSERT(size % TOMB_RECORD_ELEM_NUM == 0);
|
ASSERT(size % TOMB_RECORD_ELEM_NUM == 0);
|
||||||
size = size / TOMB_RECORD_ELEM_NUM;
|
size = size / TOMB_RECORD_ELEM_NUM;
|
||||||
ASSERT(size % sizeof(int64_t) == 0);
|
tombBlock->numOfRecords = size / sizeof(int64_t);
|
||||||
|
|
||||||
int64_t* data = (int64_t*)hdr->data;
|
// int64_t* data = (int64_t*)hdr->data;
|
||||||
|
uint8_t* data = hdr->data;
|
||||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||||
code = TARRAY2_APPEND_BATCH(&tombBlock->dataArr[i], hdr->data + i * size, size / sizeof(int64_t));
|
code = tBufferPut(tombBlock->buffers + i, data, size);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
data += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -1061,7 +1072,8 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, void* pRang
|
||||||
writer[0]->compactVersion = INT64_MAX;
|
writer[0]->compactVersion = INT64_MAX;
|
||||||
writer[0]->now = taosGetTimestampMs();
|
writer[0]->now = taosGetTimestampMs();
|
||||||
|
|
||||||
code = tsdbFSCreateCopyRangedSnapshot(pTsdb->pFS, (TFileSetRangeArray*)pRanges, &writer[0]->fsetArr, writer[0]->fopArr);
|
code =
|
||||||
|
tsdbFSCreateCopyRangedSnapshot(pTsdb->pFS, (TFileSetRangeArray*)pRanges, &writer[0]->fsetArr, writer[0]->fopArr);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -1127,8 +1139,8 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** writer, int8_t rollback) {
|
||||||
TARRAY2_DESTROY(writer[0]->fopArr, NULL);
|
TARRAY2_DESTROY(writer[0]->fopArr, NULL);
|
||||||
tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr);
|
tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr);
|
||||||
|
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->aBuf); ++i) {
|
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->buffers); ++i) {
|
||||||
tFree(writer[0]->aBuf[i]);
|
tBufferDestroy(writer[0]->buffers + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(writer[0]);
|
taosMemoryFree(writer[0]);
|
||||||
|
|
|
@ -29,7 +29,8 @@ struct SSttFileReader {
|
||||||
TSttBlkArray sttBlkArray[1];
|
TSttBlkArray sttBlkArray[1];
|
||||||
TStatisBlkArray statisBlkArray[1];
|
TStatisBlkArray statisBlkArray[1];
|
||||||
TTombBlkArray tombBlkArray[1];
|
TTombBlkArray tombBlkArray[1];
|
||||||
uint8_t *bufArr[5];
|
SBuffer local[10];
|
||||||
|
SBuffer *buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
// SSttFileReader
|
// SSttFileReader
|
||||||
|
@ -41,8 +42,9 @@ int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *con
|
||||||
if (reader[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (reader[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
reader[0]->config[0] = config[0];
|
reader[0]->config[0] = config[0];
|
||||||
if (reader[0]->config->bufArr == NULL) {
|
reader[0]->buffers = config->buffers;
|
||||||
reader[0]->config->bufArr = reader[0]->bufArr;
|
if (reader[0]->buffers == NULL) {
|
||||||
|
reader[0]->buffers = reader[0]->local;
|
||||||
}
|
}
|
||||||
|
|
||||||
// open file
|
// open file
|
||||||
|
@ -73,8 +75,8 @@ _exit:
|
||||||
|
|
||||||
int32_t tsdbSttFileReaderClose(SSttFileReader **reader) {
|
int32_t tsdbSttFileReaderClose(SSttFileReader **reader) {
|
||||||
if (reader[0]) {
|
if (reader[0]) {
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->bufArr); ++i) {
|
for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->local); ++i) {
|
||||||
tFree(reader[0]->bufArr[i]);
|
tBufferDestroy(reader[0]->local + i);
|
||||||
}
|
}
|
||||||
tsdbCloseFile(&reader[0]->fd);
|
tsdbCloseFile(&reader[0]->fd);
|
||||||
TARRAY2_DESTROY(reader[0]->tombBlkArray, NULL);
|
TARRAY2_DESTROY(reader[0]->tombBlkArray, NULL);
|
||||||
|
@ -175,13 +177,16 @@ int32_t tsdbSttFileReadBlockData(SSttFileReader *reader, const SSttBlk *sttBlk,
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
code = tRealloc(&reader->config->bufArr[0], sttBlk->bInfo.szBlock);
|
SBuffer *buffer0 = reader->buffers + 0;
|
||||||
|
SBuffer *assist = reader->buffers + 1;
|
||||||
|
|
||||||
|
// load data
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
code = tsdbReadFileToBuffer(reader->fd, sttBlk->bInfo.offset, sttBlk->bInfo.szBlock, buffer0, 0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbReadFile(reader->fd, sttBlk->bInfo.offset, reader->config->bufArr[0], sttBlk->bInfo.szBlock, 0);
|
SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
code = tBlockDataDecompress(&br, bData, assist);
|
||||||
|
|
||||||
code = tDecmprBlockData(reader->config->bufArr[0], sttBlk->bInfo.szBlock, bData, &reader->config->bufArr[1]);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -196,117 +201,103 @@ int32_t tsdbSttFileReadBlockDataByColumn(SSttFileReader *reader, const SSttBlk *
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
TABLEID tbid = {.suid = sttBlk->suid};
|
SDiskDataHdr hdr;
|
||||||
if (tbid.suid == 0) {
|
SBuffer *buffer0 = reader->buffers + 0;
|
||||||
tbid.uid = sttBlk->minUid;
|
SBuffer *buffer1 = reader->buffers + 1;
|
||||||
} else {
|
SBuffer *assist = reader->buffers + 2;
|
||||||
tbid.uid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tBlockDataInit(bData, &tbid, pTSchema, cids, ncid);
|
// load key part
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
code = tsdbReadFileToBuffer(reader->fd, sttBlk->bInfo.offset, sttBlk->bInfo.szKey, buffer0, 0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// uid + version + tskey
|
// decode header
|
||||||
code = tRealloc(&reader->config->bufArr[0], sttBlk->bInfo.szKey);
|
SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer0);
|
||||||
|
code = tGetDiskDataHdr(&br, &hdr);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbReadFile(reader->fd, sttBlk->bInfo.offset, reader->config->bufArr[0], sttBlk->bInfo.szKey, 0);
|
ASSERT(hdr.delimiter == TSDB_FILE_DLMT);
|
||||||
|
|
||||||
|
// set data container
|
||||||
|
tBlockDataReset(bData);
|
||||||
|
bData->suid = hdr.suid;
|
||||||
|
bData->uid = (sttBlk->suid == 0) ? sttBlk->minUid : 0;
|
||||||
|
bData->nRow = hdr.nRow;
|
||||||
|
|
||||||
|
// key part
|
||||||
|
code = tBlockDataDecompressKeyPart(&hdr, &br, bData, assist);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
ASSERT(br.offset == buffer0->size);
|
||||||
|
|
||||||
// hdr
|
bool loadExtra = false;
|
||||||
SDiskDataHdr hdr[1];
|
for (int i = 0; i < ncid; i++) {
|
||||||
int32_t size = 0;
|
if (tBlockDataGetColData(bData, cids[i]) == NULL) {
|
||||||
|
loadExtra = true;
|
||||||
size += tGetDiskDataHdr(reader->config->bufArr[0] + size, hdr);
|
break;
|
||||||
|
|
||||||
ASSERT(hdr->delimiter == TSDB_FILE_DLMT);
|
|
||||||
|
|
||||||
bData->nRow = hdr->nRow;
|
|
||||||
bData->uid = hdr->uid;
|
|
||||||
|
|
||||||
// uid
|
|
||||||
if (hdr->uid == 0) {
|
|
||||||
ASSERT(hdr->szUid);
|
|
||||||
code = tsdbDecmprData(reader->config->bufArr[0] + size, hdr->szUid, TSDB_DATA_TYPE_BIGINT, hdr->cmprAlg,
|
|
||||||
(uint8_t **)&bData->aUid, sizeof(int64_t) * hdr->nRow, &reader->config->bufArr[1]);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
} else {
|
|
||||||
ASSERT(hdr->szUid == 0);
|
|
||||||
}
|
|
||||||
size += hdr->szUid;
|
|
||||||
|
|
||||||
// version
|
|
||||||
code = tsdbDecmprData(reader->config->bufArr[0] + size, hdr->szVer, TSDB_DATA_TYPE_BIGINT, hdr->cmprAlg,
|
|
||||||
(uint8_t **)&bData->aVersion, sizeof(int64_t) * hdr->nRow, &reader->config->bufArr[1]);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
size += hdr->szVer;
|
|
||||||
|
|
||||||
// ts
|
|
||||||
code = tsdbDecmprData(reader->config->bufArr[0] + size, hdr->szKey, TSDB_DATA_TYPE_TIMESTAMP, hdr->cmprAlg,
|
|
||||||
(uint8_t **)&bData->aTSKEY, sizeof(TSKEY) * hdr->nRow, &reader->config->bufArr[1]);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
size += hdr->szKey;
|
|
||||||
|
|
||||||
ASSERT(size == sttBlk->bInfo.szKey);
|
|
||||||
|
|
||||||
// other columns
|
|
||||||
if (bData->nColData > 0) {
|
|
||||||
if (hdr->szBlkCol > 0) {
|
|
||||||
code = tRealloc(&reader->config->bufArr[0], hdr->szBlkCol);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
code = tsdbReadFile(reader->fd, sttBlk->bInfo.offset + sttBlk->bInfo.szKey, reader->config->bufArr[0],
|
|
||||||
hdr->szBlkCol, 0);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
SBlockCol bc[1] = {{.cid = 0}};
|
|
||||||
SBlockCol *blockCol = bc;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
for (int32_t i = 0; i < bData->nColData; i++) {
|
|
||||||
SColData *colData = tBlockDataGetColDataByIdx(bData, i);
|
|
||||||
|
|
||||||
while (blockCol && blockCol->cid < colData->cid) {
|
|
||||||
if (size < hdr->szBlkCol) {
|
|
||||||
size += tGetBlockCol(reader->config->bufArr[0] + size, blockCol);
|
|
||||||
} else {
|
|
||||||
ASSERT(size == hdr->szBlkCol);
|
|
||||||
blockCol = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockCol == NULL || blockCol->cid > colData->cid) {
|
if (!loadExtra) {
|
||||||
for (int32_t iRow = 0; iRow < hdr->nRow; iRow++) {
|
goto _exit;
|
||||||
code = tColDataAppendValue(colData, &COL_VAL_NONE(colData->cid, colData->type));
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ASSERT(blockCol->type == colData->type);
|
|
||||||
ASSERT(blockCol->flag && blockCol->flag != HAS_NONE);
|
|
||||||
|
|
||||||
if (blockCol->flag == HAS_NULL) {
|
// load SBlockCol part
|
||||||
for (int32_t iRow = 0; iRow < hdr->nRow; iRow++) {
|
tBufferClear(buffer0);
|
||||||
code = tColDataAppendValue(colData, &COL_VAL_NULL(blockCol->cid, blockCol->type));
|
code = tsdbReadFileToBuffer(reader->fd, sttBlk->bInfo.offset + sttBlk->bInfo.szKey, hdr.szBlkCol, buffer0, 0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int32_t size1 = blockCol->szBitmap + blockCol->szOffset + blockCol->szValue;
|
|
||||||
|
|
||||||
code = tRealloc(&reader->config->bufArr[1], size1);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbReadFile(reader->fd, sttBlk->bInfo.offset + sttBlk->bInfo.szKey + hdr->szBlkCol + blockCol->offset,
|
// load each column
|
||||||
reader->config->bufArr[1], size1, 0);
|
SBlockCol blockCol = {
|
||||||
|
.cid = 0,
|
||||||
|
};
|
||||||
|
br = BUFFER_READER_INITIALIZER(0, buffer0);
|
||||||
|
for (int32_t i = 0; i < ncid; i++) {
|
||||||
|
int16_t cid = cids[i];
|
||||||
|
|
||||||
|
if (tBlockDataGetColData(bData, cid)) { // already loaded
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (cid > blockCol.cid) {
|
||||||
|
if (br.offset >= buffer0->size) {
|
||||||
|
blockCol.cid = INT16_MAX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tGetBlockCol(&br, &blockCol);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cid < blockCol.cid) {
|
||||||
|
const STColumn *tcol = tTSchemaSearchColumn(pTSchema, cid);
|
||||||
|
ASSERT(tcol);
|
||||||
|
SBlockCol none = {
|
||||||
|
.cid = cid,
|
||||||
|
.type = tcol->type,
|
||||||
|
.cflag = tcol->flags,
|
||||||
|
.flag = HAS_NONE,
|
||||||
|
.szOrigin = 0,
|
||||||
|
.szBitmap = 0,
|
||||||
|
.szOffset = 0,
|
||||||
|
.szValue = 0,
|
||||||
|
.offset = 0,
|
||||||
|
};
|
||||||
|
code = tBlockDataDecompressColData(&hdr, &none, &br, bData, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
} else if (cid == blockCol.cid) {
|
||||||
|
// load from file
|
||||||
|
tBufferClear(buffer1);
|
||||||
|
code =
|
||||||
|
tsdbReadFileToBuffer(reader->fd, sttBlk->bInfo.offset + sttBlk->bInfo.szKey + hdr.szBlkCol + blockCol.offset,
|
||||||
|
blockCol.szBitmap + blockCol.szOffset + blockCol.szValue, buffer1, 0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbDecmprColData(reader->config->bufArr[1], blockCol, hdr->cmprAlg, hdr->nRow, colData,
|
// decode the buffer
|
||||||
&reader->config->bufArr[2]);
|
SBufferReader br1 = BUFFER_READER_INITIALIZER(0, buffer1);
|
||||||
|
code = tBlockDataDecompressColData(&hdr, &blockCol, &br1, bData, assist);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
|
@ -319,26 +310,32 @@ int32_t tsdbSttFileReadTombBlock(SSttFileReader *reader, const STombBlk *tombBlk
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
code = tRealloc(&reader->config->bufArr[0], tombBlk->dp->size);
|
SBuffer *buffer0 = reader->buffers + 0;
|
||||||
|
SBuffer *assist = reader->buffers + 1;
|
||||||
|
|
||||||
|
// load
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
code = tsdbReadFileToBuffer(reader->fd, tombBlk->dp->offset, tombBlk->dp->size, buffer0, 0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbReadFile(reader->fd, tombBlk->dp->offset, reader->config->bufArr[0], tombBlk->dp->size, 0);
|
// decode
|
||||||
if (code) TSDB_CHECK_CODE(code, lino, _exit);
|
int32_t size = 0;
|
||||||
|
SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer0);
|
||||||
int64_t size = 0;
|
|
||||||
tTombBlockClear(tombBlock);
|
tTombBlockClear(tombBlock);
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(tombBlock->dataArr); ++i) {
|
tombBlock->numOfRecords = tombBlk->numRec;
|
||||||
code = tsdbDecmprData(reader->config->bufArr[0] + size, tombBlk->size[i], TSDB_DATA_TYPE_BIGINT, tombBlk->cmprAlg,
|
for (int32_t i = 0; i < ARRAY_SIZE(tombBlock->buffers); ++i) {
|
||||||
&reader->config->bufArr[1], sizeof(int64_t) * tombBlk->numRec, &reader->config->bufArr[2]);
|
SCompressInfo cinfo = {
|
||||||
|
.cmprAlg = tombBlk->cmprAlg,
|
||||||
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
|
.originalSize = tombBlk->numRec * sizeof(int64_t),
|
||||||
|
.compressedSize = tombBlk->size[i],
|
||||||
|
};
|
||||||
|
code = tDecompressDataToBuffer(BR_PTR(&br), &cinfo, tombBlock->buffers + i, assist);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
br.offset += tombBlk->size[i];
|
||||||
code = TARRAY2_APPEND_BATCH(&tombBlock->dataArr[i], reader->config->bufArr[1], tombBlk->numRec);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
size += tombBlk->size[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(size == tombBlk->dp->size);
|
ASSERT(br.offset == tombBlk->dp->size);
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
TSDB_ERROR_LOG(TD_VID(reader->config->tsdb->pVnode), lino, code);
|
TSDB_ERROR_LOG(TD_VID(reader->config->tsdb->pVnode), lino, code);
|
||||||
|
@ -350,27 +347,62 @@ int32_t tsdbSttFileReadStatisBlock(SSttFileReader *reader, const SStatisBlk *sta
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
code = tRealloc(&reader->config->bufArr[0], statisBlk->dp->size);
|
SBuffer *buffer0 = reader->buffers + 0;
|
||||||
|
SBuffer *assist = reader->buffers + 1;
|
||||||
|
|
||||||
|
// load data
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
code = tsdbReadFileToBuffer(reader->fd, statisBlk->dp->offset, statisBlk->dp->size, buffer0, 0);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbReadFile(reader->fd, statisBlk->dp->offset, reader->config->bufArr[0], statisBlk->dp->size, 0);
|
// decode data
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
|
|
||||||
int64_t size = 0;
|
|
||||||
tStatisBlockClear(statisBlock);
|
tStatisBlockClear(statisBlock);
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->dataArr); ++i) {
|
statisBlock->numOfPKs = statisBlk->numOfPKs;
|
||||||
code =
|
statisBlock->numOfRecords = statisBlk->numRec;
|
||||||
tsdbDecmprData(reader->config->bufArr[0] + size, statisBlk->size[i], TSDB_DATA_TYPE_BIGINT, statisBlk->cmprAlg,
|
SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer0);
|
||||||
&reader->config->bufArr[1], sizeof(int64_t) * statisBlk->numRec, &reader->config->bufArr[2]);
|
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
SCompressInfo info = {
|
||||||
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
|
.cmprAlg = statisBlk->cmprAlg,
|
||||||
|
.compressedSize = statisBlk->size[i],
|
||||||
|
.originalSize = statisBlk->numRec * sizeof(int64_t),
|
||||||
|
};
|
||||||
|
|
||||||
code = TARRAY2_APPEND_BATCH(statisBlock->dataArr + i, reader->config->bufArr[1], statisBlk->numRec);
|
code = tDecompressDataToBuffer(BR_PTR(&br), &info, &statisBlock->buffers[i], assist);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
br.offset += statisBlk->size[i];
|
||||||
size += statisBlk->size[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(size == statisBlk->dp->size);
|
if (statisBlk->numOfPKs > 0) {
|
||||||
|
SValueColumnCompressInfo firstKeyInfos[TD_MAX_PK_COLS];
|
||||||
|
SValueColumnCompressInfo lastKeyInfos[TD_MAX_PK_COLS];
|
||||||
|
|
||||||
|
// decode compress info
|
||||||
|
for (int32_t i = 0; i < statisBlk->numOfPKs; i++) {
|
||||||
|
code = tValueColumnCompressInfoDecode(&br, &firstKeyInfos[i]);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < statisBlk->numOfPKs; i++) {
|
||||||
|
code = tValueColumnCompressInfoDecode(&br, &lastKeyInfos[i]);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// decode value columns
|
||||||
|
for (int32_t i = 0; i < statisBlk->numOfPKs; i++) {
|
||||||
|
code = tValueColumnDecompress(BR_PTR(&br), firstKeyInfos + i, &statisBlock->firstKeyPKs[i], assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
br.offset += (firstKeyInfos[i].dataCompressedSize + firstKeyInfos[i].offsetCompressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < statisBlk->numOfPKs; i++) {
|
||||||
|
code = tValueColumnDecompress(BR_PTR(&br), &lastKeyInfos[i], &statisBlock->lastKeyPKs[i], assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
br.offset += (lastKeyInfos[i].dataCompressedSize + lastKeyInfos[i].offsetCompressedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(br.offset == buffer0->size);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
|
@ -402,11 +434,12 @@ struct SSttFileWriter {
|
||||||
// helper data
|
// helper data
|
||||||
SSkmInfo skmTb[1];
|
SSkmInfo skmTb[1];
|
||||||
SSkmInfo skmRow[1];
|
SSkmInfo skmRow[1];
|
||||||
uint8_t *bufArr[5];
|
SBuffer local[10];
|
||||||
|
SBuffer *buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int32_t tsdbFileDoWriteSttBlockData(STsdbFD *fd, SBlockData *blockData, int8_t cmprAlg, int64_t *fileSize,
|
static int32_t tsdbFileDoWriteSttBlockData(STsdbFD *fd, SBlockData *blockData, int8_t cmprAlg, int64_t *fileSize,
|
||||||
TSttBlkArray *sttBlkArray, uint8_t **bufArr, SVersionRange *range) {
|
TSttBlkArray *sttBlkArray, SBuffer *buffers, SVersionRange *range) {
|
||||||
if (blockData->nRow == 0) return 0;
|
if (blockData->nRow == 0) return 0;
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -431,19 +464,17 @@ static int32_t tsdbFileDoWriteSttBlockData(STsdbFD *fd, SBlockData *blockData, i
|
||||||
|
|
||||||
tsdbWriterUpdVerRange(range, sttBlk->minVer, sttBlk->maxVer);
|
tsdbWriterUpdVerRange(range, sttBlk->minVer, sttBlk->maxVer);
|
||||||
|
|
||||||
int32_t sizeArr[5] = {0};
|
code = tBlockDataCompress(blockData, cmprAlg, buffers, buffers + 4);
|
||||||
code = tCmprBlockData(blockData, cmprAlg, NULL, NULL, bufArr, sizeArr);
|
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
|
|
||||||
sttBlk->bInfo.offset = *fileSize;
|
sttBlk->bInfo.offset = *fileSize;
|
||||||
sttBlk->bInfo.szKey = sizeArr[2] + sizeArr[3];
|
sttBlk->bInfo.szKey = buffers[0].size + buffers[1].size;
|
||||||
sttBlk->bInfo.szBlock = sizeArr[0] + sizeArr[1] + sttBlk->bInfo.szKey;
|
sttBlk->bInfo.szBlock = buffers[2].size + buffers[3].size + sttBlk->bInfo.szKey;
|
||||||
|
|
||||||
for (int32_t i = 3; i >= 0; i--) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (sizeArr[i]) {
|
if (buffers[i].size) {
|
||||||
code = tsdbWriteFile(fd, *fileSize, bufArr[i], sizeArr[i]);
|
code = tsdbWriteFile(fd, *fileSize, buffers[i].data, buffers[i].size);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
*fileSize += sizeArr[i];
|
*fileSize += buffers[i].size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,7 +493,7 @@ static int32_t tsdbSttFileDoWriteBlockData(SSttFileWriter *writer) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
code = tsdbFileDoWriteSttBlockData(writer->fd, writer->blockData, writer->config->cmprAlg, &writer->file->size,
|
code = tsdbFileDoWriteSttBlockData(writer->fd, writer->blockData, writer->config->cmprAlg, &writer->file->size,
|
||||||
writer->sttBlkArray, writer->config->bufArr, &writer->ctx->range);
|
writer->sttBlkArray, writer->buffers, &writer->ctx->range);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -473,45 +504,86 @@ _exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbSttFileDoWriteStatisBlock(SSttFileWriter *writer) {
|
static int32_t tsdbSttFileDoWriteStatisBlock(SSttFileWriter *writer) {
|
||||||
if (STATIS_BLOCK_SIZE(writer->staticBlock) == 0) return 0;
|
if (writer->staticBlock->numOfRecords == 0) return 0;
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
SStatisBlk statisBlk[1] = {{
|
SBuffer *buffer0 = writer->buffers + 0;
|
||||||
.dp[0] =
|
SBuffer *buffer1 = writer->buffers + 1;
|
||||||
{
|
SBuffer *assist = writer->buffers + 2;
|
||||||
.offset = writer->file->size,
|
|
||||||
.size = 0,
|
|
||||||
},
|
|
||||||
.minTbid =
|
|
||||||
{
|
|
||||||
.suid = TARRAY2_FIRST(writer->staticBlock->suid),
|
|
||||||
.uid = TARRAY2_FIRST(writer->staticBlock->uid),
|
|
||||||
},
|
|
||||||
.maxTbid =
|
|
||||||
{
|
|
||||||
.suid = TARRAY2_LAST(writer->staticBlock->suid),
|
|
||||||
.uid = TARRAY2_LAST(writer->staticBlock->uid),
|
|
||||||
},
|
|
||||||
.numRec = STATIS_BLOCK_SIZE(writer->staticBlock),
|
|
||||||
.cmprAlg = writer->config->cmprAlg,
|
|
||||||
}};
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < STATIS_RECORD_NUM_ELEM; i++) {
|
STbStatisRecord record;
|
||||||
code = tsdbCmprData((uint8_t *)TARRAY2_DATA(writer->staticBlock->dataArr + i),
|
STbStatisBlock *statisBlock = writer->staticBlock;
|
||||||
TARRAY2_DATA_LEN(&writer->staticBlock->dataArr[i]), TSDB_DATA_TYPE_BIGINT, statisBlk->cmprAlg,
|
SStatisBlk statisBlk = {0};
|
||||||
&writer->config->bufArr[0], 0, &statisBlk->size[i], &writer->config->bufArr[1]);
|
|
||||||
|
statisBlk.dp->offset = writer->file->size;
|
||||||
|
statisBlk.dp->size = 0;
|
||||||
|
statisBlk.numRec = statisBlock->numOfRecords;
|
||||||
|
statisBlk.cmprAlg = writer->config->cmprAlg;
|
||||||
|
statisBlk.numOfPKs = statisBlock->numOfPKs;
|
||||||
|
|
||||||
|
tStatisBlockGet(statisBlock, 0, &record);
|
||||||
|
statisBlk.minTbid.suid = record.suid;
|
||||||
|
statisBlk.minTbid.uid = record.uid;
|
||||||
|
|
||||||
|
tStatisBlockGet(statisBlock, statisBlock->numOfRecords - 1, &record);
|
||||||
|
statisBlk.maxTbid.suid = record.suid;
|
||||||
|
statisBlk.maxTbid.uid = record.uid;
|
||||||
|
|
||||||
|
// compress each column
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(statisBlk.size); i++) {
|
||||||
|
SCompressInfo info = {
|
||||||
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
|
.cmprAlg = statisBlk.cmprAlg,
|
||||||
|
.originalSize = statisBlock->buffers[i].size,
|
||||||
|
};
|
||||||
|
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
code = tCompressDataToBuffer(statisBlock->buffers[i].data, &info, buffer0, assist);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbWriteFile(writer->fd, writer->file->size, writer->config->bufArr[0], statisBlk->size[i]);
|
code = tsdbWriteFile(writer->fd, writer->file->size, buffer0->data, info.compressedSize);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
statisBlk->dp->size += statisBlk->size[i];
|
statisBlk.size[i] = info.compressedSize;
|
||||||
writer->file->size += statisBlk->size[i];
|
statisBlk.dp->size += info.compressedSize;
|
||||||
|
writer->file->size += info.compressedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = TARRAY2_APPEND_PTR(writer->statisBlkArray, statisBlk);
|
// compress primary keys
|
||||||
|
if (statisBlk.numOfPKs > 0) {
|
||||||
|
SValueColumnCompressInfo compressInfo = {.cmprAlg = statisBlk.cmprAlg};
|
||||||
|
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
tBufferClear(buffer0);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < statisBlk.numOfPKs; i++) {
|
||||||
|
code = tValueColumnCompress(&statisBlock->firstKeyPKs[i], &compressInfo, buffer1, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
code = tValueColumnCompressInfoEncode(&compressInfo, buffer0);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < statisBlk.numOfPKs; i++) {
|
||||||
|
code = tValueColumnCompress(&statisBlock->lastKeyPKs[i], &compressInfo, buffer1, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
code = tValueColumnCompressInfoEncode(&compressInfo, buffer0);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tsdbWriteFile(writer->fd, writer->file->size, buffer0->data, buffer0->size);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
writer->file->size += buffer0->size;
|
||||||
|
statisBlk.dp->size += buffer0->size;
|
||||||
|
|
||||||
|
code = tsdbWriteFile(writer->fd, writer->file->size, buffer1->data, buffer1->size);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
writer->file->size += buffer1->size;
|
||||||
|
statisBlk.dp->size += buffer1->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = TARRAY2_APPEND_PTR(writer->statisBlkArray, &statisBlk);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
tStatisBlockClear(writer->staticBlock);
|
tStatisBlockClear(writer->staticBlock);
|
||||||
|
@ -530,7 +602,7 @@ static int32_t tsdbSttFileDoWriteTombBlock(SSttFileWriter *writer) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
code = tsdbFileWriteTombBlock(writer->fd, writer->tombBlock, writer->config->cmprAlg, &writer->file->size,
|
code = tsdbFileWriteTombBlock(writer->fd, writer->tombBlock, writer->config->cmprAlg, &writer->file->size,
|
||||||
writer->tombBlkArray, writer->config->bufArr, &writer->ctx->range);
|
writer->tombBlkArray, writer->buffers, &writer->ctx->range);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -621,7 +693,10 @@ static int32_t tsdbSttFWriterDoOpen(SSttFileWriter *writer) {
|
||||||
// set
|
// set
|
||||||
if (!writer->config->skmTb) writer->config->skmTb = writer->skmTb;
|
if (!writer->config->skmTb) writer->config->skmTb = writer->skmTb;
|
||||||
if (!writer->config->skmRow) writer->config->skmRow = writer->skmRow;
|
if (!writer->config->skmRow) writer->config->skmRow = writer->skmRow;
|
||||||
if (!writer->config->bufArr) writer->config->bufArr = writer->bufArr;
|
writer->buffers = writer->config->buffers;
|
||||||
|
if (writer->buffers == NULL) {
|
||||||
|
writer->buffers = writer->local;
|
||||||
|
}
|
||||||
|
|
||||||
writer->file[0] = (STFile){
|
writer->file[0] = (STFile){
|
||||||
.type = TSDB_FTYPE_STT,
|
.type = TSDB_FTYPE_STT,
|
||||||
|
@ -665,8 +740,8 @@ _exit:
|
||||||
static void tsdbSttFWriterDoClose(SSttFileWriter *writer) {
|
static void tsdbSttFWriterDoClose(SSttFileWriter *writer) {
|
||||||
ASSERT(writer->fd == NULL);
|
ASSERT(writer->fd == NULL);
|
||||||
|
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(writer->bufArr); ++i) {
|
for (int32_t i = 0; i < ARRAY_SIZE(writer->local); ++i) {
|
||||||
tFree(writer->bufArr[i]);
|
tBufferDestroy(writer->local + i);
|
||||||
}
|
}
|
||||||
tDestroyTSchema(writer->skmRow->pTSchema);
|
tDestroyTSchema(writer->skmRow->pTSchema);
|
||||||
tDestroyTSchema(writer->skmTb->pTSchema);
|
tDestroyTSchema(writer->skmTb->pTSchema);
|
||||||
|
@ -796,40 +871,24 @@ int32_t tsdbSttFileWriteRow(SSttFileWriter *writer, SRowInfo *row) {
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBKEY key[1];
|
|
||||||
if (row->row.type == TSDBROW_ROW_FMT) {
|
|
||||||
key->ts = row->row.pTSRow->ts;
|
|
||||||
key->version = row->row.version;
|
|
||||||
} else {
|
|
||||||
key->ts = row->row.pBlockData->aTSKEY[row->row.iRow];
|
|
||||||
key->version = row->row.pBlockData->aVersion[row->row.iRow];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (writer->ctx->tbid->uid != row->uid) {
|
if (writer->ctx->tbid->uid != row->uid) {
|
||||||
writer->ctx->tbid->suid = row->suid;
|
writer->ctx->tbid->suid = row->suid;
|
||||||
writer->ctx->tbid->uid = row->uid;
|
writer->ctx->tbid->uid = row->uid;
|
||||||
|
}
|
||||||
|
|
||||||
if (STATIS_BLOCK_SIZE(writer->staticBlock) >= writer->config->maxRow) {
|
STsdbRowKey key;
|
||||||
|
tsdbRowGetKey(&row->row, &key);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
code = tStatisBlockPut(writer->staticBlock, row, writer->config->maxRow);
|
||||||
|
if (code == TSDB_CODE_INVALID_PARA) {
|
||||||
code = tsdbSttFileDoWriteStatisBlock(writer);
|
code = tsdbSttFileDoWriteStatisBlock(writer);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
continue;
|
||||||
|
|
||||||
STbStatisRecord record = {
|
|
||||||
.suid = row->suid,
|
|
||||||
.uid = row->uid,
|
|
||||||
.firstKey = key->ts,
|
|
||||||
.lastKey = key->ts,
|
|
||||||
.count = 1,
|
|
||||||
};
|
|
||||||
code = tStatisBlockPut(writer->staticBlock, &record);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
} else {
|
} else {
|
||||||
ASSERT(key->ts >= TARRAY2_LAST(writer->staticBlock->lastKey));
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
if (key->ts > TARRAY2_LAST(writer->staticBlock->lastKey)) {
|
|
||||||
TARRAY2_LAST(writer->staticBlock->count)++;
|
|
||||||
TARRAY2_LAST(writer->staticBlock->lastKey) = key->ts;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row->row.type == TSDBROW_ROW_FMT) {
|
if (row->row.type == TSDBROW_ROW_FMT) {
|
||||||
|
@ -839,12 +898,13 @@ int32_t tsdbSttFileWriteRow(SSttFileWriter *writer, SRowInfo *row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// row to col conversion
|
// row to col conversion
|
||||||
if (key->version <= writer->config->compactVersion //
|
if (key.version <= writer->config->compactVersion //
|
||||||
&& writer->blockData->nRow > 0 //
|
&& writer->blockData->nRow > 0 //
|
||||||
&& writer->blockData->aTSKEY[writer->blockData->nRow - 1] == key->ts //
|
|
||||||
&& (writer->blockData->uid //
|
&& (writer->blockData->uid //
|
||||||
? writer->blockData->uid //
|
? writer->blockData->uid //
|
||||||
: writer->blockData->aUid[writer->blockData->nRow - 1]) == row->uid //
|
: writer->blockData->aUid[writer->blockData->nRow - 1]) == row->uid //
|
||||||
|
&& tsdbRowCompareWithoutVersion(&row->row,
|
||||||
|
&tsdbRowFromBlockData(writer->blockData, writer->blockData->nRow - 1)) == 0 //
|
||||||
) {
|
) {
|
||||||
code = tBlockDataUpdateRow(writer->blockData, &row->row, writer->config->skmRow->pTSchema);
|
code = tBlockDataUpdateRow(writer->blockData, &row->row, writer->config->skmRow->pTSchema);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct SSttFileReaderConfig {
|
||||||
STsdb *tsdb;
|
STsdb *tsdb;
|
||||||
int32_t szPage;
|
int32_t szPage;
|
||||||
STFile file[1];
|
STFile file[1];
|
||||||
uint8_t **bufArr;
|
SBuffer *buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
// SSttFileWriter ==========================================
|
// SSttFileWriter ==========================================
|
||||||
|
@ -86,7 +86,7 @@ struct SSttFileWriterConfig {
|
||||||
int32_t level;
|
int32_t level;
|
||||||
SSkmInfo *skmTb;
|
SSkmInfo *skmTb;
|
||||||
SSkmInfo *skmRow;
|
SSkmInfo *skmRow;
|
||||||
uint8_t **bufArr;
|
SBuffer *buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -36,7 +36,7 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
||||||
int32_t maxRow;
|
int32_t maxRow;
|
||||||
int8_t cmprAlg;
|
int8_t cmprAlg;
|
||||||
int32_t szPage;
|
int32_t szPage;
|
||||||
uint8_t *bufArr[8];
|
SBuffer buffers[10];
|
||||||
// reader
|
// reader
|
||||||
SArray *aBlockIdx;
|
SArray *aBlockIdx;
|
||||||
SMapData mDataBlk[1];
|
SMapData mDataBlk[1];
|
||||||
|
@ -97,10 +97,24 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
||||||
SBrinRecord record = {
|
SBrinRecord record = {
|
||||||
.suid = pBlockIdx->suid,
|
.suid = pBlockIdx->suid,
|
||||||
.uid = pBlockIdx->uid,
|
.uid = pBlockIdx->uid,
|
||||||
.firstKey = dataBlk->minKey.ts,
|
.firstKey =
|
||||||
.firstKeyVer = dataBlk->minKey.version,
|
(STsdbRowKey){
|
||||||
.lastKey = dataBlk->maxKey.ts,
|
.key =
|
||||||
.lastKeyVer = dataBlk->maxKey.version,
|
(SRowKey){
|
||||||
|
.ts = dataBlk->minKey.ts,
|
||||||
|
.numOfPKs = 0,
|
||||||
|
},
|
||||||
|
.version = dataBlk->minKey.version,
|
||||||
|
},
|
||||||
|
.lastKey =
|
||||||
|
(STsdbRowKey){
|
||||||
|
.key =
|
||||||
|
(SRowKey){
|
||||||
|
.ts = dataBlk->maxKey.ts,
|
||||||
|
.numOfPKs = 0,
|
||||||
|
},
|
||||||
|
.version = dataBlk->maxKey.version,
|
||||||
|
},
|
||||||
.minVer = dataBlk->minVer,
|
.minVer = dataBlk->minVer,
|
||||||
.maxVer = dataBlk->maxVer,
|
.maxVer = dataBlk->maxVer,
|
||||||
.blockOffset = dataBlk->aSubBlock->offset,
|
.blockOffset = dataBlk->aSubBlock->offset,
|
||||||
|
@ -119,19 +133,19 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
||||||
code = tBrinBlockPut(ctx->brinBlock, &record);
|
code = tBrinBlockPut(ctx->brinBlock, &record);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
if (BRIN_BLOCK_SIZE(ctx->brinBlock) >= ctx->maxRow) {
|
if (ctx->brinBlock->numOfRecords >= ctx->maxRow) {
|
||||||
SVersionRange range = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
SVersionRange range = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||||
code = tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
code = tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
||||||
ctx->brinBlkArray, ctx->bufArr, &range);
|
ctx->brinBlkArray, ctx->buffers, &range);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BRIN_BLOCK_SIZE(ctx->brinBlock) > 0) {
|
if (ctx->brinBlock->numOfRecords > 0) {
|
||||||
SVersionRange range = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
SVersionRange range = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||||
code = tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
code = tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
||||||
ctx->brinBlkArray, ctx->bufArr, &range);
|
ctx->brinBlkArray, ctx->buffers, &range);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +171,8 @@ _exit:
|
||||||
tBlockDataDestroy(ctx->blockData);
|
tBlockDataDestroy(ctx->blockData);
|
||||||
tMapDataClear(ctx->mDataBlk);
|
tMapDataClear(ctx->mDataBlk);
|
||||||
taosArrayDestroy(ctx->aBlockIdx);
|
taosArrayDestroy(ctx->aBlockIdx);
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(ctx->bufArr); ++i) {
|
for (int32_t i = 0; i < ARRAY_SIZE(ctx->buffers); ++i) {
|
||||||
tFree(ctx->bufArr[i]);
|
tBufferDestroy(ctx->buffers + i);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +453,7 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
|
||||||
int32_t maxRow;
|
int32_t maxRow;
|
||||||
int64_t minKey;
|
int64_t minKey;
|
||||||
int64_t maxKey;
|
int64_t maxKey;
|
||||||
uint8_t *bufArr[8];
|
SBuffer buffers[10];
|
||||||
// reader
|
// reader
|
||||||
SArray *aDelData;
|
SArray *aDelData;
|
||||||
// writer
|
// writer
|
||||||
|
@ -488,7 +502,7 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
|
||||||
}
|
}
|
||||||
SVersionRange tombRange = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
SVersionRange tombRange = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||||
code = tsdbFileWriteTombBlock(ctx->fd, ctx->tombBlock, ctx->cmprAlg, &ctx->fobj->f->size, ctx->tombBlkArray,
|
code = tsdbFileWriteTombBlock(ctx->fd, ctx->tombBlock, ctx->cmprAlg, &ctx->fobj->f->size, ctx->tombBlkArray,
|
||||||
ctx->bufArr, &tombRange);
|
ctx->buffers, &tombRange);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -501,7 +515,7 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
|
||||||
}
|
}
|
||||||
SVersionRange tombRange = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
SVersionRange tombRange = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||||
code = tsdbFileWriteTombBlock(ctx->fd, ctx->tombBlock, ctx->cmprAlg, &ctx->fobj->f->size, ctx->tombBlkArray,
|
code = tsdbFileWriteTombBlock(ctx->fd, ctx->tombBlock, ctx->cmprAlg, &ctx->fobj->f->size, ctx->tombBlkArray,
|
||||||
ctx->bufArr, &tombRange);
|
ctx->buffers, &tombRange);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,8 +544,8 @@ _exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(ctx->bufArr); i++) {
|
for (int32_t i = 0; i < ARRAY_SIZE(ctx->buffers); i++) {
|
||||||
tFree(ctx->bufArr[i]);
|
tBufferDestroy(ctx->buffers + i);
|
||||||
}
|
}
|
||||||
TARRAY2_DESTROY(ctx->tombBlkArray, NULL);
|
TARRAY2_DESTROY(ctx->tombBlkArray, NULL);
|
||||||
tTombBlockDestroy(ctx->tombBlock);
|
tTombBlockDestroy(ctx->tombBlock);
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "tdataformat.h"
|
#include "tdataformat.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
|
|
||||||
|
static int32_t tBlockDataCompressKeyPart(SBlockData *bData, SDiskDataHdr *hdr, SBuffer *buffer, SBuffer *assist);
|
||||||
|
|
||||||
// SMapData =======================================================================
|
// SMapData =======================================================================
|
||||||
void tMapDataReset(SMapData *pMapData) {
|
void tMapDataReset(SMapData *pMapData) {
|
||||||
pMapData->nItem = 0;
|
pMapData->nItem = 0;
|
||||||
|
@ -380,47 +382,44 @@ int32_t tGetSttBlk(uint8_t *p, void *ph) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBlockCol ======================================================
|
// SBlockCol ======================================================
|
||||||
int32_t tPutBlockCol(uint8_t *p, void *ph) {
|
int32_t tPutBlockCol(SBuffer *buffer, const SBlockCol *pBlockCol) {
|
||||||
int32_t n = 0;
|
int32_t code;
|
||||||
SBlockCol *pBlockCol = (SBlockCol *)ph;
|
|
||||||
|
|
||||||
ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE));
|
ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE));
|
||||||
|
|
||||||
n += tPutI16v(p ? p + n : p, pBlockCol->cid);
|
if ((code = tBufferPutI16v(buffer, pBlockCol->cid))) return code;
|
||||||
n += tPutI8(p ? p + n : p, pBlockCol->type);
|
if ((code = tBufferPutI8(buffer, pBlockCol->type))) return code;
|
||||||
n += tPutI8(p ? p + n : p, pBlockCol->smaOn);
|
if ((code = tBufferPutI8(buffer, pBlockCol->cflag))) return code;
|
||||||
n += tPutI8(p ? p + n : p, pBlockCol->flag);
|
if ((code = tBufferPutI8(buffer, pBlockCol->flag))) return code;
|
||||||
n += tPutI32v(p ? p + n : p, pBlockCol->szOrigin);
|
if ((code = tBufferPutI32v(buffer, pBlockCol->szOrigin))) return code;
|
||||||
|
|
||||||
if (pBlockCol->flag != HAS_NULL) {
|
if (pBlockCol->flag != HAS_NULL) {
|
||||||
if (pBlockCol->flag != HAS_VALUE) {
|
if (pBlockCol->flag != HAS_VALUE) {
|
||||||
n += tPutI32v(p ? p + n : p, pBlockCol->szBitmap);
|
if ((code = tBufferPutI32v(buffer, pBlockCol->szBitmap))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pBlockCol->type)) {
|
if (IS_VAR_DATA_TYPE(pBlockCol->type)) {
|
||||||
n += tPutI32v(p ? p + n : p, pBlockCol->szOffset);
|
if ((code = tBufferPutI32v(buffer, pBlockCol->szOffset))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockCol->flag != (HAS_NULL | HAS_NONE)) {
|
if (pBlockCol->flag != (HAS_NULL | HAS_NONE)) {
|
||||||
n += tPutI32v(p ? p + n : p, pBlockCol->szValue);
|
if ((code = tBufferPutI32v(buffer, pBlockCol->szValue))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
n += tPutI32v(p ? p + n : p, pBlockCol->offset);
|
if ((code = tBufferPutI32v(buffer, pBlockCol->offset))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
return 0;
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tGetBlockCol(uint8_t *p, void *ph) {
|
int32_t tGetBlockCol(SBufferReader *br, SBlockCol *pBlockCol) {
|
||||||
int32_t n = 0;
|
int32_t code;
|
||||||
SBlockCol *pBlockCol = (SBlockCol *)ph;
|
|
||||||
|
|
||||||
n += tGetI16v(p + n, &pBlockCol->cid);
|
if ((code = tBufferGetI16v(br, &pBlockCol->cid))) return code;
|
||||||
n += tGetI8(p + n, &pBlockCol->type);
|
if ((code = tBufferGetI8(br, &pBlockCol->type))) return code;
|
||||||
n += tGetI8(p + n, &pBlockCol->smaOn);
|
if ((code = tBufferGetI8(br, &pBlockCol->cflag))) return code;
|
||||||
n += tGetI8(p + n, &pBlockCol->flag);
|
if ((code = tBufferGetI8(br, &pBlockCol->flag))) return code;
|
||||||
n += tGetI32v(p + n, &pBlockCol->szOrigin);
|
if ((code = tBufferGetI32v(br, &pBlockCol->szOrigin))) return code;
|
||||||
|
|
||||||
ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE));
|
ASSERT(pBlockCol->flag && (pBlockCol->flag != HAS_NONE));
|
||||||
|
|
||||||
|
@ -431,21 +430,21 @@ int32_t tGetBlockCol(uint8_t *p, void *ph) {
|
||||||
|
|
||||||
if (pBlockCol->flag != HAS_NULL) {
|
if (pBlockCol->flag != HAS_NULL) {
|
||||||
if (pBlockCol->flag != HAS_VALUE) {
|
if (pBlockCol->flag != HAS_VALUE) {
|
||||||
n += tGetI32v(p + n, &pBlockCol->szBitmap);
|
if ((code = tBufferGetI32v(br, &pBlockCol->szBitmap))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pBlockCol->type)) {
|
if (IS_VAR_DATA_TYPE(pBlockCol->type)) {
|
||||||
n += tGetI32v(p + n, &pBlockCol->szOffset);
|
if ((code = tBufferGetI32v(br, &pBlockCol->szOffset))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockCol->flag != (HAS_NULL | HAS_NONE)) {
|
if (pBlockCol->flag != (HAS_NULL | HAS_NONE)) {
|
||||||
n += tGetI32v(p + n, &pBlockCol->szValue);
|
if ((code = tBufferGetI32v(br, &pBlockCol->szValue))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
n += tGetI32v(p + n, &pBlockCol->offset);
|
if ((code = tBufferGetI32v(br, &pBlockCol->offset))) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BUILD_NO_CALL
|
#ifdef BUILD_NO_CALL
|
||||||
|
@ -589,9 +588,7 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
|
||||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal);
|
tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal);
|
||||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||||
SColData *pColData;
|
SColData *pColData = tBlockDataGetColData(pRow->pBlockData, pTColumn->colId);
|
||||||
|
|
||||||
tBlockDataGetColData(pRow->pBlockData, pTColumn->colId, &pColData);
|
|
||||||
|
|
||||||
if (pColData) {
|
if (pColData) {
|
||||||
tColDataGetValue(pColData, pRow->iRow, pColVal);
|
tColDataGetValue(pColData, pRow->iRow, pColVal);
|
||||||
|
@ -603,8 +600,58 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbRowCmprFn(const void *p1, const void *p2) {
|
void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key) {
|
||||||
return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2));
|
if (row->type == TSDBROW_ROW_FMT) {
|
||||||
|
key->version = row->version;
|
||||||
|
tRowGetKey(row->pTSRow, &key->key);
|
||||||
|
} else {
|
||||||
|
key->version = row->pBlockData->aVersion[row->iRow];
|
||||||
|
key->key.ts = row->pBlockData->aTSKEY[row->iRow];
|
||||||
|
key->key.numOfPKs = 0;
|
||||||
|
for (int32_t i = 0; i < row->pBlockData->nColData; i++) {
|
||||||
|
SColData *pColData = &row->pBlockData->aColData[i];
|
||||||
|
if (pColData->cflag & COL_IS_KEY) {
|
||||||
|
SColVal cv;
|
||||||
|
tColDataGetValue(pColData, row->iRow, &cv);
|
||||||
|
ASSERT(COL_VAL_IS_VALUE(&cv));
|
||||||
|
key->key.pks[key->key.numOfPKs] = cv.value;
|
||||||
|
key->key.numOfPKs++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2) {
|
||||||
|
int32_t c = tRowKeyCompare(&key1->key, &key2->key);
|
||||||
|
|
||||||
|
if (c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key1->version < key2->version) {
|
||||||
|
return -1;
|
||||||
|
} else if (key1->version > key2->version) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbRowCompare(const void *p1, const void *p2) {
|
||||||
|
STsdbRowKey key1, key2;
|
||||||
|
|
||||||
|
tsdbRowGetKey((TSDBROW *)p1, &key1);
|
||||||
|
tsdbRowGetKey((TSDBROW *)p2, &key2);
|
||||||
|
return tsdbRowKeyCmpr(&key1, &key2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbRowCompareWithoutVersion(const void *p1, const void *p2) {
|
||||||
|
STsdbRowKey key1, key2;
|
||||||
|
|
||||||
|
tsdbRowGetKey((TSDBROW *)p1, &key1);
|
||||||
|
tsdbRowGetKey((TSDBROW *)p2, &key2);
|
||||||
|
return tRowKeyCompare(&key1.key, &key2.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// STSDBRowIter ======================================================
|
// STSDBRowIter ======================================================
|
||||||
|
@ -636,8 +683,9 @@ SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
|
||||||
return tRowIterNext(pIter->pIter);
|
return tRowIterNext(pIter->pIter);
|
||||||
} else if (pIter->pRow->type == TSDBROW_COL_FMT) {
|
} else if (pIter->pRow->type == TSDBROW_COL_FMT) {
|
||||||
if (pIter->iColData == 0) {
|
if (pIter->iColData == 0) {
|
||||||
pIter->cv = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP,
|
pIter->cv = COL_VAL_VALUE(
|
||||||
(SValue){.val = pIter->pRow->pBlockData->aTSKEY[pIter->pRow->iRow]});
|
PRIMARYKEY_TIMESTAMP_COL_ID,
|
||||||
|
((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP, .val = pIter->pRow->pBlockData->aTSKEY[pIter->pRow->iRow]}));
|
||||||
++pIter->iColData;
|
++pIter->iColData;
|
||||||
return &pIter->cv;
|
return &pIter->cv;
|
||||||
}
|
}
|
||||||
|
@ -674,7 +722,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
|
|
||||||
ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
|
ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||||
|
|
||||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = key.ts});
|
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = key.ts}));
|
||||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return code;
|
return code;
|
||||||
|
@ -694,7 +742,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
||||||
if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
uint8_t *pVal = pColVal->value.pData;
|
uint8_t *pVal = pColVal->value.pData;
|
||||||
|
|
||||||
pColVal->value.pData = NULL;
|
pColVal->value.pData = NULL;
|
||||||
|
@ -738,7 +786,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
|
|
||||||
if (key.version > pMerger->version) {
|
if (key.version > pMerger->version) {
|
||||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
if (!COL_VAL_IS_NULL(pColVal)) {
|
if (!COL_VAL_IS_NULL(pColVal)) {
|
||||||
code = tRealloc(&pTColVal->value.pData, pColVal->value.nData);
|
code = tRealloc(&pTColVal->value.pData, pColVal->value.nData);
|
||||||
|
@ -760,7 +808,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
} else if (key.version < pMerger->version) {
|
} else if (key.version < pMerger->version) {
|
||||||
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
||||||
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
||||||
if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->value.type)) {
|
||||||
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
|
|
||||||
|
@ -796,7 +844,7 @@ int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pSchema) {
|
||||||
void tsdbRowMergerClear(SRowMerger *pMerger) {
|
void tsdbRowMergerClear(SRowMerger *pMerger) {
|
||||||
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
||||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
if (IS_VAR_DATA_TYPE(pTColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pTColVal->value.type)) {
|
||||||
tFree(pTColVal->value.pData);
|
tFree(pTColVal->value.pData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -808,7 +856,7 @@ void tsdbRowMergerCleanup(SRowMerger *pMerger) {
|
||||||
int32_t numOfCols = taosArrayGetSize(pMerger->pArray);
|
int32_t numOfCols = taosArrayGetSize(pMerger->pArray);
|
||||||
for (int32_t iCol = 1; iCol < numOfCols; iCol++) {
|
for (int32_t iCol = 1; iCol < numOfCols; iCol++) {
|
||||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
if (IS_VAR_DATA_TYPE(pTColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pTColVal->value.type)) {
|
||||||
tFree(pTColVal->value.pData);
|
tFree(pTColVal->value.pData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1140,8 +1188,7 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tColDataInit(&pBlockData->aColData[iCid], pTColumn->colId, pTColumn->type,
|
tColDataInit(&pBlockData->aColData[iCid], pTColumn->colId, pTColumn->type, pTColumn->flags);
|
||||||
(pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
|
||||||
|
|
||||||
iColumn++;
|
iColumn++;
|
||||||
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
||||||
|
@ -1152,8 +1199,7 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
|
||||||
|
|
||||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||||
STColumn *pTColumn = &pTSchema->columns[iColData + 1];
|
STColumn *pTColumn = &pTSchema->columns[iColData + 1];
|
||||||
tColDataInit(&pBlockData->aColData[iColData], pTColumn->colId, pTColumn->type,
|
tColDataInit(&pBlockData->aColData[iColData], pTColumn->colId, pTColumn->type, pTColumn->flags);
|
||||||
(pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,6 +1227,24 @@ void tBlockDataClear(SBlockData *pBlockData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tBlockDataAddColData(SBlockData *pBlockData, int16_t cid, int8_t type, int8_t cflag, SColData **ppColData) {
|
||||||
|
ASSERT(pBlockData->nColData == 0 || pBlockData->aColData[pBlockData->nColData - 1].cid < cid);
|
||||||
|
|
||||||
|
SColData *newColData = taosMemoryRealloc(pBlockData->aColData, sizeof(SColData) * (pBlockData->nColData + 1));
|
||||||
|
if (newColData == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBlockData->aColData = newColData;
|
||||||
|
pBlockData->nColData++;
|
||||||
|
|
||||||
|
*ppColData = &pBlockData->aColData[pBlockData->nColData - 1];
|
||||||
|
memset(*ppColData, 0, sizeof(SColData));
|
||||||
|
tColDataInit(*ppColData, cid, type, cflag);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* flag > 0: forward update
|
/* flag > 0: forward update
|
||||||
* flag == 0: insert
|
* flag == 0: insert
|
||||||
* flag < 0: backward update
|
* flag < 0: backward update
|
||||||
|
@ -1303,7 +1367,7 @@ int32_t tBlockDataUpsertRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData) {
|
SColData *tBlockDataGetColData(SBlockData *pBlockData, int16_t cid) {
|
||||||
ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID);
|
ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||||
int32_t lidx = 0;
|
int32_t lidx = 0;
|
||||||
int32_t ridx = pBlockData->nColData - 1;
|
int32_t ridx = pBlockData->nColData - 1;
|
||||||
|
@ -1314,8 +1378,7 @@ void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColD
|
||||||
int32_t c = (pColData->cid == cid) ? 0 : ((pColData->cid > cid) ? 1 : -1);
|
int32_t c = (pColData->cid == cid) ? 0 : ((pColData->cid > cid) ? 1 : -1);
|
||||||
|
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
*ppColData = pColData;
|
return pColData;
|
||||||
return;
|
|
||||||
} else if (c < 0) {
|
} else if (c < 0) {
|
||||||
lidx = midx + 1;
|
lidx = midx + 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1323,170 +1386,112 @@ void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppColData = NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[],
|
/* buffers[0]: SDiskDataHdr
|
||||||
int32_t aBufN[]) {
|
* buffers[1]: key part: uid + version + ts + primary keys
|
||||||
|
* buffers[2]: SBlockCol part
|
||||||
|
* buffers[3]: regular column part
|
||||||
|
*/
|
||||||
|
int32_t tBlockDataCompress(SBlockData *bData, int8_t cmprAlg, SBuffer *buffers, SBuffer *assist) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
|
|
||||||
SDiskDataHdr hdr = {.delimiter = TSDB_FILE_DLMT,
|
SDiskDataHdr hdr = {
|
||||||
.fmtVer = 0,
|
.delimiter = TSDB_FILE_DLMT,
|
||||||
.suid = pBlockData->suid,
|
.fmtVer = 1,
|
||||||
.uid = pBlockData->uid,
|
.suid = bData->suid,
|
||||||
.nRow = pBlockData->nRow,
|
.uid = bData->uid,
|
||||||
.cmprAlg = cmprAlg};
|
.szUid = 0, // filled by compress key
|
||||||
|
.szVer = 0, // filled by compress key
|
||||||
|
.szKey = 0, // filled by compress key
|
||||||
|
.szBlkCol = 0, // filled by this func
|
||||||
|
.nRow = bData->nRow,
|
||||||
|
.cmprAlg = cmprAlg,
|
||||||
|
.numOfPKs = 0, // filled by compress key
|
||||||
|
};
|
||||||
|
|
||||||
// encode =================
|
// Key part
|
||||||
// columns AND SBlockCol
|
tBufferClear(&buffers[1]);
|
||||||
aBufN[0] = 0;
|
code = tBlockDataCompressKeyPart(bData, &hdr, &buffers[1], assist);
|
||||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData);
|
|
||||||
|
|
||||||
ASSERT(pColData->flag);
|
// Regulart column part
|
||||||
|
tBufferClear(&buffers[2]);
|
||||||
|
tBufferClear(&buffers[3]);
|
||||||
|
for (int i = 0; i < bData->nColData; i++) {
|
||||||
|
SColData *colData = tBlockDataGetColDataByIdx(bData, i);
|
||||||
|
|
||||||
if (pColData->flag == HAS_NONE) continue;
|
if (colData->cflag & COL_IS_KEY) {
|
||||||
|
continue;
|
||||||
SBlockCol blockCol = {.cid = pColData->cid,
|
}
|
||||||
.type = pColData->type,
|
if (colData->flag == HAS_NONE) {
|
||||||
.smaOn = pColData->smaOn,
|
continue;
|
||||||
.flag = pColData->flag,
|
|
||||||
.szOrigin = pColData->nData};
|
|
||||||
|
|
||||||
if (pColData->flag != HAS_NULL) {
|
|
||||||
code = tsdbCmprColData(pColData, cmprAlg, &blockCol, &aBuf[0], aBufN[0], &aBuf[2]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
blockCol.offset = aBufN[0];
|
|
||||||
aBufN[0] = aBufN[0] + blockCol.szBitmap + blockCol.szOffset + blockCol.szValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tRealloc(&aBuf[1], hdr.szBlkCol + tPutBlockCol(NULL, &blockCol));
|
SColDataCompressInfo cinfo = {
|
||||||
if (code) goto _exit;
|
.cmprAlg = cmprAlg,
|
||||||
hdr.szBlkCol += tPutBlockCol(aBuf[1] + hdr.szBlkCol, &blockCol);
|
};
|
||||||
|
int32_t offset = buffers[3].size;
|
||||||
|
code = tColDataCompress(colData, &cinfo, &buffers[3], assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
|
SBlockCol blockCol = (SBlockCol){
|
||||||
|
.cid = cinfo.columnId,
|
||||||
|
.type = cinfo.dataType,
|
||||||
|
.cflag = cinfo.columnFlag,
|
||||||
|
.flag = cinfo.flag,
|
||||||
|
.szOrigin = cinfo.dataOriginalSize,
|
||||||
|
.szBitmap = cinfo.bitmapCompressedSize,
|
||||||
|
.szOffset = cinfo.offsetCompressedSize,
|
||||||
|
.szValue = cinfo.dataCompressedSize,
|
||||||
|
.offset = offset,
|
||||||
|
};
|
||||||
|
|
||||||
|
code = tPutBlockCol(&buffers[2], &blockCol);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
hdr.szBlkCol = buffers[2].size;
|
||||||
|
|
||||||
// SBlockCol
|
// SDiskDataHdr part
|
||||||
aBufN[1] = hdr.szBlkCol;
|
tBufferClear(&buffers[0]);
|
||||||
|
code = tPutDiskDataHdr(&buffers[0], &hdr);
|
||||||
// uid + version + tskey
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
aBufN[2] = 0;
|
|
||||||
if (pBlockData->uid == 0) {
|
|
||||||
code = tsdbCmprData((uint8_t *)pBlockData->aUid, sizeof(int64_t) * pBlockData->nRow, TSDB_DATA_TYPE_BIGINT, cmprAlg,
|
|
||||||
&aBuf[2], aBufN[2], &hdr.szUid, &aBuf[3]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
|
||||||
aBufN[2] += hdr.szUid;
|
|
||||||
|
|
||||||
code = tsdbCmprData((uint8_t *)pBlockData->aVersion, sizeof(int64_t) * pBlockData->nRow, TSDB_DATA_TYPE_BIGINT,
|
|
||||||
cmprAlg, &aBuf[2], aBufN[2], &hdr.szVer, &aBuf[3]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
aBufN[2] += hdr.szVer;
|
|
||||||
|
|
||||||
code = tsdbCmprData((uint8_t *)pBlockData->aTSKEY, sizeof(TSKEY) * pBlockData->nRow, TSDB_DATA_TYPE_TIMESTAMP,
|
|
||||||
cmprAlg, &aBuf[2], aBufN[2], &hdr.szKey, &aBuf[3]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
aBufN[2] += hdr.szKey;
|
|
||||||
|
|
||||||
// hdr
|
|
||||||
aBufN[3] = tPutDiskDataHdr(NULL, &hdr);
|
|
||||||
code = tRealloc(&aBuf[3], aBufN[3]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
tPutDiskDataHdr(aBuf[3], &hdr);
|
|
||||||
|
|
||||||
// aggragate
|
|
||||||
if (ppOut) {
|
|
||||||
*szOut = aBufN[0] + aBufN[1] + aBufN[2] + aBufN[3];
|
|
||||||
code = tRealloc(ppOut, *szOut);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
memcpy(*ppOut, aBuf[3], aBufN[3]);
|
|
||||||
memcpy(*ppOut + aBufN[3], aBuf[2], aBufN[2]);
|
|
||||||
if (aBufN[1]) {
|
|
||||||
memcpy(*ppOut + aBufN[3] + aBufN[2], aBuf[1], aBufN[1]);
|
|
||||||
}
|
|
||||||
if (aBufN[0]) {
|
|
||||||
memcpy(*ppOut + aBufN[3] + aBufN[2] + aBufN[1], aBuf[0], aBufN[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]) {
|
int32_t tBlockDataDecompress(SBufferReader *br, SBlockData *blockData, SBuffer *assist) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
tBlockDataReset(pBlockData);
|
|
||||||
|
|
||||||
int32_t n = 0;
|
|
||||||
SDiskDataHdr hdr = {0};
|
SDiskDataHdr hdr = {0};
|
||||||
|
SCompressInfo cinfo;
|
||||||
|
|
||||||
// SDiskDataHdr
|
// SDiskDataHdr
|
||||||
n += tGetDiskDataHdr(pIn + n, &hdr);
|
code = tGetDiskDataHdr(br, &hdr);
|
||||||
ASSERT(hdr.delimiter == TSDB_FILE_DLMT);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
pBlockData->suid = hdr.suid;
|
tBlockDataReset(blockData);
|
||||||
pBlockData->uid = hdr.uid;
|
blockData->suid = hdr.suid;
|
||||||
pBlockData->nRow = hdr.nRow;
|
blockData->uid = hdr.uid;
|
||||||
|
blockData->nRow = hdr.nRow;
|
||||||
|
|
||||||
// uid
|
// Key part
|
||||||
if (hdr.uid == 0) {
|
code = tBlockDataDecompressKeyPart(&hdr, br, blockData, assist);
|
||||||
ASSERT(hdr.szUid);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
code = tsdbDecmprData(pIn + n, hdr.szUid, TSDB_DATA_TYPE_BIGINT, hdr.cmprAlg, (uint8_t **)&pBlockData->aUid,
|
|
||||||
sizeof(int64_t) * hdr.nRow, &aBuf[0]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
} else {
|
|
||||||
ASSERT(!hdr.szUid);
|
|
||||||
}
|
|
||||||
n += hdr.szUid;
|
|
||||||
|
|
||||||
// version
|
// Column part
|
||||||
code = tsdbDecmprData(pIn + n, hdr.szVer, TSDB_DATA_TYPE_BIGINT, hdr.cmprAlg, (uint8_t **)&pBlockData->aVersion,
|
SBufferReader br2 = *br;
|
||||||
sizeof(int64_t) * hdr.nRow, &aBuf[0]);
|
br->offset += hdr.szBlkCol;
|
||||||
if (code) goto _exit;
|
for (uint32_t startOffset = br2.offset; br2.offset - startOffset < hdr.szBlkCol;) {
|
||||||
n += hdr.szVer;
|
SBlockCol blockCol;
|
||||||
|
|
||||||
// TSKEY
|
code = tGetBlockCol(&br2, &blockCol);
|
||||||
code = tsdbDecmprData(pIn + n, hdr.szKey, TSDB_DATA_TYPE_TIMESTAMP, hdr.cmprAlg, (uint8_t **)&pBlockData->aTSKEY,
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
sizeof(TSKEY) * hdr.nRow, &aBuf[0]);
|
code = tBlockDataDecompressColData(&hdr, &blockCol, br, blockData, assist);
|
||||||
if (code) goto _exit;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
n += hdr.szKey;
|
|
||||||
|
|
||||||
// loop to decode each column data
|
|
||||||
if (hdr.szBlkCol == 0) goto _exit;
|
|
||||||
|
|
||||||
int32_t nColData = 0;
|
|
||||||
int32_t nt = 0;
|
|
||||||
while (nt < hdr.szBlkCol) {
|
|
||||||
SBlockCol blockCol = {0};
|
|
||||||
nt += tGetBlockCol(pIn + n + nt, &blockCol);
|
|
||||||
++nColData;
|
|
||||||
}
|
|
||||||
ASSERT(nt == hdr.szBlkCol);
|
|
||||||
|
|
||||||
code = tBlockDataAdjustColData(pBlockData, nColData);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
nt = 0;
|
|
||||||
int32_t iColData = 0;
|
|
||||||
while (nt < hdr.szBlkCol) {
|
|
||||||
SBlockCol blockCol = {0};
|
|
||||||
nt += tGetBlockCol(pIn + n + nt, &blockCol);
|
|
||||||
|
|
||||||
SColData *pColData = &pBlockData->aColData[iColData++];
|
|
||||||
|
|
||||||
tColDataInit(pColData, blockCol.cid, blockCol.type, blockCol.smaOn);
|
|
||||||
if (blockCol.flag == HAS_NULL) {
|
|
||||||
for (int32_t iRow = 0; iRow < hdr.nRow; iRow++) {
|
|
||||||
code = tColDataAppendValue(pColData, &COL_VAL_NULL(blockCol.cid, blockCol.type));
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
code = tsdbDecmprColData(pIn + n + hdr.szBlkCol + blockCol.offset, &blockCol, hdr.cmprAlg, hdr.nRow, pColData,
|
|
||||||
&aBuf[0]);
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -1494,218 +1499,254 @@ _exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
// SDiskDataHdr ==============================
|
// SDiskDataHdr ==============================
|
||||||
int32_t tPutDiskDataHdr(uint8_t *p, const SDiskDataHdr *pHdr) {
|
int32_t tPutDiskDataHdr(SBuffer *buffer, const SDiskDataHdr *pHdr) {
|
||||||
int32_t n = 0;
|
int32_t code;
|
||||||
|
|
||||||
n += tPutU32(p ? p + n : p, pHdr->delimiter);
|
if ((code = tBufferPutU32(buffer, pHdr->delimiter))) return code;
|
||||||
n += tPutU32v(p ? p + n : p, pHdr->fmtVer);
|
if ((code = tBufferPutU32v(buffer, pHdr->fmtVer))) return code;
|
||||||
n += tPutI64(p ? p + n : p, pHdr->suid);
|
if ((code = tBufferPutI64(buffer, pHdr->suid))) return code;
|
||||||
n += tPutI64(p ? p + n : p, pHdr->uid);
|
if ((code = tBufferPutI64(buffer, pHdr->uid))) return code;
|
||||||
n += tPutI32v(p ? p + n : p, pHdr->szUid);
|
if ((code = tBufferPutI32v(buffer, pHdr->szUid))) return code;
|
||||||
n += tPutI32v(p ? p + n : p, pHdr->szVer);
|
if ((code = tBufferPutI32v(buffer, pHdr->szVer))) return code;
|
||||||
n += tPutI32v(p ? p + n : p, pHdr->szKey);
|
if ((code = tBufferPutI32v(buffer, pHdr->szKey))) return code;
|
||||||
n += tPutI32v(p ? p + n : p, pHdr->szBlkCol);
|
if ((code = tBufferPutI32v(buffer, pHdr->szBlkCol))) return code;
|
||||||
n += tPutI32v(p ? p + n : p, pHdr->nRow);
|
if ((code = tBufferPutI32v(buffer, pHdr->nRow))) return code;
|
||||||
n += tPutI8(p ? p + n : p, pHdr->cmprAlg);
|
if ((code = tBufferPutI8(buffer, pHdr->cmprAlg))) return code;
|
||||||
|
if (pHdr->fmtVer == 1) {
|
||||||
return n;
|
if ((code = tBufferPutI8(buffer, pHdr->numOfPKs))) return code;
|
||||||
|
for (int i = 0; i < pHdr->numOfPKs; i++) {
|
||||||
|
if ((code = tPutBlockCol(buffer, &pHdr->primaryBlockCols[i]))) return code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tGetDiskDataHdr(uint8_t *p, void *ph) {
|
return 0;
|
||||||
int32_t n = 0;
|
}
|
||||||
SDiskDataHdr *pHdr = (SDiskDataHdr *)ph;
|
|
||||||
|
|
||||||
n += tGetU32(p + n, &pHdr->delimiter);
|
int32_t tGetDiskDataHdr(SBufferReader *br, SDiskDataHdr *pHdr) {
|
||||||
n += tGetU32v(p + n, &pHdr->fmtVer);
|
int32_t code;
|
||||||
n += tGetI64(p + n, &pHdr->suid);
|
|
||||||
n += tGetI64(p + n, &pHdr->uid);
|
|
||||||
n += tGetI32v(p + n, &pHdr->szUid);
|
|
||||||
n += tGetI32v(p + n, &pHdr->szVer);
|
|
||||||
n += tGetI32v(p + n, &pHdr->szKey);
|
|
||||||
n += tGetI32v(p + n, &pHdr->szBlkCol);
|
|
||||||
n += tGetI32v(p + n, &pHdr->nRow);
|
|
||||||
n += tGetI8(p + n, &pHdr->cmprAlg);
|
|
||||||
|
|
||||||
return n;
|
if ((code = tBufferGetU32(br, &pHdr->delimiter))) return code;
|
||||||
|
if ((code = tBufferGetU32v(br, &pHdr->fmtVer))) return code;
|
||||||
|
if ((code = tBufferGetI64(br, &pHdr->suid))) return code;
|
||||||
|
if ((code = tBufferGetI64(br, &pHdr->uid))) return code;
|
||||||
|
if ((code = tBufferGetI32v(br, &pHdr->szUid))) return code;
|
||||||
|
if ((code = tBufferGetI32v(br, &pHdr->szVer))) return code;
|
||||||
|
if ((code = tBufferGetI32v(br, &pHdr->szKey))) return code;
|
||||||
|
if ((code = tBufferGetI32v(br, &pHdr->szBlkCol))) return code;
|
||||||
|
if ((code = tBufferGetI32v(br, &pHdr->nRow))) return code;
|
||||||
|
if ((code = tBufferGetI8(br, &pHdr->cmprAlg))) return code;
|
||||||
|
if (pHdr->fmtVer == 1) {
|
||||||
|
if ((code = tBufferGetI8(br, &pHdr->numOfPKs))) return code;
|
||||||
|
for (int i = 0; i < pHdr->numOfPKs; i++) {
|
||||||
|
if ((code = tGetBlockCol(br, &pHdr->primaryBlockCols[i]))) return code;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pHdr->numOfPKs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ALGORITHM ==============================
|
// ALGORITHM ==============================
|
||||||
int32_t tPutColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg) {
|
int32_t tPutColumnDataAgg(SBuffer *buffer, SColumnDataAgg *pColAgg) {
|
||||||
int32_t n = 0;
|
int32_t code;
|
||||||
|
|
||||||
n += tPutI16v(p ? p + n : p, pColAgg->colId);
|
if ((code = tBufferPutI16v(buffer, pColAgg->colId))) return code;
|
||||||
n += tPutI16v(p ? p + n : p, pColAgg->numOfNull);
|
if ((code = tBufferPutI16v(buffer, pColAgg->numOfNull))) return code;
|
||||||
n += tPutI64(p ? p + n : p, pColAgg->sum);
|
if ((code = tBufferPutI64(buffer, pColAgg->sum))) return code;
|
||||||
n += tPutI64(p ? p + n : p, pColAgg->max);
|
if ((code = tBufferPutI64(buffer, pColAgg->max))) return code;
|
||||||
n += tPutI64(p ? p + n : p, pColAgg->min);
|
if ((code = tBufferPutI64(buffer, pColAgg->min))) return code;
|
||||||
|
|
||||||
return n;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tGetColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg) {
|
int32_t tGetColumnDataAgg(SBufferReader *br, SColumnDataAgg *pColAgg) {
|
||||||
int32_t n = 0;
|
int32_t code;
|
||||||
|
|
||||||
n += tGetI16v(p + n, &pColAgg->colId);
|
if ((code = tBufferGetI16v(br, &pColAgg->colId))) return code;
|
||||||
n += tGetI16v(p + n, &pColAgg->numOfNull);
|
if ((code = tBufferGetI16v(br, &pColAgg->numOfNull))) return code;
|
||||||
n += tGetI64(p + n, &pColAgg->sum);
|
if ((code = tBufferGetI64(br, &pColAgg->sum))) return code;
|
||||||
n += tGetI64(p + n, &pColAgg->max);
|
if ((code = tBufferGetI64(br, &pColAgg->max))) return code;
|
||||||
n += tGetI64(p + n, &pColAgg->min);
|
if ((code = tBufferGetI64(br, &pColAgg->min))) return code;
|
||||||
|
|
||||||
return n;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbCmprData(uint8_t *pIn, int32_t szIn, int8_t type, int8_t cmprAlg, uint8_t **ppOut, int32_t nOut,
|
static int32_t tBlockDataCompressKeyPart(SBlockData *bData, SDiskDataHdr *hdr, SBuffer *buffer, SBuffer *assist) {
|
||||||
int32_t *szOut, uint8_t **ppBuf) {
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
|
SCompressInfo cinfo;
|
||||||
|
|
||||||
ASSERT(szIn > 0 && ppOut);
|
// uid
|
||||||
|
if (bData->uid == 0) {
|
||||||
if (cmprAlg == NO_COMPRESSION) {
|
cinfo = (SCompressInfo){
|
||||||
code = tRealloc(ppOut, nOut + szIn);
|
.cmprAlg = hdr->cmprAlg,
|
||||||
if (code) goto _exit;
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
|
.originalSize = sizeof(int64_t) * bData->nRow,
|
||||||
memcpy(*ppOut + nOut, pIn, szIn);
|
};
|
||||||
*szOut = szIn;
|
code = tCompressDataToBuffer(bData->aUid, &cinfo, buffer, assist);
|
||||||
} else {
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
int32_t size = szIn + COMP_OVERFLOW_BYTES;
|
hdr->szUid = cinfo.compressedSize;
|
||||||
|
|
||||||
code = tRealloc(ppOut, nOut + size);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
if (cmprAlg == TWO_STAGE_COMP) {
|
|
||||||
ASSERT(ppBuf);
|
|
||||||
code = tRealloc(ppBuf, size);
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*szOut =
|
// version
|
||||||
tDataTypes[type].compFunc(pIn, szIn, szIn / tDataTypes[type].bytes, *ppOut + nOut, size, cmprAlg, *ppBuf, size);
|
cinfo = (SCompressInfo){
|
||||||
if (*szOut <= 0) {
|
.cmprAlg = hdr->cmprAlg,
|
||||||
code = TSDB_CODE_COMPRESS_ERROR;
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
goto _exit;
|
.originalSize = sizeof(int64_t) * bData->nRow,
|
||||||
|
};
|
||||||
|
code = tCompressDataToBuffer((uint8_t *)bData->aVersion, &cinfo, buffer, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
hdr->szVer = cinfo.compressedSize;
|
||||||
|
|
||||||
|
// ts
|
||||||
|
cinfo = (SCompressInfo){
|
||||||
|
.cmprAlg = hdr->cmprAlg,
|
||||||
|
.dataType = TSDB_DATA_TYPE_TIMESTAMP,
|
||||||
|
.originalSize = sizeof(TSKEY) * bData->nRow,
|
||||||
|
};
|
||||||
|
code = tCompressDataToBuffer((uint8_t *)bData->aTSKEY, &cinfo, buffer, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
hdr->szKey = cinfo.compressedSize;
|
||||||
|
|
||||||
|
// primary keys
|
||||||
|
for (hdr->numOfPKs = 0; hdr->numOfPKs < bData->nColData; hdr->numOfPKs++) {
|
||||||
|
ASSERT(hdr->numOfPKs <= TD_MAX_PK_COLS);
|
||||||
|
|
||||||
|
SBlockCol *blockCol = &hdr->primaryBlockCols[hdr->numOfPKs];
|
||||||
|
SColData *colData = tBlockDataGetColDataByIdx(bData, hdr->numOfPKs);
|
||||||
|
|
||||||
|
if ((colData->cflag & COL_IS_KEY) == 0) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SColDataCompressInfo info = {
|
||||||
|
.cmprAlg = hdr->cmprAlg,
|
||||||
|
};
|
||||||
|
code = tColDataCompress(colData, &info, buffer, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
|
*blockCol = (SBlockCol){
|
||||||
|
.cid = info.columnId,
|
||||||
|
.type = info.dataType,
|
||||||
|
.cflag = info.columnFlag,
|
||||||
|
.flag = info.flag,
|
||||||
|
.szOrigin = info.dataOriginalSize,
|
||||||
|
.szBitmap = info.bitmapCompressedSize,
|
||||||
|
.szOffset = info.offsetCompressedSize,
|
||||||
|
.szValue = info.dataCompressedSize,
|
||||||
|
.offset = 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbDecmprData(uint8_t *pIn, int32_t szIn, int8_t type, int8_t cmprAlg, uint8_t **ppOut, int32_t szOut,
|
int32_t tBlockDataDecompressColData(const SDiskDataHdr *hdr, const SBlockCol *blockCol, SBufferReader *br,
|
||||||
uint8_t **ppBuf) {
|
SBlockData *blockData, SBuffer *assist) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
|
|
||||||
code = tRealloc(ppOut, szOut);
|
SColData *colData;
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
if (cmprAlg == NO_COMPRESSION) {
|
code = tBlockDataAddColData(blockData, blockCol->cid, blockCol->type, blockCol->cflag, &colData);
|
||||||
ASSERT(szIn == szOut);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
memcpy(*ppOut, pIn, szOut);
|
|
||||||
} else {
|
// ASSERT(blockCol->flag != HAS_NONE);
|
||||||
if (cmprAlg == TWO_STAGE_COMP) {
|
|
||||||
code = tRealloc(ppBuf, szOut + COMP_OVERFLOW_BYTES);
|
SColDataCompressInfo info = {
|
||||||
if (code) goto _exit;
|
.cmprAlg = hdr->cmprAlg,
|
||||||
|
.columnFlag = blockCol->cflag,
|
||||||
|
.flag = blockCol->flag,
|
||||||
|
.dataType = blockCol->type,
|
||||||
|
.columnId = blockCol->cid,
|
||||||
|
.numOfData = hdr->nRow,
|
||||||
|
.bitmapOriginalSize = 0,
|
||||||
|
.bitmapCompressedSize = blockCol->szBitmap,
|
||||||
|
.offsetOriginalSize = blockCol->szOffset ? sizeof(int32_t) * hdr->nRow : 0,
|
||||||
|
.offsetCompressedSize = blockCol->szOffset,
|
||||||
|
.dataOriginalSize = blockCol->szOrigin,
|
||||||
|
.dataCompressedSize = blockCol->szValue,
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (blockCol->flag) {
|
||||||
|
case (HAS_NONE | HAS_NULL | HAS_VALUE):
|
||||||
|
info.bitmapOriginalSize = BIT2_SIZE(hdr->nRow);
|
||||||
|
break;
|
||||||
|
case (HAS_NONE | HAS_NULL):
|
||||||
|
case (HAS_NONE | HAS_VALUE):
|
||||||
|
case (HAS_NULL | HAS_VALUE):
|
||||||
|
info.bitmapOriginalSize = BIT1_SIZE(hdr->nRow);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t size = tDataTypes[type].decompFunc(pIn, szIn, szOut / tDataTypes[type].bytes, *ppOut, szOut, cmprAlg,
|
code = tColDataDecompress(BR_PTR(br), &info, colData, assist);
|
||||||
*ppBuf, szOut + COMP_OVERFLOW_BYTES);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
if (size <= 0) {
|
br->offset += blockCol->szBitmap + blockCol->szOffset + blockCol->szValue;
|
||||||
code = TSDB_CODE_COMPRESS_ERROR;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(size == szOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbCmprColData(SColData *pColData, int8_t cmprAlg, SBlockCol *pBlockCol, uint8_t **ppOut, int32_t nOut,
|
int32_t tBlockDataDecompressKeyPart(const SDiskDataHdr *hdr, SBufferReader *br, SBlockData *blockData,
|
||||||
uint8_t **ppBuf) {
|
SBuffer *assist) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
|
SCompressInfo cinfo;
|
||||||
|
|
||||||
ASSERT(pColData->flag && (pColData->flag != HAS_NONE) && (pColData->flag != HAS_NULL));
|
// uid
|
||||||
|
if (hdr->szUid > 0) {
|
||||||
|
cinfo = (SCompressInfo){
|
||||||
|
.cmprAlg = hdr->cmprAlg,
|
||||||
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
|
.compressedSize = hdr->szUid,
|
||||||
|
.originalSize = sizeof(int64_t) * hdr->nRow,
|
||||||
|
};
|
||||||
|
|
||||||
pBlockCol->szBitmap = 0;
|
code = tRealloc((uint8_t **)&blockData->aUid, cinfo.originalSize);
|
||||||
pBlockCol->szOffset = 0;
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
pBlockCol->szValue = 0;
|
code = tDecompressData(BR_PTR(br), &cinfo, blockData->aUid, cinfo.originalSize, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
int32_t size = 0;
|
br->offset += cinfo.compressedSize;
|
||||||
// bitmap
|
|
||||||
if (pColData->flag != HAS_VALUE) {
|
|
||||||
int32_t szBitMap;
|
|
||||||
if (pColData->flag == (HAS_VALUE | HAS_NULL | HAS_NONE)) {
|
|
||||||
szBitMap = BIT2_SIZE(pColData->nVal);
|
|
||||||
} else {
|
|
||||||
szBitMap = BIT1_SIZE(pColData->nVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tsdbCmprData(pColData->pBitMap, szBitMap, TSDB_DATA_TYPE_TINYINT, cmprAlg, ppOut, nOut + size,
|
// version
|
||||||
&pBlockCol->szBitmap, ppBuf);
|
cinfo = (SCompressInfo){
|
||||||
if (code) goto _exit;
|
.cmprAlg = hdr->cmprAlg,
|
||||||
}
|
.dataType = TSDB_DATA_TYPE_BIGINT,
|
||||||
size += pBlockCol->szBitmap;
|
.compressedSize = hdr->szVer,
|
||||||
|
.originalSize = sizeof(int64_t) * hdr->nRow,
|
||||||
|
};
|
||||||
|
code = tRealloc((uint8_t **)&blockData->aVersion, cinfo.originalSize);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
code = tDecompressData(BR_PTR(br), &cinfo, blockData->aVersion, cinfo.originalSize, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
br->offset += cinfo.compressedSize;
|
||||||
|
|
||||||
// offset
|
// ts
|
||||||
if (IS_VAR_DATA_TYPE(pColData->type) && pColData->flag != (HAS_NULL | HAS_NONE)) {
|
cinfo = (SCompressInfo){
|
||||||
code = tsdbCmprData((uint8_t *)pColData->aOffset, sizeof(int32_t) * pColData->nVal, TSDB_DATA_TYPE_INT, cmprAlg,
|
.cmprAlg = hdr->cmprAlg,
|
||||||
ppOut, nOut + size, &pBlockCol->szOffset, ppBuf);
|
.dataType = TSDB_DATA_TYPE_TIMESTAMP,
|
||||||
if (code) goto _exit;
|
.compressedSize = hdr->szKey,
|
||||||
}
|
.originalSize = sizeof(TSKEY) * hdr->nRow,
|
||||||
size += pBlockCol->szOffset;
|
};
|
||||||
|
code = tRealloc((uint8_t **)&blockData->aTSKEY, cinfo.originalSize);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
code = tDecompressData(BR_PTR(br), &cinfo, blockData->aTSKEY, cinfo.originalSize, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
br->offset += cinfo.compressedSize;
|
||||||
|
|
||||||
// value
|
// primary keys
|
||||||
if ((pColData->flag != (HAS_NULL | HAS_NONE)) && pColData->nData) {
|
for (int i = 0; i < hdr->numOfPKs; i++) {
|
||||||
code = tsdbCmprData((uint8_t *)pColData->pData, pColData->nData, pColData->type, cmprAlg, ppOut, nOut + size,
|
const SBlockCol *blockCol = &hdr->primaryBlockCols[i];
|
||||||
&pBlockCol->szValue, ppBuf);
|
|
||||||
if (code) goto _exit;
|
ASSERT(blockCol->flag == HAS_VALUE);
|
||||||
|
ASSERT(blockCol->cflag & COL_IS_KEY);
|
||||||
|
|
||||||
|
code = tBlockDataDecompressColData(hdr, blockCol, br, blockData, assist);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
size += pBlockCol->szValue;
|
|
||||||
|
|
||||||
_exit:
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, int32_t nVal, SColData *pColData,
|
|
||||||
uint8_t **ppBuf) {
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
ASSERT(pColData->cid == pBlockCol->cid);
|
|
||||||
ASSERT(pColData->type == pBlockCol->type);
|
|
||||||
pColData->smaOn = pBlockCol->smaOn;
|
|
||||||
pColData->flag = pBlockCol->flag;
|
|
||||||
pColData->nVal = nVal;
|
|
||||||
pColData->nData = pBlockCol->szOrigin;
|
|
||||||
|
|
||||||
uint8_t *p = pIn;
|
|
||||||
// bitmap
|
|
||||||
if (pBlockCol->szBitmap) {
|
|
||||||
int32_t szBitMap;
|
|
||||||
if (pColData->flag == (HAS_VALUE | HAS_NULL | HAS_NONE)) {
|
|
||||||
szBitMap = BIT2_SIZE(pColData->nVal);
|
|
||||||
} else {
|
|
||||||
szBitMap = BIT1_SIZE(pColData->nVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbDecmprData(p, pBlockCol->szBitmap, TSDB_DATA_TYPE_TINYINT, cmprAlg, &pColData->pBitMap, szBitMap, ppBuf);
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
|
||||||
p += pBlockCol->szBitmap;
|
|
||||||
|
|
||||||
// offset
|
|
||||||
if (pBlockCol->szOffset) {
|
|
||||||
code = tsdbDecmprData(p, pBlockCol->szOffset, TSDB_DATA_TYPE_INT, cmprAlg, (uint8_t **)&pColData->aOffset,
|
|
||||||
sizeof(int32_t) * pColData->nVal, ppBuf);
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
|
||||||
p += pBlockCol->szOffset;
|
|
||||||
|
|
||||||
// value
|
|
||||||
if (pBlockCol->szValue) {
|
|
||||||
code = tsdbDecmprData(p, pBlockCol->szValue, pColData->type, cmprAlg, &pColData->pData, pColData->nData, ppBuf);
|
|
||||||
if (code) goto _exit;
|
|
||||||
}
|
|
||||||
p += pBlockCol->szValue;
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -17,39 +17,46 @@
|
||||||
|
|
||||||
// SDelBlock ----------
|
// SDelBlock ----------
|
||||||
int32_t tTombBlockInit(STombBlock *tombBlock) {
|
int32_t tTombBlockInit(STombBlock *tombBlock) {
|
||||||
|
tombBlock->numOfRecords = 0;
|
||||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||||
TARRAY2_INIT(&tombBlock->dataArr[i]);
|
tBufferInit(&tombBlock->buffers[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
||||||
|
tombBlock->numOfRecords = 0;
|
||||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||||
TARRAY2_DESTROY(&tombBlock->dataArr[i], NULL);
|
tBufferDestroy(&tombBlock->buffers[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tTombBlockClear(STombBlock *tombBlock) {
|
int32_t tTombBlockClear(STombBlock *tombBlock) {
|
||||||
|
tombBlock->numOfRecords = 0;
|
||||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||||
TARRAY2_CLEAR(&tombBlock->dataArr[i], NULL);
|
tBufferClear(&tombBlock->buffers[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record) {
|
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record) {
|
||||||
int32_t code;
|
|
||||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||||
code = TARRAY2_APPEND(&tombBlock->dataArr[i], record->dataArr[i]);
|
int32_t code = tBufferPutI64(&tombBlock->buffers[i], record->data[i]);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
}
|
}
|
||||||
|
tombBlock->numOfRecords++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record) {
|
int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record) {
|
||||||
if (idx >= TOMB_BLOCK_SIZE(tombBlock)) return TSDB_CODE_OUT_OF_RANGE;
|
if (idx < 0 || idx >= tombBlock->numOfRecords) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||||
record->dataArr[i] = TARRAY2_GET(&tombBlock->dataArr[i], idx);
|
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * idx, &tombBlock->buffers[i]);
|
||||||
|
tBufferGetI64(&br, &record->data[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -66,95 +73,374 @@ int32_t tTombRecordCompare(const STombRecord *r1, const STombRecord *r2) {
|
||||||
|
|
||||||
// STbStatisBlock ----------
|
// STbStatisBlock ----------
|
||||||
int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
|
int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
|
||||||
for (int32_t i = 0; i < STATIS_RECORD_NUM_ELEM; ++i) {
|
statisBlock->numOfPKs = 0;
|
||||||
TARRAY2_INIT(&statisBlock->dataArr[i]);
|
statisBlock->numOfRecords = 0;
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||||
|
tBufferInit(&statisBlock->buffers[i]);
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||||
|
tValueColumnInit(&statisBlock->firstKeyPKs[i]);
|
||||||
|
tValueColumnInit(&statisBlock->lastKeyPKs[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
|
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
|
||||||
for (int32_t i = 0; i < STATIS_RECORD_NUM_ELEM; ++i) {
|
statisBlock->numOfPKs = 0;
|
||||||
TARRAY2_DESTROY(&statisBlock->dataArr[i], NULL);
|
statisBlock->numOfRecords = 0;
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||||
|
tBufferDestroy(&statisBlock->buffers[i]);
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||||
|
tValueColumnDestroy(&statisBlock->firstKeyPKs[i]);
|
||||||
|
tValueColumnDestroy(&statisBlock->lastKeyPKs[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
|
int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
|
||||||
for (int32_t i = 0; i < STATIS_RECORD_NUM_ELEM; ++i) {
|
statisBlock->numOfPKs = 0;
|
||||||
TARRAY2_CLEAR(&statisBlock->dataArr[i], NULL);
|
statisBlock->numOfRecords = 0;
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||||
|
tBufferClear(&statisBlock->buffers[i]);
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||||
|
tValueColumnClear(&statisBlock->firstKeyPKs[i]);
|
||||||
|
tValueColumnClear(&statisBlock->lastKeyPKs[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, const STbStatisRecord *record) {
|
static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
for (int32_t i = 0; i < STATIS_RECORD_NUM_ELEM; ++i) {
|
STsdbRowKey key;
|
||||||
code = TARRAY2_APPEND(&statisBlock->dataArr[i], record->dataArr[i]);
|
|
||||||
|
tsdbRowGetKey(&row->row, &key);
|
||||||
|
if (block->numOfRecords == 0) {
|
||||||
|
block->numOfPKs = key.key.numOfPKs;
|
||||||
|
} else if (block->numOfPKs != key.key.numOfPKs) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < block->numOfPKs; i++) {
|
||||||
|
if (key.key.pks[i].type != block->firstKeyPKs[i].type) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((code = tBufferPutI64(&block->suids, row->suid))) return code;
|
||||||
|
if ((code = tBufferPutI64(&block->uids, row->uid))) return code;
|
||||||
|
if ((code = tBufferPutI64(&block->firstKeyTimestamps, key.key.ts))) return code;
|
||||||
|
if ((code = tBufferPutI64(&block->lastKeyTimestamps, key.key.ts))) return code;
|
||||||
|
if ((code = tBufferPutI64(&block->counts, 1))) return code;
|
||||||
|
for (int32_t i = 0; i < block->numOfPKs; ++i) {
|
||||||
|
if ((code = tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i))) return code;
|
||||||
|
if ((code = tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i))) return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
block->numOfRecords++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
||||||
|
STbStatisRecord record;
|
||||||
|
STsdbRowKey key;
|
||||||
|
int32_t c;
|
||||||
|
int32_t code;
|
||||||
|
|
||||||
|
tStatisBlockGet(block, block->numOfRecords - 1, &record);
|
||||||
|
tsdbRowGetKey(&row->row, &key);
|
||||||
|
|
||||||
|
c = tRowKeyCompare(&record.lastKey, &key.key);
|
||||||
|
if (c == 0) {
|
||||||
|
return 0;
|
||||||
|
} else if (c < 0) {
|
||||||
|
// last ts
|
||||||
|
code = tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts), &key.key.ts,
|
||||||
|
sizeof(key.key.ts));
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
// last primary keys
|
||||||
|
for (int i = 0; i < block->numOfPKs; i++) {
|
||||||
|
code = tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// count
|
||||||
|
record.count++;
|
||||||
|
code = tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||||
|
sizeof(record.count));
|
||||||
|
if (code) return code;
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords) {
|
||||||
|
if (block->numOfRecords > 0) {
|
||||||
|
int64_t lastUid;
|
||||||
|
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * (block->numOfRecords - 1), &block->uids);
|
||||||
|
tBufferGetI64(&br, &lastUid);
|
||||||
|
|
||||||
|
if (lastUid == row->uid) {
|
||||||
|
return tStatisBlockUpdate(block, row);
|
||||||
|
} else if (block->numOfRecords >= maxRecords) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tStatisBlockAppend(block, row);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record) {
|
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record) {
|
||||||
if (idx >= STATIS_BLOCK_SIZE(statisBlock)) return TSDB_CODE_OUT_OF_RANGE;
|
int32_t code;
|
||||||
for (int32_t i = 0; i < STATIS_RECORD_NUM_ELEM; ++i) {
|
SBufferReader reader;
|
||||||
record->dataArr[i] = TARRAY2_GET(&statisBlock->dataArr[i], idx);
|
|
||||||
|
if (idx < 0 || idx >= statisBlock->numOfRecords) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->suid), &statisBlock->suids);
|
||||||
|
code = tBufferGetI64(&reader, &record->suid);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->uid), &statisBlock->uids);
|
||||||
|
code = tBufferGetI64(&reader, &record->uid);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->firstKey.ts), &statisBlock->firstKeyTimestamps);
|
||||||
|
code = tBufferGetI64(&reader, &record->firstKey.ts);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->lastKey.ts), &statisBlock->lastKeyTimestamps);
|
||||||
|
code = tBufferGetI64(&reader, &record->lastKey.ts);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->count), &statisBlock->counts);
|
||||||
|
code = tBufferGetI64(&reader, &record->count);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
// primary keys
|
||||||
|
for (record->firstKey.numOfPKs = 0; record->firstKey.numOfPKs < statisBlock->numOfPKs; record->firstKey.numOfPKs++) {
|
||||||
|
code = tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||||
|
&record->firstKey.pks[record->firstKey.numOfPKs]);
|
||||||
|
if (code) return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (record->lastKey.numOfPKs = 0; record->lastKey.numOfPKs < statisBlock->numOfPKs; record->lastKey.numOfPKs++) {
|
||||||
|
code = tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||||
|
&record->lastKey.pks[record->lastKey.numOfPKs]);
|
||||||
|
if (code) return code;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SBrinRecord ----------
|
// SBrinRecord ----------
|
||||||
int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
|
int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr1); ++i) {
|
brinBlock->numOfPKs = 0;
|
||||||
TARRAY2_INIT(&brinBlock->dataArr1[i]);
|
brinBlock->numOfRecords = 0;
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||||
|
tBufferInit(&brinBlock->buffers[i]);
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr2); ++i) {
|
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||||
TARRAY2_INIT(&brinBlock->dataArr2[i]);
|
tValueColumnInit(&brinBlock->firstKeyPKs[i]);
|
||||||
|
tValueColumnInit(&brinBlock->lastKeyPKs[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
|
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr1); ++i) {
|
brinBlock->numOfPKs = 0;
|
||||||
TARRAY2_DESTROY(&brinBlock->dataArr1[i], NULL);
|
brinBlock->numOfRecords = 0;
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||||
|
tBufferDestroy(&brinBlock->buffers[i]);
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr2); ++i) {
|
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||||
TARRAY2_DESTROY(&brinBlock->dataArr2[i], NULL);
|
tValueColumnDestroy(&brinBlock->firstKeyPKs[i]);
|
||||||
|
tValueColumnDestroy(&brinBlock->lastKeyPKs[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
|
int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr1); ++i) {
|
brinBlock->numOfPKs = 0;
|
||||||
TARRAY2_CLEAR(&brinBlock->dataArr1[i], NULL);
|
brinBlock->numOfRecords = 0;
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||||
|
tBufferClear(&brinBlock->buffers[i]);
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr2); ++i) {
|
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||||
TARRAY2_CLEAR(&brinBlock->dataArr2[i], NULL);
|
tValueColumnClear(&brinBlock->firstKeyPKs[i]);
|
||||||
|
tValueColumnClear(&brinBlock->lastKeyPKs[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr1); ++i) {
|
|
||||||
code = TARRAY2_APPEND(&brinBlock->dataArr1[i], record->dataArr1[i]);
|
ASSERT(record->firstKey.key.numOfPKs == record->lastKey.key.numOfPKs);
|
||||||
|
|
||||||
|
if (brinBlock->numOfRecords == 0) { // the first row
|
||||||
|
brinBlock->numOfPKs = record->firstKey.key.numOfPKs;
|
||||||
|
} else if (brinBlock->numOfPKs != record->firstKey.key.numOfPKs) {
|
||||||
|
// if the number of primary keys are not the same,
|
||||||
|
// return an error code and the caller should handle it
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < brinBlock->numOfPKs; i++) {
|
||||||
|
if (record->firstKey.key.pks[i].type != brinBlock->firstKeyPKs[i].type) {
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->suids, record->suid);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->uids, record->uid);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->minVers, record->minVer);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->maxVers, record->maxVer);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI32(&brinBlock->blockSizes, record->blockSize);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI32(&brinBlock->smaSizes, record->smaSize);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI32(&brinBlock->numRows, record->numRow);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tBufferPutI32(&brinBlock->counts, record->count);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
if (brinBlock->numOfPKs > 0) {
|
||||||
|
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||||
|
code = tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr2); ++i) {
|
|
||||||
code = TARRAY2_APPEND(&brinBlock->dataArr2[i], record->dataArr2[i]);
|
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||||
|
code = tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
brinBlock->numOfRecords++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
||||||
if (idx >= BRIN_BLOCK_SIZE(brinBlock)) return TSDB_CODE_OUT_OF_RANGE;
|
int32_t code;
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr1); ++i) {
|
SBufferReader reader;
|
||||||
record->dataArr1[i] = TARRAY2_GET(&brinBlock->dataArr1[i], idx);
|
|
||||||
|
if (idx < 0 || idx >= brinBlock->numOfRecords) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->dataArr2); ++i) {
|
|
||||||
record->dataArr2[i] = TARRAY2_GET(&brinBlock->dataArr2[i], idx);
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->suids);
|
||||||
|
code = tBufferGetI64(&reader, &record->suid);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->uids);
|
||||||
|
code = tBufferGetI64(&reader, &record->uid);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyTimestamps);
|
||||||
|
code = tBufferGetI64(&reader, &record->firstKey.key.ts);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyVersions);
|
||||||
|
code = tBufferGetI64(&reader, &record->firstKey.version);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyTimestamps);
|
||||||
|
code = tBufferGetI64(&reader, &record->lastKey.key.ts);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyVersions);
|
||||||
|
code = tBufferGetI64(&reader, &record->lastKey.version);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->minVers);
|
||||||
|
code = tBufferGetI64(&reader, &record->minVer);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->maxVers);
|
||||||
|
code = tBufferGetI64(&reader, &record->maxVer);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->blockOffsets);
|
||||||
|
code = tBufferGetI64(&reader, &record->blockOffset);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->smaOffsets);
|
||||||
|
code = tBufferGetI64(&reader, &record->smaOffset);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockSizes);
|
||||||
|
code = tBufferGetI32(&reader, &record->blockSize);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockKeySizes);
|
||||||
|
code = tBufferGetI32(&reader, &record->blockKeySize);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->smaSizes);
|
||||||
|
code = tBufferGetI32(&reader, &record->smaSize);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->numRows);
|
||||||
|
code = tBufferGetI32(&reader, &record->numRow);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->counts);
|
||||||
|
code = tBufferGetI32(&reader, &record->count);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
// primary keys
|
||||||
|
for (record->firstKey.key.numOfPKs = 0; record->firstKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||||
|
record->firstKey.key.numOfPKs++) {
|
||||||
|
code = tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||||
|
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]);
|
||||||
|
if (code) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (record->lastKey.key.numOfPKs = 0; record->lastKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||||
|
record->lastKey.key.numOfPKs++) {
|
||||||
|
code = tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||||
|
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]);
|
||||||
|
if (code) return code;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
||||||
// STombRecord ----------
|
// STombRecord ----------
|
||||||
#define TOMB_RECORD_ELEM_NUM 5
|
#define TOMB_RECORD_ELEM_NUM 5
|
||||||
typedef union {
|
typedef union {
|
||||||
int64_t dataArr[TOMB_RECORD_ELEM_NUM];
|
int64_t data[TOMB_RECORD_ELEM_NUM];
|
||||||
struct {
|
struct {
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
|
@ -35,14 +35,17 @@ typedef union {
|
||||||
};
|
};
|
||||||
} STombRecord;
|
} STombRecord;
|
||||||
|
|
||||||
typedef union {
|
typedef struct {
|
||||||
TARRAY2(int64_t) dataArr[TOMB_RECORD_ELEM_NUM];
|
int32_t numOfRecords;
|
||||||
|
union {
|
||||||
|
SBuffer buffers[TOMB_RECORD_ELEM_NUM];
|
||||||
struct {
|
struct {
|
||||||
TARRAY2(int64_t) suid[1];
|
SBuffer suids;
|
||||||
TARRAY2(int64_t) uid[1];
|
SBuffer uids;
|
||||||
TARRAY2(int64_t) version[1];
|
SBuffer versions;
|
||||||
TARRAY2(int64_t) skey[1];
|
SBuffer skeys;
|
||||||
TARRAY2(int64_t) ekey[1];
|
SBuffer ekeys;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
} STombBlock;
|
} STombBlock;
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef TARRAY2(STombBlk) TTombBlkArray;
|
typedef TARRAY2(STombBlk) TTombBlkArray;
|
||||||
|
|
||||||
#define TOMB_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)
|
#define TOMB_BLOCK_SIZE(db) ((db)->numOfRecords)
|
||||||
|
|
||||||
int32_t tTombBlockInit(STombBlock *tombBlock);
|
int32_t tTombBlockInit(STombBlock *tombBlock);
|
||||||
int32_t tTombBlockDestroy(STombBlock *tombBlock);
|
int32_t tTombBlockDestroy(STombBlock *tombBlock);
|
||||||
|
@ -70,27 +73,29 @@ int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record);
|
||||||
int32_t tTombRecordCompare(const STombRecord *record1, const STombRecord *record2);
|
int32_t tTombRecordCompare(const STombRecord *record1, const STombRecord *record2);
|
||||||
|
|
||||||
// STbStatisRecord ----------
|
// STbStatisRecord ----------
|
||||||
#define STATIS_RECORD_NUM_ELEM 5
|
typedef struct {
|
||||||
typedef union {
|
|
||||||
int64_t dataArr[STATIS_RECORD_NUM_ELEM];
|
|
||||||
struct {
|
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
int64_t firstKey;
|
SRowKey firstKey;
|
||||||
int64_t lastKey;
|
SRowKey lastKey;
|
||||||
int64_t count;
|
int64_t count;
|
||||||
};
|
|
||||||
} STbStatisRecord;
|
} STbStatisRecord;
|
||||||
|
|
||||||
typedef union {
|
typedef struct {
|
||||||
TARRAY2(int64_t) dataArr[STATIS_RECORD_NUM_ELEM];
|
int8_t numOfPKs;
|
||||||
|
int32_t numOfRecords;
|
||||||
|
union {
|
||||||
|
SBuffer buffers[5];
|
||||||
struct {
|
struct {
|
||||||
TARRAY2(int64_t) suid[1];
|
SBuffer suids; // int64_t
|
||||||
TARRAY2(int64_t) uid[1];
|
SBuffer uids; // int64_t
|
||||||
TARRAY2(int64_t) firstKey[1];
|
SBuffer firstKeyTimestamps; // int64_t
|
||||||
TARRAY2(int64_t) lastKey[1];
|
SBuffer lastKeyTimestamps; // int64_t
|
||||||
TARRAY2(int64_t) count[1];
|
SBuffer counts; // int64_t
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
SValueColumn firstKeyPKs[TD_MAX_PK_COLS];
|
||||||
|
SValueColumn lastKeyPKs[TD_MAX_PK_COLS];
|
||||||
} STbStatisBlock;
|
} STbStatisBlock;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -98,32 +103,26 @@ typedef struct {
|
||||||
TABLEID minTbid;
|
TABLEID minTbid;
|
||||||
TABLEID maxTbid;
|
TABLEID maxTbid;
|
||||||
int32_t numRec;
|
int32_t numRec;
|
||||||
int32_t size[STATIS_RECORD_NUM_ELEM];
|
int32_t size[5];
|
||||||
int8_t cmprAlg;
|
int8_t cmprAlg;
|
||||||
int8_t rsvd[7];
|
int8_t numOfPKs; // number of primary keys
|
||||||
|
int8_t rsvd[6];
|
||||||
} SStatisBlk;
|
} SStatisBlk;
|
||||||
|
|
||||||
#define STATIS_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)
|
#define STATIS_BLOCK_SIZE(db) ((db)->numOfRecords)
|
||||||
|
|
||||||
int32_t tStatisBlockInit(STbStatisBlock *statisBlock);
|
int32_t tStatisBlockInit(STbStatisBlock *statisBlock);
|
||||||
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock);
|
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock);
|
||||||
int32_t tStatisBlockClear(STbStatisBlock *statisBlock);
|
int32_t tStatisBlockClear(STbStatisBlock *statisBlock);
|
||||||
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, const STbStatisRecord *record);
|
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, SRowInfo *row, int32_t maxRecords);
|
||||||
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record);
|
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record);
|
||||||
|
|
||||||
// SBrinRecord ----------
|
// SBrinRecord ----------
|
||||||
typedef union {
|
typedef struct {
|
||||||
struct {
|
|
||||||
int64_t dataArr1[10];
|
|
||||||
int32_t dataArr2[5];
|
|
||||||
};
|
|
||||||
struct {
|
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
int64_t firstKey;
|
STsdbRowKey firstKey;
|
||||||
int64_t firstKeyVer;
|
STsdbRowKey lastKey;
|
||||||
int64_t lastKey;
|
|
||||||
int64_t lastKeyVer;
|
|
||||||
int64_t minVer;
|
int64_t minVer;
|
||||||
int64_t maxVer;
|
int64_t maxVer;
|
||||||
int64_t blockOffset;
|
int64_t blockOffset;
|
||||||
|
@ -133,31 +132,33 @@ typedef union {
|
||||||
int32_t smaSize;
|
int32_t smaSize;
|
||||||
int32_t numRow;
|
int32_t numRow;
|
||||||
int32_t count;
|
int32_t count;
|
||||||
};
|
|
||||||
} SBrinRecord;
|
} SBrinRecord;
|
||||||
|
|
||||||
typedef union {
|
typedef struct {
|
||||||
|
int8_t numOfPKs;
|
||||||
|
int32_t numOfRecords;
|
||||||
|
union {
|
||||||
|
SBuffer buffers[15];
|
||||||
struct {
|
struct {
|
||||||
TARRAY2(int64_t) dataArr1[10];
|
SBuffer suids; // int64_t
|
||||||
TARRAY2(int32_t) dataArr2[5];
|
SBuffer uids; // int64_t
|
||||||
|
SBuffer firstKeyTimestamps; // int64_t
|
||||||
|
SBuffer firstKeyVersions; // int64_t
|
||||||
|
SBuffer lastKeyTimestamps; // int64_t
|
||||||
|
SBuffer lastKeyVersions; // int64_t
|
||||||
|
SBuffer minVers; // int64_t
|
||||||
|
SBuffer maxVers; // int64_t
|
||||||
|
SBuffer blockOffsets; // int64_t
|
||||||
|
SBuffer smaOffsets; // int64_t
|
||||||
|
SBuffer blockSizes; // int32_t
|
||||||
|
SBuffer blockKeySizes; // int32_t
|
||||||
|
SBuffer smaSizes; // int32_t
|
||||||
|
SBuffer numRows; // int32_t
|
||||||
|
SBuffer counts; // int32_t
|
||||||
};
|
};
|
||||||
struct {
|
|
||||||
TARRAY2(int64_t) suid[1];
|
|
||||||
TARRAY2(int64_t) uid[1];
|
|
||||||
TARRAY2(int64_t) firstKey[1];
|
|
||||||
TARRAY2(int64_t) firstKeyVer[1];
|
|
||||||
TARRAY2(int64_t) lastKey[1];
|
|
||||||
TARRAY2(int64_t) lastKeyVer[1];
|
|
||||||
TARRAY2(int64_t) minVer[1];
|
|
||||||
TARRAY2(int64_t) maxVer[1];
|
|
||||||
TARRAY2(int64_t) blockOffset[1];
|
|
||||||
TARRAY2(int64_t) smaOffset[1];
|
|
||||||
TARRAY2(int32_t) blockSize[1];
|
|
||||||
TARRAY2(int32_t) blockKeySize[1];
|
|
||||||
TARRAY2(int32_t) smaSize[1];
|
|
||||||
TARRAY2(int32_t) numRow[1];
|
|
||||||
TARRAY2(int32_t) count[1];
|
|
||||||
};
|
};
|
||||||
|
SValueColumn firstKeyPKs[TD_MAX_PK_COLS];
|
||||||
|
SValueColumn lastKeyPKs[TD_MAX_PK_COLS];
|
||||||
} SBrinBlock;
|
} SBrinBlock;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -169,12 +170,13 @@ typedef struct {
|
||||||
int32_t numRec;
|
int32_t numRec;
|
||||||
int32_t size[15];
|
int32_t size[15];
|
||||||
int8_t cmprAlg;
|
int8_t cmprAlg;
|
||||||
int8_t rsvd[7];
|
int8_t numOfPKs; // number of primary keys
|
||||||
|
int8_t rsvd[6];
|
||||||
} SBrinBlk;
|
} SBrinBlk;
|
||||||
|
|
||||||
typedef TARRAY2(SBrinBlk) TBrinBlkArray;
|
typedef TARRAY2(SBrinBlk) TBrinBlkArray;
|
||||||
|
|
||||||
#define BRIN_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)
|
#define BRIN_BLOCK_SIZE(db) ((db)->numOfRecords)
|
||||||
|
|
||||||
int32_t tBrinBlockInit(SBrinBlock *brinBlock);
|
int32_t tBrinBlockInit(SBrinBlock *brinBlock);
|
||||||
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock);
|
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock);
|
||||||
|
|
|
@ -221,8 +221,9 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
} else {
|
} else {
|
||||||
void* data = colDataGetVarData(pColInfoData, j);
|
void* data = colDataGetVarData(pColInfoData, j);
|
||||||
SValue sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
SValue sv = (SValue){
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
.type = pCol->type, .nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
||||||
|
SColVal cv = COL_VAL_VALUE(pCol->colId, sv);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -257,9 +258,9 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SValue sv;
|
SValue sv = {.type = pCol->type};
|
||||||
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
||||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
SColVal cv = COL_VAL_VALUE(pCol->colId, sv);
|
||||||
taosArrayPush(pVals, &cv);
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4704,6 +4704,7 @@ static const char* jkColumnDefColName = "ColName";
|
||||||
static const char* jkColumnDefDataType = "DataType";
|
static const char* jkColumnDefDataType = "DataType";
|
||||||
static const char* jkColumnDefComments = "Comments";
|
static const char* jkColumnDefComments = "Comments";
|
||||||
static const char* jkColumnDefSma = "Sma";
|
static const char* jkColumnDefSma = "Sma";
|
||||||
|
static const char* jkColumnDefIsPK = "IsPK";
|
||||||
|
|
||||||
static int32_t columnDefNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t columnDefNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
const SColumnDefNode* pNode = (const SColumnDefNode*)pObj;
|
const SColumnDefNode* pNode = (const SColumnDefNode*)pObj;
|
||||||
|
@ -4718,6 +4719,9 @@ static int32_t columnDefNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddBoolToObject(pJson, jkColumnDefSma, pNode->sma);
|
code = tjsonAddBoolToObject(pJson, jkColumnDefSma, pNode->sma);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddBoolToObject(pJson, jkColumnDefIsPK, pNode->is_pk);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -4735,7 +4739,9 @@ static int32_t jsonToColumnDefNode(const SJson* pJson, void* pObj) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonGetBoolValue(pJson, jkColumnDefSma, &pNode->sma);
|
code = tjsonGetBoolValue(pJson, jkColumnDefSma, &pNode->sma);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBoolValue(pJson, jkColumnDefIsPK, &pNode->is_pk);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@ typedef enum EColumnOptionType {
|
||||||
COLUMN_OPTION_ENCODE,
|
COLUMN_OPTION_ENCODE,
|
||||||
COLUMN_OPTION_COMPRESS,
|
COLUMN_OPTION_COMPRESS,
|
||||||
COLUMN_OPTION_LEVEL,
|
COLUMN_OPTION_LEVEL,
|
||||||
|
COLUMN_OPTION_PRIMARYKEY,
|
||||||
} EColumnOptionType;
|
} EColumnOptionType;
|
||||||
|
|
||||||
typedef struct SAlterOption {
|
typedef struct SAlterOption {
|
||||||
|
|
|
@ -1286,6 +1286,7 @@ null_ordering_opt(A) ::= NULLS LAST.
|
||||||
STRICT STRING TIMES VALUES VARIABLE VIEW WAL.
|
STRICT STRING TIMES VALUES VARIABLE VIEW WAL.
|
||||||
|
|
||||||
column_options(A) ::= . { A = createDefaultColumnOptions(pCxt); }
|
column_options(A) ::= . { A = createDefaultColumnOptions(pCxt); }
|
||||||
|
column_options(A) ::= column_options(B) PRIMARY KEY. { A = setColumnOptions(pCxt, B, COLUMN_OPTION_PRIMARYKEY, NULL); }
|
||||||
column_options(A) ::= column_options(B) ENCODE NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_ENCODE, &C); }
|
column_options(A) ::= column_options(B) ENCODE NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_ENCODE, &C); }
|
||||||
column_options(A) ::= column_options(B) COMPRESS NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_COMPRESS, &C); }
|
column_options(A) ::= column_options(B) COMPRESS NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_COMPRESS, &C); }
|
||||||
column_options(A) ::= column_options(B) LEVEL NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_LEVEL, &C); }
|
column_options(A) ::= column_options(B) LEVEL NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_LEVEL, &C); }
|
||||||
|
|
|
@ -1503,6 +1503,7 @@ SNode* createDefaultColumnOptions(SAstCreateContext* pCxt) {
|
||||||
SColumnOptions* pOptions = (SColumnOptions*)nodesMakeNode(QUERY_NODE_COLUMN_OPTIONS);
|
SColumnOptions* pOptions = (SColumnOptions*)nodesMakeNode(QUERY_NODE_COLUMN_OPTIONS);
|
||||||
CHECK_OUT_OF_MEM(pOptions);
|
CHECK_OUT_OF_MEM(pOptions);
|
||||||
pOptions->commentNull = true;
|
pOptions->commentNull = true;
|
||||||
|
pOptions->bPrimaryKey = false;
|
||||||
return (SNode*)pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1530,6 +1531,9 @@ SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, EColumnOptionT
|
||||||
pCxt->errCode = TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
|
pCxt->errCode = TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case COLUMN_OPTION_PRIMARYKEY:
|
||||||
|
((SColumnOptions*)pOptions)->bPrimaryKey = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1551,6 +1555,8 @@ SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType
|
||||||
pCol->dataType = dataType;
|
pCol->dataType = dataType;
|
||||||
pCol->pOptions = (SColumnOptions*)pNode;
|
pCol->pOptions = (SColumnOptions*)pNode;
|
||||||
pCol->sma = true;
|
pCol->sma = true;
|
||||||
|
// pNode equals to NULL means that the column is a tag.
|
||||||
|
pCol->is_pk = (SColumnOptions*)pNode ? ((SColumnOptions*)pNode)->bPrimaryKey : false;
|
||||||
return (SNode*)pCol;
|
return (SNode*)pCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,7 +185,8 @@ void clearColValArraySml(SArray* pCols) {
|
||||||
int32_t num = taosArrayGetSize(pCols);
|
int32_t num = taosArrayGetSize(pCols);
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
SColVal* pCol = taosArrayGet(pCols, i);
|
SColVal* pCol = taosArrayGet(pCols, i);
|
||||||
if (TSDB_DATA_TYPE_NCHAR == pCol->type || TSDB_DATA_TYPE_GEOMETRY == pCol->type || TSDB_DATA_TYPE_VARBINARY == pCol->type) {
|
if (TSDB_DATA_TYPE_NCHAR == pCol->value.type || TSDB_DATA_TYPE_GEOMETRY == pCol->value.type ||
|
||||||
|
TSDB_DATA_TYPE_VARBINARY == pCol->value.type) {
|
||||||
taosMemoryFreeClear(pCol->value.pData);
|
taosMemoryFreeClear(pCol->value.pData);
|
||||||
}
|
}
|
||||||
pCol->flag = CV_FLAG_NONE;
|
pCol->flag = CV_FLAG_NONE;
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ static void clearColValArray(SArray* pCols) {
|
||||||
int32_t num = taosArrayGetSize(pCols);
|
int32_t num = taosArrayGetSize(pCols);
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
SColVal* pCol = taosArrayGet(pCols, i);
|
SColVal* pCol = taosArrayGet(pCols, i);
|
||||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
if (IS_VAR_DATA_TYPE(pCol->value.type)) {
|
||||||
taosMemoryFreeClear(pCol->value.pData);
|
taosMemoryFreeClear(pCol->value.pData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,7 +350,8 @@ int32_t insGetTableDataCxt(SHashObj* pHash, void* id, int32_t idLen, STableMeta*
|
||||||
|
|
||||||
static void destroyColVal(void* p) {
|
static void destroyColVal(void* p) {
|
||||||
SColVal* pVal = p;
|
SColVal* pVal = p;
|
||||||
if (TSDB_DATA_TYPE_NCHAR == pVal->type || TSDB_DATA_TYPE_GEOMETRY == pVal->type || TSDB_DATA_TYPE_VARBINARY == pVal->type) {
|
if (TSDB_DATA_TYPE_NCHAR == pVal->value.type || TSDB_DATA_TYPE_GEOMETRY == pVal->value.type ||
|
||||||
|
TSDB_DATA_TYPE_VARBINARY == pVal->value.type) {
|
||||||
taosMemoryFreeClear(pVal->value.pData);
|
taosMemoryFreeClear(pVal->value.pData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"JOIN", TK_JOIN},
|
{"JOIN", TK_JOIN},
|
||||||
{"JSON", TK_JSON},
|
{"JSON", TK_JSON},
|
||||||
{"KEEP", TK_KEEP},
|
{"KEEP", TK_KEEP},
|
||||||
|
{"KEY", TK_KEY},
|
||||||
{"KILL", TK_KILL},
|
{"KILL", TK_KILL},
|
||||||
{"LANGUAGE", TK_LANGUAGE},
|
{"LANGUAGE", TK_LANGUAGE},
|
||||||
{"LAST", TK_LAST},
|
{"LAST", TK_LAST},
|
||||||
|
@ -179,6 +180,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"PASS", TK_PASS},
|
{"PASS", TK_PASS},
|
||||||
{"PORT", TK_PORT},
|
{"PORT", TK_PORT},
|
||||||
{"PPS", TK_PPS},
|
{"PPS", TK_PPS},
|
||||||
|
{"PRIMARY", TK_PRIMARY},
|
||||||
{"PRECISION", TK_PRECISION},
|
{"PRECISION", TK_PRECISION},
|
||||||
{"PREV", TK_PREV},
|
{"PREV", TK_PREV},
|
||||||
{"PRIVILEGES", TK_PRIVILEGES},
|
{"PRIVILEGES", TK_PRIVILEGES},
|
||||||
|
|
|
@ -5808,6 +5808,9 @@ static int32_t tagDefNodeToField(SNodeList* pList, SArray** pArray) {
|
||||||
if (pCol->sma) {
|
if (pCol->sma) {
|
||||||
field.flags |= COL_SMA_ON;
|
field.flags |= COL_SMA_ON;
|
||||||
}
|
}
|
||||||
|
if (pCol->is_pk) {
|
||||||
|
field.flags |= COL_IS_KEY;
|
||||||
|
}
|
||||||
taosArrayPush(*pArray, &field);
|
taosArrayPush(*pArray, &field);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -5907,6 +5910,9 @@ static int32_t checkTableTagsSchema(STranslateContext* pCxt, SHashObj* pHash, SN
|
||||||
if (NULL != taosHashGet(pHash, pTag->colName, len)) {
|
if (NULL != taosHashGet(pHash, pTag->colName, len)) {
|
||||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN);
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code && pTag->is_pk) {
|
||||||
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY, pTag->colName);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code && pTag->dataType.type == TSDB_DATA_TYPE_JSON && ntags > 1) {
|
if (TSDB_CODE_SUCCESS == code && pTag->dataType.type == TSDB_DATA_TYPE_JSON && ntags > 1) {
|
||||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG);
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG);
|
||||||
}
|
}
|
||||||
|
@ -5963,6 +5969,9 @@ static int32_t checkTableColsSchema(STranslateContext* pCxt, SHashObj* pHash, in
|
||||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FIRST_COLUMN);
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FIRST_COLUMN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code && pCol->is_pk && colIndex != 1) {
|
||||||
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SECOND_COL_PK);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code && pCol->dataType.type == TSDB_DATA_TYPE_JSON) {
|
if (TSDB_CODE_SUCCESS == code && pCol->dataType.type == TSDB_DATA_TYPE_JSON) {
|
||||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COL_JSON);
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COL_JSON);
|
||||||
}
|
}
|
||||||
|
@ -6184,6 +6193,9 @@ static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchem
|
||||||
if (pCol->sma) {
|
if (pCol->sma) {
|
||||||
flags |= COL_SMA_ON;
|
flags |= COL_SMA_ON;
|
||||||
}
|
}
|
||||||
|
if (pCol->is_pk) {
|
||||||
|
flags |= COL_IS_KEY;
|
||||||
|
}
|
||||||
pSchema->colId = colId;
|
pSchema->colId = colId;
|
||||||
pSchema->type = pCol->dataType.type;
|
pSchema->type = pCol->dataType.type;
|
||||||
pSchema->bytes = calcTypeBytes(pCol->dataType);
|
pSchema->bytes = calcTypeBytes(pCol->dataType);
|
||||||
|
|
|
@ -195,6 +195,10 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
||||||
return "ORDER BY \"%s\" is ambiguous";
|
return "ORDER BY \"%s\" is ambiguous";
|
||||||
case TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT:
|
case TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT:
|
||||||
return "Operator not supported multi result: %s";
|
return "Operator not supported multi result: %s";
|
||||||
|
case TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY:
|
||||||
|
return "tag %s can not be primary key";
|
||||||
|
case TSDB_CODE_PAR_SECOND_COL_PK:
|
||||||
|
return "primary key column must be second column";
|
||||||
default:
|
default:
|
||||||
return "Unknown error";
|
return "Unknown error";
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -619,12 +619,14 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED_FUNC, "System table not al
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "System table not allowed")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "System table not allowed")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VARBINARY, "Invalidate varbinary value")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VARBINARY, "Invalidate varbinary value")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_IP_RANGE, "Invalid IPV4 address ranges")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_IP_RANGE, "Invalid IPV4 address ranges")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error")
|
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Invalid stream query")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Invalid stream query")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VIEW_QUERY, "Invalid view query type")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VIEW_QUERY, "Invalid view query type")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_COL_QUERY_MISMATCH, "Columns number mismatch with query result")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_COL_QUERY_MISMATCH, "Columns number mismatch with query result")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE, "View name is conflict with table")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE, "View name is conflict with table")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT, "Operator not supported multi result")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT, "Operator not supported multi result")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY, "tag can not be primary key")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SECOND_COL_PK, "primary key must be second column")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error")
|
||||||
|
|
||||||
//planner
|
//planner
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_PLAN_INTERNAL_ERROR, "Planner internal error")
|
TAOS_DEFINE_ERROR(TSDB_CODE_PLAN_INTERNAL_ERROR, "Planner internal error")
|
||||||
|
|
|
@ -108,3 +108,11 @@ add_test(
|
||||||
NAME tbaseCodecTest
|
NAME tbaseCodecTest
|
||||||
COMMAND tbaseCodecTest
|
COMMAND tbaseCodecTest
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# bufferTest
|
||||||
|
add_executable(bufferTest "bufferTest.cpp")
|
||||||
|
target_link_libraries(bufferTest os util gtest_main)
|
||||||
|
add_test(
|
||||||
|
NAME bufferTest
|
||||||
|
COMMAND bufferTest
|
||||||
|
)
|
|
@ -0,0 +1,371 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "tbuffer.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int8_t value1;
|
||||||
|
int32_t value2;
|
||||||
|
int64_t value3;
|
||||||
|
} STestStruct;
|
||||||
|
|
||||||
|
TEST(BufferTest, simpleTest1) {
|
||||||
|
SBuffer buffer;
|
||||||
|
|
||||||
|
tBufferInit(&buffer);
|
||||||
|
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetSize(&buffer), 0);
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetData(&buffer), nullptr);
|
||||||
|
|
||||||
|
tBufferDestroy(&buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BufferTest, forwardWriteAndRead) {
|
||||||
|
int32_t code = 0;
|
||||||
|
bool forward = true;
|
||||||
|
SBuffer buffer;
|
||||||
|
|
||||||
|
tBufferInit(&buffer);
|
||||||
|
taosSeedRand(taosGetTimestampSec());
|
||||||
|
|
||||||
|
// write
|
||||||
|
/* fix-len struct */
|
||||||
|
STestStruct testStruct = {1, 2};
|
||||||
|
GTEST_ASSERT_EQ(tBufferPut(&buffer, &testStruct, sizeof(STestStruct)), 0);
|
||||||
|
|
||||||
|
/* int8_t */
|
||||||
|
int8_t i8 = taosRand() % UINT8_MAX - INT8_MAX;
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI8(&buffer, i8), 0);
|
||||||
|
|
||||||
|
/* int16_t */
|
||||||
|
int8_t i16 = taosRand() % UINT16_MAX - INT16_MAX;
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI16(&buffer, i16), 0);
|
||||||
|
|
||||||
|
/* int32_t */
|
||||||
|
int8_t i32 = taosRand();
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI32(&buffer, i32), 0);
|
||||||
|
|
||||||
|
/* int64_t */
|
||||||
|
int64_t i64 = taosRand();
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI64(&buffer, i64), 0);
|
||||||
|
|
||||||
|
/* uint8_t */
|
||||||
|
uint8_t u8 = taosRand() % UINT8_MAX;
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU8(&buffer, u8), 0);
|
||||||
|
|
||||||
|
/* uint16_t */
|
||||||
|
uint16_t u16 = taosRand() % UINT16_MAX;
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU16(&buffer, u16), 0);
|
||||||
|
|
||||||
|
/* uint32_t */
|
||||||
|
uint32_t u32 = taosRand();
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU32(&buffer, u32), 0);
|
||||||
|
|
||||||
|
/* uint64_t */
|
||||||
|
uint64_t u64 = taosRand();
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU64(&buffer, u64), 0);
|
||||||
|
|
||||||
|
/* float */
|
||||||
|
float f = (float)taosRand() / (float)taosRand();
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutF32(&buffer, f), 0);
|
||||||
|
|
||||||
|
/* double */
|
||||||
|
double d = (double)taosRand() / (double)taosRand();
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutF64(&buffer, d), 0);
|
||||||
|
|
||||||
|
/* binary */
|
||||||
|
uint8_t binary[10];
|
||||||
|
for (int32_t i = 0; i < sizeof(binary); ++i) {
|
||||||
|
binary[i] = taosRand() % UINT8_MAX;
|
||||||
|
}
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutBinary(&buffer, binary, sizeof(binary)), 0);
|
||||||
|
|
||||||
|
/* cstr */
|
||||||
|
const char *cstr = "hello world";
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutCStr(&buffer, cstr), 0);
|
||||||
|
|
||||||
|
/* uint16v_t */
|
||||||
|
uint16_t u16v[] = {0, 127, 128, 129, 16384, 16385, 16386, UINT16_MAX};
|
||||||
|
for (int32_t i = 0; i < sizeof(u16v) / sizeof(u16v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU16v(&buffer, u16v[i]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* uint32v_t */
|
||||||
|
uint32_t u32v[] = {0, 127, 128, 129, 16384, 16385, 16386, (1 << 21) - 1,
|
||||||
|
(1 << 21), (1 << 21) + 1, (1 << 28) - 1, (1 << 28), (1 << 28) + 1, UINT32_MAX};
|
||||||
|
for (int32_t i = 0; i < sizeof(u32v) / sizeof(u32v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU32v(&buffer, u32v[i]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* uint64v_t */
|
||||||
|
uint64_t u64v[] = {0, // 0
|
||||||
|
(1ul << (7 * 1)) - 1,
|
||||||
|
(1ul << (7 * 1)),
|
||||||
|
(1ul << (7 * 1)) + 1,
|
||||||
|
(1ul << (7 * 2)) - 1,
|
||||||
|
(1ul << (7 * 2)),
|
||||||
|
(1ul << (7 * 2)) + 1,
|
||||||
|
(1ul << (7 * 3)) - 1,
|
||||||
|
(1ul << (7 * 3)),
|
||||||
|
(1ul << (7 * 3)) + 1,
|
||||||
|
(1ul << (7 * 4)) - 1,
|
||||||
|
(1ul << (7 * 4)),
|
||||||
|
(1ul << (7 * 4)) + 1,
|
||||||
|
(1ul << (7 * 5)) - 1,
|
||||||
|
(1ul << (7 * 5)),
|
||||||
|
(1ul << (7 * 5)) + 1,
|
||||||
|
(1ul << (7 * 6)) - 1,
|
||||||
|
(1ul << (7 * 6)),
|
||||||
|
(1ul << (7 * 6)) + 1,
|
||||||
|
(1ul << (7 * 7)) - 1,
|
||||||
|
(1ul << (7 * 7)),
|
||||||
|
(1ul << (7 * 7)) + 1,
|
||||||
|
(1ul << (7 * 8)) - 1,
|
||||||
|
(1ul << (7 * 8)),
|
||||||
|
(1ul << (7 * 8)) + 1,
|
||||||
|
(1ul << (7 * 9)) - 1,
|
||||||
|
(1ul << (7 * 9)),
|
||||||
|
(1ul << (7 * 9)) + 1,
|
||||||
|
UINT64_MAX};
|
||||||
|
for (int32_t i = 0; i < sizeof(u64v) / sizeof(u64v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutU64v(&buffer, u64v[i]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int16v_t */
|
||||||
|
int16_t i16v[] = {
|
||||||
|
INT16_MIN, //
|
||||||
|
-((1 << (7 * 1)) - 1),
|
||||||
|
-((1 << (7 * 1))),
|
||||||
|
-((1 << (7 * 1)) + 1),
|
||||||
|
-((1 << (7 * 2)) - 1),
|
||||||
|
-((1 << (7 * 2))),
|
||||||
|
-((1 << (7 * 2)) + 1),
|
||||||
|
(1 << (7 * 0)) - 1,
|
||||||
|
(1 << (7 * 0)),
|
||||||
|
(1 << (7 * 0)) + 1,
|
||||||
|
(1 << (7 * 1)) - 1,
|
||||||
|
(1 << (7 * 1)),
|
||||||
|
(1 << (7 * 1)) + 1,
|
||||||
|
(1 << (7 * 2)) - 1,
|
||||||
|
(1 << (7 * 2)),
|
||||||
|
(1 << (7 * 2)) + 1,
|
||||||
|
INT16_MAX,
|
||||||
|
};
|
||||||
|
for (int32_t i = 0; i < sizeof(i16v) / sizeof(i16v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI16v(&buffer, i16v[i]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int32v_t */
|
||||||
|
int32_t i32v[] = {
|
||||||
|
INT32_MIN, //
|
||||||
|
-((1 << (7 * 1)) - 1),
|
||||||
|
-((1 << (7 * 1))),
|
||||||
|
-((1 << (7 * 1)) + 1),
|
||||||
|
-((1 << (7 * 2)) - 1),
|
||||||
|
-((1 << (7 * 2))),
|
||||||
|
-((1 << (7 * 2)) + 1),
|
||||||
|
-((1 << (7 * 3)) - 1),
|
||||||
|
-((1 << (7 * 3))),
|
||||||
|
-((1 << (7 * 3)) + 1),
|
||||||
|
-((1 << (7 * 4)) - 1),
|
||||||
|
-((1 << (7 * 4))),
|
||||||
|
-((1 << (7 * 4)) + 1),
|
||||||
|
(1 << (7 * 0)) - 1,
|
||||||
|
(1 << (7 * 0)),
|
||||||
|
(1 << (7 * 0)) + 1,
|
||||||
|
(1 << (7 * 1)) - 1,
|
||||||
|
(1 << (7 * 1)),
|
||||||
|
(1 << (7 * 1)) + 1,
|
||||||
|
(1 << (7 * 2)) - 1,
|
||||||
|
(1 << (7 * 2)),
|
||||||
|
(1 << (7 * 2)) + 1,
|
||||||
|
(1 << (7 * 3)) - 1,
|
||||||
|
(1 << (7 * 3)),
|
||||||
|
(1 << (7 * 3)) + 1,
|
||||||
|
(1 << (7 * 4)) - 1,
|
||||||
|
(1 << (7 * 4)),
|
||||||
|
(1 << (7 * 4)) + 1,
|
||||||
|
INT32_MAX,
|
||||||
|
};
|
||||||
|
for (int32_t i = 0; i < sizeof(i32v) / sizeof(i32v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI32v(&buffer, i32v[i]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int64v_t */
|
||||||
|
int64_t i64v[] = {
|
||||||
|
INT64_MIN, //
|
||||||
|
-((1l << (7 * 1)) - 1),
|
||||||
|
-((1l << (7 * 1))),
|
||||||
|
-((1l << (7 * 1)) + 1),
|
||||||
|
-((1l << (7 * 2)) - 1),
|
||||||
|
-((1l << (7 * 2))),
|
||||||
|
-((1l << (7 * 2)) + 1),
|
||||||
|
-((1l << (7 * 3)) - 1),
|
||||||
|
-((1l << (7 * 3))),
|
||||||
|
-((1l << (7 * 3)) + 1),
|
||||||
|
-((1l << (7 * 4)) - 1),
|
||||||
|
-((1l << (7 * 4))),
|
||||||
|
-((1l << (7 * 4)) + 1),
|
||||||
|
-((1l << (7 * 5)) - 1),
|
||||||
|
-((1l << (7 * 5))),
|
||||||
|
-((1l << (7 * 5)) + 1),
|
||||||
|
-((1l << (7 * 6)) - 1),
|
||||||
|
-((1l << (7 * 6))),
|
||||||
|
-((1l << (7 * 6)) + 1),
|
||||||
|
-((1l << (7 * 7)) - 1),
|
||||||
|
-((1l << (7 * 7))),
|
||||||
|
-((1l << (7 * 7)) + 1),
|
||||||
|
-((1l << (7 * 8)) - 1),
|
||||||
|
-((1l << (7 * 8))),
|
||||||
|
-((1l << (7 * 8)) + 1),
|
||||||
|
-((1l << (7 * 9)) + 1),
|
||||||
|
((1l << (7 * 1)) - 1),
|
||||||
|
((1l << (7 * 1))),
|
||||||
|
((1l << (7 * 1)) + 1),
|
||||||
|
((1l << (7 * 2)) - 1),
|
||||||
|
((1l << (7 * 2))),
|
||||||
|
((1l << (7 * 2)) + 1),
|
||||||
|
((1l << (7 * 3)) - 1),
|
||||||
|
((1l << (7 * 3))),
|
||||||
|
((1l << (7 * 3)) + 1),
|
||||||
|
((1l << (7 * 4)) - 1),
|
||||||
|
((1l << (7 * 4))),
|
||||||
|
((1l << (7 * 4)) + 1),
|
||||||
|
((1l << (7 * 5)) - 1),
|
||||||
|
((1l << (7 * 5))),
|
||||||
|
((1l << (7 * 5)) + 1),
|
||||||
|
((1l << (7 * 6)) - 1),
|
||||||
|
((1l << (7 * 6))),
|
||||||
|
((1l << (7 * 6)) + 1),
|
||||||
|
((1l << (7 * 7)) - 1),
|
||||||
|
((1l << (7 * 7))),
|
||||||
|
((1l << (7 * 7)) + 1),
|
||||||
|
((1l << (7 * 8)) - 1),
|
||||||
|
((1l << (7 * 8))),
|
||||||
|
((1l << (7 * 8)) + 1),
|
||||||
|
((1l << (7 * 9)) + 1),
|
||||||
|
INT64_MAX,
|
||||||
|
};
|
||||||
|
for (int32_t i = 0; i < sizeof(i64v) / sizeof(i64v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferPutI64v(&buffer, i64v[i]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
SBufferReader reader;
|
||||||
|
tBufferReaderInit(&reader, 0, &buffer);
|
||||||
|
|
||||||
|
/* fix-len struct */
|
||||||
|
STestStruct testStruct2 = {1, 2};
|
||||||
|
GTEST_ASSERT_EQ(tBufferGet(&reader, sizeof(STestStruct), &testStruct2), 0);
|
||||||
|
GTEST_ASSERT_EQ(testStruct.value1, testStruct2.value1);
|
||||||
|
GTEST_ASSERT_EQ(testStruct.value2, testStruct2.value2);
|
||||||
|
GTEST_ASSERT_EQ(testStruct.value3, testStruct2.value3);
|
||||||
|
|
||||||
|
/* int8_t */
|
||||||
|
int8_t i8_2 = 97;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI8(&reader, &i8_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(i8, i8_2);
|
||||||
|
|
||||||
|
/* int16_t */
|
||||||
|
int16_t i16_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI16(&reader, &i16_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(i16, i16_2);
|
||||||
|
|
||||||
|
/* int32_t */
|
||||||
|
int32_t i32_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI32(&reader, &i32_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(i32, i32_2);
|
||||||
|
|
||||||
|
/* int64_t */
|
||||||
|
int64_t i64_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI64(&reader, &i64_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(i64, i64_2);
|
||||||
|
|
||||||
|
/* uint8_t */
|
||||||
|
uint8_t u8_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU8(&reader, &u8_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(u8, u8_2);
|
||||||
|
|
||||||
|
/* uint16_t */
|
||||||
|
uint16_t u16_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU16(&reader, &u16_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(u16, u16_2);
|
||||||
|
|
||||||
|
/* uint32_t */
|
||||||
|
uint32_t u32_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU32(&reader, &u32_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(u32, u32_2);
|
||||||
|
|
||||||
|
/* uint64_t */
|
||||||
|
uint64_t u64_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU64(&reader, &u64_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(u64, u64_2);
|
||||||
|
|
||||||
|
/* float */
|
||||||
|
float f_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetF32(&reader, &f_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(f, f_2);
|
||||||
|
|
||||||
|
/* double */
|
||||||
|
double d_2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetF64(&reader, &d_2), 0);
|
||||||
|
GTEST_ASSERT_EQ(d, d_2);
|
||||||
|
|
||||||
|
/* binary */
|
||||||
|
const void *binary2;
|
||||||
|
uint32_t binarySize;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetBinary(&reader, &binary2, &binarySize), 0);
|
||||||
|
GTEST_ASSERT_EQ(memcmp(binary, binary2, sizeof(binary)), 0);
|
||||||
|
GTEST_ASSERT_EQ(binarySize, sizeof(binary));
|
||||||
|
|
||||||
|
/* cstr */
|
||||||
|
const char *cstr2;
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetCStr(&reader, &cstr2), 0);
|
||||||
|
GTEST_ASSERT_EQ(strcmp(cstr, cstr2), 0);
|
||||||
|
|
||||||
|
/* uint16v_t */
|
||||||
|
uint16_t u16v2[sizeof(u16v) / sizeof(u16v[0])];
|
||||||
|
for (int32_t i = 0; i < sizeof(u16v) / sizeof(u16v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU16v(&reader, &u16v2[i]), 0);
|
||||||
|
GTEST_ASSERT_EQ(u16v[i], u16v2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* uint32v_t */
|
||||||
|
uint32_t u32v2[sizeof(u32v) / sizeof(u32v[0])];
|
||||||
|
for (int32_t i = 0; i < sizeof(u32v) / sizeof(u32v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU32v(&reader, &u32v2[i]), 0);
|
||||||
|
GTEST_ASSERT_EQ(u32v[i], u32v2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* uint64v_t */
|
||||||
|
uint64_t u64v2[sizeof(u64v) / sizeof(u64v[0])];
|
||||||
|
for (int32_t i = 0; i < sizeof(u64v) / sizeof(u64v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetU64v(&reader, &u64v2[i]), 0);
|
||||||
|
GTEST_ASSERT_EQ(u64v[i], u64v2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int16v_t */
|
||||||
|
int16_t i16v2[sizeof(i16v) / sizeof(i16v[0])];
|
||||||
|
for (int32_t i = 0; i < sizeof(i16v) / sizeof(i16v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI16v(&reader, &i16v2[i]), 0);
|
||||||
|
GTEST_ASSERT_EQ(i16v[i], i16v2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int32v_t */
|
||||||
|
int32_t i32v2[sizeof(i32v) / sizeof(i32v[0])];
|
||||||
|
for (int32_t i = 0; i < sizeof(i32v) / sizeof(i32v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI32v(&reader, &i32v2[i]), 0);
|
||||||
|
GTEST_ASSERT_EQ(i32v[i], i32v2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int64v_t */
|
||||||
|
int64_t i64v2[sizeof(i64v) / sizeof(i64v[0])];
|
||||||
|
for (int32_t i = 0; i < sizeof(i64v) / sizeof(i64v[0]); ++i) {
|
||||||
|
GTEST_ASSERT_EQ(tBufferGetI64v(&reader, &i64v2[i]), 0);
|
||||||
|
GTEST_ASSERT_EQ(i64v[i], i64v2[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tBufferReaderDestroy(&reader);
|
||||||
|
|
||||||
|
// clear
|
||||||
|
tBufferDestroy(&buffer);
|
||||||
|
}
|
Loading…
Reference in New Issue