Skip to content

Commit

Permalink
IGNITE-18794 .NET: Fix DivideByZeroException in GetPreferredNode (apa…
Browse files Browse the repository at this point in the history
…che#1669)

Partition assignment can be null or empty on table drop. Skip awareness logic in this case.
  • Loading branch information
ptupitsyn authored and lowka committed Mar 18, 2023
1 parent 798ee95 commit a3f39dd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs
Expand Up @@ -194,13 +194,20 @@ internal async ValueTask<PreferredNode> 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<string[]> GetPartitionAssignmentAsync()
private async ValueTask<string[]?> GetPartitionAssignmentAsync()
{
var socketVer = _socket.PartitionAssignmentVersion;
var assignment = _partitionAssignment;
Expand Down Expand Up @@ -346,18 +353,24 @@ private Schema ReadSchema(ref MsgPackReader r)
/// Loads the partition assignment.
/// </summary>
/// <returns>Partition assignment.</returns>
private async Task<string[]> LoadPartitionAssignmentAsync()
private async Task<string[]?> LoadPartitionAssignmentAsync()
{
using var writer = ProtoCommon.GetMessageWriter();
writer.MessageWriter.Write(Id);

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++)
Expand Down

0 comments on commit a3f39dd

Please sign in to comment.