feat: support zlib compression on windows platform
This commit is contained in:
parent
4e79e8f489
commit
1c2072eb80
|
@ -18,7 +18,7 @@ taosdump 是用于备份 TDengine 数据到本地目录和从本地目录恢复
|
||||||
#### 对于 Ubuntu/Debian 系统
|
#### 对于 Ubuntu/Debian 系统
|
||||||
|
|
||||||
```shell
|
```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 系统
|
#### 对于 CentOS 7/RHEL 系统
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
#ifndef INC_BENCHCSV_H_
|
#ifndef INC_BENCHCSV_H_
|
||||||
#define INC_BENCHCSV_H_
|
#define INC_BENCHCSV_H_
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "bench.h"
|
#include "bench.h"
|
||||||
|
|
||||||
|
@ -41,9 +39,7 @@ typedef struct {
|
||||||
CsvCompressionLevel compress_level;
|
CsvCompressionLevel compress_level;
|
||||||
CsvIoError result;
|
CsvIoError result;
|
||||||
union {
|
union {
|
||||||
#ifndef _WIN32
|
|
||||||
gzFile gf;
|
gzFile gf;
|
||||||
#endif
|
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
} handle;
|
} handle;
|
||||||
} CsvFileHandle;
|
} CsvFileHandle;
|
||||||
|
|
|
@ -317,7 +317,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin
|
||||||
|
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
target_link_libraries(taosBenchmark z)
|
TARGET_LINK_LIBRARIES(taosBenchmark z)
|
||||||
|
|
||||||
ELSE ()
|
ELSE ()
|
||||||
ADD_DEFINITIONS(-DWINDOWS)
|
ADD_DEFINITIONS(-DWINDOWS)
|
||||||
|
@ -334,6 +334,7 @@ ELSE ()
|
||||||
ADD_DEPENDENCIES(taosdump deps-snappy)
|
ADD_DEPENDENCIES(taosdump deps-snappy)
|
||||||
ADD_DEPENDENCIES(taosdump deps-libargp)
|
ADD_DEPENDENCIES(taosdump deps-libargp)
|
||||||
ADD_DEPENDENCIES(taosdump apache-avro)
|
ADD_DEPENDENCIES(taosdump apache-avro)
|
||||||
|
ADD_DEPENDENCIES(taosBenchmark tools-zlib)
|
||||||
|
|
||||||
IF (${WEBSOCKET})
|
IF (${WEBSOCKET})
|
||||||
INCLUDE_DIRECTORIES(/usr/local/include/)
|
INCLUDE_DIRECTORIES(/usr/local/include/)
|
||||||
|
@ -365,5 +366,8 @@ ELSE ()
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS})
|
TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS})
|
||||||
|
|
||||||
|
TARGET_LINK_LIBRARIES(taosBenchmark zlibstatic)
|
||||||
|
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
|
|
|
@ -953,15 +953,12 @@ static CsvFileHandle* csvOpen(const char* filename, CsvCompressionLevel compress
|
||||||
if (compress_level == CSV_COMPRESS_NONE) {
|
if (compress_level == CSV_COMPRESS_NONE) {
|
||||||
fhdl->handle.fp = fopen(filename, "w");
|
fhdl->handle.fp = fopen(filename, "w");
|
||||||
failed = (!fhdl->handle.fp);
|
failed = (!fhdl->handle.fp);
|
||||||
}
|
} else {
|
||||||
#ifndef _WIN32
|
|
||||||
else {
|
|
||||||
char mode[TINY_BUFF_LEN];
|
char mode[TINY_BUFF_LEN];
|
||||||
(void)snprintf(mode, sizeof(mode), "wb%d", compress_level);
|
(void)snprintf(mode, sizeof(mode), "wb%d", compress_level);
|
||||||
fhdl->handle.gf = gzopen(filename, mode);
|
fhdl->handle.gf = gzopen(filename, mode);
|
||||||
failed = (!fhdl->handle.gf);
|
failed = (!fhdl->handle.gf);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
tmfree(fhdl);
|
tmfree(fhdl);
|
||||||
|
@ -989,9 +986,7 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) {
|
||||||
fhdl->result = CSV_ERR_WRITE_FAILED;
|
fhdl->result = CSV_ERR_WRITE_FAILED;
|
||||||
return CSV_ERR_WRITE_FAILED;
|
return CSV_ERR_WRITE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
#ifndef _WIN32
|
|
||||||
else {
|
|
||||||
int ret = gzwrite(fhdl->handle.gf, buf, size);
|
int ret = gzwrite(fhdl->handle.gf, buf, size);
|
||||||
if (ret != size) {
|
if (ret != size) {
|
||||||
errorPrint("Failed to write csv file: %s. expected written %zu but %d.\n",
|
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;
|
return CSV_ERR_WRITE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return CSV_ERR_OK;
|
return CSV_ERR_OK;
|
||||||
}
|
}
|
||||||
|
@ -1019,15 +1013,12 @@ static void csvClose(CsvFileHandle* fhdl) {
|
||||||
fclose(fhdl->handle.fp);
|
fclose(fhdl->handle.fp);
|
||||||
fhdl->handle.fp = NULL;
|
fhdl->handle.fp = NULL;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
#ifndef _WIN32
|
|
||||||
else {
|
|
||||||
if (fhdl->handle.gf) {
|
if (fhdl->handle.gf) {
|
||||||
gzclose(fhdl->handle.gf);
|
gzclose(fhdl->handle.gf);
|
||||||
fhdl->handle.gf = NULL;
|
fhdl->handle.gf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
tmfree(fhdl);
|
tmfree(fhdl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue