From eda233dd8d37e84fe0d1e444d5a382e5bdf67e03 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 12 Aug 2024 13:56:14 +0800 Subject: [PATCH] enh: simulate random i/o error --- source/os/src/osFile.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 9052669881..6c4b8aa768 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -892,7 +892,6 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { } int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { - STUB_RAND_IO_ERR(terrno) if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -923,6 +922,8 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { *mtime = fileStat.st_mtime; } + STUB_RAND_IO_ERR(terrno) + return 0; } @@ -1214,7 +1215,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { } int32_t taosCloseFile(TdFilePtr *ppFile) { - STUB_RAND_IO_ERR(terrno) int32_t code = 0; if (ppFile == NULL || *ppFile == NULL) { return 0; @@ -1253,6 +1253,11 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { taosMemoryFree(*ppFile); *ppFile = NULL; +#if BUILD_WITH_RAND_ERR + if (terrno == 0) { + STUB_RAND_IO_ERR(terrno) + } +#endif return code; } @@ -1642,8 +1647,13 @@ size_t taosWriteToCFile(const void *ptr, size_t size, size_t nitems, FILE *strea } int taosCloseCFile(FILE *f) { - STUB_RAND_IO_ERR(terrno) - return fclose(f); + int32_t code = fclose(f); +#if BUILD_WITH_RAND_ERR + if (code == 0) { + STUB_RAND_IO_ERR(terrno) + } +#endif + return code == 0 ? code : TAOS_SYSTEM_ERROR(errno); } int taosSetAutoDelFile(char *path) {