From de67c324bbcd817a0a974fd802689546c8c5da72 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Fri, 24 May 2024 14:39:42 -0700 Subject: [PATCH] storage: factor out config specific storage bits This follows along the path that security::config library has taken which is to create a dependency-free library in the subsystem that exports the bits that are shared between the subsystem and the configuration. Signed-off-by: Noah Watkins --- src/v/config/configuration.cc | 5 ++--- src/v/storage/config.h | 38 ++++++++++++++++++++++++++++++++ src/v/storage/segment_appender.h | 18 +++------------ 3 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 src/v/storage/config.h diff --git a/src/v/config/configuration.cc b/src/v/config/configuration.cc index 563c3be9f4f30..268f569af677e 100644 --- a/src/v/config/configuration.cc +++ b/src/v/config/configuration.cc @@ -21,8 +21,7 @@ #include "security/oidc_principal_mapping.h" #include "security/oidc_url_parser.h" #include "ssx/sformat.h" -#include "storage/chunk_cache.h" -#include "storage/segment_appender.h" +#include "storage/config.h" #include #include @@ -1170,7 +1169,7 @@ configuration::configuration() .example = "32768", .visibility = visibility::tunable}, 32_MiB, - storage::segment_appender::validate_fallocation_step) + storage::validate_fallocation_step) , storage_target_replay_bytes( *this, "storage_target_replay_bytes", diff --git a/src/v/storage/config.h b/src/v/storage/config.h new file mode 100644 index 0000000000000..417953d32e25d --- /dev/null +++ b/src/v/storage/config.h @@ -0,0 +1,38 @@ +/* + * Copyright 2023 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 "base/seastarx.h" +#include "base/units.h" + +#include + +#include + +namespace storage { + +inline constexpr const size_t segment_appender_fallocation_alignment = 4_KiB; + +/** Validator for fallocation step configuration setting */ +inline std::optional +validate_fallocation_step(const size_t& value) { + if (value % segment_appender_fallocation_alignment != 0) { + return "Fallocation step must be multiple of 4096"; + } else if (value < segment_appender_fallocation_alignment) { + return "Fallocation step must be at least 4 KiB (4096)"; + } else if (value > 1_GiB) { + return "Fallocation step can't be larger than 1 GiB (1073741824)"; + } else { + return std::nullopt; + } +} + +} // namespace storage diff --git a/src/v/storage/segment_appender.h b/src/v/storage/segment_appender.h index 446680f350253..3dd8a875d9f39 100644 --- a/src/v/storage/segment_appender.h +++ b/src/v/storage/segment_appender.h @@ -19,6 +19,7 @@ #include "container/intrusive_list_helpers.h" #include "model/record.h" #include "ssx/semaphore.h" +#include "storage/config.h" #include "storage/fwd.h" #include "storage/segment_appender_chunk.h" #include "storage/storage_resources.h" @@ -53,7 +54,8 @@ class segment_appender { public: using chunk = segment_appender_chunk; - static constexpr const size_t fallocation_alignment = 4_KiB; + static constexpr const size_t fallocation_alignment + = segment_appender_fallocation_alignment; static constexpr const size_t write_behind_memory = 1_MiB; struct options { @@ -131,20 +133,6 @@ class segment_appender { void set_callbacks(callbacks* callbacks) { _callbacks = callbacks; } - /** Validator for fallocation step configuration setting */ - static std::optional - validate_fallocation_step(const size_t& value) { - if (value % segment_appender::fallocation_alignment != 0) { - return "Fallocation step must be multiple of 4096"; - } else if (value < segment_appender::fallocation_alignment) { - return "Fallocation step must be at least 4 KiB (4096)"; - } else if (value > 1_GiB) { - return "Fallocation step can't be larger than 1 GiB (1073741824)"; - } else { - return std::nullopt; - } - } - constexpr ss::io_priority_class get_priority_class() const { return _opts.priority; }