ilikepi63 commented on code in PR #1624: URL: https://github.com/apache/iggy/pull/1624#discussion_r1993611521
########## sdk/src/segments/delete_segments.rs: ########## @@ -0,0 +1,204 @@ +/* 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. + */ +use crate::bytes_serializable::BytesSerializable; +use crate::command::{Command, DELETE_SEGMENTS_CODE}; +use crate::error::IggyError; +use crate::identifier::Identifier; +use crate::utils::sizeable::Sizeable; +use crate::validatable::Validatable; +use bytes::{BufMut, Bytes, BytesMut}; +use serde::{Deserialize, Serialize}; +use std::fmt::Display; + +use super::MAX_NO_OF_SEGMENTS_TO_BE_DELETED; + +/// `DeleteSegments` command is used to delete segments from a partition. +/// It has additional payload: +/// - `stream_id` - unique stream ID (numeric or name). +/// - `topic_id` - unique topic ID (numeric or name). +/// - `partition_id` - unique partition ID (numeric or name). +/// - `segments_count` - number of segments in the partition to delete, max value is defined in MAX_NO_OF_SEGMENTS_TO_BE_DELETED. +#[derive(Debug, Serialize, Deserialize, PartialEq)] +pub struct DeleteSegments { + /// Unique stream ID (numeric or name). + #[serde(skip)] + pub stream_id: Identifier, + /// Unique topic ID (numeric or name). + #[serde(skip)] + pub topic_id: Identifier, + /// Unique partition ID (numeric or name). + #[serde(skip)] + pub partition_id: u32, + /// Number of segments in the partition to delete, max value is 1000. + pub segments_count: u32, +} + +impl Command for DeleteSegments { + fn code(&self) -> u32 { + DELETE_SEGMENTS_CODE + } +} + +impl Default for DeleteSegments { + fn default() -> Self { + DeleteSegments { + segments_count: 1, + stream_id: Identifier::default(), + topic_id: Identifier::default(), + partition_id: u32::default(), + } + } +} + +impl Validatable<IggyError> for DeleteSegments { + fn validate(&self) -> Result<(), IggyError> { + if !(1..=MAX_NO_OF_SEGMENTS_TO_BE_DELETED).contains(&self.segments_count) { + return Err(IggyError::TooManySegments(self.segments_count)); Review Comment: :white_check_mark: -- 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]
