You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by ra...@apache.org on 2026/10/08 23:47:48 UTC

(iggy) 01/01: Fixing the merge issues

This is an automated email from the ASF dual-hosted git repository.

ryerraguntla pushed a commit to branch feat/gateways-3546-describe-list-groups
in repository https://gitbox.apache.org/repos/asf/iggy.git

commit 389a40c5504901e40fb431f3c832a202a59b293c
Author: ryerraguntla <ra...@gmail.com>
AuthorDate: Thu Oct 8 19:46:44 2026 -0400

    Fixing the merge issues
---
 gateways/kafka/src/group/mod.rs                    |  2 +-
 gateways/kafka/src/group/state.rs                  |  9 ++--
 gateways/kafka/src/protocol/bounds_guard.rs        | 59 +++++++++++++++++++++-
 gateways/kafka/src/protocol/handlers/mod.rs        |  8 +--
 gateways/kafka/tests/common/wire.rs                |  8 +--
 gateways/kafka/tests/golden_wire_fixtures_tests.rs | 12 ++---
 gateways/kafka/tests/server_e2e_tests.rs           |  4 +-
 gateways/kafka/tests/version_firewall_tests.rs     | 25 ++++-----
 8 files changed, 90 insertions(+), 37 deletions(-)

diff --git a/gateways/kafka/src/group/mod.rs b/gateways/kafka/src/group/mod.rs
index 0604571fb..4af5d481a 100644
--- a/gateways/kafka/src/group/mod.rs
+++ b/gateways/kafka/src/group/mod.rs
@@ -581,7 +581,7 @@ impl GroupCoordinator {
         };
         let groups = self.groups.lock().await;
         state::offset_hold(&groups, member, hold, Instant::now())
-  }
+    }
     /// Every group currently in the map, ordered by group id.
     ///
     /// Does not tick. A list names no group, and sweeping here would open rebalances as a side
