From 89b4c7a3edb1e819524cf041e0e89071e4c58489 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 12 Aug 2024 13:37:11 +0800 Subject: [PATCH] enh: simulate random i/o error --- source/os/src/osFile.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index db63198a9d..9052669881 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -65,7 +65,6 @@ typedef struct TdFile { #define FILE_WITH_LOCK 1 #ifdef BUILD_WITH_RAND_ERR -#define BUILD_WITH_RAND_IO_ERR #define STUB_RAND_IO_ERR(ret) \ if (tsEnableRandErr) { \ uint32_t r = taosRand() % 10001; \ @@ -75,6 +74,8 @@ typedef struct TdFile { return (ret); \ } \ } +#else +#define STUB_RAND_IO_ERR(ret) #endif void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) { @@ -215,9 +216,7 @@ TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) { } int32_t taosRemoveFile(const char *path) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif int32_t code = remove(path); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -227,9 +226,7 @@ int32_t taosRemoveFile(const char *path) { } int32_t taosRenameFile(const char *oldName, const char *newName) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif #ifdef WINDOWS bool finished = false; @@ -713,9 +710,7 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { } int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); #endif @@ -769,9 +764,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { } int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; @@ -817,9 +810,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { } int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; @@ -901,9 +892,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { } int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -997,9 +986,7 @@ int32_t taosUnLockFile(TdFilePtr pFile) { } int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (NULL == pFile || pFile->fd < 0) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -1060,9 +1047,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { } int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFileOut == NULL || pFileIn == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -1168,9 +1153,7 @@ bool lastErrorIsFileNotExist() { return terrno == TAOS_SYSTEM_ERROR(ENOENT); } #endif // WINDOWS TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(NULL) -#endif FILE *fp = NULL; #ifdef WINDOWS HANDLE hFile = NULL; @@ -1231,9 +1214,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { } int32_t taosCloseFile(TdFilePtr *ppFile) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif int32_t code = 0; if (ppFile == NULL || *ppFile == NULL) { return 0; @@ -1276,9 +1257,7 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { } int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -1341,9 +1320,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) } int32_t taosFsyncFile(TdFilePtr pFile) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFile == NULL) { return 0; } @@ -1408,9 +1385,7 @@ int32_t taosUmaskFile(int32_t maskVal) { } int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif int64_t ret = -1; int32_t code = 0; @@ -1485,9 +1460,7 @@ END: } int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -1638,9 +1611,7 @@ int32_t taosLinkFile(char *src, char *dst) { } FILE *taosOpenCFile(const char *filename, const char *mode) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(NULL) -#endif FILE *f = fopen(filename, mode); if (NULL == f) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -1661,23 +1632,17 @@ int taosSeekCFile(FILE *file, int64_t offset, int whence) { } size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif return fread(buffer, size, count, stream); } size_t taosWriteToCFile(const void *ptr, size_t size, size_t nitems, FILE *stream) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif return fwrite(ptr, size, nitems, stream); } int taosCloseCFile(FILE *f) { -#ifdef BUILD_WITH_RAND_IO_ERR STUB_RAND_IO_ERR(terrno) -#endif return fclose(f); }