Elioooon commented on code in PR #4017:
URL: https://github.com/apache/iggy/pull/4017#discussion_r3939474786


##########
foreign/python/src/client.rs:
##########
@@ -777,6 +777,74 @@ impl IggyClient {
         })
     }
 
+    /// Create partitions for a topic.
+    ///
+    /// Args:
+    ///     stream_id: Stream identifier as `str | int`.
+    ///     topic_id: Topic identifier as `str | int`.
+    ///     partitions_count: Number of partitions to create.
+    ///
+    /// Returns:
+    ///     An awaitable that resolves to `None` when the partitions are 
created.
+    ///
+    /// Raises:
+    ///     ValueError: If an identifier is invalid.
+    ///     RuntimeError: If the request fails.
+    
#[gen_stub(override_return_type(type_repr="collections.abc.Awaitable[None]", 
imports=("collections.abc")))]
+    fn create_partitions<'a>(
+        &self,
+        py: Python<'a>,
+        stream_id: PyIdentifier,
+        topic_id: PyIdentifier,
+        partitions_count: u32,
+    ) -> PyResult<Bound<'a, PyAny>> {
+        let stream_id = Identifier::try_from(stream_id)?;
+        let topic_id = Identifier::try_from(topic_id)?;
+        let inner = self.inner.clone();
+
+        future_into_py(py, async move {
+            inner
+                .create_partitions(&stream_id, &topic_id, partitions_count)
+                .await
+                .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, 
_>(e.to_string()))?;
+            Ok(())
+        })
+    }
+
+    /// Delete the last partitions from a topic, including all messages stored 
in them.

Review Comment:
   Addressed in 67df430. Create documents that new partitions remain unassigned 
until the next consumer-group rebalance; delete documents that groups are 
rebalanced away from removed partitions.



##########
foreign/python/src/client.rs:
##########
@@ -777,6 +777,74 @@ impl IggyClient {
         })
     }
 
+    /// Create partitions for a topic.
+    ///
+    /// Args:
+    ///     stream_id: Stream identifier as `str | int`.
+    ///     topic_id: Topic identifier as `str | int`.
+    ///     partitions_count: Number of partitions to create.
+    ///
+    /// Returns:
+    ///     An awaitable that resolves to `None` when the partitions are 
created.
+    ///
+    /// Raises:

Review Comment:
   Addressed in 67df430. Both methods now document `OverflowError` for negative 
or oversized Python integers, with parametrized tests for -1 and 2**32.



##########
foreign/python/src/client.rs:
##########
@@ -777,6 +777,74 @@ impl IggyClient {
         })
     }
 
+    /// Create partitions for a topic.
+    ///
+    /// Args:
+    ///     stream_id: Stream identifier as `str | int`.
+    ///     topic_id: Topic identifier as `str | int`.
+    ///     partitions_count: Number of partitions to create.
+    ///
+    /// Returns:
+    ///     An awaitable that resolves to `None` when the partitions are 
created.

Review Comment:
   Addressed in 67df430. The create docstring now describes consecutive 
zero-based IDs above the current maximum and reuse after deletion.



##########
foreign/python/tests/test_partition.py:
##########
@@ -0,0 +1,124 @@
+# 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.
+
+import pytest
+
+from apache_iggy import IggyClient
+
+
[email protected]
+async def test_create_and_delete_partitions(iggy_client: IggyClient, 
unique_name):
+    stream_name = unique_name()
+    topic_name = unique_name()
+
+    await iggy_client.create_stream(stream_name)
+    await iggy_client.create_topic(
+        stream=stream_name, name=topic_name, partitions_count=2
+    )
+
+    await iggy_client.create_partitions(stream_name, topic_name, 2)
+    topic = await iggy_client.get_topic(stream_name, topic_name)
+    assert topic is not None
+    assert topic.partitions_count == 4
+    assert [partition.id for partition in topic.partitions] == [0, 1, 2, 3]
+
+    await iggy_client.delete_partitions(stream_name, topic_name, 2)
+    topic = await iggy_client.get_topic(stream_name, topic_name)
+    assert topic is not None
+    assert topic.partitions_count == 2
+    assert [partition.id for partition in topic.partitions] == [0, 1]
+
+
[email protected]
+async def test_partition_management_accepts_numeric_ids(
+    iggy_client: IggyClient, unique_name
+):
+    stream_name = unique_name()
+    topic_name = unique_name()
+
+    await iggy_client.create_stream(stream_name)
+    stream = await iggy_client.get_stream(stream_name)
+    assert stream is not None
+    await iggy_client.create_topic(
+        stream=stream.id, name=topic_name, partitions_count=2
+    )
+    topic = await iggy_client.get_topic(stream.id, topic_name)
+    assert topic is not None
+
+    await iggy_client.create_partitions(stream.id, topic.id, 1)
+    await iggy_client.delete_partitions(stream.id, topic.id, 1)
+
+    topic = await iggy_client.get_topic(stream.id, topic.id)
+    assert topic is not None
+    assert [partition.id for partition in topic.partitions] == [0, 1]

Review Comment:
   Addressed in 67df430. The numeric-ID test now reads immediately after create 
and asserts count 3 and IDs `[0, 1, 2]` before deleting and asserting the final 
state.



##########
foreign/python/tests/test_partition.py:
##########
@@ -0,0 +1,124 @@
+# 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.
+
+import pytest
+
+from apache_iggy import IggyClient
+
+
[email protected]
+async def test_create_and_delete_partitions(iggy_client: IggyClient, 
unique_name):

Review Comment:
   Addressed in 67df430. The success test sends a message to newly created 
partition 3 before deleting it. The server-side fix also zeros deleted 
`PartitionStats` before eviction so their message and byte counters are rolled 
out of topic and stream totals; the metadata regression test pins this behavior.



-- 
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]

Reply via email to