From 88dd38aac11f9b83312c582583cb5731e31fbd39 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 4 Jul 2020 18:10:42 +0800 Subject: [PATCH] add lseek random failure. --- src/query/src/qExecutor.c | 1 + src/tsdb/src/tsdbFile.c | 1 + src/tsdb/src/tsdbRWHelper.c | 1 + src/util/inc/tfile.h | 2 ++ src/util/src/tfile.c | 12 ++++++++++++ src/util/src/tkvstore.c | 3 ++- 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 8156967d5d..9f0b0b67b1 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -27,6 +27,7 @@ #include "exception.h" #include "tscompression.h" #include "ttime.h" +#include "tfile.h" /** * check if the primary column is load by default, otherwise, the program will diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 33eae639b8..95cc47292b 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -28,6 +28,7 @@ #include "tsdbMain.h" #include "tutil.h" #include "ttime.h" +#include "tfile.h" const char *tsdbFileSuffix[] = {".head", ".data", ".last", "", ".h", ".l"}; diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 934fa8e733..eab9a5e056 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -19,6 +19,7 @@ #include "tcoding.h" #include "tscompression.h" #include "tsdbMain.h" +#include "tfile.h" #define TSDB_GET_COMPCOL_LEN(nCols) (sizeof(SCompData) + sizeof(SCompCol) * (nCols) + sizeof(TSCKSUM)) diff --git a/src/util/inc/tfile.h b/src/util/inc/tfile.h index 566a429d32..5bddc76266 100644 --- a/src/util/inc/tfile.h +++ b/src/util/inc/tfile.h @@ -20,9 +20,11 @@ ssize_t taos_tread(int fd, void *buf, size_t count); ssize_t taos_twrite(int fd, void *buf, size_t count); +off_t taos_lseek(int fd, off_t offset, int whence); #define tread(fd, buf, count) taos_tread(fd, buf, count) #define twrite(fd, buf, count) taos_twrite(fd, buf, count) +#define lseek(fd, offset, whence) taos_lseek(fd, offset, whence) #endif // TAOS_RANDOM_FILE_FAIL diff --git a/src/util/src/tfile.c b/src/util/src/tfile.c index 200d0f8af5..97eeda010e 100644 --- a/src/util/src/tfile.c +++ b/src/util/src/tfile.c @@ -51,3 +51,15 @@ ssize_t taos_twrite(int fd, void *buf, size_t count) return twrite(fd, buf, count); } + +off_t taos_lseek(int fd, off_t offset, int whence) +{ +#ifdef TAOS_RANDOM_FILE_FAIL + if (rand() % RANDOM_FACTOR == 0) { + errno = EIO; + return -1; + } +#endif + + return lseek(fd, offset, whence); +} diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index f33941376f..2a24a59742 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -27,6 +27,7 @@ #include "tcoding.h" #include "tkvstore.h" #include "tulog.h" +#include "tfile.h" #define TD_KVSTORE_HEADER_SIZE 512 #define TD_KVSTORE_MAJOR_VERSION 1 @@ -581,4 +582,4 @@ _err: taosHashDestroyIter(pIter); tfree(buf); return -1; -} \ No newline at end of file +}