From 0d9cf34882fc380978fb605e477bb4f87115e47e Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 30 Jun 2021 18:52:26 +0800 Subject: [PATCH] SKVRow offset bug fix --- src/client/src/tscUtil.c | 9 +++------ src/common/inc/tdataformat.h | 6 +++--- src/common/src/tdataformat.c | 3 ++- src/tsdb/src/tsdbRead.c | 3 ++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 2c53d90cea..c05c5e3d3b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1667,7 +1667,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i // pBuilder->size = 0; // } -#define KvRowNColsThresh 1 // default value: 32 TODO: for test, restore to 32 after test finished +#define KvRowNColsThresh 1 // default value: 128 TODO: for test, restore to default value after test finished static FORCE_INLINE uint8_t tdRowTypeJudger(SSchema* pSchema, void* pData, int32_t nCols, int32_t flen, uint16_t* nColsNotNull) { @@ -1724,7 +1724,6 @@ SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) { uint16_t nColsNotNull = 0; uint8_t memRowType = tdRowTypeJudger(pSchema, p, pBuilder->nCols, pBuilder->flen, &nColsNotNull); tscDebug("prop:memType is %d", memRowType); - memRowType = SMEM_ROW_DATA; SMemRow* memRow = (SMemRow)pBuilder->pDataBlock; memRowSetType(memRow, memRowType); @@ -1744,12 +1743,10 @@ SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) { pBuilder->buf = p; } else if (memRowType == SMEM_ROW_KV) { ASSERT(nColsNotNull < pBuilder->nCols); - - uint16_t tlen = TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nColsNotNull + pBuilder->size; SKVRow kvRow = (SKVRow)memRowBody(memRow); - - kvRowSetNCols(kvRow, nColsNotNull); + uint16_t tlen = TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nColsNotNull; kvRowSetLen(kvRow, tlen); + kvRowSetNCols(kvRow, nColsNotNull); int toffset = 0; p = (char*)pBuilder->buf; diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 5c3ccdd781..ca8b4d33da 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -214,7 +214,7 @@ typedef void *SMemRow; #define TD_DATA_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t)) #define dataRowLen(r) (*(uint16_t *)(r)) -#define dataRowVersion(r) *(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)) +#define dataRowVersion(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t))) #define dataRowTuple(r) POINTER_SHIFT(r, TD_DATA_ROW_HEAD_SIZE) #define dataRowTKey(r) (*(TKEY *)(dataRowTuple(r))) #define dataRowKey(r) tdGetKey(dataRowTKey(r)) @@ -425,7 +425,7 @@ typedef struct { #define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(uint16_t))) #define kvRowSetLen(r, len) kvRowLen(r) = (len) #define kvRowSetNCols(r, n) kvRowNCols(r) = (n) -#define kvRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE) +#define kvRowColIdx(r) ((SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE)) #define kvRowValues(r) POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * kvRowNCols(r)) #define kvRowCpy(dst, r) memcpy((dst), (r), kvRowLen(r)) #define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset) @@ -468,7 +468,7 @@ static FORCE_INLINE int tdAppendKvColVal(SKVRow row, const void *value, int16_t char * ptr = (char *)POINTER_SHIFT(row, kvRowLen(row)); pColIdx->colId = colId; - pColIdx->offset = kvRowLen(row); + pColIdx->offset = kvRowLen(row); // offset of pColIdx including the TD_KV_ROW_HEAD_SIZE if (IS_VAR_DATA_TYPE(type)) { memcpy(ptr, value, varDataTLen(value)); diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index ac7b15ea02..2a19d504dd 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -527,7 +527,8 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo int nRowColsMatched = 0; STColumn stColumn[nRowCols]; tdGetKVRowColInfo(pSchema, kvRowColIdx(row), nRowCols, stColumn, &nRowColsMatched); - uDebug("kvRow: nRowCols=%d, nRowColsMatched=%d, nSchemaCols=%d", nRowCols, nRowColsMatched, schemaNCols(pSchema)); + uDebug("prop:kvRow: nRowCols=%d, nRowColsMatched=%d, nSchemaCols=%d", nRowCols, nRowColsMatched, + schemaNCols(pSchema)); while (dcol < pCols->numOfCols) { SDataCol *pDataCol = &(pCols->cols[dcol]); diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index faf099cdd2..27502f67f7 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1550,7 +1550,8 @@ static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity, if (pColIdx->colId == pColInfo->info.colId) { STColumn* pSTColumn = tdGetColOfID(pSchema, pColIdx->colId); if (pSTColumn != NULL) { - void* value = tdGetKvRowDataOfCol(row, pSTColumn->type, TD_MEM_ROW_HEAD_SIZE + pColIdx->offset); + // offset of pColIdx including the TD_KV_ROW_HEAD_SIZE + void* value = tdGetKvRowDataOfCol(kvRow, pSTColumn->type, pColIdx->offset); switch (pColInfo->info.type) { case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: -- GitLab