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

k/group_metadata: added support for v1 offset metadata value #7923

Merged
merged 1 commit into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/v/kafka/server/group_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,32 @@ void offset_metadata_value::encode(
response_writer& writer, const offset_metadata_value& v) {
writer.write(v.version);
writer.write(v.offset);
writer.write(v.leader_epoch);
if (v.version >= group_metadata_version{3}) {
writer.write(v.leader_epoch);
}
writer.write(v.metadata);
writer.write(v.commit_timestamp);
if (v.version == group_metadata_version{1}) {
writer.write(v.expiry_timestamp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question, could there ever be an issue with compatibility across versions because we were always deserializing this int64 value but never serializing it?

Copy link
Member Author

Choose a reason for hiding this comment

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

not really since we only deserializing this for version == 1

}
}

offset_metadata_value offset_metadata_value::decode(request_reader& reader) {
offset_metadata_value ret;
auto version = read_metadata_version(reader);
validate_version_range(
version, "offset_metadata_value", offset_metadata_value::version);
version, "offset_metadata_value", offset_metadata_value::latest_version);

ret.version = version;
ret.offset = model::offset(reader.read_int64());
if (version >= group_metadata_version{3}) {
ret.leader_epoch = kafka::leader_epoch(reader.read_int32());
}
ret.metadata = reader.read_string();
ret.commit_timestamp = model::timestamp(reader.read_int64());
// read and ignore expiry_timestamp only present in version 1
// read expiry_timestamp only present in version 1
if (version == group_metadata_version{1}) {
reader.read_int64();
ret.expiry_timestamp = model::timestamp(reader.read_int64());
}

return ret;
Expand Down Expand Up @@ -418,11 +424,14 @@ std::ostream& operator<<(std::ostream& o, const offset_metadata_key& v) {
std::ostream& operator<<(std::ostream& o, const offset_metadata_value& v) {
fmt::print(
o,
"{{offset: {}, leader_epoch: {}, metadata: {}, commit_timestap: {}}}",
"{{offset: {}, leader_epoch: {}, metadata: {}, commit_timestamp: {}, "
"expiry_timestamp: {}, version: {}}}",
v.offset,
v.leader_epoch,
v.metadata,
v.commit_timestamp);
v.commit_timestamp,
v.expiry_timestamp,
v.version);
return o;
}
} // namespace kafka
6 changes: 5 additions & 1 deletion src/v/kafka/server/group_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ struct offset_metadata_key {
* The value type for offset commit records, consistent with Kafka format
*/
struct offset_metadata_value {
static constexpr group_metadata_version version{3};
static constexpr group_metadata_version latest_version{3};
group_metadata_version version = latest_version;
model::offset offset;
// present only in version >= 3
kafka::leader_epoch leader_epoch = invalid_leader_epoch;
ss::sstring metadata;
model::timestamp commit_timestamp;
// present only in version 1
model::timestamp expiry_timestamp{-1};

friend std::ostream&
operator<<(std::ostream&, const offset_metadata_value&);
Expand Down
11 changes: 11 additions & 0 deletions src/v/kafka/server/tests/group_metadata_serialization_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ FIXTURE_TEST(metadata_rt_test, fixture) {
offset_key.partition = random_named_int<model::partition_id>();

roundtrip_test(offset_key);
// version 1
kafka::offset_metadata_value offset_md_v1;
offset_md_v1.version = kafka::group_metadata_version(1);

offset_md_v1.offset = random_named_int<model::offset>();
offset_md_v1.metadata = random_named_string<ss::sstring>();
offset_md_v1.commit_timestamp = model::timestamp::now();
offset_md_v1.expiry_timestamp = model::timestamp::now();

roundtrip_test(offset_md_v1);