From 5b56599766d0d51e4ee1db5cedcad4492bef6038 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Fri, 27 Apr 2012 21:18:59 +0000 Subject: [PATCH] svn merge -c 1331598 from trunk for 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/branches/branch-2@1331599 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 a3992f89579..5f2260ce4b9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -798,7 +798,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 0c16c7f5d1b..7f795cd4a84 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 @@ public class DatanodeManager { * 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 c92ee852e43..790212182bb 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 @@ public class FSNamesystem implements Namesystem, FSClusterStats, } 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 165fd56530c..0d8cdb0f9cf 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 @@ -708,9 +708,7 @@ class NameNodeRpcServer implements NamenodeProtocols { @Override // ClientProtocol public void refreshNodes() throws IOException { - namesystem.checkOperation(OperationCategory.UNCHECKED); - namesystem.getBlockManager().getDatanodeManager().refreshNodes( - new HdfsConfiguration()); + namesystem.refreshNodes(); } @Override // NamenodeProtocol @@ -733,7 +731,6 @@ class NameNodeRpcServer implements NamenodeProtocols { @Override // ClientProtocol public void finalizeUpgrade() throws IOException { - namesystem.checkOperation(OperationCategory.WRITE); namesystem.finalizeUpgrade(); } @@ -773,8 +770,7 @@ class NameNodeRpcServer implements NamenodeProtocols { */ @Override // ClientProtocol public void setBalancerBandwidth(long bandwidth) throws IOException { - namesystem.checkOperation(OperationCategory.UNCHECKED); - namesystem.getBlockManager().getDatanodeManager().setBalancerBandwidth(bandwidth); + namesystem.setBalancerBandwidth(bandwidth); } @Override // ClientProtocol