Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-18794 .NET: Fix DivideByZeroException in GetPreferredNode #1669

Merged
merged 5 commits into from Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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