Skip to content

Commit fa8dc81

Browse files
MCOL-4814 Add a cmake build option to enable LZ4 compression.
This patch adds an option for cmake flags to enable lz4 compression.
1 parent a5135f1 commit fa8dc81

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

CMakeLists.txt

+17-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SET(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
3737
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/obj)
3838
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
3939
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
40+
SET(WITH_COLUMNSTORE_LZ4 AUTO CACHE STRING "Build with lz4. Possible values are 'ON', 'OFF', 'AUTO' and default is 'AUTO'")
4041

4142
SET (ENGINE_SYSCONFDIR "/etc")
4243
SET (ENGINE_DATADIR "/var/lib/columnstore")
@@ -163,11 +164,22 @@ if(NOT AWK_EXECUTABLE)
163164
return()
164165
endif()
165166

166-
FIND_PACKAGE(LZ4)
167-
if (NOT LZ4_FOUND)
168-
MESSAGE_ONCE(CS_NO_LZ4 "lz4 not found")
169-
return()
170-
endif()
167+
SET(HAVE_LZ4 0 CACHE INTERNAL "")
168+
IF (WITH_COLUMNSTORE_LZ4 STREQUAL "ON" OR WITH_COLUMNSTORE_LZ4 STREQUAL "AUTO")
169+
FIND_PACKAGE(LZ4)
170+
IF (NOT LZ4_FOUND)
171+
IF (WITH_COLUMNSTORE_LZ4 STREQUAL "AUTO")
172+
MESSAGE_ONCE(STATUS "LZ4 not found, building without LZ4")
173+
ELSE()
174+
MESSAGE_ONCE(FATAL_ERROR "LZ4 not found.")
175+
ENDIF()
176+
ELSE()
177+
MESSAGE_ONCE(STATUS "Building with LZ4")
178+
SET(HAVE_LZ4 1 CACHE INTERNAL "")
179+
ENDIF()
180+
ELSE()
181+
MESSAGE_ONCE(STATUS "Building without LZ4")
182+
ENDIF()
171183

172184
IF (NOT INSTALL_LAYOUT)
173185
INCLUDE(check_compiler_flag)

dbcon/mysql/ha_mcs_sysvars.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
#include <my_config.h>
2020
#include "idb_mysql.h"
2121
#include "ha_mcs_sysvars.h"
22+
#include "mcsconfig.h"
2223

2324
const char* mcs_compression_type_names[] = {
2425
"SNAPPY", // 0
2526
"SNAPPY", // 1
2627
"SNAPPY", // 2
28+
#ifdef HAVE_LZ4
2729
"LZ4", // 3
30+
#endif
2831
NullS
2932
};
3033

dbcon/mysql/ha_mcs_sysvars.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <my_config.h>
2323
#include "idb_mysql.h"
24+
#include "mcsconfig.h"
2425

2526
extern st_mysql_sys_var* mcs_system_variables[];
2627
extern st_mysql_show_var mcs_status_variables[];
@@ -31,7 +32,9 @@ extern char cs_commit_hash[];
3132
enum mcs_compression_type_t {
3233
NO_COMPRESSION = 0,
3334
SNAPPY = 2,
35+
#ifdef HAVE_LZ4
3436
LZ4 = 3
37+
#endif
3538
};
3639

3740
// use_import_for_batchinsert mode

mcsconfig.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@
268268
/* Define to 1 if you have the <zlib.h> header file. */
269269
#cmakedefine HAVE_ZLIB_H 1
270270

271+
/* Define to 1 if you have lz4 library. */
272+
#cmakedefine HAVE_LZ4 1
273+
271274
/* Define to 1 if the system has the type `_Bool'. */
272275
#cmakedefine HAVE__BOOL 1
273276

utils/compress/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ add_definitions(-DNDEBUG)
1010

1111
add_library(compress SHARED ${compress_LIB_SRCS})
1212

13-
target_link_libraries(compress ${SNAPPY_LIBRARIES} ${LZ4_LIBRARIES})
13+
target_link_libraries(compress ${SNAPPY_LIBRARIES})
14+
IF(HAVE_LZ4)
15+
MESSAGE_ONCE(STATUS "LINK WITH LZ4")
16+
target_link_libraries(compress ${LZ4_LIBRARIES})
17+
ENDIF()
1418

1519
install(TARGETS compress DESTINATION ${ENGINE_LIBDIR} COMPONENT columnstore-engine)
16-

utils/compress/idbcompress.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ using namespace std;
2929
#include "logger.h"
3030
#include "snappy.h"
3131
#include "hasher.h"
32+
#include "mcsconfig.h"
33+
#ifdef HAVE_LZ4
3234
#include "lz4.h"
35+
#else
36+
// Taken from lz4.h.
37+
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
38+
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
39+
#endif
3340

3441
#define IDBCOMP_DLLEXPORT
3542
#include "idbcompress.h"
@@ -590,6 +597,7 @@ CompressInterfaceLZ4::CompressInterfaceLZ4(uint32_t numUserPaddingBytes)
590597
int32_t CompressInterfaceLZ4::compress(const char* in, size_t inLen, char* out,
591598
size_t* outLen) const
592599
{
600+
#ifdef HAVE_LZ4
593601
auto compressedLen = LZ4_compress_default(in, out, inLen, *outLen);
594602

595603
if (!compressedLen)
@@ -606,11 +614,15 @@ int32_t CompressInterfaceLZ4::compress(const char* in, size_t inLen, char* out,
606614

607615
*outLen = compressedLen;
608616
return ERR_OK;
617+
#else
618+
return ERR_COMPRESS;
619+
#endif
609620
}
610621

611622
int32_t CompressInterfaceLZ4::uncompress(const char* in, size_t inLen,
612623
char* out, size_t* outLen) const
613624
{
625+
#ifdef HAVE_LZ4
614626
auto decompressedLen = LZ4_decompress_safe(in, out, inLen, *outLen);
615627

616628
if (decompressedLen < 0)
@@ -629,6 +641,9 @@ int32_t CompressInterfaceLZ4::uncompress(const char* in, size_t inLen,
629641
#endif
630642

631643
return ERR_OK;
644+
#else
645+
return ERR_DECOMPRESS;
646+
#endif
632647
}
633648

634649
size_t CompressInterfaceLZ4::maxCompressedSize(size_t uncompSize) const

0 commit comments

Comments
 (0)