From 889aa8a11b74b57d165eb0e6ac8cb4d03d9063f6 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 12 Jul 2021 05:10:33 +0000 Subject: [PATCH] code refactor --- src/client/inc/tsclient.h | 14 +++++--------- src/client/src/tscParseInsert.c | 10 +++++----- src/client/src/tscUtil.c | 1 - src/common/inc/tdataformat.h | 5 ++--- src/inc/taosdef.h | 7 ++++--- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 187b7393e6..bb14b28499 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -104,15 +104,11 @@ typedef struct SParsedDataColInfo { } SParsedDataColInfo; typedef struct { - // for SDataRow - SSchema *pSchema; - int16_t sversion; - int32_t flen; - // for SKVRow - uint16_t nCols; - uint16_t size; - void * buf; - + SSchema * pSchema; + int16_t sversion; + int32_t flen; + uint16_t nCols; + void * buf; void * pDataBlock; SSubmitBlk *pSubmitBlk; } SMemRowBuilder; diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 9d50c1c62b..3b21601caf 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -48,7 +48,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat static FORCE_INLINE int32_t getExtendedRowSize(STableComInfo *tinfo) { 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 if (pHelper->allNullLen == 0) { for (uint16_t i = 0; i < nCols; ++i) { @@ -406,7 +406,7 @@ static FORCE_INLINE TDRowLenT tsSetPayloadColValue(char *payloadStart, char *pay payloadColSetId(payload, columnId); payloadColSetType(payload, columnType); memcpy(POINTER_SHIFT(payloadStart,tOffset), value, valueLen); - payloadSetTLen(payloadStart, payloadTLen(payloadStart) + valueLen); + // payloadSetTLen(payloadStart, payloadTLen(payloadStart) + valueLen); return valueLen; } @@ -793,7 +793,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i payloadSetNCols(payload, spd->numOfBound); payloadValOffset = payloadValuesOffset(payload); // rely on payloadNCols - payloadSetTLen(payload, payloadValOffset); + // payloadSetTLen(payload, payloadValOffset); char *kvPrimaryKeyStart = payload + PAYLOAD_HEADER_LEN; // primaryKey in 1st column tuple char *kvStart = kvPrimaryKeyStart + PAYLOAD_COL_HEAD_LEN; // the column tuple behind the primaryKey @@ -1138,7 +1138,7 @@ int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlk size_t nAlloc = nRows * sizeof(SBlockKeyTuple); if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { size_t nRealAlloc = nAlloc + 10 * sizeof(SBlockKeyTuple); - char * tmp = realloc(pBlkKeyInfo->pKeyTuple, nRealAlloc); + char * tmp = trealloc(pBlkKeyInfo->pKeyTuple, nRealAlloc); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1609,7 +1609,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat pColInfo->isOrdered = isOrdered; if (!isOrdered) { - pColInfo->colIdxInfo = calloc(pColInfo->numOfBound, sizeof(SBoundIdxInfo)); + pColInfo->colIdxInfo = tcalloc(pColInfo->numOfBound, sizeof(SBoundIdxInfo)); if (pColInfo->colIdxInfo == NULL) { code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _clean; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index ced48d35b2..40f1b7b2fb 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1829,7 +1829,6 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo rowBuilder.pDataBlock = pDataBlock; rowBuilder.pSubmitBlk = pBlock; rowBuilder.buf = p; - rowBuilder.size = 0; for (int32_t i = 0; i < numOfRows; ++i) { rowBuilder.buf = (blkKeyTuple + i)->payloadAddr; diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 46d13d7094..add2a656f5 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -190,7 +190,7 @@ static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) { // ----------------- Data row structure /* A data row, the format is like below: - * |<--------------------+--------------------------- len ---------------------------------->| + * |<------------------------------------------------ len ---------------------------------->| * |<-- Head -->|<--------- flen -------------->| | * +---------------------+---------------------------------+---------------------------------+ * | uint16_t | int16_t | | | @@ -224,11 +224,10 @@ SDataRow tdDataRowDup(SDataRow row); static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) { ASSERT(value != NULL); int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE; - char * ptr = (char *)POINTER_SHIFT(row, dataRowLen(row)); if (IS_VAR_DATA_TYPE(type)) { *(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); } else { if (offset == 0) { diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 30d79f7116..acebdaa30a 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -196,9 +196,10 @@ do { \ #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. - * So, 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 + * In some scenarios uint16_t (0~65535) is used to store the row len. + * - Firstly, we use 65531(65535 - 4), as the SDataRow and SKVRow including 4 bits header. + * - 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_TAGS_LEN 16384 -- GitLab