From b628b891e4effe8c1929aa689ac73755feb0623e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Jul 2020 14:44:31 +0800 Subject: [PATCH] [TD-992] --- src/os/inc/osFile.h | 27 ++++++++++-------- src/os/inc/osMemory.h | 55 +++++++++++++++++++++---------------- src/os/inc/osSocket.h | 26 ++++++++++-------- src/tsdb/src/tsdbFile.c | 2 +- src/tsdb/src/tsdbMain.c | 3 -- src/tsdb/src/tsdbRWHelper.c | 1 + src/util/src/tkvstore.c | 1 + src/util/src/tlog.c | 3 -- src/util/src/tnote.c | 4 +-- src/wal/src/walMain.c | 1 + 10 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h index 4f4d9e8aed..c43428ab82 100644 --- a/src/os/inc/osFile.h +++ b/src/os/inc/osFile.h @@ -30,19 +30,24 @@ int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) #define taosFSendFile(outfile, infile, offset, count) taosTSendFileImp(fileno(outfile), fileno(infile), offset, size) -#ifndef TAOS_RANDOM_FILE_FAIL - #define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) - #define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) - #define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) -#else +#define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) +#define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) +#define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) + +#ifdef TAOS_RANDOM_FILE_FAIL void taosSetRandomFileFailFactor(int factor); void taosSetRandomFileFailOutput(const char *path); - ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); - ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); - off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line); - #define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) + #ifdef TAOS_RANDOM_FILE_FAIL_TEST + ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); + ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); + off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line); + #undef taosTRead + #undef taosTWrite + #undef taosLSeek + #define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) + #define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) + #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) + #endif #endif // TAOS_OS_FUNC_FILE_GETTMPFILEPATH diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index eb2ff02f77..aaac8c68e3 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -46,29 +46,38 @@ void taosTMemset(void *ptr, int c); } \ } while (0); -#ifndef TAOS_MEM_CHECK - #define taosMalloc(size) malloc(size) - #define taosCalloc(num, size) calloc(num, size) - #define taosRealloc(ptr, size) realloc(ptr, size) - #define taosFree(ptr) free(ptr) - #define taosStrdup(str) taosStrdupImp(str) - #define taosStrndup(str, size) taosStrndupImp(str, size) - #define taosGetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) -#else - void * taos_malloc(size_t size, const char *file, uint32_t line); - void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line); - void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line); - void taos_free(void *ptr, const char *file, uint32_t line); - char * taos_strdup(const char *str, const char *file, uint32_t line); - char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line); - ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line); - #define taosMalloc(size) taos_malloc(size, __FILE__, __LINE__) - #define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) - #define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) - #define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__) - #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) - #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) - #define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) +#define taosMalloc(size) malloc(size) +#define taosCalloc(num, size) calloc(num, size) +#define taosRealloc(ptr, size) realloc(ptr, size) +#define taosFree(ptr) free(ptr) +#define taosStrdup(str) taosStrdupImp(str) +#define taosStrndup(str, size) taosStrndupImp(str, size) +#define taosGetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) + +#ifdef TAOS_MEM_CHECK + #ifdef TAOS_MEM_CHECK_TEST + void * taos_malloc(size_t size, const char *file, uint32_t line); + void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line); + void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line); + void taos_free(void *ptr, const char *file, uint32_t line); + char * taos_strdup(const char *str, const char *file, uint32_t line); + char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line); + ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line); + #undef taosMalloc + #undef taosCalloc + #undef taosRealloc + #undef taosFree + #undef taosStrdup + #undef taosStrndup + #undef taosGetline + #define taosMalloc(size) taos_malloc(size, __FILE__, __LINE__) + #define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) + #define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) + #define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__) + #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) + #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) + #define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) + #endif #endif #ifdef __cplusplus diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index f013ae4a3a..749d3906f5 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -35,18 +35,20 @@ extern "C" { #define taosClose(x) taosCloseSocket(x) #ifdef TAOS_RANDOM_NETWORK_FAIL - ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags); - ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); - ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count); - ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count); - #undef taosSend - #undef taosSendto - #undef taosReadSocket - #undef taosWriteSocket - #define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags) - #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen) - #define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len) - #define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len) + #ifdef TAOS_RANDOM_NETWORK_FAIL_TEST + ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags); + ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); + ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count); + ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count); + #undef taosSend + #undef taosSendto + #undef taosReadSocket + #undef taosWriteSocket + #define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags) + #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen) + #define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len) + #define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len) + #endif #endif // TAOS_OS_FUNC_SOCKET diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 299802f9b4..e3800f8117 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -14,11 +14,11 @@ */ #define _DEFAULT_SOURCE #include "os.h" - #include "talgo.h" #include "tchecksum.h" #include "tsdbMain.h" #include "tutil.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #ifdef TSDB_IDX const char *tsdbFileSuffix[] = {".idx", ".head", ".data", ".last", "", ".i", ".h", ".l"}; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index e23228cc0e..0d7a2866b7 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -14,8 +14,6 @@ */ // no test file errors here -#undef TAOS_RANDOM_FILE_FAIL - #include "tsdbMain.h" #include "os.h" #include "talgo.h" @@ -25,7 +23,6 @@ #include "tsdb.h" #include "tulog.h" - #define TSDB_CFG_FILE_NAME "config" #define TSDB_DATA_DIR_NAME "data" #define TSDB_META_FILE_NAME "meta" diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 9a96ec62e2..6e14a86bd7 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -20,6 +20,7 @@ #include "tcoding.h" #include "tscompression.h" #include "tsdbMain.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #define TSDB_GET_COMPCOL_LEN(nCols) (sizeof(SCompData) + sizeof(SCompCol) * (nCols) + sizeof(TSCKSUM)) #define TSDB_KEY_COL_OFFSET 0 diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index 2cea295c82..edcf9d45f2 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -21,6 +21,7 @@ #include "tcoding.h" #include "tkvstore.h" #include "tulog.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #define TD_KVSTORE_HEADER_SIZE 512 #define TD_KVSTORE_MAJOR_VERSION 1 diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 6bba8885b1..913989bf52 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -14,9 +14,6 @@ */ #define _DEFAULT_SOURCE -// no test file errors here -#undef TAOS_RANDOM_FILE_FAIL - #include "os.h" #include "tulog.h" #include "tlog.h" diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 91916c92d7..ea09709449 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -13,9 +13,7 @@ * along with this program. If not, see . */ -// no test file errors here -#undef TAOS_RANDOM_FILE_FAIL - +#include "os.h" #include "tnote.h" taosNoteInfo m_HttpNote; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index a8f88c7be9..4ac8a096c6 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -22,6 +22,7 @@ #include "taoserror.h" #include "twal.h" #include "tqueue.h" +#define TAOS_RANDOM_FILE_FAIL_TEST #define walPrefix "wal"