New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compressor: Add Brotli Compressor #19549
Conversation
.gitmodules
Outdated
@@ -55,3 +55,6 @@ | |||
[submodule "src/rapidjson"] | |||
path = src/rapidjson | |||
url = https://github.com/ceph/rapidjson | |||
[submodule "src/brotli"] | |||
path = src/brotli | |||
url = https://github.com/google/brotli.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, but i'd suggest add brotli using ExternalProject_Add()
and download brotli on the fly, see also https://github.com/ceph/ceph/blob/master/src/os/CMakeLists.txt#L122
c44e005
to
c7cd84d
Compare
@tchaikov I have modified as you suggested, can you review again, thanks. |
src/CMakeLists.txt
Outdated
@@ -719,6 +719,7 @@ add_subdirectory(include) | |||
add_subdirectory(librados) | |||
add_subdirectory(libradosstriper) | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop this change.
src/compressor/CMakeLists.txt
Outdated
@@ -18,7 +19,8 @@ endif() | |||
set(ceph_compressor_libs | |||
ceph_snappy | |||
ceph_zlib | |||
ceph_zstd) | |||
ceph_zstd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you avoid using tab in CMake scripts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bi-shun this comment is not addressed.
src/compressor/Compressor.cc
Outdated
@@ -31,6 +31,7 @@ const char * Compressor::get_comp_alg_name(int a) { | |||
#ifdef HAVE_LZ4 | |||
case COMP_ALG_LZ4: return "lz4"; | |||
#endif | |||
case COMP_ALG_BROTLI: return "brotli"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should guard this case statement with #ifdef HAVE_BROTLI
. as "brotli" could be disabled at compile-time.
src/compressor/Compressor.cc
Outdated
@@ -46,6 +47,8 @@ boost::optional<Compressor::CompressionAlgorithm> Compressor::get_comp_alg_type( | |||
if (s == "lz4") | |||
return COMP_ALG_LZ4; | |||
#endif | |||
if (s == "brotli") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
src/compressor/Compressor.h
Outdated
@@ -37,6 +37,7 @@ class Compressor { | |||
#ifdef HAVE_LZ4 | |||
COMP_ALG_LZ4 = 4, | |||
#endif | |||
COMP_ALG_BROTLI = 5, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
size_t available_out = 0; | ||
uint8_t* next_out = NULL; | ||
if (!s) { | ||
BrotliEncoderDestroyInstance(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to destroy s
, if it's not created at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bi-shun this comment is not addressed.
BrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)9); | ||
BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, 22); | ||
unsigned char* c_in; | ||
for (std::list<buffer::ptr>::const_iterator i = in.buffers().begin(); i != in.buffers().end();) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, use auto
out.append(ptr, 0, have); | ||
} while (available_out == 0); | ||
if (BrotliEncoderIsFinished(s)) { | ||
BrotliEncoderDestroyInstance(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just break
here?
have = MAX_LEN - available_out; | ||
out.append(ptr, 0, have); | ||
} while (available_out == 0); | ||
if (BrotliDecoderIsFinished(s)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could just break
here.
src/compressor/brotli/CMakeLists.txt
Outdated
COMMAND "true" | ||
ALWAYS 1) | ||
|
||
add_library(brotlicommon STATIC IMPORTED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could name it brotli::common
and use a loop to set the dependency and the properties of these libraries.
7033bfa
to
081a3f8
Compare
@tchaikov I have to change the compressor plugin as optional and modify for you suggestions, can you review again, thanks. |
@@ -330,7 +330,11 @@ INSTANTIATE_TEST_CASE_P( | |||
#endif | |||
"zlib/noisal", | |||
"snappy", | |||
"zstd")); | |||
"zstd" | |||
#ifdef HAVE_BROTLI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could add this line before "zstd", less code churn, and better looking this way =)
src/compressor/brotli/CMakeLists.txt
Outdated
COMMAND "true" | ||
ALWAYS 1) | ||
|
||
set(bortli_libs brotlicommon brotlidec brotlienc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/brotlicommon/brotli::common/
s/brotlidec/brotli::dec/
s/brotlienc/brotli::enc/
CMakeLists.txt
Outdated
option(WITH_BROTLI "Brotli compression support" OFF) | ||
if(WITH_BROTLI) | ||
set(HAVE_BROTLI TRUE) | ||
endif(WITH_BROTLI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove WITH_BROTLI
from endif()
, as it's a very short if
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bi-shun this one.
CMakeLists.txt
Outdated
set(HAVE_BROTLI TRUE) | ||
endif(WITH_BROTLI) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this empty line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bi-shun and this one.
src/compressor/CMakeLists.txt
Outdated
@@ -15,6 +15,10 @@ if (HAVE_LZ4) | |||
add_subdirectory(lz4) | |||
endif() | |||
|
|||
if (HAVE_BROTLI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, remove the space after if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bi-shun here.
@tchaikov I have fixed the problems. |
@tchaikov Cloud you review again, thanks. |
src/compressor/CMakeLists.txt
Outdated
@@ -24,6 +28,10 @@ if (HAVE_LZ4) | |||
list(APPEND ceph_compressor_libs ceph_lz4) | |||
endif() | |||
|
|||
if (HAVE_BROTLI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
@bi-shun please let me know once all comments are addressed. |
8a67338
to
f03292e
Compare
@tchaikov I merge the branch commits into one, and all comments are addressed, thanks. |
f4b09f3
to
db1b72f
Compare
int BrotliCompressor::compress(const bufferlist &in, bufferlist &out) | ||
{ | ||
BrotliEncoderState* s = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr); | ||
auto sg = make_scope_guard([&s] { BrotliEncoderDestroyInstance(s); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#19549 (comment) , please move this after if (!s) {}
block.
size_t available_in = 0; | ||
const uint8_t* next_in = nullptr; | ||
size_t available_out = 0; | ||
uint8_t* next_out = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
BrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)9); | ||
BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, 22); | ||
unsigned char* c_in; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to have this variable, IMHO.
unsigned char* c_in; | ||
for (auto i = in.buffers().begin(); i != in.buffers().end();) { | ||
c_in = (unsigned char*) i->c_str(); | ||
size_t len = i->length(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this variable?
bufferptr ptr = buffer::create_page_aligned(max_comp_size); | ||
next_out = (unsigned char*)ptr.c_str(); | ||
available_out = max_comp_size; | ||
if (!BrotliEncoderCompressStream(s,finish,&available_in, &next_in, &available_out, &next_out, nullptr)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after ,
please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please wrap at 80 chars.
add_library(ceph_brotli SHARED ${brotli_sources}) | ||
add_dependencies(ceph_brotli ${CMAKE_SOURCE_DIR}/src/ceph_ver.h) | ||
target_include_directories(ceph_brotli PRIVATE "${CMAKE_BINARY_DIR}/src/brotli/c/include") | ||
List(REVERSE bortli_libs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why reverse the libs list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because depend sequence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, if brotli::dec
and brotli::enc
depend on brotli::common
, why not ordering it the right way at https://github.com/ceph/ceph/pull/19549/files#diff-66716f6999869d6458bd6a9251638b70R25 ?
#ifdef HAVE_BROTLI | ||
"brotli", | ||
#endif | ||
"zstd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop this change.
1c3e2f1
to
7a4dd35
Compare
7a4dd35
to
a496ad7
Compare
@tchaikov Thank you very much for your helpful comments and corrections. I tried to correct according to your comments . Could you review again, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! lgtm, would be great if you can address the comments.
add_library(ceph_brotli SHARED ${brotli_sources}) | ||
add_dependencies(ceph_brotli ${CMAKE_SOURCE_DIR}/src/ceph_ver.h) | ||
target_include_directories(ceph_brotli PRIVATE "${CMAKE_BINARY_DIR}/src/brotli/c/include") | ||
List(REVERSE bortli_libs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, if brotli::dec
and brotli::enc
depend on brotli::common
, why not ordering it the right way at https://github.com/ceph/ceph/pull/19549/files#diff-66716f6999869d6458bd6a9251638b70R25 ?
src/compressor/brotli/CMakeLists.txt
Outdated
target_include_directories(ceph_brotli PRIVATE "${CMAKE_BINARY_DIR}/src/brotli/c/include") | ||
List(REVERSE bortli_libs) | ||
target_link_libraries(ceph_brotli ${bortli_libs}) | ||
set_target_properties(ceph_brotli PROPERTIES VERSION 2.0.0 SOVERSION 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to version the plugin.
src/compressor/brotli/CMakeLists.txt
Outdated
COMMAND "true" | ||
ALWAYS 1) | ||
|
||
set(bortli_libs brotli::common brotli::dec brotli::enc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could avoid the string manipulation, and dedup the brotli::
prefix, see
ceph/cmake/modules/BuildDPDK.cmake
Line 88 in 28c79fa
foreach(c |
src/compressor/brotli/CMakeLists.txt
Outdated
|
||
if(WITH_EMBEDDED) | ||
add_library(cephd_compressor_brotli STATIC ${brotli_sources}) | ||
target_include_directories(cephd_compressor_brotli PRIVATE "${CMAKE_BINARY_DIR}/src/brotli/c/include") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the extra space.
|
||
virtual int factory(CompressorRef *cs, std::ostream *ss) | ||
{ | ||
if (compressor == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could just put
if (compressor) {
// ...
}
or s/0/nullptr/ if you prefer to be explicit.
the change looks good, could you please squash these two commits into a single one? |
Signed-off-by: BI SHUN KE <aionshun@livemail.tw>
a496ad7
to
f0aa226
Compare
@tchaikov Sure, last the comments, I have corrected and squash it into one, thanks. |
Signed-off-by: BI SHUN KE aionshun@livemail.tw