Skip to content

HDFS-17848. OIV should not use PrintStream for XML/FileDistribution output#8327

Open
balodesecurity wants to merge 2 commits intoapache:trunkfrom
balodesecurity:HDFS-17848
Open

HDFS-17848. OIV should not use PrintStream for XML/FileDistribution output#8327
balodesecurity wants to merge 2 commits intoapache:trunkfrom
balodesecurity:HDFS-17848

Conversation

@balodesecurity
Copy link

Summary

PBImageXmlWriter and FileDistributionCalculator in the Offline Image Viewer (OIV) currently accept a PrintStream and call print()/println(). PrintStream silently swallows IOExceptions — errors are only detectable after the fact via checkError(), which can miss failures entirely.

This patch replaces PrintStream with java.io.Writer in both classes so that write errors propagate immediately as IOException.

  • Replace PrintStream out field with Writer out in PBImageXmlWriter and FileDistributionCalculator
  • Convert all out.print(x)out.write(x) and out.println(x)out.write(x + "\n")
  • Add throws IOException to private helper methods in PBImageXmlWriter that call out.write()
  • OfflineImageViewerPB bridges the gap by wrapping the output PrintStream in an OutputStreamWriter (with explicit flush() after visit() to drain the buffer)
  • Update all test call sites to pass new OutputStreamWriter(ps, StandardCharsets.UTF_8) instead of a raw PrintStream

Test plan

  • TestOfflineImageViewer — 29 tests pass (includes testReverseXmlRoundTrip, testCorruptionDetection*, testOfflineImageViewerWithFormatOption, testFileDistributionCalculator*)
  • TestOfflineImageViewerForAcl — 3 tests pass
  • TestSnapshot#testOfflineImageViewer — passes

amitbalode and others added 2 commits March 9, 2026 06:13
…geType stats.

The StorageType stats map maintained a nodesInService counter using
increments/decrements (via StorageTypeStats.addNode / subtractNode).
When nodesInService dropped to 0, the entry for that storage type was
removed from the map — even when decommissioning nodes still used the
storage type and still contributed capacity data.

When the entry was later recreated by an addStorage call, it started
fresh with nodesInService = 0.  Subsequent in-service node heartbeats
then performed subtract (no-op, entry was gone) followed by add (creates
entry, nodesInService = 1), which was correct.  But any in-service node
whose subtract ran against the freshly-created entry saw nodesInService
decrement past 0 to -1, and then add brought it back to 0 — so that
node's in-service contribution was lost for the rest of the session.

Fix: add a totalNodes counter to StorageTypeStats that tracks ALL nodes
using a storage type (in-service + decommissioning + maintenance).
Change the map-entry removal condition from nodesInService == 0 to
totalNodes == 0.  An entry is now removed only when no node of any
admin state still uses that storage type, preventing the premature
removal that caused the count corruption.

Added TestStorageTypeStatsMap with 4 unit tests covering:
- Basic add/remove correctness
- Entry survival when a decommissioning node still uses the storage type
- nodesInService stability after the last in-service node decommissions
- Entry removal only when all nodes (including decommissioning) are gone

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…utput.

Replace PrintStream with Writer in PBImageXmlWriter and
FileDistributionCalculator. Writer.write() propagates IOException
immediately, while PrintStream.print/println() silently swallows errors.

OfflineImageViewerPB wraps the output PrintStream in an OutputStreamWriter
(with explicit flush after visit) to bridge the two APIs. All test callers
of PBImageXmlWriter and FileDistributionCalculator are updated to pass
an OutputStreamWriter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 6s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 5 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 50m 37s trunk passed
+1 💚 compile 1m 50s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 1m 53s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 48s trunk passed
+1 💚 mvnsite 1m 54s trunk passed
+1 💚 javadoc 1m 26s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 26s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 27s trunk passed
+1 💚 shadedclient 38m 5s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 25s the patch passed
+1 💚 compile 1m 17s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 1m 17s the patch passed
+1 💚 compile 1m 21s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 1m 21s the patch passed
+1 💚 blanks 0m 1s The patch has no blanks issues.
-0 ⚠️ checkstyle 1m 16s /results-checkstyle-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs-project/hadoop-hdfs: The patch generated 2 new + 109 unchanged - 0 fixed = 111 total (was 109)
+1 💚 mvnsite 1m 29s the patch passed
+1 💚 javadoc 0m 58s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 3s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 7s the patch passed
+1 💚 shadedclient 36m 51s patch has no errors when building and testing our client artifacts.
_ Other Tests _
-1 ❌ unit 256m 1s /patch-unit-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 49s The patch does not generate ASF License warnings.
408m 54s
Reason Tests
Failed junit tests hadoop.hdfs.TestEncryptionZones
hadoop.hdfs.server.datanode.fsdataset.impl.TestFsVolumeList
hadoop.hdfs.TestEncryptionZonesWithKMS
hadoop.hdfs.server.namenode.ha.TestStandbyCheckpoints
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8327/1/artifact/out/Dockerfile
GITHUB PR #8327
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 3a776b074c78 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 723438e
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8327/1/testReport/
Max. process+thread count 2439 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project/hadoop-hdfs
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8327/1/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

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.

3 participants