Skip to content
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

cluster: serde_fields for various structs #23118

Merged
merged 11 commits into from
Aug 30, 2024
11 changes: 11 additions & 0 deletions src/v/cluster/archival/archival_metadata_stm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ struct archival_metadata_stm::segment
// Segment meta value generated by old redpanda versions will have the
// default value of 'no'.
segment_validated is_validated{segment_validated::no};

auto serde_fields() {
return std::tie(ntp_revision_deprecated, name, meta, is_validated);
}
};

struct archival_metadata_stm::start_offset
: public serde::
envelope<start_offset, serde::version<0>, serde::compat_version<0>> {
model::offset start_offset;
auto serde_fields() { return std::tie(start_offset); }
};

struct archival_metadata_stm::start_offset_with_delta
Expand All @@ -99,6 +104,7 @@ struct archival_metadata_stm::start_offset_with_delta
serde::compat_version<0>> {
model::offset start_offset;
model::offset_delta delta;
auto serde_fields() { return std::tie(start_offset, delta); }
};

struct archival_metadata_stm::add_segment_cmd {
Expand Down Expand Up @@ -142,6 +148,7 @@ struct archival_metadata_stm::truncate_archive_commit_cmd {
: serde::envelope<value, serde::version<0>, serde::compat_version<0>> {
model::offset start_offset;
uint64_t bytes_removed;
auto serde_fields() { return std::tie(start_offset, bytes_removed); }
};
};

Expand All @@ -164,6 +171,8 @@ struct archival_metadata_stm::spillover_cmd
static constexpr cmd_key key{9};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder why serde doesn't encode static fields

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably you could, but I suppose it's strictly wasted bits since the value wouldn't change per instance. or maybe more straightforwardly, "the same reason statics don't appear in structured bindings".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeh i think it makes sense that they do not appear in the encodings!


cloud_storage::segment_meta manifest_meta;

auto serde_fields() { return std::tie(manifest_meta); }
};

struct archival_metadata_stm::replace_manifest_cmd {
Expand Down Expand Up @@ -208,6 +217,8 @@ struct archival_metadata_stm::read_write_fence_cmd
static constexpr cmd_key key{14};

model::offset last_applied_offset;

auto serde_fields() { return std::tie(last_applied_offset); }
};

// Serde format description
Expand Down
6 changes: 6 additions & 0 deletions src/v/cluster/archival/tests/archival_metadata_stm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,19 @@ struct segment
model::initial_revision_id ntp_revision_deprecated;
cloud_storage::segment_name name;
cloud_storage::partition_manifest::segment_meta meta;

auto serde_fields() {
return std::tie(ntp_revision_deprecated, name, meta);
}
};

struct snapshot
: public serde::
envelope<snapshot, serde::version<0>, serde::compat_version<0>> {
/// List of segments
std::vector<segment> segments;

auto serde_fields() { return std::tie(segments); }
};

} // namespace old
Expand Down
17 changes: 17 additions & 0 deletions src/v/cluster/client_quota_serde.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct entity_key
const client_id_default_match&, const client_id_default_match&)
= default;

auto serde_fields() { return std::tie(); }

friend std::ostream&
operator<<(std::ostream&, const client_id_default_match&);

Expand Down Expand Up @@ -96,6 +98,8 @@ struct entity_key
}

ss::sstring value;

auto serde_fields() { return std::tie(value); }
};

/// client_id_prefix_match is the quota entity type corresponding to the
Expand All @@ -122,8 +126,11 @@ struct entity_key
}

ss::sstring value;
auto serde_fields() { return std::tie(value); }
};

auto serde_fields() { return std::tie(part); }

serde::variant<
client_id_default_match,
client_id_match,
Expand Down Expand Up @@ -166,6 +173,11 @@ struct entity_value
std::optional<uint64_t> producer_byte_rate;
std::optional<uint64_t> consumer_byte_rate;
std::optional<uint64_t> controller_mutation_rate;

auto serde_fields() {
return std::tie(
producer_byte_rate, consumer_byte_rate, controller_mutation_rate);
}
};

/// entity_value_diff describes the quotas diff for an entity_key
Expand Down Expand Up @@ -237,6 +249,8 @@ struct alter_delta_cmd_data

std::vector<op> ops;

auto serde_fields() { return std::tie(ops); }

friend bool
operator==(const alter_delta_cmd_data&, const alter_delta_cmd_data&)
= default;
Expand Down Expand Up @@ -286,6 +300,8 @@ struct alter_quotas_request
alter_delta_cmd_data cmd_data;
model::timeout_clock::duration timeout{};

auto serde_fields() { return std::tie(cmd_data, timeout); }

