From cd271773ac45d36875862d771b05476ce1f23c1f Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Fri, 27 Apr 2012 21:17:53 +0000 Subject: [PATCH] HDFS-3331. In namenode, check superuser privilege for setBalancerBandwidth and acquire the write lock for finalizeUpgrade. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1331598 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 6 +++++- .../blockmanagement/DatanodeManager.java | 1 - .../hdfs/server/namenode/FSNamesystem.java | 20 ++++++++++++++++++- .../server/namenode/NameNodeRpcServer.java | 8 ++------ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index daf09e90fe..fadf930e8b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -917,7 +917,11 @@ Release 0.23.3 - UNRELEASED HDFS-3321. Fix safe mode turn off tip message. (Ravi Prakash via szetszwo) - HDFS-3334. Fix ByteRangeInputStream stream leakage. (Daryn Sharp via szetszwo) + HDFS-3334. Fix ByteRangeInputStream stream leakage. (Daryn Sharp via + szetszwo) + + HDFS-3331. In namenode, check superuser privilege for setBalancerBandwidth + and acquire the write lock for finalizeUpgrade. (szetszwo) Release 0.23.2 - UNRELEASED diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index 0c16c7f5d1..7f795cd4a8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java @@ -651,7 +651,6 @@ nodes with its data cleared (or user can just remove the StorageID * checks if any of the hosts have changed states: */ public void refreshNodes(final Configuration conf) throws IOException { - namesystem.checkSuperuserPrivilege(); refreshHostsReader(conf); namesystem.writeLock(); try { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index c92ee852e4..790212182b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -3332,8 +3332,26 @@ Date getStartTime() { } void finalizeUpgrade() throws IOException { + writeLock(); + try { + checkOperation(OperationCategory.WRITE); + checkSuperuserPrivilege(); + getFSImage().finalizeUpgrade(); + } finally { + writeUnlock(); + } + } + + void refreshNodes() throws IOException { + checkOperation(OperationCategory.UNCHECKED); checkSuperuserPrivilege(); - getFSImage().finalizeUpgrade(); + getBlockManager().getDatanodeManager().refreshNodes(new HdfsConfiguration()); + } + + void setBalancerBandwidth(long bandwidth) throws IOException { + checkOperation(OperationCategory.UNCHECKED); + checkSuperuserPrivilege(); + getBlockManager().getDatanodeManager().setBalancerBandwidth(bandwidth); } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index af3dd16d76..b61fbe8f00 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -707,9 +707,7 @@ public void saveNamespace() throws IOException { @Override // ClientProtocol public void refreshNodes() throws IOException { - namesystem.checkOperation(OperationCategory.UNCHECKED); - namesystem.getBlockManager().getDatanodeManager().refreshNodes( - new HdfsConfiguration()); + namesystem.refreshNodes(); } @Override // NamenodeProtocol @@ -732,7 +730,6 @@ public RemoteEditLogManifest getEditLogManifest(long sinceTxId) @Override // ClientProtocol public void finalizeUpgrade() throws IOException { - namesystem.checkOperation(OperationCategory.WRITE); namesystem.finalizeUpgrade(); } @@ -772,8 +769,7 @@ public CorruptFileBlocks listCorruptFileBlocks(String path, String cookie) */ @Override // ClientProtocol public void setBalancerBandwidth(long bandwidth) throws IOException { - namesystem.checkOperation(OperationCategory.UNCHECKED); - namesystem.getBlockManager().getDatanodeManager().setBalancerBandwidth(bandwidth); + namesystem.setBalancerBandwidth(bandwidth); } @Override // ClientProtocol