From 9a29075f915173e24c77cf8aea2908da0aa328e3 Mon Sep 17 00:00:00 2001 From: Kidd5368 <57645247+Kidd53685368@users.noreply.github.com> Date: Fri, 23 Sep 2022 11:27:56 +0800 Subject: [PATCH] HDFS-16776 Erasure Coding: The length of targets should be checked when DN gets a reconstruction task (#4901) --- .../server/datanode/erasurecode/StripedReconstructor.java | 4 ++++ .../hdfs/server/datanode/erasurecode/StripedWriter.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedReconstructor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedReconstructor.java index 466c7c4254..7acb679200 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedReconstructor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedReconstructor.java @@ -288,6 +288,10 @@ RawErasureDecoder getDecoder() { return decoder; } + int getNumLiveBlocks(){ + return liveBitSet.cardinality(); + } + void cleanup() { if (decoder != null) { decoder.release(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedWriter.java index ca06dfc120..00be1279c8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedWriter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedWriter.java @@ -82,8 +82,10 @@ class StripedWriter { assert targetStorageIds != null; writers = new StripedBlockWriter[targets.length]; - targetIndices = new short[targets.length]; + Preconditions.checkArgument( + targetIndices.length <= dataBlkNum + parityBlkNum - reconstructor.getNumLiveBlocks(), + "Reconstruction work gets too much targets."); Preconditions.checkArgument(targetIndices.length <= parityBlkNum, "Too much missed striped blocks."); initTargetIndices();