friend bool
operator==(const alter_quotas_request&, const alter_quotas_request&)
= default;
Expand All @@ -299,6 +315,7 @@ struct alter_quotas_response
using rpc_adl_exempt = std::true_type;

cluster::errc ec;
auto serde_fields() { return std::tie(ec); }

friend bool
operator==(const alter_quotas_response&, const alter_quotas_response&)
Expand Down
2 changes: 2 additions & 0 deletions src/v/cluster/data_migration_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ struct copy_target
: serde::envelope<copy_target, serde::version<0>, serde::compat_version<0>> {
ss::sstring bucket;

auto serde_fields() { return std::tie(bucket); }

friend bool operator==(const copy_target&, const copy_target&) = default;
friend std::ostream& operator<<(std::ostream&, const copy_target&);
};
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/node/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ struct local_state
uint64_t data_target_size{0};
uint64_t data_current_size{0};
uint64_t data_reclaimable_size{0};
auto serde_fields() {
return std::tie(
data_target_size, data_current_size, data_reclaimable_size);
}
friend bool operator==(const log_data_state&, const log_data_state&)
= default;
friend std::ostream& operator<<(std::ostream&, const log_data_state&);
Expand Down
6 changes: 6 additions & 0 deletions src/v/cluster/node_status_rpc_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct node_status_metadata

model::node_id node_id;

auto serde_fields() { return std::tie(node_id); }

friend std::ostream&
operator<<(std::ostream& o, const node_status_metadata& nsm) {
fmt::print(o, "{{node_id:{}}}", nsm.node_id);
Expand All @@ -43,6 +45,8 @@ struct node_status_request

node_status_metadata sender_metadata;

auto serde_fields() { return std::tie(sender_metadata); }

friend std::ostream&
operator<<(std::ostream& o, const node_status_request& r) {
fmt::print(o, "{{sender_metadata: {}}}", r.sender_metadata);
Expand All @@ -57,6 +61,8 @@ struct node_status_reply

node_status_metadata replier_metadata;

auto serde_fields() { return std::tie(replier_metadata); }

friend std::ostream&
operator<<(std::ostream& o, const node_status_reply& r) {
fmt::print(o, "{{replier_metadata: {}}}", r.replier_metadata);
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/prefix_truncate_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct prefix_truncate_record

// May not be empty.
kafka::offset kafka_start_offset{};

auto serde_fields() {
return std::tie(rp_start_offset, kafka_start_offset);
}
};

} // namespace cluster
8 changes: 8 additions & 0 deletions src/v/cluster/self_test_rpc_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ struct empty_request
: serde::
envelope<empty_request, serde::version<0>, serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;

auto serde_fields() { return std::tie(); }
};

struct start_test_request
Expand Down Expand Up @@ -386,6 +388,8 @@ struct get_status_response
std::vector<self_test_result> results;
self_test_stage stage{};

auto serde_fields() { return std::tie(id, status, results, stage); }

friend std::ostream&
operator<<(std::ostream& o, const get_status_response& r) {
fmt::print(
Expand All @@ -405,6 +409,7 @@ struct netcheck_request
using rpc_adl_exempt = std::true_type;
model::node_id source;
iobuf buf;
auto serde_fields() { return std::tie(source, buf); }
friend std::ostream&
operator<<(std::ostream& o, const netcheck_request& r) {
fmt::print(o, "{{source: {} buf: {}}}", r.source, r.buf.size_bytes());
Expand All @@ -417,6 +422,9 @@ struct netcheck_response
envelope<netcheck_response, serde::version<0>, serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;
size_t bytes_read{0};

auto serde_fields() { return std::tie(bytes_read); }

friend std::ostream&
operator<<(std::ostream& o, const netcheck_response& r) {
fmt::print(o, "{{bytes_read: {}}}", r.bytes_read);
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/tests/commands_serialization_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct fake_serde_only_key
using rpc_adl_exempt = std::true_type;

ss::sstring str;

auto serde_fields() { return std::tie(str); }
};
struct fake_serde_only_val
: serde::envelope<
Expand All @@ -55,6 +57,8 @@ struct fake_serde_only_val
using rpc_adl_exempt = std::true_type;

ss::sstring str;

auto serde_fields() { return std::tie(str); }
};
using fake_serde_only_cmd = cluster::controller_command<
fake_serde_only_key,
Expand Down
2 changes: 2 additions & 0 deletions src/v/cluster/topic_recovery_status_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct status_request
: serde::
envelope<status_request, serde::version<0>, serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;

auto serde_fields() { return std::tie(); }
};

struct topic_downloads
Expand Down
2 changes: 2 additions & 0 deletions src/v/cluster/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,8 @@ struct controller_committed_offset_request
serde::version<0>,
serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;

auto serde_fields() { return std::tie(); }
};

struct controller_committed_offset_reply
Expand Down