Skip to content

HDDS-15350. SCM crashes with ArithmeticException when topology reports zero racks during DN decommission#10339

Draft
smengcl wants to merge 1 commit into
apache:masterfrom
smengcl:HDDS-15350
Draft

HDDS-15350. SCM crashes with ArithmeticException when topology reports zero racks during DN decommission#10339
smengcl wants to merge 1 commit into
apache:masterfrom
smengcl:HDDS-15350

Conversation

@smengcl
Copy link
Copy Markdown
Contributor

@smengcl smengcl commented May 23, 2026

Generated-by: Claude Code (Opus 4.7)

What changes were proposed in this pull request?

SCMCommonPlacementPolicy.getMaxReplicasPerRack divides by numberOfRacks without a zero check. The caller (validateContainerPlacement) reaches the divide via Math.min(requiredRacks, numRacks).

When the network topology transiently reports zero racks (observed during a DN decommission) the existing requiredRacks==1 short-circuit does not catch it. The ReplicationMonitor catches the exception and calls:

ExitUtil.terminate(1, t)

so the SCM JVM exits.

Fix:

  • Compute numRacks before the early-return guard and short-circuit when numRacks <= 0 or requiredRacks <= 1 (was: == 1).
  • Add a defensive guard in getMaxReplicasPerRack that returns numReplicas when numberOfRacks <= 0, mirroring HDDS-14371's pattern for an analogous div-by-zero in ContainerManagerImpl.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-15350

How was this patch tested?

  • Added test TestSCMCommonPlacementPolicy.testValidateContainerPlacementWithZeroRackTopology that reproduces the empty-topology window with a mocked NetworkTopology returning 0 from getNumOfNodes. Without the fix the test errors out with "Arithmetic / by zero". With the fix it passes and all 20 tests in TestSCMCommonPlacementPolicy remain green.

…s zero racks during DN decommission

SCMCommonPlacementPolicy.getMaxReplicasPerRack divides by numberOfRacks
without a zero check. The caller (validateContainerPlacement) reaches the
divide via Math.min(requiredRacks, numRacks); when the network topology
transiently reports zero racks (observed during a DN decommission) the
existing requiredRacks==1 short-circuit does not catch it. The
ReplicationMonitor catches the exception and calls ExitUtil.terminate(1, t)
("When we get runtime exception, we should terminate SCM."), so the SCM
JVM exits and is restarted by the supervisor (CM / systemd).

Fix:
* Compute numRacks before the early-return guard and short-circuit when
  numRacks <= 0 or requiredRacks <= 1 (was: == 1).
* Add a defensive guard in getMaxReplicasPerRack that returns numReplicas
  when numberOfRacks <= 0, mirroring HDDS-14371's pattern for an
  analogous div-by-zero in ContainerManagerImpl.

Test:
* TestSCMCommonPlacementPolicy.testValidateContainerPlacementWithZeroRackTopology
  reproduces the empty-topology window with a mocked NetworkTopology
  returning 0 from getNumOfNodes. Without the fix the test errors out
  with "Arithmetic / by zero". With the fix it passes and all 20 tests
  in TestSCMCommonPlacementPolicy remain green.

Generated-by: Claude Code (Opus 4.7)
@smengcl smengcl requested a review from jojochuang May 23, 2026 01:29
@smengcl smengcl self-assigned this May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant