From 8db31c5972873a4f919469fb3387454116a02869 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Thu, 23 Feb 2012 02:08:54 +0000 Subject: [PATCH] HDFS-2922. HA: close out operation categories. Contributed by Eli Collins git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1292620 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-1623.txt | 2 + .../hdfs/server/namenode/BackupNode.java | 3 ++ .../hadoop/hdfs/server/namenode/NameNode.java | 2 + .../server/namenode/NameNodeRpcServer.java | 37 +++++++++---------- .../hdfs/server/namenode/ha/StandbyState.java | 3 +- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index 93ae86a37de..baa7cec6e75 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -226,3 +226,5 @@ HDFS-2929. Stress test and fixes for block synchronization (todd) HDFS-2972. Small optimization building incremental block report (todd) HDFS-2973. Re-enable NO_ACK optimization for block deletion. (todd) + +HDFS-2922. HA: close out operation categories (eli) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java index d6aa5e5a705..5e7de78d77b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java @@ -407,6 +407,9 @@ public class BackupNode extends NameNode { @Override // NameNode public void checkOperation(OperationCategory op) throws StandbyException { + if (op == OperationCategory.UNCHECKED) { + return; + } if (OperationCategory.JOURNAL != op && !(OperationCategory.READ == op && allowStaleStandbyReads)) { String msg = "Operation category " + op diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java index caedb5bae35..a243971453c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java @@ -114,6 +114,8 @@ public class NameNode { * Categories of operations supported by the namenode. */ public static enum OperationCategory { + /** Operations that are state agnostic */ + UNCHECKED, /** Read operation that does not change the namespace state */ READ, /** Write operation that changes the namespace state */ 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 98d09101e8b..b6444ce65f9 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 @@ -353,9 +353,7 @@ class NameNodeRpcServer implements NamenodeProtocols { public void errorReport(NamenodeRegistration registration, int errorCode, String msg) throws IOException { - // nn.checkOperation(OperationCategory.WRITE); - // TODO: I dont think this should be checked - it's just for logging - // and dropping backups + namesystem.checkOperation(OperationCategory.UNCHECKED); verifyRequest(registration); LOG.info("Error report from " + registration + ": " + msg); if(errorCode == FATAL) @@ -707,8 +705,8 @@ class NameNodeRpcServer implements NamenodeProtocols { @Override // ClientProtocol public DatanodeInfo[] getDatanodeReport(DatanodeReportType type) - throws IOException { - // TODO(HA): decide on OperationCategory for this + throws IOException { + namesystem.checkOperation(OperationCategory.UNCHECKED); DatanodeInfo results[] = namesystem.datanodeReport(type); if (results == null ) { throw new IOException("Cannot find datanode report"); @@ -718,32 +716,32 @@ class NameNodeRpcServer implements NamenodeProtocols { @Override // ClientProtocol public boolean setSafeMode(SafeModeAction action) throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.UNCHECKED); return namesystem.setSafeMode(action); } + @Override // ClientProtocol - public boolean restoreFailedStorage(String arg) - throws AccessControlException { - // TODO:HA decide on OperationCategory for this + public boolean restoreFailedStorage(String arg) throws IOException { + namesystem.checkOperation(OperationCategory.UNCHECKED); return namesystem.restoreFailedStorage(arg); } @Override // ClientProtocol public void saveNamespace() throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.UNCHECKED); namesystem.saveNamespace(); } @Override // ClientProtocol public void refreshNodes() throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.UNCHECKED); namesystem.getBlockManager().getDatanodeManager().refreshNodes( new HdfsConfiguration()); } @Override // NamenodeProtocol - public long getTransactionID() { - // TODO:HA decide on OperationCategory for this + public long getTransactionID() throws IOException { + namesystem.checkOperation(OperationCategory.CHECKPOINT); return namesystem.getEditLog().getSyncTxId(); } @@ -755,28 +753,29 @@ class NameNodeRpcServer implements NamenodeProtocols { @Override // NamenodeProtocol public RemoteEditLogManifest getEditLogManifest(long sinceTxId) throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.READ); return namesystem.getEditLog().getEditLogManifest(sinceTxId); } @Override // ClientProtocol public void finalizeUpgrade() throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.WRITE); namesystem.finalizeUpgrade(); } @Override // ClientProtocol public UpgradeStatusReport distributedUpgradeProgress(UpgradeAction action) throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.READ); return namesystem.distributedUpgradeProgress(action); } @Override // ClientProtocol public void metaSave(String filename) throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.UNCHECKED); namesystem.metaSave(filename); } + @Override // ClientProtocol public CorruptFileBlocks listCorruptFileBlocks(String path, String cookie) throws IOException { @@ -795,12 +794,12 @@ class NameNodeRpcServer implements NamenodeProtocols { /** * Tell all datanodes to use a new, non-persistent bandwidth value for * dfs.datanode.balance.bandwidthPerSec. - * @param bandwidth Blanacer bandwidth in bytes per second for all datanodes. + * @param bandwidth Balancer bandwidth in bytes per second for all datanodes. * @throws IOException */ @Override // ClientProtocol public void setBalancerBandwidth(long bandwidth) throws IOException { - // TODO:HA decide on OperationCategory for this + namesystem.checkOperation(OperationCategory.UNCHECKED); namesystem.getBlockManager().getDatanodeManager().setBalancerBandwidth(bandwidth); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java index 80f42e60fea..60e83713b86 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java @@ -78,7 +78,8 @@ public class StandbyState extends HAState { @Override public void checkOperation(HAContext context, OperationCategory op) throws StandbyException { - if (op == OperationCategory.READ && context.allowStaleReads()) { + if (op == OperationCategory.UNCHECKED || + (op == OperationCategory.READ && context.allowStaleReads())) { return; } String msg = "Operation category " + op + " is not supported in state "