From 28652fea9407464194150dcb4b4d0634bd931e92 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Mon, 1 May 2023 18:51:59 -0700 Subject: [PATCH] compression: avoid optimizing away logger registration rpk syncs its set of logger names with redpanda. a previous commit was backported that removed the only usage of the compression logger. it seems that in release mode the entire construction of the object (which is what registers it) was compiled out, so the logger didn't show up in the list and broke a flow in rpk. Fixes: #10480 Signed-off-by: Noah Watkins (cherry picked from commit cd8bc57e3e8a7852ea6a78086100cbcf579f91bf) --- src/v/compression/CMakeLists.txt | 1 - src/v/compression/async_stream_zstd.cc | 1 - src/v/compression/compression.cc | 16 ++++++++++++++ .../internal/snappy_java_compressor.cc | 1 - src/v/compression/logger.cc | 13 ------------ src/v/compression/logger.h | 21 ------------------- src/v/compression/stream_zstd.cc | 1 - 7 files changed, 16 insertions(+), 38 deletions(-) delete mode 100644 src/v/compression/logger.cc delete mode 100644 src/v/compression/logger.h diff --git a/src/v/compression/CMakeLists.txt b/src/v/compression/CMakeLists.txt index 76857a743ca9..e621f2a36335 100644 --- a/src/v/compression/CMakeLists.txt +++ b/src/v/compression/CMakeLists.txt @@ -14,7 +14,6 @@ v_cc_library( "compression.cc" "stream_zstd.cc" "async_stream_zstd.cc" - "logger.cc" "snappy_standard_compressor.cc" "internal/snappy_java_compressor.cc" "internal/lz4_frame_compressor.cc" diff --git a/src/v/compression/async_stream_zstd.cc b/src/v/compression/async_stream_zstd.cc index 30398cbc06dc..7afaec82ca0d 100644 --- a/src/v/compression/async_stream_zstd.cc +++ b/src/v/compression/async_stream_zstd.cc @@ -11,7 +11,6 @@ #include "bytes/bytes.h" #include "bytes/details/io_allocation_size.h" -#include "compression/logger.h" #include "likely.h" #include "units.h" #include "vassert.h" diff --git a/src/v/compression/compression.cc b/src/v/compression/compression.cc index 18149959fce7..8eacc4eb1ebd 100644 --- a/src/v/compression/compression.cc +++ b/src/v/compression/compression.cc @@ -14,8 +14,23 @@ #include "compression/internal/snappy_java_compressor.h" #include "compression/internal/zstd_compressor.h" #include "vassert.h" +#include "vlog.h" namespace compression { + +/* + * There are no users of this, but we need to make sure it isn't compiled away + * in release mode so that it still shows up in the registered loggers list + * which rpk needs to be in sync with. + * + * Putting it here instead of in its own compilation unit seemed to have tricked + * the optimizer. Added a log statement below too, just for good measure. + * + * As soon as rpk supports logger name discovery via admin api this can be fully + * removed. + */ +ss::logger complog{"compression"}; + iobuf compressor::compress(const iobuf& io, type t) { switch (t) { case type::none: @@ -29,6 +44,7 @@ iobuf compressor::compress(const iobuf& io, type t) { case type::zstd: return internal::zstd_compressor::compress(io); default: + vlog(complog.error, "Cannot compress type {}", t); vassert(false, "Cannot compress type {}", t); } } diff --git a/src/v/compression/internal/snappy_java_compressor.cc b/src/v/compression/internal/snappy_java_compressor.cc index d342d78bb36b..06c78cb03a1c 100644 --- a/src/v/compression/internal/snappy_java_compressor.cc +++ b/src/v/compression/internal/snappy_java_compressor.cc @@ -12,7 +12,6 @@ #include "bytes/bytes.h" #include "bytes/details/io_iterator_consumer.h" #include "bytes/iobuf.h" -#include "compression/logger.h" #include "compression/snappy_standard_compressor.h" #include "likely.h" #include "vlog.h" diff --git a/src/v/compression/logger.cc b/src/v/compression/logger.cc deleted file mode 100644 index da1a3414e5df..000000000000 --- a/src/v/compression/logger.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2020 Redpanda Data, Inc. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.md -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0 - -#include "compression/logger.h" -namespace compression { -ss::logger complog{"compression"}; -} // namespace compression diff --git a/src/v/compression/logger.h b/src/v/compression/logger.h deleted file mode 100644 index 5615337e12d3..000000000000 --- a/src/v/compression/logger.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2020 Redpanda Data, Inc. - * - * Use of this software is governed by the Business Source License - * included in the file licenses/BSL.md - * - * As of the Change Date specified in that file, in accordance with - * the Business Source License, use of this software will be governed - * by the Apache License, Version 2.0 - */ - -#pragma once - -#include "seastarx.h" - -#include -#include - -namespace compression { -extern ss::logger complog; -} // namespace compression diff --git a/src/v/compression/stream_zstd.cc b/src/v/compression/stream_zstd.cc index 663e742ea248..6e5d540d117e 100644 --- a/src/v/compression/stream_zstd.cc +++ b/src/v/compression/stream_zstd.cc @@ -11,7 +11,6 @@ #include "bytes/bytes.h" #include "bytes/details/io_allocation_size.h" -#include "compression/logger.h" #include "likely.h" #include "units.h" #include "vassert.h"