enh: simulate random i/o error

This commit is contained in:
kailixu 2024-08-12 13:56:14 +08:00
parent 89b4c7a3ed
commit eda233dd8d
1 changed files with 14 additions and 4 deletions

View File

@ -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) { int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
STUB_RAND_IO_ERR(terrno)
if (pFile == NULL) { if (pFile == NULL) {
terrno = TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;
return terrno; return terrno;
@ -923,6 +922,8 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
*mtime = fileStat.st_mtime; *mtime = fileStat.st_mtime;
} }
STUB_RAND_IO_ERR(terrno)
return 0; return 0;
} }
@ -1214,7 +1215,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
} }
int32_t taosCloseFile(TdFilePtr *ppFile) { int32_t taosCloseFile(TdFilePtr *ppFile) {
STUB_RAND_IO_ERR(terrno)
int32_t code = 0; int32_t code = 0;
if (ppFile == NULL || *ppFile == NULL) { if (ppFile == NULL || *ppFile == NULL) {
return 0; return 0;
@ -1253,6 +1253,11 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
taosMemoryFree(*ppFile); taosMemoryFree(*ppFile);
*ppFile = NULL; *ppFile = NULL;
#if BUILD_WITH_RAND_ERR
if (terrno == 0) {
STUB_RAND_IO_ERR(terrno)
}
#endif
return code; return code;
} }
@ -1642,8 +1647,13 @@ size_t taosWriteToCFile(const void *ptr, size_t size, size_t nitems, FILE *strea
} }
int taosCloseCFile(FILE *f) { int taosCloseCFile(FILE *f) {
STUB_RAND_IO_ERR(terrno) int32_t code = fclose(f);
return 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) { int taosSetAutoDelFile(char *path) {