From 30b7a6835843b59b01cbe82180e22e51aaf97a98 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Mon, 1 Jun 2020 09:55:32 +0800 Subject: [PATCH] [TD-458] --- src/tsdb/src/tsdbRWHelper.c | 6 ++++++ src/util/inc/tutil.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index eebe0b6b46..eeb212fe95 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -443,6 +443,11 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { for (uint32_t i = 0; i < pHelper->config.maxTables; i++) { SCompIdx *pCompIdx = pHelper->pCompIdx + i; if (pCompIdx->offset > 0) { + int drift = POINTER_DISTANCE(buf, pHelper->pBuffer); + if (tsizeof(pHelper->pBuffer) - drift < 128) { + pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer)*2); + } + buf = POINTER_SHIFT(pHelper->pBuffer, drift); buf = taosEncodeVariant32(buf, i); buf = tsdbEncodeSCompIdx(buf, pCompIdx); } @@ -469,6 +474,7 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) { ASSERT(pFile->info.offset > TSDB_FILE_HEAD_SIZE); if (lseek(fd, pFile->info.offset, SEEK_SET) < 0) return -1; + if ((pHelper->pBuffer = trealloc(pHelper->pBuffer, pFile->info.len)) == NULL) return -1; if (tread(fd, (void *)(pHelper->pBuffer), pFile->info.len) < pFile->info.len) return -1; if (!taosCheckChecksumWhole((uint8_t *)(pHelper->pBuffer), pFile->info.len)) { diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 5dcb6e406f..255680496a 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -46,6 +46,7 @@ extern "C" { // Pointer p drift right by b bytes #define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) +#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) #ifndef NDEBUG #define ASSERT(x) assert(x)