Alexey Gidaspov created IGNITE-29350: ----------------------------------------
Summary: ArithmeticException: / by zero in affinity calculation
when a dynamic cache group start coincides with a node join exchange merge
Key: IGNITE-29350
URL: https://issues.apache.org/jira/browse/IGNITE-29350
Project: Ignite
Issue Type: Task
Reporter: Alexey Gidaspov
Assignee: Alexey Gidaspov
When a dynamic cache group is started while a server node join exchange is
still in progress, the coordinator may recalculate affinity for that group
using an outdated discovery
snapshot.
Under the following conditions:
• the cache group is already present in the affinity registry;
• a non-empty prevAssignment or baseline assignment exists;
• the discovery snapshot for the current exchange contains no affinity nodes
for the group;
IdealAffinityAssignment.calculatePrimaries() calls nodes.size() and then
divides by that value. Since it is zero, an ArithmeticException: / by zero is
raised. The error is
classified as CRITICAL_ERROR and may cause the coordinator JVM to halt.
Typical log sequence:
```text
Coordinator received all messages, try merge
Stop merge, custom event found: DynamicCacheChangeBatch
java.lang.ArithmeticException: / by zero
```
Relevant stack trace:
```text
IdealAffinityAssignment.calculatePrimaries
IdealAffinityAssignment.create
GridAffinityAssignmentCache.calculate
CacheAffinitySharedManager.initAffinityOnNodeJoin
CacheAffinitySharedManager.onServerJoinWithExchangeMergeProtocol
GridDhtPartitionsExchangeFuture.finishExchangeOnCoordinator
```
Steps to reproduce
1. Start one server node and activate the cluster.
2. Start a second server node.
3. Before the node join exchange completes, initiate creation of a new
partitioned cache group from the first server node.
4. Allow the coordinator to stop the exchange merge because of the
DynamicCacheChangeBatch custom event and finish the node join exchange.
Expected behavior
The coordinator skips affinity initialization for a cache group whose
startTopologyVersion is later than the current exchange version. The group is
initialized by its own exchange.
No critical failure occurs.
Actual behavior
The coordinator recalculates affinity using an outdated snapshot with an
empty affinity node list and fails with ArithmeticException: / by zero.
Suggested fix
In CacheAffinitySharedManager.initAffinityOnNodeJoin, skip cache groups
whose startTopologyVersion is after fut.initialVersion(), similarly to the
guard introduced for the local
join path by IGNITE-28806.
As additional protection against a coordinator halt,
IdealAffinityAssignment.calculatePrimaries() could handle nodes == null ||
nodes.isEmpty() without dividing by zero. This
defensive change should not replace the topology-version guard, since it
does not prevent an inconsistent assignment.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
