From f2e1bd55d37c6ebccc3305fbd1c393529dcfe849 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 2 Nov 2022 17:08:15 +0800 Subject: [PATCH] fix: failed to read sdb while udf larger then 10M --- source/dnode/mnode/sdb/src/sdbFile.c | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index b33c01a962..99814f0d5f 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -265,34 +265,48 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { if (ret < 0) { code = TAOS_SYSTEM_ERROR(errno); mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + goto _OVER; } if (ret != readLen) { code = TSDB_CODE_FILE_CORRUPTED; - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen); + goto _OVER; } readLen = pRaw->dataLen + sizeof(int32_t); + if (readLen >= pRaw->dataLen) { + SSdbRaw *pNewRaw = taosMemoryMalloc(pRaw->dataLen + TSDB_MAX_MSG_SIZE); + if (pNewRaw == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed read sdb file since malloc new sdbRaw size:%d failed", pRaw->dataLen + TSDB_MAX_MSG_SIZE); + return -1; + } else { + mInfo("malloc new sdbRaw size:%d, type:%d",pRaw->dataLen + TSDB_MAX_MSG_SIZE, pRaw->type); + } + memcpy(pNewRaw, pRaw, sizeof(SSdbRaw)); + sdbFreeRaw(pRaw); + pRaw = pNewRaw; + } + ret = taosReadFile(pFile, pRaw->pData, readLen); if (ret < 0) { code = TAOS_SYSTEM_ERROR(errno); - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen); + goto _OVER; } if (ret != readLen) { code = TSDB_CODE_FILE_CORRUPTED; - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen); + goto _OVER; } int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t); if ((!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen)) != 0) { code = TSDB_CODE_CHECKSUM_ERROR; - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, readLen:%d", file, tstrerror(code), readLen); + goto _OVER; } code = sdbWriteWithoutFree(pSdb, pRaw); -- GitLab