enh: simulate random i/o error
This commit is contained in:
parent
410008ac2f
commit
787715a519
|
@ -64,6 +64,7 @@ typedef struct TdFile {
|
|||
|
||||
#define FILE_WITH_LOCK 1
|
||||
|
||||
#define BUILD_WITH_RAND_IO_ERR BUILD_WITH_RAND_ERR
|
||||
#define STUB_RAND_IO_ERR(ret) \
|
||||
if (tsEnableRandErr) { \
|
||||
uint32_t r = taosRand() % 10001; \
|
||||
|
@ -212,7 +213,7 @@ TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) {
|
|||
}
|
||||
|
||||
int32_t taosRemoveFile(const char *path) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
int32_t code = remove(path);
|
||||
|
@ -224,7 +225,7 @@ int32_t taosRemoveFile(const char *path) {
|
|||
}
|
||||
|
||||
int32_t taosRenameFile(const char *oldName, const char *newName) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
|
@ -351,7 +352,7 @@ FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) {
|
|||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
FILE* f = fopen(path, mode);
|
||||
FILE *f = fopen(path, mode);
|
||||
if (NULL == f) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
@ -710,7 +711,7 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) {
|
|||
}
|
||||
|
||||
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
#if FILE_WITH_LOCK
|
||||
|
@ -766,7 +767,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_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFile == NULL) {
|
||||
|
@ -814,7 +815,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_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFile == NULL) {
|
||||
|
@ -898,7 +899,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_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFile == NULL) {
|
||||
|
@ -994,7 +995,7 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
|
|||
}
|
||||
|
||||
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (NULL == pFile || pFile->fd < 0) {
|
||||
|
@ -1057,7 +1058,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_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFileOut == NULL || pFileIn == NULL) {
|
||||
|
@ -1165,7 +1166,7 @@ bool lastErrorIsFileNotExist() { return terrno == TAOS_SYSTEM_ERROR(ENOENT); }
|
|||
#endif // WINDOWS
|
||||
|
||||
TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(NULL)
|
||||
#endif
|
||||
FILE *fp = NULL;
|
||||
|
@ -1228,7 +1229,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
|
|||
}
|
||||
|
||||
int32_t taosCloseFile(TdFilePtr *ppFile) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
int32_t code = 0;
|
||||
|
@ -1273,7 +1274,7 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
|
|||
}
|
||||
|
||||
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFile == NULL) {
|
||||
|
@ -1338,7 +1339,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
}
|
||||
|
||||
int32_t taosFsyncFile(TdFilePtr pFile) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFile == NULL) {
|
||||
|
@ -1405,7 +1406,7 @@ int32_t taosUmaskFile(int32_t maskVal) {
|
|||
}
|
||||
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
int64_t ret = -1;
|
||||
|
@ -1482,7 +1483,7 @@ END:
|
|||
}
|
||||
|
||||
int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
if (pFile == NULL || buf == NULL) {
|
||||
|
@ -1545,13 +1546,13 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
|
|||
bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); };
|
||||
|
||||
int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
||||
int32_t compressSize = 163840;
|
||||
int32_t ret = 0;
|
||||
int32_t len = 0;
|
||||
gzFile dstFp = NULL;
|
||||
int32_t compressSize = 163840;
|
||||
int32_t ret = 0;
|
||||
int32_t len = 0;
|
||||
gzFile dstFp = NULL;
|
||||
TdFilePtr pSrcFile = NULL;
|
||||
|
||||
char *data = taosMemoryMalloc(compressSize);
|
||||
char *data = taosMemoryMalloc(compressSize);
|
||||
if (NULL == data) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -1635,10 +1636,10 @@ int32_t taosLinkFile(char *src, char *dst) {
|
|||
}
|
||||
|
||||
FILE *taosOpenCFile(const char *filename, const char *mode) {
|
||||
#ifdef BUILD_WITH_RAND_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(NULL)
|
||||
#endif
|
||||
FILE* f = fopen(filename, mode);
|
||||
FILE *f = fopen(filename, mode);
|
||||
if (NULL == f) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
@ -1658,21 +1659,21 @@ 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_ERR
|
||||
#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_ERR
|
||||
#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_ERR
|
||||
#ifdef BUILD_WITH_RAND_IO_ERR
|
||||
STUB_RAND_IO_ERR(terrno)
|
||||
#endif
|
||||
return fclose(f);
|
||||
|
|
Loading…
Reference in New Issue