|
@@ -31,6 +31,8 @@ import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.ha.HealthCheckFailedException;
|
|
|
|
+import org.apache.hadoop.ha.ServiceFailedException;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
import org.apache.hadoop.fs.ContentSummary;
|
|
import org.apache.hadoop.fs.ContentSummary;
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
@@ -67,11 +69,15 @@ import org.apache.hadoop.hdfs.server.common.HdfsConstants.NamenodeRole;
|
|
import org.apache.hadoop.hdfs.server.common.HdfsConstants.StartupOption;
|
|
import org.apache.hadoop.hdfs.server.common.HdfsConstants.StartupOption;
|
|
import org.apache.hadoop.hdfs.server.common.IncorrectVersionException;
|
|
import org.apache.hadoop.hdfs.server.common.IncorrectVersionException;
|
|
import org.apache.hadoop.hdfs.server.common.UpgradeStatusReport;
|
|
import org.apache.hadoop.hdfs.server.common.UpgradeStatusReport;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.ha.ActiveState;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.ha.HAState;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.ha.StandbyState;
|
|
import org.apache.hadoop.hdfs.server.namenode.metrics.NameNodeMetrics;
|
|
import org.apache.hadoop.hdfs.server.namenode.metrics.NameNodeMetrics;
|
|
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations;
|
|
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations;
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeCommand;
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
|
|
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.JournalProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeCommand;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeCommand;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
|
|
@@ -145,6 +151,20 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
HdfsConfiguration.init();
|
|
HdfsConfiguration.init();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Categories of operations supported by the namenode.
|
|
|
|
+ */
|
|
|
|
+ public static enum OperationCategory {
|
|
|
|
+ /** Read operation that does not change the namespace state */
|
|
|
|
+ READ,
|
|
|
|
+ /** Write operation that changes the namespace state */
|
|
|
|
+ WRITE,
|
|
|
|
+ /** Operations related to checkpointing */
|
|
|
|
+ CHECKPOINT,
|
|
|
|
+ /** Operations related to {@link JournalProtocol} */
|
|
|
|
+ JOURNAL
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* HDFS federation configuration can have two types of parameters:
|
|
* HDFS federation configuration can have two types of parameters:
|
|
* <ol>
|
|
* <ol>
|
|
@@ -204,9 +224,15 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
public static final Log LOG = LogFactory.getLog(NameNode.class.getName());
|
|
public static final Log LOG = LogFactory.getLog(NameNode.class.getName());
|
|
public static final Log stateChangeLog = LogFactory.getLog("org.apache.hadoop.hdfs.StateChange");
|
|
public static final Log stateChangeLog = LogFactory.getLog("org.apache.hadoop.hdfs.StateChange");
|
|
|
|
+ public static final HAState ACTIVE_STATE = new ActiveState();
|
|
|
|
+ public static final HAState STANDBY_STATE = new StandbyState();
|
|
|
|
|
|
protected FSNamesystem namesystem;
|
|
protected FSNamesystem namesystem;
|
|
protected NamenodeRole role;
|
|
protected NamenodeRole role;
|
|
|
|
+ private HAState state;
|
|
|
|
+ private final boolean haEnabled;
|
|
|
|
+
|
|
|
|
+
|
|
/** RPC server. Package-protected for use in tests. */
|
|
/** RPC server. Package-protected for use in tests. */
|
|
Server server;
|
|
Server server;
|
|
/** RPC server for HDFS Services communication.
|
|
/** RPC server for HDFS Services communication.
|
|
@@ -402,6 +428,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
* @param conf the configuration
|
|
* @param conf the configuration
|
|
*/
|
|
*/
|
|
protected void initialize(Configuration conf) throws IOException {
|
|
protected void initialize(Configuration conf) throws IOException {
|
|
|
|
+ initializeGenericKeys(conf);
|
|
InetSocketAddress socAddr = getRpcServerAddress(conf);
|
|
InetSocketAddress socAddr = getRpcServerAddress(conf);
|
|
UserGroupInformation.setConfiguration(conf);
|
|
UserGroupInformation.setConfiguration(conf);
|
|
loginAsNameNodeUser(conf);
|
|
loginAsNameNodeUser(conf);
|
|
@@ -450,10 +477,6 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
}
|
|
}
|
|
|
|
|
|
activate(conf);
|
|
activate(conf);
|
|
- LOG.info(getRole() + " up at: " + rpcAddress);
|
|
|
|
- if (serviceRPCAddress != null) {
|
|
|
|
- LOG.info(getRole() + " service server is up at: " + serviceRPCAddress);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -503,6 +526,10 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
LOG.warn("ServicePlugin " + p + " could not be started", t);
|
|
LOG.warn("ServicePlugin " + p + " could not be started", t);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ LOG.info(getRole() + " up at: " + rpcAddress);
|
|
|
|
+ if (serviceRPCAddress != null) {
|
|
|
|
+ LOG.info(getRole() + " service server is up at: " + serviceRPCAddress);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void startTrashEmptier(Configuration conf) throws IOException {
|
|
private void startTrashEmptier(Configuration conf) throws IOException {
|
|
@@ -556,8 +583,9 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
protected NameNode(Configuration conf, NamenodeRole role)
|
|
protected NameNode(Configuration conf, NamenodeRole role)
|
|
throws IOException {
|
|
throws IOException {
|
|
this.role = role;
|
|
this.role = role;
|
|
|
|
+ this.haEnabled = DFSUtil.isHAEnabled(conf);
|
|
|
|
+ this.state = !haEnabled ? ACTIVE_STATE : STANDBY_STATE;
|
|
try {
|
|
try {
|
|
- initializeGenericKeys(conf);
|
|
|
|
initialize(conf);
|
|
initialize(conf);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
this.stop();
|
|
this.stop();
|
|
@@ -638,6 +666,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
public void errorReport(NamenodeRegistration registration,
|
|
public void errorReport(NamenodeRegistration registration,
|
|
int errorCode,
|
|
int errorCode,
|
|
String msg) throws IOException {
|
|
String msg) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
verifyRequest(registration);
|
|
verifyRequest(registration);
|
|
LOG.info("Error report from " + registration + ": " + msg);
|
|
LOG.info("Error report from " + registration + ": " + msg);
|
|
if(errorCode == FATAL)
|
|
if(errorCode == FATAL)
|
|
@@ -665,27 +694,28 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // NamenodeProtocol
|
|
@Override // NamenodeProtocol
|
|
public void endCheckpoint(NamenodeRegistration registration,
|
|
public void endCheckpoint(NamenodeRegistration registration,
|
|
CheckpointSignature sig) throws IOException {
|
|
CheckpointSignature sig) throws IOException {
|
|
- verifyRequest(registration);
|
|
|
|
- if(!isRole(NamenodeRole.NAMENODE))
|
|
|
|
- throw new IOException("Only an ACTIVE node can invoke endCheckpoint.");
|
|
|
|
|
|
+ checkOperation(OperationCategory.CHECKPOINT);
|
|
namesystem.endCheckpoint(registration, sig);
|
|
namesystem.endCheckpoint(registration, sig);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
|
|
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
return namesystem.getDelegationToken(renewer);
|
|
return namesystem.getDelegationToken(renewer);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public long renewDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
public long renewDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
throws InvalidToken, IOException {
|
|
throws InvalidToken, IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
return namesystem.renewDelegationToken(token);
|
|
return namesystem.renewDelegationToken(token);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.cancelDelegationToken(token);
|
|
namesystem.cancelDelegationToken(token);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -694,6 +724,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
long offset,
|
|
long offset,
|
|
long length)
|
|
long length)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
metrics.incrGetBlockLocations();
|
|
metrics.incrGetBlockLocations();
|
|
return namesystem.getBlockLocations(getClientMachine(),
|
|
return namesystem.getBlockLocations(getClientMachine(),
|
|
src, offset, length);
|
|
src, offset, length);
|
|
@@ -712,6 +743,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
boolean createParent,
|
|
boolean createParent,
|
|
short replication,
|
|
short replication,
|
|
long blockSize) throws IOException {
|
|
long blockSize) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
String clientMachine = getClientMachine();
|
|
String clientMachine = getClientMachine();
|
|
if (stateChangeLog.isDebugEnabled()) {
|
|
if (stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* NameNode.create: file "
|
|
stateChangeLog.debug("*DIR* NameNode.create: file "
|
|
@@ -732,6 +764,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public LocatedBlock append(String src, String clientName)
|
|
public LocatedBlock append(String src, String clientName)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
String clientMachine = getClientMachine();
|
|
String clientMachine = getClientMachine();
|
|
if (stateChangeLog.isDebugEnabled()) {
|
|
if (stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* NameNode.append: file "
|
|
stateChangeLog.debug("*DIR* NameNode.append: file "
|
|
@@ -744,6 +777,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean recoverLease(String src, String clientName) throws IOException {
|
|
public boolean recoverLease(String src, String clientName) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
String clientMachine = getClientMachine();
|
|
String clientMachine = getClientMachine();
|
|
return namesystem.recoverLease(src, clientName, clientMachine);
|
|
return namesystem.recoverLease(src, clientName, clientMachine);
|
|
}
|
|
}
|
|
@@ -751,18 +785,21 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean setReplication(String src, short replication)
|
|
public boolean setReplication(String src, short replication)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
return namesystem.setReplication(src, replication);
|
|
return namesystem.setReplication(src, replication);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void setPermission(String src, FsPermission permissions)
|
|
public void setPermission(String src, FsPermission permissions)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.setPermission(src, permissions);
|
|
namesystem.setPermission(src, permissions);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void setOwner(String src, String username, String groupname)
|
|
public void setOwner(String src, String username, String groupname)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.setOwner(src, username, groupname);
|
|
namesystem.setOwner(src, username, groupname);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -772,6 +809,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
ExtendedBlock previous,
|
|
ExtendedBlock previous,
|
|
DatanodeInfo[] excludedNodes)
|
|
DatanodeInfo[] excludedNodes)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*BLOCK* NameNode.addBlock: file "
|
|
stateChangeLog.debug("*BLOCK* NameNode.addBlock: file "
|
|
+src+" for "+clientName);
|
|
+src+" for "+clientName);
|
|
@@ -795,6 +833,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
final DatanodeInfo[] existings, final DatanodeInfo[] excludes,
|
|
final DatanodeInfo[] existings, final DatanodeInfo[] excludes,
|
|
final int numAdditionalNodes, final String clientName
|
|
final int numAdditionalNodes, final String clientName
|
|
) throws IOException {
|
|
) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if (LOG.isDebugEnabled()) {
|
|
if (LOG.isDebugEnabled()) {
|
|
LOG.debug("getAdditionalDatanode: src=" + src
|
|
LOG.debug("getAdditionalDatanode: src=" + src
|
|
+ ", blk=" + blk
|
|
+ ", blk=" + blk
|
|
@@ -820,8 +859,10 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
/**
|
|
/**
|
|
* The client needs to give up on the block.
|
|
* The client needs to give up on the block.
|
|
*/
|
|
*/
|
|
|
|
+ @Override // ClientProtocol
|
|
public void abandonBlock(ExtendedBlock b, String src, String holder)
|
|
public void abandonBlock(ExtendedBlock b, String src, String holder)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*BLOCK* NameNode.abandonBlock: "
|
|
stateChangeLog.debug("*BLOCK* NameNode.abandonBlock: "
|
|
+b+" of file "+src);
|
|
+b+" of file "+src);
|
|
@@ -834,6 +875,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean complete(String src, String clientName, ExtendedBlock last)
|
|
public boolean complete(String src, String clientName, ExtendedBlock last)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* NameNode.complete: "
|
|
stateChangeLog.debug("*DIR* NameNode.complete: "
|
|
+ src + " for " + clientName);
|
|
+ src + " for " + clientName);
|
|
@@ -847,8 +889,9 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
* mark the block as corrupt. In the future we might
|
|
* mark the block as corrupt. In the future we might
|
|
* check the blocks are actually corrupt.
|
|
* check the blocks are actually corrupt.
|
|
*/
|
|
*/
|
|
- @Override
|
|
|
|
|
|
+ @Override // ClientProtocol, DatanodeProtocol
|
|
public void reportBadBlocks(LocatedBlock[] blocks) throws IOException {
|
|
public void reportBadBlocks(LocatedBlock[] blocks) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
stateChangeLog.info("*DIR* NameNode.reportBadBlocks");
|
|
stateChangeLog.info("*DIR* NameNode.reportBadBlocks");
|
|
for (int i = 0; i < blocks.length; i++) {
|
|
for (int i = 0; i < blocks.length; i++) {
|
|
ExtendedBlock blk = blocks[i].getBlock();
|
|
ExtendedBlock blk = blocks[i].getBlock();
|
|
@@ -863,6 +906,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public LocatedBlock updateBlockForPipeline(ExtendedBlock block, String clientName)
|
|
public LocatedBlock updateBlockForPipeline(ExtendedBlock block, String clientName)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
return namesystem.updateBlockForPipeline(block, clientName);
|
|
return namesystem.updateBlockForPipeline(block, clientName);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -871,6 +915,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
public void updatePipeline(String clientName, ExtendedBlock oldBlock,
|
|
public void updatePipeline(String clientName, ExtendedBlock oldBlock,
|
|
ExtendedBlock newBlock, DatanodeID[] newNodes)
|
|
ExtendedBlock newBlock, DatanodeID[] newNodes)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.updatePipeline(clientName, oldBlock, newBlock, newNodes);
|
|
namesystem.updatePipeline(clientName, oldBlock, newBlock, newNodes);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -879,6 +924,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
long newgenerationstamp, long newlength,
|
|
long newgenerationstamp, long newlength,
|
|
boolean closeFile, boolean deleteblock, DatanodeID[] newtargets)
|
|
boolean closeFile, boolean deleteblock, DatanodeID[] newtargets)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.commitBlockSynchronization(block,
|
|
namesystem.commitBlockSynchronization(block,
|
|
newgenerationstamp, newlength, closeFile, deleteblock, newtargets);
|
|
newgenerationstamp, newlength, closeFile, deleteblock, newtargets);
|
|
}
|
|
}
|
|
@@ -886,12 +932,14 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public long getPreferredBlockSize(String filename)
|
|
public long getPreferredBlockSize(String filename)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
return namesystem.getPreferredBlockSize(filename);
|
|
return namesystem.getPreferredBlockSize(filename);
|
|
}
|
|
}
|
|
|
|
|
|
@Deprecated
|
|
@Deprecated
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean rename(String src, String dst) throws IOException {
|
|
public boolean rename(String src, String dst) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
|
|
stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
|
|
}
|
|
}
|
|
@@ -908,12 +956,14 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void concat(String trg, String[] src) throws IOException {
|
|
public void concat(String trg, String[] src) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.concat(trg, src);
|
|
namesystem.concat(trg, src);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void rename(String src, String dst, Options.Rename... options)
|
|
public void rename(String src, String dst, Options.Rename... options)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
|
|
stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
|
|
}
|
|
}
|
|
@@ -928,11 +978,13 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Deprecated
|
|
@Deprecated
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean delete(String src) throws IOException {
|
|
public boolean delete(String src) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
return delete(src, true);
|
|
return delete(src, true);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean delete(String src, boolean recursive) throws IOException {
|
|
public boolean delete(String src, boolean recursive) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if (stateChangeLog.isDebugEnabled()) {
|
|
if (stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* Namenode.delete: src=" + src
|
|
stateChangeLog.debug("*DIR* Namenode.delete: src=" + src
|
|
+ ", recursive=" + recursive);
|
|
+ ", recursive=" + recursive);
|
|
@@ -957,6 +1009,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean mkdirs(String src, FsPermission masked, boolean createParent)
|
|
public boolean mkdirs(String src, FsPermission masked, boolean createParent)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
if(stateChangeLog.isDebugEnabled()) {
|
|
stateChangeLog.debug("*DIR* NameNode.mkdirs: " + src);
|
|
stateChangeLog.debug("*DIR* NameNode.mkdirs: " + src);
|
|
}
|
|
}
|
|
@@ -971,13 +1024,14 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void renewLease(String clientName) throws IOException {
|
|
public void renewLease(String clientName) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.renewLease(clientName);
|
|
namesystem.renewLease(clientName);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public DirectoryListing getListing(String src, byte[] startAfter,
|
|
public DirectoryListing getListing(String src, byte[] startAfter,
|
|
- boolean needLocation)
|
|
|
|
- throws IOException {
|
|
|
|
|
|
+ boolean needLocation) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
DirectoryListing files = namesystem.getListing(
|
|
DirectoryListing files = namesystem.getListing(
|
|
src, startAfter, needLocation);
|
|
src, startAfter, needLocation);
|
|
if (files != null) {
|
|
if (files != null) {
|
|
@@ -989,12 +1043,14 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public HdfsFileStatus getFileInfo(String src) throws IOException {
|
|
public HdfsFileStatus getFileInfo(String src) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
metrics.incrFileInfoOps();
|
|
metrics.incrFileInfoOps();
|
|
return namesystem.getFileInfo(src, true);
|
|
return namesystem.getFileInfo(src, true);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public HdfsFileStatus getFileLinkInfo(String src) throws IOException {
|
|
public HdfsFileStatus getFileLinkInfo(String src) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
metrics.incrFileInfoOps();
|
|
metrics.incrFileInfoOps();
|
|
return namesystem.getFileInfo(src, false);
|
|
return namesystem.getFileInfo(src, false);
|
|
}
|
|
}
|
|
@@ -1007,6 +1063,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public DatanodeInfo[] getDatanodeReport(DatanodeReportType type)
|
|
public DatanodeInfo[] getDatanodeReport(DatanodeReportType type)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
DatanodeInfo results[] = namesystem.datanodeReport(type);
|
|
DatanodeInfo results[] = namesystem.datanodeReport(type);
|
|
if (results == null ) {
|
|
if (results == null ) {
|
|
throw new IOException("Cannot find datanode report");
|
|
throw new IOException("Cannot find datanode report");
|
|
@@ -1016,6 +1073,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean setSafeMode(SafeModeAction action) throws IOException {
|
|
public boolean setSafeMode(SafeModeAction action) throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
return namesystem.setSafeMode(action);
|
|
return namesystem.setSafeMode(action);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1029,54 +1087,64 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public boolean restoreFailedStorage(String arg)
|
|
public boolean restoreFailedStorage(String arg)
|
|
throws AccessControlException {
|
|
throws AccessControlException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
return namesystem.restoreFailedStorage(arg);
|
|
return namesystem.restoreFailedStorage(arg);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void saveNamespace() throws IOException {
|
|
public void saveNamespace() throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
namesystem.saveNamespace();
|
|
namesystem.saveNamespace();
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void refreshNodes() throws IOException {
|
|
public void refreshNodes() throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
namesystem.refreshNodes(new HdfsConfiguration());
|
|
namesystem.refreshNodes(new HdfsConfiguration());
|
|
}
|
|
}
|
|
|
|
|
|
@Override // NamenodeProtocol
|
|
@Override // NamenodeProtocol
|
|
public long getTransactionID() {
|
|
public long getTransactionID() {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
return namesystem.getTransactionID();
|
|
return namesystem.getTransactionID();
|
|
}
|
|
}
|
|
|
|
|
|
@Override // NamenodeProtocol
|
|
@Override // NamenodeProtocol
|
|
public CheckpointSignature rollEditLog() throws IOException {
|
|
public CheckpointSignature rollEditLog() throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
return namesystem.rollEditLog();
|
|
return namesystem.rollEditLog();
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
|
|
+ @Override // NamenodeProtocol
|
|
public RemoteEditLogManifest getEditLogManifest(long sinceTxId)
|
|
public RemoteEditLogManifest getEditLogManifest(long sinceTxId)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
return namesystem.getEditLogManifest(sinceTxId);
|
|
return namesystem.getEditLogManifest(sinceTxId);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void finalizeUpgrade() throws IOException {
|
|
public void finalizeUpgrade() throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
namesystem.finalizeUpgrade();
|
|
namesystem.finalizeUpgrade();
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public UpgradeStatusReport distributedUpgradeProgress(UpgradeAction action)
|
|
public UpgradeStatusReport distributedUpgradeProgress(UpgradeAction action)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
return namesystem.distributedUpgradeProgress(action);
|
|
return namesystem.distributedUpgradeProgress(action);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void metaSave(String filename) throws IOException {
|
|
public void metaSave(String filename) throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
namesystem.metaSave(filename);
|
|
namesystem.metaSave(filename);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public CorruptFileBlocks listCorruptFileBlocks(String path, String cookie)
|
|
public CorruptFileBlocks listCorruptFileBlocks(String path, String cookie)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
Collection<FSNamesystem.CorruptFileBlockInfo> fbs =
|
|
Collection<FSNamesystem.CorruptFileBlockInfo> fbs =
|
|
namesystem.listCorruptFileBlocks(path, cookie);
|
|
namesystem.listCorruptFileBlocks(path, cookie);
|
|
|
|
|
|
@@ -1096,35 +1164,42 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
* @param bandwidth Blanacer bandwidth in bytes per second for all datanodes.
|
|
* @param bandwidth Blanacer bandwidth in bytes per second for all datanodes.
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
|
|
+ @Override // ClientProtocol
|
|
public void setBalancerBandwidth(long bandwidth) throws IOException {
|
|
public void setBalancerBandwidth(long bandwidth) throws IOException {
|
|
|
|
+ // TODO:HA decide on OperationCategory for this
|
|
namesystem.setBalancerBandwidth(bandwidth);
|
|
namesystem.setBalancerBandwidth(bandwidth);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public ContentSummary getContentSummary(String path) throws IOException {
|
|
public ContentSummary getContentSummary(String path) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
return namesystem.getContentSummary(path);
|
|
return namesystem.getContentSummary(path);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void setQuota(String path, long namespaceQuota, long diskspaceQuota)
|
|
public void setQuota(String path, long namespaceQuota, long diskspaceQuota)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.setQuota(path, namespaceQuota, diskspaceQuota);
|
|
namesystem.setQuota(path, namespaceQuota, diskspaceQuota);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void fsync(String src, String clientName) throws IOException {
|
|
public void fsync(String src, String clientName) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.fsync(src, clientName);
|
|
namesystem.fsync(src, clientName);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void setTimes(String src, long mtime, long atime)
|
|
public void setTimes(String src, long mtime, long atime)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
namesystem.setTimes(src, mtime, atime);
|
|
namesystem.setTimes(src, mtime, atime);
|
|
}
|
|
}
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public void createSymlink(String target, String link, FsPermission dirPerms,
|
|
public void createSymlink(String target, String link, FsPermission dirPerms,
|
|
boolean createParent) throws IOException {
|
|
boolean createParent) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.WRITE);
|
|
metrics.incrCreateSymlinkOps();
|
|
metrics.incrCreateSymlinkOps();
|
|
/* We enforce the MAX_PATH_LENGTH limit even though a symlink target
|
|
/* We enforce the MAX_PATH_LENGTH limit even though a symlink target
|
|
* URI may refer to a non-HDFS file system.
|
|
* URI may refer to a non-HDFS file system.
|
|
@@ -1144,6 +1219,7 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
|
|
|
|
@Override // ClientProtocol
|
|
@Override // ClientProtocol
|
|
public String getLinkTarget(String path) throws IOException {
|
|
public String getLinkTarget(String path) throws IOException {
|
|
|
|
+ checkOperation(OperationCategory.READ);
|
|
metrics.incrGetLinkTargetOps();
|
|
metrics.incrGetLinkTargetOps();
|
|
/* Resolves the first symlink in the given path, returning a
|
|
/* Resolves the first symlink in the given path, returning a
|
|
* new path consisting of the target of the symlink and any
|
|
* new path consisting of the target of the symlink and any
|
|
@@ -1591,4 +1667,43 @@ public class NameNode implements NamenodeProtocols, FSConstants {
|
|
}
|
|
}
|
|
return clientMachine;
|
|
return clientMachine;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override // HAServiceProtocol
|
|
|
|
+ public synchronized void monitorHealth() throws HealthCheckFailedException {
|
|
|
|
+ if (!haEnabled) {
|
|
|
|
+ return; // no-op, if HA is not eanbled
|
|
|
|
+ }
|
|
|
|
+ // TODO:HA implement health check
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override // HAServiceProtocol
|
|
|
|
+ public synchronized void transitionToActive() throws ServiceFailedException {
|
|
|
|
+ if (!haEnabled) {
|
|
|
|
+ throw new ServiceFailedException("HA for namenode is not enabled");
|
|
|
|
+ }
|
|
|
|
+ state.setState(this, ACTIVE_STATE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override // HAServiceProtocol
|
|
|
|
+ public synchronized void transitionToStandby() throws ServiceFailedException {
|
|
|
|
+ if (!haEnabled) {
|
|
|
|
+ throw new ServiceFailedException("HA for namenode is not enabled");
|
|
|
|
+ }
|
|
|
|
+ state.setState(this, STANDBY_STATE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** Check if an operation of given category is allowed */
|
|
|
|
+ protected synchronized void checkOperation(final OperationCategory op)
|
|
|
|
+ throws UnsupportedActionException {
|
|
|
|
+ state.checkOperation(this, op);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized HAState getState() {
|
|
|
|
+ return state;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized void setState(final HAState s) {
|
|
|
|
+ state = s;
|
|
|
|
+ }
|
|
}
|
|
}
|