From 582242f430ae49cd88edc4d4e3b5f7f06e384d4e Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 9 May 2024 11:39:21 +0800 Subject: [PATCH] sw Signed-off-by: Lloyd-Pottiger --- .../CompressionCodecIntegerLightweight.cpp | 17 +++++++++++++++++ .../CompressionCodecIntegerLightweight.h | 4 ++++ .../Storages/DeltaMerge/File/DMFileWriter.h | 19 ++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.cpp b/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.cpp index 27ca11b2cf5..4238cb71771 100644 --- a/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.cpp +++ b/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.cpp @@ -52,6 +52,11 @@ UInt32 CompressionCodecIntegerLightweight::getMaxCompressedDataSize(UInt32 uncom return 1 + 1 + LZ4_COMPRESSBOUND(uncompressed_size); } +CompressionCodecIntegerLightweight::~CompressionCodecIntegerLightweight() +{ + LOG_INFO(Logger::get(), "lightweight codec: {}", ctx.toDebugString()); +} + template size_t CompressionCodecIntegerLightweight::compressDataForType(const char * source, UInt32 source_size, char * dest) const @@ -166,6 +171,18 @@ void CompressionCodecIntegerLightweight::decompressDataForType( } } +String CompressionCodecIntegerLightweight::CompressContext::toDebugString() const +{ + return fmt::format( + "lz4: {} times, {} -> {}, lightweight: {} times, {} -> {}", + lz4_counter, + lz4_uncompressed_size, + lz4_compressed_size, + lw_counter, + lw_uncompressed_size, + lw_compressed_size); +} + void CompressionCodecIntegerLightweight::CompressContext::update(size_t uncompressed_size, size_t compressed_size) { if (mode == Mode::LZ4) diff --git a/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.h b/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.h index f2760bcaf05..ca88d7affba 100644 --- a/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.h +++ b/dbms/src/IO/Compression/CompressionCodecIntegerLightweight.h @@ -29,6 +29,8 @@ class CompressionCodecIntegerLightweight : public ICompressionCodec UInt8 getMethodByte() const override; + ~CompressionCodecIntegerLightweight() override; + protected: UInt32 doCompressData(const char * source, UInt32 source_size, char * dest) const override; void doDecompressData(const char * source, UInt32 source_size, char * dest, UInt32 uncompressed_size) @@ -93,6 +95,8 @@ class CompressionCodecIntegerLightweight : public ICompressionCodec void update(size_t uncompressed_size, size_t compressed_size); + String toDebugString() const; + Mode mode = Mode::LZ4; private: diff --git a/dbms/src/Storages/DeltaMerge/File/DMFileWriter.h b/dbms/src/Storages/DeltaMerge/File/DMFileWriter.h index d6732b8da9a..d46669e88d5 100644 --- a/dbms/src/Storages/DeltaMerge/File/DMFileWriter.h +++ b/dbms/src/Storages/DeltaMerge/File/DMFileWriter.h @@ -65,9 +65,26 @@ class DMFileWriter /*flags*/ -1, /*mode*/ 0666, max_compress_block_size)) - , compressed_buf(CompressedWriteBuffer<>::build(*plain_file, compression_settings, !dmfile->configuration)) , minmaxes(do_index ? std::make_shared(*type) : nullptr) { + // TODO: better, now only for test + if (type->isInteger()) + { + assert(compression_settings.settings.size() == 1); + // init only once + static CompressionSettings settings(CompressionMethod::Lightweight); + auto & setting = settings.settings[0]; + setting.type_bytes_size = type->getSizeOfValueInMemory(); + compressed_buf = CompressedWriteBuffer<>::build(*plain_file, settings, !dmfile->configuration); + } + else + { + compressed_buf = CompressedWriteBuffer<>::build( // + *plain_file, + compression_settings, + !dmfile->configuration); + } + if (!dmfile->useMetaV2()) { mark_file = ChecksumWriteBufferBuilder::