diff --git a/gateways/kafka/src/group/state.rs b/gateways/kafka/src/group/state.rs
index 832564c45..9106e6daa 100644
--- a/gateways/kafka/src/group/state.rs
+++ b/gateways/kafka/src/group/state.rs
@@ -36,10 +36,11 @@ use tokio::time::Instant;
 use uuid::Uuid;
 
 use crate::group::{
-    DESCRIBE_RESPONSE_TOO_LARGE, GROUP_STATE_COMPLETING_REBALANCE, GROUP_STATE_EMPTY,
-    GROUP_STATE_PREPARING_REBALANCE, GROUP_STATE_STABLE, CommitRequest, GroupCoordinatorConfig, GroupDescription,
-    GroupListing, GroupMember, JoinRequest, JoinResult, JoinedMember, LeaveRequest, LeaveResult, LeavingMember,
-    LeftMember, MemberDescription, SyncRequest, SyncResult, owned_str,
+    CommitRequest, DESCRIBE_RESPONSE_TOO_LARGE, GROUP_STATE_COMPLETING_REBALANCE,
+    GROUP_STATE_EMPTY, GROUP_STATE_PREPARING_REBALANCE, GROUP_STATE_STABLE, GroupCoordinatorConfig,
+    GroupDescription, GroupListing, GroupMember, JoinRequest, JoinResult, JoinedMember,
+    LeaveRequest, LeaveResult, LeavingMember, LeftMember, MemberDescription, SyncRequest,
+    SyncResult, owned_str,
 };
 use crate::protocol::api::{
     API_KEY_DESCRIBE_GROUPS, ERROR_COORDINATOR_NOT_AVAILABLE, ERROR_FENCED_INSTANCE_ID,
diff --git a/gateways/kafka/src/protocol/bounds_guard.rs b/gateways/kafka/src/protocol/bounds_guard.rs
index a45140845..ca541431e 100644
--- a/gateways/kafka/src/protocol/bounds_guard.rs
+++ b/gateways/kafka/src/protocol/bounds_guard.rs
@@ -1116,6 +1116,57 @@ pub fn validate_offset_commit_shape(
     Ok(())
 }
 
+/// Mirrors the field order `OffsetFetchRequest::decode` walks: one group up to v7, a `groups`
+/// array from v8.
+///
+/// # Errors
+///
+/// Returns an error when a declared array/string length cannot fit in the bytes remaining in the
+/// frame, or the body is truncated or malformed in a way that cannot be walked.
+pub fn validate_offset_fetch_shape(
+    version: i16,
+    body: &Bytes,
+    max_frame_size: usize,
+) -> Result<()> {
+    let mut c = ShapeCursor::new(body.clone(), max_frame_size);
+    let flexible = version >= 6;
+
+    if version <= 7 {
+        if flexible {
+            c.compact_string(false)?;
+        } else {
+            c.legacy_string(false)?;
+        }
+        let topics_count = if flexible {
+            c.compact_array_count_nullable()?
+        } else if version >= 2 {
+            c.legacy_array_count_nullable()?
+        } else {
+            c.legacy_array_count()?
+        };
+        walk_offset_fetch_topics(&mut c, topics_count, flexible)?;
+    } else {
+        let groups_count = c.compact_array_count()?;
+        for _ in 0..groups_count {
+            c.compact_string(false)?;
+            if version >= 9 {
+                c.compact_string(true)?;
+                let _member_epoch = c.read_i32()?;
+            }
+            let topics_count = c.compact_array_count_nullable()?;
+            walk_offset_fetch_topics(&mut c, topics_count, flexible)?;
+            c.tagged_fields()?;
+        }
+    }
+    if version >= 7 {
+        let _require_stable = c.read_bool()?;
+    }
+    if flexible {
+        c.tagged_fields()?;
+    }
+    Ok(())
+}
+
 /// Mirrors the field order `DescribeGroupsRequest::decode` walks.
 ///
 /// Group ids are echoed, so their lengths count toward the projected response.
@@ -1293,7 +1344,10 @@ fn walk_offset_fetch_topics(
 #[cfg(test)]
 mod tests {
     use bytes::BytesMut;
-    use kafka_protocol::messages::{DescribeGroupsRequest, LeaveGroupRequest, ListGroupsRequest,OffsetCommitRequest, OffsetFetchRequest};
+    use kafka_protocol::messages::{
+        DescribeGroupsRequest, LeaveGroupRequest, ListGroupsRequest, OffsetCommitRequest,
+        OffsetFetchRequest,
+    };
 
     use super::*;
     use crate::protocol::handlers::decode_exhaustive;
@@ -1839,6 +1893,9 @@ mod tests {
     fn list_groups_v4_huge_states_filter_rejected() {
         let body = Bytes::from_static(&[0xFF, 0xFF, 0xFF, 0xFF, 0x0F]);
         assert!(validate_list_groups_shape(4, &body, TEST_MAX_FRAME_SIZE).is_err());
+    }
+
+    #[test]
     fn offset_commit_v2_null_metadata_accepted() {
         let body = Bytes::from_static(&[
             0x00, 0x01, b'g', // group_id
diff --git a/gateways/kafka/src/protocol/handlers/mod.rs b/gateways/kafka/src/protocol/handlers/mod.rs
index 618244649..78f70a983 100644
--- a/gateways/kafka/src/protocol/handlers/mod.rs
+++ b/gateways/kafka/src/protocol/handlers/mod.rs
@@ -53,10 +53,10 @@ use crate::error::{KafkaProtocolError, Result};
 use crate::protocol::api::{
     API_KEY_API_VERSIONS, API_KEY_CREATE_TOPICS, API_KEY_DESCRIBE_GROUPS, API_KEY_FETCH,
     API_KEY_FIND_COORDINATOR, API_KEY_HEARTBEAT, API_KEY_INIT_PRODUCER_ID, API_KEY_JOIN_GROUP,
-    API_KEY_LEAVE_GROUP, API_KEY_LIST_GROUPS, API_KEY_LIST_OFFSETS, API_KEY_METADATA,API_KEY_OFFSET_COMMIT, API_KEY_OFFSET_FETCH,
-    API_KEY_PRODUCE, API_KEY_SYNC_GROUP, ConnectionState, ERROR_INVALID_REQUEST,
-    ERROR_UNSUPPORTED_VERSION, GatewayState, HandleOutcome, is_supported_version,
-    supported_max_version,
+    API_KEY_LEAVE_GROUP, API_KEY_LIST_GROUPS, API_KEY_LIST_OFFSETS, API_KEY_METADATA,
+    API_KEY_OFFSET_COMMIT, API_KEY_OFFSET_FETCH, API_KEY_PRODUCE, API_KEY_SYNC_GROUP,
+    ConnectionState, ERROR_INVALID_REQUEST, ERROR_UNSUPPORTED_VERSION, GatewayState, HandleOutcome,
+    is_supported_version, supported_max_version,
 };
 
 /// Record encodes and decodes of this many bytes or more run off the async worker.
diff --git a/gateways/kafka/tests/common/wire.rs b/gateways/kafka/tests/common/wire.rs
index 6b1eb5038..3fe19fdfc 100644
--- a/gateways/kafka/tests/common/wire.rs
+++ b/gateways/kafka/tests/common/wire.rs
@@ -31,13 +31,7 @@ use bytes::Bytes;
 use super::codec::Encoder;
 
 /// Consumer-group and admin keys explicitly out of scope in SCOPE.md.
-pub const OUT_OF_SCOPE_API_KEYS: &[(i16, &str)] = &[
-    (8, "OffsetCommit"),
-    (9, "OffsetFetch"),
-    (15, "DescribeGroups"),
-    (16, "ListGroups"),
-    (20, "DeleteTopics"),
-];
+pub const OUT_OF_SCOPE_API_KEYS: &[(i16, &str)] = &[(20, "DeleteTopics")];
 
 /// Append Metadata request fields that follow the topics array for `version`.
 fn write_metadata_request_trailer(enc: &mut Encoder, version: i16) {
diff --git a/gateways/kafka/tests/golden_wire_fixtures_tests.rs b/gateways/kafka/tests/golden_wire_fixtures_tests.rs
index a02509fca..66976ddb0 100644
--- a/gateways/kafka/tests/golden_wire_fixtures_tests.rs
+++ b/gateways/kafka/tests/golden_wire_fixtures_tests.rs
@@ -41,11 +41,11 @@ async fn golden_apiversions_v3_flexible_response_fixture() {
         .await
         .expect_response("test request has acks != 0 and expects a response");
 
-    // error_code=0, api_count=14 (compact array: N+1=15)
+    // error_code=0, api_count=16 (compact array: N+1=17)
     // each entry followed by an empty tagged-fields byte; throttle_ms=0; top-level tagged fields
-    let expected: [u8; 106] = [
+    let expected: [u8; 120] = [
         0x00, 0x00, // error_code
-        0x0F, // compact array count (14+1)
+        0x11, // compact array count (16+1)
         0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, // key 0:  Produce         0-9 (advertised)
         0x00, 0x01, 0x00, 0x04, 0x00, 0x0C, 0x00, // key 1:  Fetch           4-12
         0x00, 0x02, 0x00, 0x01, 0x00, 0x06, 0x00, // key 2:  ListOffsets     1-6
@@ -75,10 +75,10 @@ async fn golden_apiversions_v1_response_fixture() {
         .await
         .expect_response("test request has acks != 0 and expects a response");
 
-    // error_code=0, api_count=14; Produce advertises min=0 per KAFKA-18659; throttle_ms=0
-    let expected: [u8; 94] = [
+    // error_code=0, api_count=16; Produce advertises min=0 per KAFKA-18659; throttle_ms=0
+    let expected: [u8; 106] = [
         0x00, 0x00, // error_code
-        0x00, 0x00, 0x00, 0x0E, // api count = 14
+        0x00, 0x00, 0x00, 0x10, // api count = 16
         0x00, 0x00, 0x00, 0x00, 0x00, 0x09, // key 0:  Produce         0-9 (advertised)
         0x00, 0x01, 0x00, 0x04, 0x00, 0x0C, // key 1:  Fetch           4-12
         0x00, 0x02, 0x00, 0x01, 0x00, 0x06, // key 2:  ListOffsets     1-6
diff --git a/gateways/kafka/tests/server_e2e_tests.rs b/gateways/kafka/tests/server_e2e_tests.rs
index d9105a6a4..7ab5ebec4 100644
--- a/gateways/kafka/tests/server_e2e_tests.rs
+++ b/gateways/kafka/tests/server_e2e_tests.rs
@@ -105,9 +105,9 @@ async fn e2e_unsupported_api_key_closes_connection() {
     let (addr, _shutdown) = spawn_test_server().await;
     let mut stream = TcpStream::connect(addr).await.unwrap();
 
-    // Unknown api key (16, ListGroups) has no response schema this gateway can encode, so the
+    // Unknown api key (20, DeleteTopics) has no response schema this gateway can encode, so the
     // server closes the connection without a (misparseable) response body.
-    let frame1 = build_request_frame(16, 2, 99, Some("e2e-test"), &[]);
+    let frame1 = build_request_frame(20, 2, 99, Some("e2e-test"), &[]);
     stream.write_all(&frame1).await.unwrap();
 
     assert_eq!(
diff --git a/gateways/kafka/tests/version_firewall_tests.rs b/gateways/kafka/tests/version_firewall_tests.rs
index 5cec28aeb..7568428b9 100644
--- a/gateways/kafka/tests/version_firewall_tests.rs
+++ b/gateways/kafka/tests/version_firewall_tests.rs
@@ -39,10 +39,10 @@ use tokio::net::TcpStream;
 use iggy_gateway_kafka::protocol::api::{
     API_KEY_API_VERSIONS, API_KEY_CREATE_TOPICS, API_KEY_DESCRIBE_GROUPS, API_KEY_FETCH,
     API_KEY_FIND_COORDINATOR, API_KEY_HEARTBEAT, API_KEY_INIT_PRODUCER_ID, API_KEY_JOIN_GROUP,
-    API_KEY_LEAVE_GROUP, API_KEY_LIST_GROUPS, API_KEY_LIST_OFFSETS, API_KEY_METADATA, API_KEY_OFFSET_COMMIT, API_KEY_OFFSET_FETCH,
-    API_KEY_PRODUCE, API_KEY_SYNC_GROUP, ERROR_INVALID_REQUEST, ERROR_NONE,
-    ERROR_UNSUPPORTED_VERSION, advertised_min_version, handle_request, is_supported_version,
-    supported_api_ranges,
+    API_KEY_LEAVE_GROUP, API_KEY_LIST_GROUPS, API_KEY_LIST_OFFSETS, API_KEY_METADATA,
+    API_KEY_OFFSET_COMMIT, API_KEY_OFFSET_FETCH, API_KEY_PRODUCE, API_KEY_SYNC_GROUP,
+    ERROR_INVALID_REQUEST, ERROR_NONE, ERROR_UNSUPPORTED_VERSION, advertised_min_version,
+    handle_request, is_supported_version, supported_api_ranges,
 };
 
 use codec::Decoder;
@@ -58,15 +58,15 @@ use wire::{
     JoinGroupParams, OUT_OF_SCOPE_API_KEYS, SyncGroupParams, build_api_versions_flexible_request,
     build_create_topics_empty_request, build_describe_groups_request,
     build_fetch_empty_topics_request, build_find_coordinator_request, build_heartbeat_request,
-    build_init_producer_id_request, build_join_group_request, build_leave_group_request, build_list_offsets_request,
+    build_init_producer_id_request, build_join_group_request, build_leave_group_request,
     build_list_groups_request, build_list_offsets_request, build_metadata_all_topics_flexible,
-    build_metadata_all_topics_legacy, build_metadata_flexible_request_v10,build_offset_commit_request, build_offset_fetch_request,
-    build_sync_group_request,
+    build_metadata_all_topics_legacy, build_metadata_flexible_request_v10,
+    build_offset_commit_request, build_offset_fetch_request, build_sync_group_request,
 };
 
 #[test]
-fn supported_ranges_table_has_fourteen_entries() {
-    assert_eq!(supported_api_ranges().len(), 14);
+fn supported_ranges_table_has_sixteen_entries() {
+    assert_eq!(supported_api_ranges().len(), 16);
 }
 
 #[test]
@@ -102,9 +102,10 @@ fn is_supported_version_matches_scope_table() {
 /// `advertised_min_version` - the same reasoning applies to it as the function under test.
 ///
 /// Relies on `SUPPORTED_RANGES` (src) and `SCOPED_API_KEYS` (test) sharing declaration order
-/// (Produce, Fetch, `ListOffsets`, Metadata, `ApiVersions`, `CreateTopics`, `FindCoordinator`,
-/// `JoinGroup`, Heartbeat, `LeaveGroup`, `SyncGroup`, `DescribeGroups`, `ListGroups`) -
-/// `supported_ranges_table_has_fourteen_entries` plus
+/// (Produce, Fetch, `ListOffsets`, Metadata, `OffsetCommit`, `OffsetFetch`, `ApiVersions`,
+/// `CreateTopics`, `InitProducerId`, `FindCoordinator`, `JoinGroup`, Heartbeat, `LeaveGroup`,
+/// `SyncGroup`, `DescribeGroups`, `ListGroups`) -
+/// `supported_ranges_table_has_sixteen_entries` plus
 /// `is_supported_version_matches_scope_table` already pin that both tables cover the same keys.
 #[tokio::test]
 async fn apiversions_advertises_exact_supported_ranges_v1() {