Professional Documents
Culture Documents
2013-08-03
=>
=>DataNode
=> NameNode
=>DataNode DataNode
NameNode DataNode DataNode
InterDatanodeProtocol ClientDatanodeProtocol NameNode
ClientProtocol NameNode
HDFS GFS HDFS POSIX
org.apache.hadoop.fs.FileSystem HDFS
register DataNode
sendHeartbeat/blockReport/blockReceived DataNode offerService
errorReport NameNode Block
BlockReceiver
DataBlockScanner
nextGenerationStamp
java
RefreshUserMappingsProtocol {
//
static{
Configuration.addDefaultResource("hdfs-default.xml");
Configuration.addDefaultResource("hdfs-site.xml");
}
FSNamesystem org.apache.hadoop.hdfs.server.namenode
Namenode
5
//
public static NameNode createNameNode(String argv[],
Configuration conf) throws IOException {
...
StartupOption startOpt = parseArguments(argv);
...
switch (startOpt) {
case FORMAT: // namenode namenode
boolean aborted = format(conf, true);
System.exit(aborted ? 1 : 0);
case FINALIZE: // hadoop
aborted = finalize(conf, true);
System.exit(aborted ? 1 : 0);
default:
}
...
// NameNode initialize
NameNode namenode = new NameNode(conf);
return namenode;
}
private void initialize(Configuration conf) throws IOException {
...
// fsimage edits log
this.namesystem = new FSNamesystem(this, conf);
....
// RPCServer rpc 10 8020
this.server = RPC.getServer(this, socAddr.getHostName(),
socAddr.getPort(), handlerCount, false, conf, namesystem
.getDelegationTokenSecretManager());
startHttpServer(conf);// http http://namenode:50070 hdfs
....
this.server.start(); // RPC server
....
// fs.trash.interval
60
startTrashEmptier(conf);
}
6
org.apache.hadoop.hdfs.server.namenode.FSNamesystem Namenode
NameNode
FSNamesystem NameNode FSNamesystem
=> FSImage
=>DataNode DataNode
DataNode
DataNodeLRU
FSNamesystem
public class FSNamesystem implements FSConstants, FSNamesystemMBean,
NameNodeMXBean, MetricsSource {
//
public FSDirectory dir;
//BlocksMap Block inode
Datanode
final
BlocksMap
blocksMap
=
new
BlocksMap(DEFAULT_INITIAL_MAP_CAPACITY,DEFAULT_MAP_LOAD_FACTOR);
//
7
//
Data CenterRack
Namenode
private HostsFileReader hostsReader;
}
FSNamesystem
private void initialize(NameNode nn, Configuration conf) throws IOException {
this.systemStart = now();
setConfigurationParameters(conf);
dtSecretManager = createDelegationTokenSecretManager(conf);
this.nameNodeAddress = nn.getNameNodeAddress();
this.registerMBean(conf); // register the MBean for the FSNamesystemStutus
this.dir = new FSDirectory(this, conf);
StartupOption startOpt = NameNode.getStartupOption(conf);
// fsimage edits
this.dir.loadFSImage(getNamespaceDirs(conf),
getNamespaceEditsDirs(conf), startOpt);
long timeTakenToLoadFSImage = now() - systemStart;
LOG.info("Finished loading FSImage in " + timeTakenToLoadFSImage + " msecs");
NameNode.getNameNodeMetrics().setFsImageLoadTime(timeTakenToLoadFSImage);
this.safeMode = new SafeModeInfo(conf);
setBlockTotal();
pendingReplications = new PendingReplicationBlocks(
conf.getInt("dfs.replication.pending.timeout.sec",
-1) * 1000L);
if (isAccessTokenEnabled) {
accessTokenHandler = new BlockTokenSecretManager(true,
accessKeyUpdateInterval, accessTokenLifetime);
}
this.hbthread = new Daemon(new HeartbeatMonitor());// Datanode
conf.getInt("dfs.namenode.decommission.nodes.per.interval", 5)));
dnthread.start();
this.dnsToSwitchMapping = ReflectionUtils.newInstance(
conf.getClass("topology.node.switch.mapping.impl", ScriptBasedMapping.class,
DNSToSwitchMapping.class), conf);
/* If the dns to swith mapping supports cache, resolve network
* locations of those hosts in the include list,
* and store the mapping in the cache; so future calls to resolve
* will be fast.
*/
if (dnsToSwitchMapping instanceof CachedDNSToSwitchMapping) {
dnsToSwitchMapping.resolve(new ArrayList<String>(hostsReader.getHosts()));
}
InetSocketAddress socAddr = NameNode.getAddress(conf);
this.nameNodeHostName = socAddr.getHostName();
registerWith(DefaultMetricsSystem.INSTANCE);
}
FSDirectory FSNamesystem
FSDirectory hdfs
INode file/block
INode inode Field
INodeDirectory INodeDirectory INode
INode
INodeFile INodeFile INode INodeDirectory
INodeFile
Datanode
INodeFileUnderConstruction HDFS
Namenode
10
INodeFile
INodeFile Hadoop
INodeFileUnderConstruction INodeFile INodeFile
INodeFileUnderConstruction
INodeFileUnderConstruction
HDFS Datanode
FSDirectory FSDirectory
filename->blockset
FSImage fsImage
loadFSImage FSImage
FSImage EditLog
FSImage
EditLog
EditLog FSImage FSImage EditLog
FSImage
namenode
namenode
hdfs
rpc namenode
namenode FSNamesystem namesystem
namesystem
12
INode*
NameNode
inode inode INode*
INode*
INode INodeDirectory
13
INodeFileINodeDirectoryWithQuota
INodeFileUnderConstruction
HDFS
INode name/modificationTime accessTime
parent permission
HDFS UNIX/Linux UNIX
groupuser IDpermission
INode long
INode get set
collectSubtreeBlocksAndClear INode
BlockcomputeContentSummary INode
INodeDirectory HDFS
private List<INode> children;
/INodeDirectory get
set INodeDirectoryWithQuota INodeDirectory
INodeDirectory NameSpace
INodeFile HDFS
protected BlockInfo blocks[] = null;
Block BlockInfo Block
INodeFileUnderConstruction
clientName
clientMachine
DataNode clientNode targets
14