You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ptupitsyn (via GitHub)" <gi...@apache.org> on 2026/01/23 10:33:37 UTC

[PR] IGNITE-27265 .NET: Improve partition API [ignite-3]

ptupitsyn opened a new pull request, #7467:
URL: https://github.com/apache/ignite-3/pull/7467

   (no comment)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27265 .NET: Improve partition API [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #7467:
URL: https://github.com/apache/ignite-3/pull/7467#discussion_r2721356915


##########
modules/platforms/dotnet/Apache.Ignite/Table/IPartitionDistribution.cs:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Table;
+
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Threading.Tasks;
+using Internal.Table.Serialization;
+using Mapper;
+using Network;
+
+/// <summary>
+/// Partition distribution provides table partition information.
+/// This interface can be used to get all partitions of a table, the location of the primary replica of a partition,
+/// the partition for a specific table key.
+/// </summary>
+public interface IPartitionDistribution
+{
+    /// <summary>
+    /// Gets the primary replicas for all partitions.
+    /// <para />
+    /// NOTE: Prefer <see cref="GetPrimaryReplicaAsync"/> for performance-critical code.
+    /// </summary>
+    /// <returns>Map of partition to the primary replica node.</returns>
+    ValueTask<IReadOnlyDictionary<IPartition, IClusterNode>> GetPrimaryReplicasAsync();
+
+    /// <summary>
+    /// Gets all partitions hosted by the specified node as a primary replica as of the time of the call.
+    /// <para />
+    /// NOTE: This assignment may become outdated if a re-assignment happens on the cluster.
+    /// </summary>
+    /// <param name="node">Cluster node.</param>
+    /// <returns>A task representing the asynchronous operation with a list of all partitions hosted by the specified node
+    /// as a primary replica.</returns>
+    ValueTask<IReadOnlyList<IPartition>> GetPrimaryReplicasAsync(IClusterNode node);
+
+    /// <summary>
+    /// Gets the primary replica for the specified partition.
+    /// <para />
+    /// NOTE: Prefer this method over <see cref="GetPrimaryReplicasAsync()"/> for performance-critical code.
+    /// </summary>
+    /// <param name="partition">Partition.</param>
+    /// <returns>Primary replica.</returns>
+    ValueTask<IClusterNode> GetPrimaryReplicaAsync(IPartition partition);
+
+    /// <summary>
+    /// Gets the partition for the specified table key.
+    /// </summary>
+    /// <param name="tuple">Table key tuple.</param>

Review Comment:
   Very good catch. There is a bug, I expected it to work with full tuples, but it fails: https://issues.apache.org/jira/browse/IGNITE-27655



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27265 .NET: Improve partition API [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #7467:
URL: https://github.com/apache/ignite-3/pull/7467#discussion_r2721243953


##########
modules/platforms/dotnet/Apache.Ignite/Table/IPartitionDistribution.cs:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Table;
+
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Threading.Tasks;
+using Internal.Table.Serialization;
+using Mapper;
+using Network;
+
+/// <summary>
+/// Partition distribution provides table partition information.
+/// This interface can be used to get all partitions of a table, the location of the primary replica of a partition,
+/// the partition for a specific table key.
+/// </summary>
+public interface IPartitionDistribution
+{
+    /// <summary>
+    /// Gets the primary replicas for all partitions.
+    /// <para />
+    /// NOTE: Prefer <see cref="GetPrimaryReplicaAsync"/> for performance-critical code.
+    /// </summary>
+    /// <returns>Map of partition to the primary replica node.</returns>
+    ValueTask<IReadOnlyDictionary<IPartition, IClusterNode>> GetPrimaryReplicasAsync();
+
+    /// <summary>
+    /// Gets all partitions hosted by the specified node as a primary replica as of the time of the call.
+    /// <para />
+    /// NOTE: This assignment may become outdated if a re-assignment happens on the cluster.
+    /// </summary>
+    /// <param name="node">Cluster node.</param>
+    /// <returns>A task representing the asynchronous operation with a list of all partitions hosted by the specified node
+    /// as a primary replica.</returns>
+    ValueTask<IReadOnlyList<IPartition>> GetPrimaryReplicasAsync(IClusterNode node);
+
+    /// <summary>
+    /// Gets the primary replica for the specified partition.
+    /// <para />
+    /// NOTE: Prefer this method over <see cref="GetPrimaryReplicasAsync()"/> for performance-critical code.
+    /// </summary>
+    /// <param name="partition">Partition.</param>
+    /// <returns>Primary replica.</returns>
+    ValueTask<IClusterNode> GetPrimaryReplicaAsync(IPartition partition);
+
+    /// <summary>
+    /// Gets the partition for the specified table key.
+    /// </summary>
+    /// <param name="tuple">Table key tuple.</param>

Review Comment:
   I wonder should we specify if it's OK for the tuple to have non-key fields in cases like this?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27265 .NET: Improve partition API [ignite-3]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7467:
URL: https://github.com/apache/ignite-3/pull/7467#discussion_r2720669643


##########
modules/platforms/dotnet/Apache.Ignite.Tests/Table/PartitionManagerTests.cs:
##########
@@ -34,14 +33,15 @@ namespace Apache.Ignite.Tests.Table;
 /// <summary>
 /// Tests for <see cref="IPartitionManager"/>.
 /// </summary>
+[Obsolete("Obsolete. Replaced by PartitionDistributionTests.")]
 public class PartitionManagerTests : IgniteTestsBase
 {
     [Test]
     public async Task TestGetPrimaryReplicas()
     {
         var replicas = await Table.PartitionManager.GetPrimaryReplicasAsync();
         var replicasNodes = replicas.Values.Distinct().OrderBy(x => ((IPEndPoint)x.Address).Port).ToList();
-        var replicasPartitions = replicas.Keys.Select(x => ((HashPartition)x).PartitionId).OrderBy(x => x).ToList();
+        var replicasPartitions = replicas.Keys.Select(x => ((HashPartition)x).Id).OrderBy(x => x).ToList();
 

Review Comment:
   `replicasPartitions` is now a `List<long>` because `HashPartition.Id` is `long`. The later `CollectionAssert.AreEqual(Enumerable.Range(...), replicasPartitions, ...)` in this test will fail because it compares boxed `int` vs boxed `long` values. Convert the expected range to `long` (or convert `replicasPartitions` to `int` if long is not required here).



##########
modules/platforms/dotnet/Apache.Ignite.Tests/Table/PartitionDistributionTests.cs:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Tests.Table;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+using Common.Compute;
+using Common.Table;
+using Ignite.Compute;
+using Ignite.Table;
+using Internal.Table;
+using Network;
+using NUnit.Framework;
+using static Common.Table.TestTables;
+
+/// <summary>
+/// Tests for <see cref="IPartitionDistribution"/>.
+/// </summary>
+public class PartitionDistributionTests : IgniteTestsBase
+{
+    [Test]
+    public async Task TestGetPrimaryReplicas()
+    {
+        var replicas = await Table.PartitionDistribution.GetPrimaryReplicasAsync();
+        var replicasNodes = replicas.Values.Distinct().OrderBy(x => ((IPEndPoint)x.Address).Port).ToList();
+        var replicasPartitions = replicas.Keys.Select(x => ((HashPartition)x).Id).OrderBy(x => x).ToList();
+
+        var expectedNodes = (await Client.GetClusterNodesAsync())
+            .OrderBy(x => ((IPEndPoint)x.Address).Port)
+            .ToList();
+
+        CollectionAssert.AreEqual(expectedNodes, replicasNodes, "Primary replicas should be distributed among all nodes");
+
+        CollectionAssert.AreEqual(
+            Enumerable.Range(0, TablePartitionCount),

Review Comment:
   `replicasPartitions` is a `List<long>` (partition ids are `long`), but the expected sequence is `Enumerable.Range(...)` which yields `int`. `CollectionAssert.AreEqual` will fail because boxed `int` and boxed `long` are not equal even when values match. Convert the expected sequence to `long` (or convert `replicasPartitions` to `int` if appropriate).
   ```suggestion
               Enumerable.Range(0, TablePartitionCount).Select(x => (long)x),
   ```



##########
modules/platforms/dotnet/Apache.Ignite/Table/ITable.cs:
##########
@@ -50,7 +51,13 @@ public interface ITable
         /// <summary>
         /// Gets the partition manager.
         /// </summary>
-        public IPartitionManager PartitionManager { get; }
+        [Obsolete("Replaced by PartitionDistribution property.")]
+        public IPartitionManager PartitionManager => (IPartitionManager)PartitionDistribution;

Review Comment:
   `PartitionManager` now has a default implementation that casts `PartitionDistribution` to `IPartitionManager`. Nothing enforces that `PartitionDistribution` implementations also implement `IPartitionManager`, so this can throw `InvalidCastException` at runtime for custom `ITable` implementations. To make the obsolete API reliably usable, consider expressing the relationship in the type system (e.g., `IPartitionDistribution` inheriting from `IPartitionManager`, or making `PartitionManager` abstract again and keeping both properties implemented by concrete tables).
   ```suggestion
           public IPartitionManager PartitionManager { get; }
   ```



##########
modules/platforms/dotnet/Apache.Ignite/Internal/Table/PartitionManager.cs:
##########
@@ -76,20 +79,20 @@ public async ValueTask<IClusterNode> GetPrimaryReplicaAsync(IPartition partition
             throw new ArgumentException("Unsupported partition type: " + partition.GetType());
         }
 
-        if (hashPartition.PartitionId < 0)
+        if (hashPartition.Id < 0)
         {
             throw new ArgumentException("Partition id can't be negative: " + partition);
         }
 
         var replicas = await GetPrimaryReplicasInternalAsync().ConfigureAwait(false);
         var nodes = replicas.Nodes;
 
-        if (hashPartition.PartitionId >= nodes.Length)
+        if (hashPartition.Id >= nodes.Length)
         {
             throw new ArgumentException($"Partition id can't be greater than {nodes.Length - 1}: {partition}");
         }
 
-        return nodes[hashPartition.PartitionId];
+        return nodes[hashPartition.Id];

Review Comment:
   `hashPartition.Id` is a `long`, but `nodes` is an array indexed by `int`. `return nodes[hashPartition.Id];` will not compile (and even if casted implicitly, it would be unsafe). After validating the range, cast to `int` (prefer `checked`) and index with the `int` value (or change the partition id type back to `int` if long is not required).
   ```suggestion
           var index = checked((int)hashPartition.Id);
           return nodes[index];
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27265 .NET: Improve partition API [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn merged PR #7467:
URL: https://github.com/apache/ignite-3/pull/7467


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org