From 1c2072eb80307cc4d286d7128256a7d78a620556 Mon Sep 17 00:00:00 2001 From: Yaming Pei Date: Fri, 7 Mar 2025 13:53:05 +0800 Subject: [PATCH] feat: support zlib compression on windows platform --- tools/taos-tools/README-CN.md | 2 +- tools/taos-tools/inc/benchCsv.h | 4 ---- tools/taos-tools/src/CMakeLists.txt | 6 +++++- tools/taos-tools/src/benchCsv.c | 15 +++------------ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/tools/taos-tools/README-CN.md b/tools/taos-tools/README-CN.md index 3def035f68..da14e81cd1 100644 --- a/tools/taos-tools/README-CN.md +++ b/tools/taos-tools/README-CN.md @@ -18,7 +18,7 @@ taosdump 是用于备份 TDengine 数据到本地目录和从本地目录恢复 #### 对于 Ubuntu/Debian 系统 ```shell -sudo apt install libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g pkg-config libssl-dev +sudo apt install libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g zlib1g-dev pkg-config libssl-dev ``` #### 对于 CentOS 7/RHEL 系统 diff --git a/tools/taos-tools/inc/benchCsv.h b/tools/taos-tools/inc/benchCsv.h index f944600ecb..6bf531cf14 100644 --- a/tools/taos-tools/inc/benchCsv.h +++ b/tools/taos-tools/inc/benchCsv.h @@ -16,9 +16,7 @@ #ifndef INC_BENCHCSV_H_ #define INC_BENCHCSV_H_ -#ifndef _WIN32 #include -#endif #include "bench.h" @@ -41,9 +39,7 @@ typedef struct { CsvCompressionLevel compress_level; CsvIoError result; union { -#ifndef _WIN32 gzFile gf; -#endif FILE* fp; } handle; } CsvFileHandle; diff --git a/tools/taos-tools/src/CMakeLists.txt b/tools/taos-tools/src/CMakeLists.txt index 93b1530020..320fb1f413 100644 --- a/tools/taos-tools/src/CMakeLists.txt +++ b/tools/taos-tools/src/CMakeLists.txt @@ -317,7 +317,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin ENDIF () - target_link_libraries(taosBenchmark z) + TARGET_LINK_LIBRARIES(taosBenchmark z) ELSE () ADD_DEFINITIONS(-DWINDOWS) @@ -334,6 +334,7 @@ ELSE () ADD_DEPENDENCIES(taosdump deps-snappy) ADD_DEPENDENCIES(taosdump deps-libargp) ADD_DEPENDENCIES(taosdump apache-avro) + ADD_DEPENDENCIES(taosBenchmark tools-zlib) IF (${WEBSOCKET}) INCLUDE_DIRECTORIES(/usr/local/include/) @@ -365,5 +366,8 @@ ELSE () ENDIF () TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS}) + + TARGET_LINK_LIBRARIES(taosBenchmark zlibstatic) + ENDIF () diff --git a/tools/taos-tools/src/benchCsv.c b/tools/taos-tools/src/benchCsv.c index d08b9d19b0..f8c43dbb97 100644 --- a/tools/taos-tools/src/benchCsv.c +++ b/tools/taos-tools/src/benchCsv.c @@ -953,15 +953,12 @@ static CsvFileHandle* csvOpen(const char* filename, CsvCompressionLevel compress if (compress_level == CSV_COMPRESS_NONE) { fhdl->handle.fp = fopen(filename, "w"); failed = (!fhdl->handle.fp); - } -#ifndef _WIN32 - else { + } else { char mode[TINY_BUFF_LEN]; (void)snprintf(mode, sizeof(mode), "wb%d", compress_level); fhdl->handle.gf = gzopen(filename, mode); failed = (!fhdl->handle.gf); } -#endif if (failed) { tmfree(fhdl); @@ -989,9 +986,7 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) { fhdl->result = CSV_ERR_WRITE_FAILED; return CSV_ERR_WRITE_FAILED; } - } -#ifndef _WIN32 - else { + } else { int ret = gzwrite(fhdl->handle.gf, buf, size); if (ret != size) { errorPrint("Failed to write csv file: %s. expected written %zu but %d.\n", @@ -1003,7 +998,6 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) { return CSV_ERR_WRITE_FAILED; } } -#endif return CSV_ERR_OK; } @@ -1019,15 +1013,12 @@ static void csvClose(CsvFileHandle* fhdl) { fclose(fhdl->handle.fp); fhdl->handle.fp = NULL; } - } -#ifndef _WIN32 - else { + } else { if (fhdl->handle.gf) { gzclose(fhdl->handle.gf); fhdl->handle.gf = NULL; } } -#endif tmfree(fhdl); }