From 9972357c17b020291c91ffcbbc97ded48b7a167d Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Thu, 26 Sep 2024 18:13:52 +0800 Subject: [PATCH] file function result --- source/libs/executor/src/groupcacheoperator.c | 8 ++--- source/libs/index/inc/indexFstFile.h | 4 +-- source/libs/index/src/indexFstFile.c | 6 ++-- source/libs/index/src/indexTfile.c | 12 ++++---- source/libs/wal/src/walRead.c | 4 +-- source/libs/wal/src/walWrite.c | 30 +++++++++---------- source/os/src/osRand.c | 2 +- source/os/src/osSysinfo.c | 4 +-- source/os/test/osStringTests.cpp | 2 +- source/util/src/tpagedbuf.c | 11 ++++--- 10 files changed, 41 insertions(+), 42 deletions(-) diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index e4f6d73b7b..d785a1e619 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -333,14 +333,14 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC continue; } - int32_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET); + int64_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET); if (ret < 0) { releaseFdToFileCtx(pFd); code = terrno; goto _return; } - ret = (int32_t)taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize); + ret = taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize); if (ret != pHead->basic.bufSize) { releaseFdToFileCtx(pFd); code = terrno; @@ -578,7 +578,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } - int32_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET); + int64_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET); if (ret < 0) { code = terrno; goto _return; @@ -590,7 +590,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa goto _return; } - ret = (int32_t)taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize); + ret = taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize); if (ret != pBasic->bufSize) { taosMemoryFreeClear(*ppBuf); code = terrno; diff --git a/source/libs/index/inc/indexFstFile.h b/source/libs/index/inc/indexFstFile.h index b1ff4fee34..145e1040cd 100644 --- a/source/libs/index/inc/indexFstFile.h +++ b/source/libs/index/inc/indexFstFile.h @@ -33,7 +33,7 @@ typedef struct IFileCtx { int (*write)(struct IFileCtx* ctx, uint8_t* buf, int len); int (*read)(struct IFileCtx* ctx, uint8_t* buf, int len); int (*flush)(struct IFileCtx* ctx); - int (*readFrom)(struct IFileCtx* ctx, uint8_t* buf, int len, int32_t offset); + int64_t (*readFrom)(struct IFileCtx* ctx, uint8_t* buf, int len, int32_t offset); int (*size)(struct IFileCtx* ctx); SLRUCache* lru; @@ -64,7 +64,7 @@ typedef struct IFileCtx { static int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len); static int idxFileCtxDoRead(IFileCtx* ctx, uint8_t* buf, int len); -static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset); +static int64_t idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset); static int idxFileCtxDoFlush(IFileCtx* ctx); IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity); diff --git a/source/libs/index/src/indexFstFile.c b/source/libs/index/src/indexFstFile.c index 73ecb22b3b..793aaa810e 100644 --- a/source/libs/index/src/indexFstFile.c +++ b/source/libs/index/src/indexFstFile.c @@ -96,8 +96,8 @@ static FORCE_INLINE int idxFileCtxDoRead(IFileCtx* ctx, uint8_t* buf, int len) { return nRead; } -static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset) { - int32_t total = 0, nread = 0; +static int64_t idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset) { + int64_t total = 0, nread = 0; int32_t blkId = offset / kBlockSize; int32_t blkOffset = offset % kBlockSize; int32_t blkLeft = kBlockSize - blkOffset; @@ -122,7 +122,7 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of int32_t left = ctx->file.size - offset; if (left < kBlockSize) { nread = TMIN(left, len); - int32_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset); + int64_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset); if (bytes != nread) { total = TSDB_CODE_INDEX_INVALID_FILE; break; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 1130243e27..e2693ff4a4 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -45,7 +45,7 @@ static int tfileWriteFooter(TFileWriter* write); // handle file corrupt later static int tfileReaderLoadHeader(TFileReader* reader); -static int tfileReaderLoadFst(TFileReader* reader); +static int32_t tfileReaderLoadFst(TFileReader* reader); static int tfileReaderVerify(TFileReader* reader); static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result); @@ -1022,7 +1022,7 @@ static int tfileReaderLoadHeader(TFileReader* reader) { int64_t nread = reader->ctx->readFrom(reader->ctx, (uint8_t*)buf, sizeof(buf), 0); - if (nread == -1) { + if (nread < 0) { indexError("actual Read: %d, to read: %d, code:0x%x, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.buf); } else { @@ -1032,7 +1032,7 @@ static int tfileReaderLoadHeader(TFileReader* reader) { return 0; } -static int tfileReaderLoadFst(TFileReader* reader) { +static int32_t tfileReaderLoadFst(TFileReader* reader) { IFileCtx* ctx = reader->ctx; int size = ctx->size(ctx); @@ -1040,7 +1040,7 @@ static int tfileReaderLoadFst(TFileReader* reader) { int fstSize = size - reader->header.fstOffset - sizeof(FILE_MAGIC_NUMBER); char* buf = taosMemoryCalloc(1, fstSize); if (buf == NULL) { - return -1; + return terrno; } int64_t ts = taosGetTimestampUs(); @@ -1058,7 +1058,7 @@ static int tfileReaderLoadFst(TFileReader* reader) { taosMemoryFree(buf); fstSliceDestroy(&st); - return reader->fst != NULL ? 0 : -1; + return reader->fst != NULL ? 0 : TSDB_CODE_INDEX_INVALID_FILE; } static int32_t tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result) { // TODO(yihao): opt later @@ -1067,7 +1067,7 @@ static int32_t tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArr IFileCtx* ctx = reader->ctx; // add block cache char block[4096] = {0}; - int32_t nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset); + int64_t nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset); if (nread < sizeof(uint32_t)) { return TSDB_CODE_INDEX_INVALID_FILE; } diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index d3df76f687..610adfb0e1 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -313,8 +313,8 @@ int32_t walSkipFetchBody(SWalReader *pRead) { if (pRead->pWal->cfg.encryptAlgorithm == 1) { cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen); } - int64_t code = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR); - if (code < 0) { + int64_t ret = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR); + if (ret < 0) { TAOS_RETURN(terrno); } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index b89c233465..c8c37b11bc 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -109,20 +109,20 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { char fnameStr[WAL_FILE_LEN]; if (pWal->pLogFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) { - TAOS_RETURN(terrno); + return -1; } code = taosCloseFile(&pWal->pLogFile); if (code != 0) { - TAOS_RETURN(terrno); + return -1; } } if (pWal->pIdxFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) { - TAOS_RETURN(terrno); + return -1; } code = taosCloseFile(&pWal->pIdxFile); if (code != 0) { - TAOS_RETURN(terrno); + return -1; } } @@ -139,7 +139,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { if (pIdxTFile == NULL) { pWal->pIdxFile = NULL; - TAOS_RETURN(terrno); + return -1; } walBuildLogName(pWal, fileFirstVer, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); @@ -147,7 +147,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { TAOS_UNUSED(taosCloseFile(&pIdxTFile)); pWal->pLogFile = NULL; - TAOS_RETURN(terrno); + return -1; } pWal->pLogFile = pLogTFile; @@ -160,7 +160,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { int32_t walRollback(SWal *pWal, int64_t ver) { TAOS_UNUSED(taosThreadRwlockWrlock(&pWal->mutex)); wInfo("vgId:%d, wal rollback for version %" PRId64, pWal->cfg.vgId, ver); - int64_t code; + int64_t ret; char fnameStr[WAL_FILE_LEN]; if (ver > pWal->vers.lastVer || ver <= pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) { TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); @@ -171,11 +171,11 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // find correct file if (ver < walGetLastFileFirstVer(pWal)) { // change current files - code = walChangeWrite(pWal, ver); - if (code < 0) { + ret = walChangeWrite(pWal, ver); + if (ret < 0) { TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); - TAOS_RETURN(code); + TAOS_RETURN(terrno); } // delete files in descending order @@ -205,8 +205,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) { TAOS_RETURN(terrno); } int64_t idxOff = walGetVerIdxOffset(pWal, ver); - code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET); - if (code < 0) { + ret = taosLSeekFile(pIdxFile, idxOff, SEEK_SET); + if (ret < 0) { TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); TAOS_RETURN(terrno); @@ -229,8 +229,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) { TAOS_RETURN(terrno); } - code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET); - if (code < 0) { + ret = taosLSeekFile(pLogFile, entry.offset, SEEK_SET); + if (ret < 0) { // TODO TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); @@ -244,7 +244,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { TAOS_RETURN(terrno); } - code = walValidHeadCksum(&head); + int32_t code = walValidHeadCksum(&head); if (code != 0) { TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); diff --git a/source/os/src/osRand.c b/source/os/src/osRand.c index b99017782b..0bf67f96a0 100644 --- a/source/os/src/osRand.c +++ b/source/os/src/osRand.c @@ -65,7 +65,7 @@ uint32_t taosSafeRand(void) { if (pFile == NULL) { seed = (int)taosGetTimestampSec(); } else { - int len = taosReadFile(pFile, &seed, sizeof(seed)); + int64_t len = taosReadFile(pFile, &seed, sizeof(seed)); if (len < 0) { seed = (int)taosGetTimestampSec(); } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 4d97232806..cb6d3a7736 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -1057,7 +1057,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { int n = snprintf(uid, uidlen, "%.*s", (int)sizeof(buf), buf); // though less performance, much safer return 0; #else - int len = 0; + int64_t len = 0; // fd = open("/proc/sys/kernel/random/uuid", 0); TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ); @@ -1067,7 +1067,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { len = taosReadFile(pFile, uid, uidlen); TAOS_SKIP_ERROR(taosCloseFile(&pFile)); if (len < 0) { - return len; + return terrno; } } diff --git a/source/os/test/osStringTests.cpp b/source/os/test/osStringTests.cpp index 5e07636b1f..9565e568fb 100644 --- a/source/os/test/osStringTests.cpp +++ b/source/os/test/osStringTests.cpp @@ -74,7 +74,7 @@ TEST(osStringTests, strsepNullInput) { TEST(osStringTests, strndupNormalInput) { const char s[] = "This is a test string."; int size = strlen(s) + 1; - char * s2 = strndup(s, size); + char * s2 = taosStrndup(s, size); EXPECT_STREQ(s, s2); diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 25e10a17df..fb8e597163 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -134,9 +134,8 @@ static uint64_t allocateNewPositionInFile(SDiskbasedBuf* pBuf, size_t size) { static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize + POINTER_BYTES + sizeof(SFilePage); } static int32_t doFlushBufPageImpl(SDiskbasedBuf* pBuf, int64_t offset, const char* pData, int32_t size) { - int32_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET); - if (ret == -1) { - terrno = terrno; + int64_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET); + if (ret < 0) { return terrno; } @@ -246,14 +245,14 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { return TSDB_CODE_INVALID_PARA; } - int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); - if (ret == -1) { + int64_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); + if (ret < 0) { ret = terrno; return ret; } void* pPage = (void*)GET_PAYLOAD_DATA(pg); - ret = (int32_t)taosReadFile(pBuf->pFile, pPage, pg->length); + ret = taosReadFile(pBuf->pFile, pPage, pg->length); if (ret != pg->length) { ret = terrno; return ret;