Skip to content

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

Open
smengcl wants to merge 3 commits into
apache:masterfrom
smengcl:HDDS-15350
Open

HDDS-15350. SCM crashes with ArithmeticException when topology reports zero racks during DN decommission#10339
smengcl wants to merge 3 commits 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
@smengcl smengcl marked this pull request as ready for review May 23, 2026 22:27
Copilot AI review requested due to automatic review settings May 23, 2026 22:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an SCM crash during DN decommission when the network topology transiently reports zero racks, causing a divide-by-zero in SCMCommonPlacementPolicy.getMaxReplicasPerRack() during placement validation.

Changes:

  • Add defensive handling for numberOfRacks <= 0 in getMaxReplicasPerRack to avoid ArithmeticException.
  • Update validateContainerPlacement to compute rack count earlier and short-circuit when the topology has no rack info (numRacks <= 0) or when rack requirements are non-applicable (requiredRacks <= 1).
  • Add a regression test covering the zero-rack topology scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java Prevent divide-by-zero and short-circuit placement validation when rack info is absent.
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/TestSCMCommonPlacementPolicy.java Add test reproducing transient zero-rack topology during decommission to prevent SCM crash regressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@peterxcli peterxcli self-requested a review May 24, 2026 00:50
smengcl and others added 2 commits May 23, 2026 23:49
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The previous commit's defensive guard turns the SCM crash into a silent
return of validPlacement. That removes the loud signal that the topology
is corrupted, so downstream mis-replication and rack-aware placement
decisions then silently treat any placement as valid.

Add a WARN log at the guard site with numReplicas and numberOfRacks so
operators monitoring SCM logs see the degradation. No in-code rate
limiting; if the topology is persistently empty and the WARN floods,
configure log4j appender-side filtering. A follow-up can introduce a
metrics2 counter if Prometheus / JMX scraping is wanted.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

2 participants