-
Notifications
You must be signed in to change notification settings - Fork 592
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
cloud_storage: re-adopt topic_manifest #19666
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 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 "cluster/remote_topic_properties.h" | ||
|
||
#include "reflection/adl.h" | ||
|
||
namespace cluster { | ||
|
||
std::ostream& operator<<(std::ostream& o, const remote_topic_properties& rtps) { | ||
fmt::print( | ||
o, | ||
"{{remote_revision: {} remote_partition_count: {}}}", | ||
rtps.remote_revision, | ||
rtps.remote_partition_count); | ||
return o; | ||
} | ||
|
||
} // namespace cluster | ||
|
||
namespace reflection { | ||
|
||
void adl<cluster::remote_topic_properties>::to( | ||
iobuf& out, cluster::remote_topic_properties&& p) { | ||
reflection::serialize(out, p.remote_revision, p.remote_partition_count); | ||
} | ||
|
||
cluster::remote_topic_properties | ||
adl<cluster::remote_topic_properties>::from(iobuf_parser& parser) { | ||
auto remote_revision = reflection::adl<model::initial_revision_id>{}.from( | ||
parser); | ||
auto remote_partition_count = reflection::adl<int32_t>{}.from(parser); | ||
|
||
return {remote_revision, remote_partition_count}; | ||
} | ||
|
||
} // namespace reflection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 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 "model/adl_serde.h" | ||
#include "model/fundamental.h" | ||
#include "reflection/adl.h" | ||
#include "serde/envelope.h" | ||
|
||
namespace cluster { | ||
|
||
struct remote_topic_properties | ||
: serde::envelope< | ||
remote_topic_properties, | ||
serde::version<0>, | ||
serde::compat_version<0>> { | ||
remote_topic_properties() = default; | ||
remote_topic_properties( | ||
model::initial_revision_id remote_revision, | ||
int32_t remote_partition_count) | ||
: remote_revision(remote_revision) | ||
, remote_partition_count(remote_partition_count) {} | ||
|
||
model::initial_revision_id remote_revision; | ||
int32_t remote_partition_count; | ||
|
||
auto serde_fields() { | ||
return std::tie(remote_revision, remote_partition_count); | ||
} | ||
|
||
friend bool | ||
operator==(const remote_topic_properties&, const remote_topic_properties&) | ||
= default; | ||
|
||
friend std::ostream& | ||
operator<<(std::ostream&, const remote_topic_properties&); | ||
}; | ||
|
||
} // namespace cluster | ||
// namespace cluster | ||
|
||
namespace reflection { | ||
|
||
template<> | ||
struct adl<cluster::remote_topic_properties> { | ||
void to(iobuf&, cluster::remote_topic_properties&&); | ||
cluster::remote_topic_properties from(iobuf_parser&); | ||
}; | ||
|
||
} // namespace reflection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// Copyright 2024 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 "cluster/topic_configuration.h" | ||
|
||
#include "model/fundamental.h" | ||
#include "model/metadata.h" | ||
#include "reflection/adl.h" | ||
#include "storage/ntp_config.h" | ||
|
||
#include <seastar/core/sstring.hh> | ||
|
||
namespace cluster { | ||
|
||
storage::ntp_config topic_configuration::make_ntp_config( | ||
const ss::sstring& work_dir, | ||
model::partition_id p_id, | ||
model::revision_id rev, | ||
model::initial_revision_id init_rev) const { | ||
auto has_overrides = properties.has_overrides() || is_internal(); | ||
std::unique_ptr<storage::ntp_config::default_overrides> overrides = nullptr; | ||
|
||
if (has_overrides) { | ||
overrides = std::make_unique<storage::ntp_config::default_overrides>( | ||
storage::ntp_config::default_overrides{ | ||
.cleanup_policy_bitflags = properties.cleanup_policy_bitflags, | ||
.compaction_strategy = properties.compaction_strategy, | ||
.segment_size = properties.segment_size, | ||
.retention_bytes = properties.retention_bytes, | ||
.retention_time = properties.retention_duration, | ||
// we disable cache for internal topics as they are read only once | ||
// during bootstrap. | ||
.cache_enabled = storage::with_cache(!is_internal()), | ||
.recovery_enabled = storage::topic_recovery_enabled( | ||
properties.recovery ? *properties.recovery : false), | ||
.shadow_indexing_mode = properties.shadow_indexing, | ||
.read_replica = properties.read_replica, | ||
.retention_local_target_bytes | ||
= properties.retention_local_target_bytes, | ||
.retention_local_target_ms = properties.retention_local_target_ms, | ||
.remote_delete = properties.remote_delete, | ||
.segment_ms = properties.segment_ms, | ||
.initial_retention_local_target_bytes | ||
= properties.initial_retention_local_target_bytes, | ||
.initial_retention_local_target_ms | ||
= properties.initial_retention_local_target_ms, | ||
.write_caching = properties.write_caching, | ||
.flush_ms = properties.flush_ms, | ||
.flush_bytes = properties.flush_bytes, | ||
}); | ||
} | ||
return { | ||
model::ntp(tp_ns.ns, tp_ns.tp, p_id), | ||
work_dir, | ||
std::move(overrides), | ||
rev, | ||
init_rev}; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& o, const topic_configuration& cfg) { | ||
fmt::print( | ||
o, | ||
"{{ topic: {}, partition_count: {}, replication_factor: {}, " | ||
"properties: " | ||
"{}}}", | ||
cfg.tp_ns, | ||
cfg.partition_count, | ||
cfg.replication_factor, | ||
cfg.properties); | ||
|
||
return o; | ||
} | ||
|
||
} // namespace cluster | ||
|
||
namespace reflection { | ||
|
||
// note: adl serialization doesn't support read replica fields since serde | ||
// should be used for new versions. | ||
void adl<cluster::topic_configuration>::to( | ||
iobuf& out, cluster::topic_configuration&& t) { | ||
int32_t version = -1; | ||
reflection::serialize( | ||
out, | ||
version, | ||
t.tp_ns, | ||
t.partition_count, | ||
t.replication_factor, | ||
t.properties.compression, | ||
t.properties.cleanup_policy_bitflags, | ||
t.properties.compaction_strategy, | ||
t.properties.timestamp_type, | ||
t.properties.segment_size, | ||
t.properties.retention_bytes, | ||
t.properties.retention_duration, | ||
t.properties.recovery, | ||
t.properties.shadow_indexing); | ||
} | ||
|
||
// note: adl deserialization doesn't support read replica fields since serde | ||
// should be used for new versions. | ||
cluster::topic_configuration | ||
adl<cluster::topic_configuration>::from(iobuf_parser& in) { | ||
// NOTE: The first field of the topic_configuration is a | ||
// model::ns which has length prefix which is always | ||
// positive. | ||
// We're using negative length value to encode version. So if | ||
// the first int32_t value is positive then we're dealing with | ||
// the old format. The negative value means that the new format | ||
// was used. | ||
auto version = adl<int32_t>{}.from(in.peek(4)); | ||
if (version < 0) { | ||
// Consume version from stream | ||
in.skip(4); | ||
vassert( | ||
-1 == version, | ||
"topic_configuration version {} is not supported", | ||
version); | ||
} else { | ||
version = 0; | ||
} | ||
auto ns = model::ns(adl<ss::sstring>{}.from(in)); | ||
auto topic = model::topic(adl<ss::sstring>{}.from(in)); | ||
auto partition_count = adl<int32_t>{}.from(in); | ||
auto rf = adl<int16_t>{}.from(in); | ||
|
||
auto cfg = cluster::topic_configuration( | ||
std::move(ns), std::move(topic), partition_count, rf); | ||
|
||
cfg.properties.compression = adl<std::optional<model::compression>>{}.from( | ||
in); | ||
cfg.properties.cleanup_policy_bitflags | ||
= adl<std::optional<model::cleanup_policy_bitflags>>{}.from(in); | ||
cfg.properties.compaction_strategy | ||
= adl<std::optional<model::compaction_strategy>>{}.from(in); | ||
cfg.properties.timestamp_type | ||
= adl<std::optional<model::timestamp_type>>{}.from(in); | ||
cfg.properties.segment_size = adl<std::optional<size_t>>{}.from(in); | ||
cfg.properties.retention_bytes = adl<tristate<size_t>>{}.from(in); | ||
cfg.properties.retention_duration | ||
= adl<tristate<std::chrono::milliseconds>>{}.from(in); | ||
if (version < 0) { | ||
cfg.properties.recovery = adl<std::optional<bool>>{}.from(in); | ||
cfg.properties.shadow_indexing | ||
= adl<std::optional<model::shadow_indexing_mode>>{}.from(in); | ||
} | ||
|
||
// Legacy topics from pre-22.3 get remote delete disabled. | ||
cfg.properties.remote_delete = storage::ntp_config::legacy_remote_delete; | ||
|
||
return cfg; | ||
} | ||
|
||
} // namespace reflection |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ah cool