You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2022/09/12 10:52:10 UTC
[incubator-kvrocks] branch unstable updated: Add zstd to available compression algorithms (#863)
This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new e8efdf2 Add zstd to available compression algorithms (#863)
e8efdf2 is described below
commit e8efdf28260d31f181fc200ec9082f36d9294c47
Author: Yaroslav <to...@gmail.com>
AuthorDate: Mon Sep 12 13:52:04 2022 +0300
Add zstd to available compression algorithms (#863)
---
CMakeLists.txt | 2 ++
cmake/modules/Findzstd.cmake | 25 +++++++++++++++++++++++++
cmake/rocksdb.cmake | 1 +
cmake/zstd.cmake | 44 ++++++++++++++++++++++++++++++++++++++++++++
kvrocks.conf | 2 +-
src/config.cc | 1 +
6 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1266149..0a529bc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -90,6 +90,7 @@ include(cmake/gtest.cmake)
include(cmake/glog.cmake)
include(cmake/snappy.cmake)
include(cmake/lz4.cmake)
+include(cmake/zstd.cmake)
include(cmake/rocksdb.cmake)
include(cmake/libevent.cmake)
@@ -106,6 +107,7 @@ list(APPEND EXTERNAL_LIBS snappy)
list(APPEND EXTERNAL_LIBS rocksdb_with_headers)
list(APPEND EXTERNAL_LIBS event_with_headers)
list(APPEND EXTERNAL_LIBS lz4)
+list(APPEND EXTERNAL_LIBS zstd)
if (USE_LUAJIT)
list(APPEND EXTERNAL_LIBS luajit)
else()
diff --git a/cmake/modules/Findzstd.cmake b/cmake/modules/Findzstd.cmake
new file mode 100644
index 0000000..1f1dbe1
--- /dev/null
+++ b/cmake/modules/Findzstd.cmake
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# used for `find_package(zstd)` mechanism in rocksdb
+
+if(zstd_SOURCE_DIR)
+ message(STATUS "Found zstd in ${zstd_SOURCE_DIR}")
+
+ add_library(zstd::zstd ALIAS zstd) # rocksdb use it
+ install(TARGETS zstd EXPORT RocksDBTargets) # export for install(...)
+endif()
diff --git a/cmake/rocksdb.cmake b/cmake/rocksdb.cmake
index c388aef..d95533f 100644
--- a/cmake/rocksdb.cmake
+++ b/cmake/rocksdb.cmake
@@ -41,6 +41,7 @@ FetchContent_MakeAvailableWithArgs(rocksdb
WITH_BENCHMARK_TOOLS=OFF
WITH_SNAPPY=ON
WITH_LZ4=ON
+ WITH_ZSTD=ON
WITH_TOOLS=OFF
WITH_GFLAGS=OFF
USE_RTTI=ON
diff --git a/cmake/zstd.cmake b/cmake/zstd.cmake
new file mode 100644
index 0000000..90d2b4f
--- /dev/null
+++ b/cmake/zstd.cmake
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+include_guard()
+
+include(cmake/utils.cmake)
+
+FetchContent_DeclareGitHubWithMirror(zstd
+ facebook/zstd v1.5.2
+ MD5=93220bc2dcb92e154f443d1a886ccd6c
+)
+
+FetchContent_GetProperties(zstd)
+if(NOT zstd_POPULATED)
+ FetchContent_Populate(zstd)
+
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
+ set(APPLE_FLAG "CFLAGS=-isysroot ${CMAKE_OSX_SYSROOT}")
+ endif()
+
+ add_custom_target(make_zstd COMMAND make CC=${CMAKE_C_COMPILER} ${APPLE_FLAG} libzstd.a
+ WORKING_DIRECTORY ${zstd_SOURCE_DIR}/lib
+ BYPRODUCTS ${zstd_SOURCE_DIR}/lib/libzstd.a
+ )
+endif()
+
+add_library(zstd INTERFACE)
+target_include_directories(zstd INTERFACE $<BUILD_INTERFACE:${zstd_SOURCE_DIR}/lib>)
+target_link_libraries(zstd INTERFACE $<BUILD_INTERFACE:${zstd_SOURCE_DIR}/lib/libzstd.a>)
+add_dependencies(zstd make_zstd)
diff --git a/kvrocks.conf b/kvrocks.conf
index efe4f83..3847f07 100644
--- a/kvrocks.conf
+++ b/kvrocks.conf
@@ -588,7 +588,7 @@ rocksdb.cache_index_and_filter_blocks yes
# Specify the compression to use. Only compress level greater
# than 2 to improve performance.
-# Accept value: "no", "snappy", "lz4"
+# Accept value: "no", "snappy", "lz4", "zstd"
# default snappy
rocksdb.compression snappy
diff --git a/src/config.cc b/src/config.cc
index 48fb01d..a3cc93a 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -52,6 +52,7 @@ configEnum compression_type_enum[] = {
{"no", rocksdb::CompressionType::kNoCompression},
{"snappy", rocksdb::CompressionType::kSnappyCompression},
{"lz4", rocksdb::CompressionType::kLZ4Compression},
+ {"zstd", rocksdb::CompressionType::kZSTD},
{nullptr, 0}
};