提交 889aa8a1 编写于 作者: K kailixu

code refactor

上级 21a8b091
...@@ -104,15 +104,11 @@ typedef struct SParsedDataColInfo { ...@@ -104,15 +104,11 @@ typedef struct SParsedDataColInfo {
} SParsedDataColInfo; } SParsedDataColInfo;
typedef struct { typedef struct {
// for SDataRow SSchema * pSchema;
SSchema *pSchema; int16_t sversion;
int16_t sversion; int32_t flen;
int32_t flen; uint16_t nCols;
// for SKVRow void * buf;
uint16_t nCols;
uint16_t size;
void * buf;
void * pDataBlock; void * pDataBlock;
SSubmitBlk *pSubmitBlk; SSubmitBlk *pSubmitBlk;
} SMemRowBuilder; } SMemRowBuilder;
......
...@@ -48,7 +48,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ...@@ -48,7 +48,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
static FORCE_INLINE int32_t getExtendedRowSize(STableComInfo *tinfo) { static FORCE_INLINE int32_t getExtendedRowSize(STableComInfo *tinfo) {
return tinfo->rowSize + PAYLOAD_HEADER_LEN + PAYLOAD_COL_HEAD_LEN * tinfo->numOfColumns; return tinfo->rowSize + PAYLOAD_HEADER_LEN + PAYLOAD_COL_HEAD_LEN * tinfo->numOfColumns;
} }
int initSMemRowHelper(SMemRowHelper *pHelper, SSchema *pSSchema, uint16_t nCols, uint16_t allNullColsLen) { static int initSMemRowHelper(SMemRowHelper *pHelper, SSchema *pSSchema, uint16_t nCols, uint16_t allNullColsLen) {
pHelper->allNullLen = allNullColsLen; // TODO: get allNullColsLen when creating or altering table meta pHelper->allNullLen = allNullColsLen; // TODO: get allNullColsLen when creating or altering table meta
if (pHelper->allNullLen == 0) { if (pHelper->allNullLen == 0) {
for (uint16_t i = 0; i < nCols; ++i) { for (uint16_t i = 0; i < nCols; ++i) {
...@@ -406,7 +406,7 @@ static FORCE_INLINE TDRowLenT tsSetPayloadColValue(char *payloadStart, char *pay ...@@ -406,7 +406,7 @@ static FORCE_INLINE TDRowLenT tsSetPayloadColValue(char *payloadStart, char *pay
payloadColSetId(payload, columnId); payloadColSetId(payload, columnId);
payloadColSetType(payload, columnType); payloadColSetType(payload, columnType);
memcpy(POINTER_SHIFT(payloadStart,tOffset), value, valueLen); memcpy(POINTER_SHIFT(payloadStart,tOffset), value, valueLen);
payloadSetTLen(payloadStart, payloadTLen(payloadStart) + valueLen); // payloadSetTLen(payloadStart, payloadTLen(payloadStart) + valueLen);
return valueLen; return valueLen;
} }
...@@ -793,7 +793,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i ...@@ -793,7 +793,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
payloadSetNCols(payload, spd->numOfBound); payloadSetNCols(payload, spd->numOfBound);
payloadValOffset = payloadValuesOffset(payload); // rely on payloadNCols payloadValOffset = payloadValuesOffset(payload); // rely on payloadNCols
payloadSetTLen(payload, payloadValOffset); // payloadSetTLen(payload, payloadValOffset);
char *kvPrimaryKeyStart = payload + PAYLOAD_HEADER_LEN; // primaryKey in 1st column tuple char *kvPrimaryKeyStart = payload + PAYLOAD_HEADER_LEN; // primaryKey in 1st column tuple
char *kvStart = kvPrimaryKeyStart + PAYLOAD_COL_HEAD_LEN; // the column tuple behind the primaryKey char *kvStart = kvPrimaryKeyStart + PAYLOAD_COL_HEAD_LEN; // the column tuple behind the primaryKey
...@@ -1138,7 +1138,7 @@ int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlk ...@@ -1138,7 +1138,7 @@ int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlk
size_t nAlloc = nRows * sizeof(SBlockKeyTuple); size_t nAlloc = nRows * sizeof(SBlockKeyTuple);
if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) {
size_t nRealAlloc = nAlloc + 10 * sizeof(SBlockKeyTuple); size_t nRealAlloc = nAlloc + 10 * sizeof(SBlockKeyTuple);
char * tmp = realloc(pBlkKeyInfo->pKeyTuple, nRealAlloc); char * tmp = trealloc(pBlkKeyInfo->pKeyTuple, nRealAlloc);
if (tmp == NULL) { if (tmp == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -1609,7 +1609,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ...@@ -1609,7 +1609,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
pColInfo->isOrdered = isOrdered; pColInfo->isOrdered = isOrdered;
if (!isOrdered) { if (!isOrdered) {
pColInfo->colIdxInfo = calloc(pColInfo->numOfBound, sizeof(SBoundIdxInfo)); pColInfo->colIdxInfo = tcalloc(pColInfo->numOfBound, sizeof(SBoundIdxInfo));
if (pColInfo->colIdxInfo == NULL) { if (pColInfo->colIdxInfo == NULL) {
code = TSDB_CODE_TSC_OUT_OF_MEMORY; code = TSDB_CODE_TSC_OUT_OF_MEMORY;
goto _clean; goto _clean;
......
...@@ -1829,7 +1829,6 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo ...@@ -1829,7 +1829,6 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
rowBuilder.pDataBlock = pDataBlock; rowBuilder.pDataBlock = pDataBlock;
rowBuilder.pSubmitBlk = pBlock; rowBuilder.pSubmitBlk = pBlock;
rowBuilder.buf = p; rowBuilder.buf = p;
rowBuilder.size = 0;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
rowBuilder.buf = (blkKeyTuple + i)->payloadAddr; rowBuilder.buf = (blkKeyTuple + i)->payloadAddr;
......
...@@ -190,7 +190,7 @@ static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) { ...@@ -190,7 +190,7 @@ static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) {
// ----------------- Data row structure // ----------------- Data row structure
/* A data row, the format is like below: /* A data row, the format is like below:
* |<--------------------+--------------------------- len ---------------------------------->| * |<------------------------------------------------ len ---------------------------------->|
* |<-- Head -->|<--------- flen -------------->| | * |<-- Head -->|<--------- flen -------------->| |
* +---------------------+---------------------------------+---------------------------------+ * +---------------------+---------------------------------+---------------------------------+
* | uint16_t | int16_t | | | * | uint16_t | int16_t | | |
...@@ -224,11 +224,10 @@ SDataRow tdDataRowDup(SDataRow row); ...@@ -224,11 +224,10 @@ SDataRow tdDataRowDup(SDataRow row);
static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) { static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) {
ASSERT(value != NULL); ASSERT(value != NULL);
int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE; int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE;
char * ptr = (char *)POINTER_SHIFT(row, dataRowLen(row));
if (IS_VAR_DATA_TYPE(type)) { if (IS_VAR_DATA_TYPE(type)) {
*(VarDataOffsetT *)POINTER_SHIFT(row, toffset) = dataRowLen(row); *(VarDataOffsetT *)POINTER_SHIFT(row, toffset) = dataRowLen(row);
memcpy(ptr, value, varDataTLen(value)); memcpy(POINTER_SHIFT(row, dataRowLen(row)), value, varDataTLen(value));
dataRowLen(row) += varDataTLen(value); dataRowLen(row) += varDataTLen(value);
} else { } else {
if (offset == 0) { if (offset == 0) {
......
...@@ -196,9 +196,10 @@ do { \ ...@@ -196,9 +196,10 @@ do { \
#define TSDB_APPNAME_LEN TSDB_UNI_LEN #define TSDB_APPNAME_LEN TSDB_UNI_LEN
/** /**
* Don't change to 65536. As in some scenarios uint16_t (0~65535) is used to store the row len. * In some scenarios uint16_t (0~65535) is used to store the row len.
* So, we use 65531(65535 - 4), as the SDataRow and SKVRow including 4 bits header. * - Firstly, we use 65531(65535 - 4), as the SDataRow and SKVRow including 4 bits header.
* If all cols are VarType except primary key, we need 4 bits to store the offset. 65531-8-4095*4=49143 * - Secondly, if all cols are VarType except primary key, we need 4 bits to store the offset, thus
* the final value is 65531-8-4095*4 = 49143.
*/ */
#define TSDB_MAX_BYTES_PER_ROW 49143 #define TSDB_MAX_BYTES_PER_ROW 49143
#define TSDB_MAX_TAGS_LEN 16384 #define TSDB_MAX_TAGS_LEN 16384
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册