Class NameNode
java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.conf.ReconfigurableBase
org.apache.hadoop.hdfs.server.namenode.NameNode
- All Implemented Interfaces:
org.apache.hadoop.conf.Configurable,org.apache.hadoop.conf.Reconfigurable,TokenVerifier<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier>,NameNodeStatusMXBean
- Direct Known Subclasses:
BackupNode
@Private
@Metrics(context="dfs")
public class NameNode
extends org.apache.hadoop.conf.ReconfigurableBase
implements NameNodeStatusMXBean, TokenVerifier<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier>
NameNode serves as both directory namespace manager and
"inode table" for the Hadoop DFS. There is a single NameNode
running in any DFS deployment. (Well, except when there
is a second backup/failover NameNode, or when using federated NameNodes.)
The NameNode controls two critical tables:
1) filename->blocksequence (namespace)
2) block->machinelist ("inodes")
The first table is stored on disk and is very precious.
The second table is rebuilt every time the NameNode comes up.
'NameNode' refers to both this class as well as the 'NameNode server'.
The 'FSNamesystem' class actually performs most of the filesystem
management. The majority of the 'NameNode' class itself is concerned
with exposing the IPC interface and the HTTP server to the outside world,
plus some configuration management.
NameNode implements the
ClientProtocol interface, which
allows clients to ask for DFS services.
ClientProtocol is not designed for
direct use by authors of DFS client code. End-users should instead use the
FileSystem class.
NameNode also implements the
DatanodeProtocol interface,
used by DataNodes that actually store DFS data blocks. These
methods are invoked repeatedly and automatically by all the
DataNodes in a DFS deployment.
NameNode also implements the
NamenodeProtocol interface,
used by secondary namenodes or rebalancing processes to get partial
NameNode state, for example partial blocksMap etc.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classstatic enumCategories of operations supported by the namenode. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HAStateprotected final booleanstatic final org.slf4j.Loggerstatic final intDeprecated.protected NameNodeHttpServerhttpServerstatic final org.slf4j.Loggerstatic final Stringstatic final String[]HDFS configuration can have three types of parameters: Parameters that are common for all the name services in the cluster. Parameters that are specific to a name service.static final String[]protected FSNamesystemprotected NamenodeRegistrationRegistration information of this name-nodestatic final HAStateprotected final HdfsServerConstants.NamenodeRolestatic final HAStatestatic final org.slf4j.Loggerprotected booleanonly used for testing purposesprotected final org.apache.hadoop.tracing.Tracer -
Constructor Summary
ConstructorsModifierConstructorDescriptionNameNode(org.apache.hadoop.conf.Configuration conf) Start NameNode.protectedNameNode(org.apache.hadoop.conf.Configuration conf, HdfsServerConstants.NamenodeRole role) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckAllowFormat(org.apache.hadoop.conf.Configuration conf) static Stringprotected HAContextprotected HAStatecreateHAState(org.apache.hadoop.conf.Configuration conf) static NameNodecreateNameNode(String[] argv, org.apache.hadoop.conf.Configuration conf) protected NameNodeRpcServercreateRpcServer(org.apache.hadoop.conf.Configuration conf) Create the RPC server implementation.protected voidShutdown the NN immediately in an ungraceful way.static booleandoRollback(org.apache.hadoop.conf.Configuration conf, boolean isConfirmationNeeded) static voidformat(org.apache.hadoop.conf.Configuration conf) Format a new filesystem.longGets number of bytes in blocks with future generation stamps.static org.apache.commons.lang3.tuple.Pair<byte[],Integer> getClientIdAndCallId(String[] ipProxyUsers) Try to obtain the actual client's id and call id according to the current user.static StringgetClientMachine(String[] ipProxyUsers) Try to obtain the actual client's machine according to the current user.Get the namenode address to be used by clients.get FSImageGets the host and port colon separated.static InetSocketAddressgetHttpAddress(org.apache.hadoop.conf.Configuration conf) org.apache.hadoop.http.HttpServer2protected InetSocketAddressgetHttpServerAddress(org.apache.hadoop.conf.Configuration conf) protected InetSocketAddressgetHttpServerBindAddress(org.apache.hadoop.conf.Configuration conf) HTTP server address for binding the endpoint.longGets the most recent HA transition time in milliseconds from the epoch.static NameNodeMetricsintEmit Namenode HA service state as an integer so that one can monitor NN HA state based on this metric.protected StringgetNameServiceId(org.apache.hadoop.conf.Configuration conf) Get the name service Id for the nodeReturn theFSNamesystemobject.protected org.apache.hadoop.conf.ConfigurationReturn a host:port format string corresponds to an auxiliary port configured on NameNode.Gets the NameNode role.longgetProtocolVersion(String protocol, long clientVersion) static org.apache.hadoop.security.UserGroupInformationgetRole()protected InetSocketAddressgetRpcServerAddress(org.apache.hadoop.conf.Configuration conf) protected StringgetRpcServerBindHost(org.apache.hadoop.conf.Configuration conf) Given a configuration get the bind host of the client rpc server If the bind host is not configured returns null.static InetSocketAddressgetServiceAddress(org.apache.hadoop.conf.Configuration conf, boolean fallback) Fetches the address for services to use when connecting to namenode based on the value of fallback returns null if the special address is not specified or returns the default namenode address to be used by both clients and services.protected InetSocketAddressgetServiceRpcServerAddress(org.apache.hadoop.conf.Configuration conf) Given a configuration get the address of the service rpc server If the service rpc is not configured returns nullprotected StringgetServiceRpcServerBindHost(org.apache.hadoop.conf.Configuration conf) Given a configuration get the bind host of the service rpc server If the bind host is not configured returns null.Gets the topN slow disks in the cluster, if the feature is enabled.Retrieves information about slow DataNodes, if the feature is enabled.getStartupOption(org.apache.hadoop.conf.Configuration conf) static StartupProgressReturns object used for reporting namenode startup progress.getState()Gets the NameNode state.Return the service name of the issued delegation token.protected voidinitialize(org.apache.hadoop.conf.Configuration conf) Initialize name-node.static voidinitializeGenericKeys(org.apache.hadoop.conf.Configuration conf, String nameserviceId, String namenodeId) In federation configuration is set for a set of namenode and secondary namenode/backup/checkpointer, which are grouped under a logical nameservice ID.static booleaninitializeSharedEdits(org.apache.hadoop.conf.Configuration conf) static booleaninitializeSharedEdits(org.apache.hadoop.conf.Configuration conf, boolean force) static voidinitMetrics(org.apache.hadoop.conf.Configuration conf, HdfsServerConstants.NamenodeRole role) booleanbooleanIs the cluster currently in safe mode?booleanbooleanGets if security is enabled.booleanvoidjoin()Wait for service to finish.voidNameNodeHttpServer, used by unit tests to ensure a full shutdown, so that no bind exception is thrown during restart.protected voidloadNamesystem(org.apache.hadoop.conf.Configuration conf) static voidstatic StringparseSpecialValue(String content, String key) Try to obtain the value corresponding to the key by parsing the content.voidqueueExternalCall(org.apache.hadoop.ipc.ExternalCall<?> extCall) protected StringreconfigurePropertyImpl(String property, String newVal) protected voidsetRpcServerAddress(org.apache.hadoop.conf.Configuration conf, InetSocketAddress rpcAddress) protected voidsetRpcServiceServerAddress(org.apache.hadoop.conf.Configuration conf, InetSocketAddress serviceRPCAddress) Modifies the configuration passed to contain the service rpc address settingstatic voidsetServiceAddress(org.apache.hadoop.conf.Configuration conf, String address) Set the configuration property for the service rpc address to addressprotected voidstartMetricsLogger(org.apache.hadoop.conf.Configuration conf) Start a timer to periodically write NameNode metrics to the log file.voidstop()Stop all NameNode threads and wait for all to finish.protected voidvoidverifyToken(org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier id, byte[] password) Methods inherited from class org.apache.hadoop.conf.ReconfigurableBase
getChangedProperties, getReconfigurationTaskStatus, isPropertyReconfigurable, reconfigureProperty, setReconfigurationUtil, shutdownReconfigurationTask, startReconfigurationTaskMethods inherited from class org.apache.hadoop.conf.Configured
getConf, setConfMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.conf.Configurable
getConf, setConf
-
Field Details
-
NAMENODE_SPECIFIC_KEYS
HDFS configuration can have three types of parameters:- Parameters that are common for all the name services in the cluster.
- Parameters that are specific to a name service. These keys are suffixed with nameserviceId in the configuration. For example, "dfs.namenode.rpc-address.nameservice1".
- Parameters that are specific to a single name node. These keys are suffixed with nameserviceId and namenodeId in the configuration. for example, "dfs.namenode.rpc-address.nameservice1.namenode1"
-
NAMESERVICE_SPECIFIC_KEYS
-
DEFAULT_PORT
Deprecated.UseHdfsClientConfigKeys.DFS_NAMENODE_RPC_PORT_DEFAULTinstead.- See Also:
-
LOG
public static final org.slf4j.Logger LOG -
stateChangeLog
public static final org.slf4j.Logger stateChangeLog -
blockStateChangeLog
public static final org.slf4j.Logger blockStateChangeLog -
ACTIVE_STATE
-
STANDBY_STATE
-
OBSERVER_STATE
-
METRICS_LOG_NAME
- See Also:
-
namesystem
-
role
-
allowStaleStandbyReads
protected final boolean allowStaleStandbyReads -
httpServer
httpServer -
stopRequested
protected boolean stopRequestedonly used for testing purposes -
nodeRegistration
Registration information of this name-node -
tracer
protected final org.apache.hadoop.tracing.Tracer tracer
-
-
Constructor Details
-
NameNode
Start NameNode.The name-node can be started with one of the following startup options:
REGULAR- normal name node startupFORMAT- format name nodeBACKUP- start backup nodeCHECKPOINT- start checkpoint nodeUPGRADE- start the clusterUPGRADEONLY- upgrade the cluster upgrade and create a snapshot of the current file system stateRECOVERY- recover name node metadataROLLBACK- roll the cluster back to the previous stateIMPORT- import checkpoint
dfs.namenode.startupThe conf will be modified to reflect the actual ports on which the NameNode is up and running if the user passes the port aszeroin the conf.- Parameters:
conf- confirguration- Throws:
IOException
-
NameNode
protected NameNode(org.apache.hadoop.conf.Configuration conf, HdfsServerConstants.NamenodeRole role) throws IOException - Throws:
IOException
-
-
Method Details
-
getProtocolVersion
- Throws:
IOException
-
format
Format a new filesystem. Destroys any filesystem that may already exist at this location.- Throws:
IOException
-
getNamesystem
Return theFSNamesystemobject.- Returns:
FSNamesystemobject.
-
getRpcServer
-
getHttpServer
@VisibleForTesting public org.apache.hadoop.http.HttpServer2 getHttpServer() -
queueExternalCall
public void queueExternalCall(org.apache.hadoop.ipc.ExternalCall<?> extCall) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
initMetrics
public static void initMetrics(org.apache.hadoop.conf.Configuration conf, HdfsServerConstants.NamenodeRole role) -
getNameNodeMetrics
-
parseSpecialValue
Try to obtain the value corresponding to the key by parsing the content.- Parameters:
content- the full content to be parsed.key- trying to obtain the value of the key.- Returns:
- the value corresponding to the key.
-
getClientMachine
Try to obtain the actual client's machine according to the current user.- Parameters:
ipProxyUsers- Users who can override client infos.- Returns:
- The actual client's machine.
-
getClientIdAndCallId
public static org.apache.commons.lang3.tuple.Pair<byte[],Integer> getClientIdAndCallId(String[] ipProxyUsers) Try to obtain the actual client's id and call id according to the current user.- Parameters:
ipProxyUsers- Users who can override client infos- Returns:
- The actual client's id and call id.
-
getStartupProgress
Returns object used for reporting namenode startup progress.- Returns:
- StartupProgress for reporting namenode startup progress
-
getTokenServiceName
Return the service name of the issued delegation token.- Returns:
- The name service id in HA-mode, or the rpc address in non-HA mode
-
getClientNamenodeAddress
Get the namenode address to be used by clients.- Returns:
- nn address
-
setServiceAddress
Set the configuration property for the service rpc address to address -
getServiceAddress
public static InetSocketAddress getServiceAddress(org.apache.hadoop.conf.Configuration conf, boolean fallback) Fetches the address for services to use when connecting to namenode based on the value of fallback returns null if the special address is not specified or returns the default namenode address to be used by both clients and services. Services here are datanodes, backup node, any non client connection -
getRole
-
composeNotStartedMessage
-
getServiceRpcServerAddress
Given a configuration get the address of the service rpc server If the service rpc is not configured returns null -
getRpcServerAddress
-
getServiceRpcServerBindHost
Given a configuration get the bind host of the service rpc server If the bind host is not configured returns null. -
getRpcServerBindHost
Given a configuration get the bind host of the client rpc server If the bind host is not configured returns null. -
setRpcServiceServerAddress
protected void setRpcServiceServerAddress(org.apache.hadoop.conf.Configuration conf, InetSocketAddress serviceRPCAddress) Modifies the configuration passed to contain the service rpc address setting -
setRpcServerAddress
protected void setRpcServerAddress(org.apache.hadoop.conf.Configuration conf, InetSocketAddress rpcAddress) -
getHttpServerAddress
-
getHttpServerBindAddress
HTTP server address for binding the endpoint. This method is for use by the NameNode and its derivatives. It may return a different address than the one that should be used by clients to connect to the NameNode. SeeDFSConfigKeys.DFS_NAMENODE_HTTP_BIND_HOST_KEY- Parameters:
conf-- Returns:
-
getHttpAddress
- Returns:
- the NameNode HTTP address.
-
loadNamesystem
- Throws:
IOException
-
getRemoteUser
- Throws:
IOException
-
verifyToken
public void verifyToken(org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier id, byte[] password) throws IOException - Specified by:
verifyTokenin interfaceTokenVerifier<org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier>- Throws:
IOException
-
initialize
Initialize name-node.- Parameters:
conf- the configuration- Throws:
IOException
-
getAliasMapServer
-
startMetricsLogger
protected void startMetricsLogger(org.apache.hadoop.conf.Configuration conf) Start a timer to periodically write NameNode metrics to the log file. This behavior can be disabled by configuration.- Parameters:
conf-
-
stopMetricsLogger
protected void stopMetricsLogger() -
createRpcServer
protected NameNodeRpcServer createRpcServer(org.apache.hadoop.conf.Configuration conf) throws IOException Create the RPC server implementation. Used as an extension point for the BackupNode.- Throws:
IOException
-
createHAState
-
createHAContext
-
join
public void join()Wait for service to finish. (Normally, it runs forever.) -
stop
public void stop()Stop all NameNode threads and wait for all to finish. -
isInSafeMode
public boolean isInSafeMode()Is the cluster currently in safe mode? -
getFSImage
get FSImage -
getNameNodeAddress
- Returns:
- NameNode RPC address
-
getAuxiliaryNameNodeAddresses
- Returns:
- The auxiliary nameNode RPC addresses, or empty set if there is none.
-
getNameNodeAddressHostPortString
- Returns:
- NameNode RPC address in "host:port" string form
-
getNNAuxiliaryRpcAddress
Return a host:port format string corresponds to an auxiliary port configured on NameNode. If there are multiple auxiliary ports, an arbitrary one is returned. If there is no auxiliary listener, returns null.- Returns:
- a string of format host:port that points to an auxiliary NameNode address, or null if there is no such address.
-
getServiceRpcAddress
- Returns:
- NameNode service RPC address if configured, the NameNode RPC address otherwise
-
getHttpAddress
- Returns:
- NameNode HTTP address, used by the Web UI, image transfer, and HTTP-based file system clients like WebHDFS
-
getHttpsAddress
- Returns:
- NameNode HTTPS address, used by the Web UI, image transfer, and HTTP-based file system clients like WebHDFS
-
joinHttpServer
@VisibleForTesting public void joinHttpServer()NameNodeHttpServer, used by unit tests to ensure a full shutdown, so that no bind exception is thrown during restart. -
checkAllowFormat
- Throws:
IOException
-
doRollback
@VisibleForTesting public static boolean doRollback(org.apache.hadoop.conf.Configuration conf, boolean isConfirmationNeeded) throws IOException - Throws:
IOException
-
getStartupOption
public static HdfsServerConstants.StartupOption getStartupOption(org.apache.hadoop.conf.Configuration conf) -
createNameNode
public static NameNode createNameNode(String[] argv, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
initializeGenericKeys
public static void initializeGenericKeys(org.apache.hadoop.conf.Configuration conf, String nameserviceId, String namenodeId) In federation configuration is set for a set of namenode and secondary namenode/backup/checkpointer, which are grouped under a logical nameservice ID. The configuration keys specific to them have suffix set to configured nameserviceId. This method copies the value from specific key of format key.nameserviceId to key, to set up the generic configuration. Once this is done, only generic version of the configuration is read in rest of the code, for backward compatibility and simpler code changes.- Parameters:
conf- Configuration object to lookup specific key and to set the value to the key passed. Note the conf object is modifiednameserviceId- name service Id (to distinguish federated NNs)namenodeId- the namenode ID (to distinguish HA NNs)- See Also:
-
getNameServiceId
Get the name service Id for the node- Returns:
- name service Id or null if federation is not configured
-
main
- Throws:
Exception
-
getNameNodeState
@Metric({"NameNodeState","Namenode HA service state"}) public int getNameNodeState()Emit Namenode HA service state as an integer so that one can monitor NN HA state based on this metric.- Returns:
- 0 when not fully started 1 for active or standalone (non-HA) NN 2 for standby 3 for observer These are the same integer values for the HAServiceState enum.
-
getNNRole
Description copied from interface:NameNodeStatusMXBeanGets the NameNode role.- Specified by:
getNNRolein interfaceNameNodeStatusMXBean- Returns:
- the NameNode role.
-
getState
Description copied from interface:NameNodeStatusMXBeanGets the NameNode state.- Specified by:
getStatein interfaceNameNodeStatusMXBean- Returns:
- the NameNode state.
-
getHostAndPort
Description copied from interface:NameNodeStatusMXBeanGets the host and port colon separated.- Specified by:
getHostAndPortin interfaceNameNodeStatusMXBean- Returns:
- host and port colon separated.
-
isSecurityEnabled
public boolean isSecurityEnabled()Description copied from interface:NameNodeStatusMXBeanGets if security is enabled.- Specified by:
isSecurityEnabledin interfaceNameNodeStatusMXBean- Returns:
- true, if security is enabled.
-
getLastHATransitionTime
public long getLastHATransitionTime()Description copied from interface:NameNodeStatusMXBeanGets the most recent HA transition time in milliseconds from the epoch.- Specified by:
getLastHATransitionTimein interfaceNameNodeStatusMXBean- Returns:
- the most recent HA transition time in milliseconds from the epoch.
-
getBytesWithFutureGenerationStamps
public long getBytesWithFutureGenerationStamps()Description copied from interface:NameNodeStatusMXBeanGets number of bytes in blocks with future generation stamps.- Specified by:
getBytesWithFutureGenerationStampsin interfaceNameNodeStatusMXBean- Returns:
- number of bytes that can be deleted if exited from safe mode.
-
getSlowPeersReport
Description copied from interface:NameNodeStatusMXBeanRetrieves information about slow DataNodes, if the feature is enabled. The report is in a JSON format.- Specified by:
getSlowPeersReportin interfaceNameNodeStatusMXBean
-
getSlowDisksReport
Description copied from interface:NameNodeStatusMXBeanGets the topN slow disks in the cluster, if the feature is enabled.- Specified by:
getSlowDisksReportin interfaceNameNodeStatusMXBean- Returns:
- JSON string of list of diskIDs and latencies
-
doImmediateShutdown
protected void doImmediateShutdown(Throwable t) throws org.apache.hadoop.util.ExitUtil.ExitException Shutdown the NN immediately in an ungraceful way. Used when it would be unsafe for the NN to continue operating, e.g. during a failed HA state transition.- Parameters:
t- exception which warrants the shutdown. Printed to the NN log before exit.- Throws:
org.apache.hadoop.util.ExitUtil.ExitException- thrown only for testing.
-
isStandbyState
public boolean isStandbyState() -
isActiveState
public boolean isActiveState() -
isObserverState
public boolean isObserverState() -
getReconfigurableProperties
- Specified by:
getReconfigurablePropertiesin interfaceorg.apache.hadoop.conf.Reconfigurable- Specified by:
getReconfigurablePropertiesin classorg.apache.hadoop.conf.ReconfigurableBase
-
reconfigurePropertyImpl
protected String reconfigurePropertyImpl(String property, String newVal) throws org.apache.hadoop.conf.ReconfigurationException - Specified by:
reconfigurePropertyImplin classorg.apache.hadoop.conf.ReconfigurableBase- Throws:
org.apache.hadoop.conf.ReconfigurationException
-
getNewConf
protected org.apache.hadoop.conf.Configuration getNewConf()- Specified by:
getNewConfin classorg.apache.hadoop.conf.ReconfigurableBase
-
HdfsClientConfigKeys.DFS_NAMENODE_RPC_PORT_DEFAULTinstead.