ryerraguntla commented on code in PR #4400: URL: https://github.com/apache/iggy/pull/4400#discussion_r4179496428
########## gateways/kafka/src/protocol/handlers/delete_topics.rs: ########## @@ -0,0 +1,286 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! `DeleteTopics` (API key 20). +//! +//! Deletes the Iggy topic a Kafka topic name resolves to. Never deletes the backing Iggy +//! stream - see [`IggyBridge::delete_kafka_topic`]'s own doc comment for why: the shared +//! `default_stream` can hold other Kafka topics' data, and this bridge has no way to tell +//! whether the stream it just emptied is actually abandoned or just temporarily topic-less. +//! +//! `DeletableTopicResult.error_message` is only encoded on the wire at v5+ (`kafka_protocol`'s +//! own gate) - a client negotiating v1-v4 gets `error_code` only, with any text this module sets +//! silently dropped. Unlike `CreateTopics`, whose equivalent field is encoded at every version it +//! supports. + +use std::time::Duration; + +use bytes::Bytes; +use iggy::prelude::IggyError; +use kafka_protocol::messages::delete_topics_response::DeletableTopicResult; +use kafka_protocol::messages::{DeleteTopicsRequest, DeleteTopicsResponse, TopicName}; +use kafka_protocol::protocol::StrBytes; + +use tokio::time::Instant; + +use crate::bridge::{BridgeError, IggyBridge}; +use crate::error::Result; +use crate::protocol::api::{ + API_KEY_DELETE_TOPICS, ApiVersionRange, ERROR_INVALID_REQUEST, ERROR_NONE, + ERROR_NOT_CONTROLLER, ERROR_POLICY_VIOLATION, ERROR_REQUEST_TIMED_OUT, GatewayState, + HandleOutcome, +}; +use crate::protocol::bounds_guard::validate_delete_topics_shape; +use crate::protocol::handlers::{ + decode_guarded, encode_message, handle_versioned_request, is_supported_version, + respond_or_close, unsupported_version_response, +}; + +/// This bridge never advertises v6 (the `topics: Vec<DeleteTopicState>`, topic-id-based shape). +/// +/// It has no concept of a Kafka topic id, only the Kafka-side name `TopicMapping` resolves. v1 +/// is the crate's own floor (`kafka_protocol` does not implement v0 for this message). +pub const RANGE: ApiVersionRange = ApiVersionRange { + api_key: API_KEY_DELETE_TOPICS, + min_version: 1, + max_version: 5, +}; + +/// Cap on topic names one `DeleteTopics` request may address through the bridge. +/// +/// Same rationale as `create_topics::MAX_BRIDGE_BACKED_TOPICS`, but counted differently: every +/// name here costs its own bridge round trip against the single lockstep `IggyClient` every +/// Kafka connection on this gateway shares, duplicates included, so this charges the raw count +/// rather than the distinct one `CreateTopics` charges. +const MAX_BRIDGE_BACKED_TOPICS: usize = 100; + +/// Same bounds as `create_topics::clamp_request_timeout` - this request carries the identical +/// KIP-4 `timeout_ms` field for the identical reason (a client-supplied deadline that becomes +/// the aggregate bridge-work budget, otherwise unchecked). +const MIN_REQUEST_TIMEOUT: Duration = Duration::from_millis(1_000); +const MAX_REQUEST_TIMEOUT: Duration = Duration::from_secs(30); + +fn clamp_request_timeout(timeout_ms: i32) -> Duration { Review Comment: fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
