From 821b3cbc12fce40cc71d31692f9681e82184288e Mon Sep 17 00:00:00 2001 From: lihui Date: Wed, 8 Jan 2020 06:16:05 -0400 Subject: [PATCH] [#1102] --- src/client/inc/tsclient.h | 1 + src/client/src/tscParseInsert.c | 7 ++++--- src/client/src/tscUtil.c | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 6df78f6b7b..9116a7c60b 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -239,6 +239,7 @@ typedef struct STableDataBlocks { int32_t rowSize; // row size for current table uint32_t nAllocSize; + uint32_t headerSize; // header for metadata (submit metadata) uint32_t size; /* diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 04ddee8e05..d9c86a955e 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -579,7 +579,8 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 size_t remain = pDataBlock->nAllocSize - pDataBlock->size; const int factor = 5; uint32_t nAllocSizeOld = pDataBlock->nAllocSize; - + assert(pDataBlock->headerSize >= 0); + // expand the allocated size if (remain < rowSize * factor) { while (remain < rowSize * factor) { @@ -595,12 +596,12 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 //assert(false); // do nothing pDataBlock->nAllocSize = nAllocSizeOld; - *numOfRows = (int32_t)(pDataBlock->nAllocSize) / rowSize; + *numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize; return TSDB_CODE_CLI_OUT_OF_MEMORY; } } - *numOfRows = (int32_t)(pDataBlock->nAllocSize) / rowSize; + *numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize; return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index bc6c73aaae..5116b01418 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -598,6 +598,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff } dataBuf->nAllocSize = (uint32_t)initialSize; + dataBuf->headerSize = startOffset; // the header size will always be the startOffset value, reserved for the subumit block header dataBuf->pData = calloc(1, dataBuf->nAllocSize); dataBuf->ordered = true; dataBuf->prevTS = INT64_MIN; -- GitLab