From a3f39dd5dc8abdbe375ce0be4c6603c157f1ce29 Mon Sep 17 00:00:00 2001 From: Pavel Tupitsyn Date: Tue, 14 Feb 2023 15:34:07 +0200 Subject: [PATCH] IGNITE-18794 .NET: Fix DivideByZeroException in GetPreferredNode (#1669) Partition assignment can be null or empty on table drop. Skip awareness logic in this case. --- .../Apache.Ignite/Internal/Table/Table.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs index 2e110f246b45..d9299946586f 100644 --- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs +++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs @@ -194,13 +194,20 @@ internal async ValueTask GetPreferredNode(int colocationHash, ITr } var assignment = await GetPartitionAssignmentAsync().ConfigureAwait(false); + + if (assignment == null || assignment.Length == 0) + { + // Happens on table drop. + return default; + } + var partition = Math.Abs(colocationHash % assignment.Length); var nodeId = assignment[partition]; return PreferredNode.FromId(nodeId); } - private async ValueTask GetPartitionAssignmentAsync() + private async ValueTask GetPartitionAssignmentAsync() { var socketVer = _socket.PartitionAssignmentVersion; var assignment = _partitionAssignment; @@ -346,7 +353,7 @@ private Schema ReadSchema(ref MsgPackReader r) /// Loads the partition assignment. /// /// Partition assignment. - private async Task LoadPartitionAssignmentAsync() + private async Task LoadPartitionAssignmentAsync() { using var writer = ProtoCommon.GetMessageWriter(); writer.MessageWriter.Write(Id); @@ -354,10 +361,16 @@ private async Task LoadPartitionAssignmentAsync() using var resBuf = await _socket.DoOutInOpAsync(ClientOp.PartitionAssignmentGet, writer).ConfigureAwait(false); return Read(); - string[] Read() + string[]? Read() { var r = resBuf.GetReader(); var count = r.ReadArrayHeader(); + + if (count == 0) + { + return null; + } + var res = new string[count]; for (int i = 0; i < count; i++)