file function result
This commit is contained in:
parent
6749067c33
commit
9972357c17
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue