From cda43d71be5ff7b2d67008f6ab611e3c4c22f3aa Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Wed, 20 Jul 2011 18:52:57 +0000 Subject: [PATCH] HDFS-1774. Small optimization to FSDataset. Contributed by Uma Maheswara Rao G git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1148894 13f79535-47bb-0310-9956-ffa450edef68 --- hdfs/CHANGES.txt | 2 ++ .../hadoop/hdfs/server/datanode/FSDataset.java | 15 ++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/hdfs/CHANGES.txt b/hdfs/CHANGES.txt index 617870e0210..83d1d85f8a7 100644 --- a/hdfs/CHANGES.txt +++ b/hdfs/CHANGES.txt @@ -579,6 +579,8 @@ Trunk (unreleased changes) and Random object creation to DFSUtil; move DFSClient.stringifyToken(..) to DelegationTokenIdentifier. (szetszwo) + HDFS-1774. Small optimization to FSDataset. (Uma Maheswara Rao G via eli) + OPTIMIZATIONS HDFS-1458. Improve checkpoint performance by avoiding unnecessary image diff --git a/hdfs/src/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java b/hdfs/src/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java index b5f03763edd..f12b8403b35 100644 --- a/hdfs/src/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java +++ b/hdfs/src/java/org/apache/hadoop/hdfs/server/datanode/FSDataset.java @@ -99,23 +99,16 @@ public class FSDataset implements FSConstants, FSDatasetInterface { } } else { File[] files = FileUtil.listFiles(dir); - int numChildren = 0; + List dirList = new ArrayList(); for (int idx = 0; idx < files.length; idx++) { if (files[idx].isDirectory()) { - numChildren++; + dirList.add(new FSDir(files[idx])); } else if (Block.isBlockFilename(files[idx])) { numBlocks++; } } - if (numChildren > 0) { - children = new FSDir[numChildren]; - int curdir = 0; - for (int idx = 0; idx < files.length; idx++) { - if (files[idx].isDirectory()) { - children[curdir] = new FSDir(files[idx]); - curdir++; - } - } + if (dirList.size() > 0) { + children = dirList.toArray(new FSDir[dirList.size()]); } } }