Skip to content

Commit

Permalink
storage: factor out config specific storage bits
Browse files Browse the repository at this point in the history
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 <noahwatkins@gmail.com>
  • Loading branch information
dotnwat committed May 24, 2024
1 parent 8c0680d commit de67c32
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/v/config/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chrono>
#include <cstdint>
Expand Down Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions src/v/storage/config.h
Original file line number Diff line number Diff line change
@@ -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 <seastar/core/sstring.hh>

#include <optional>

namespace storage {

inline constexpr const size_t segment_appender_fallocation_alignment = 4_KiB;

/** Validator for fallocation step configuration setting */
inline std::optional<ss::sstring>
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
18 changes: 3 additions & 15 deletions src/v/storage/segment_appender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -131,20 +133,6 @@ class segment_appender {

void set_callbacks(callbacks* callbacks) { _callbacks = callbacks; }

/** Validator for fallocation step configuration setting */
static std::optional<ss::sstring>
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;
}
Expand Down

0 comments on commit de67c32

Please sign in to comment.