Very large files on commodity hardware,
protected against failures.
HDFS is the primary distributed storage of Hadoop applications: it stores very large files, replicates data to tolerate failures, and provides high-throughput access. Follow a file from write to read and see what happens when a machine goes down.
HDFS splits each file into blocks, stores replicas of those blocks on DataNodes spread across the cluster, and keeps the namespace, with the location of each block, on the NameNode. It is the distributed file system of Apache Hadoop.
Metadata and data
Who knows and who stores
The NameNode holds the namespace and knows where each block is. The DataNodes store the blocks. User data never passes through the NameNode.
Replicas
Each block on several machines
Blocks are replicated to tolerate failures, with one replica on another rack. When a machine goes down, the NameNode recreates the missing copies.
Close to the data
Computation moves to the data
Moving computation is cheaper than moving data: HDFS gives applications interfaces to run close to where the data is.
On this page
- See a file being written and read
- Architecture
- From namespace to replica
- When a DataNode goes down
- High availability
- Why HDFS
- In the TDP editions
See a file being written and read
Press Play or move forward step by step. Underlined names lead to the Glossary.
1 The application asks to create the file
The client sends the NameNode the full path of the new file. The NameNode checks permissions along the entire path before accepting the operation in the namespace.
In the Glossary: NameNode · Permissions · Namespace
- The application asks to create the file. The client sends the NameNode the full path of the new file. The NameNode checks permissions along the entire path before accepting the operation in the namespace.
- The NameNode records the change. Creating the file is a metadata change, and the NameNode records it in the EditLog, the transaction log it keeps on its own disk.
- The NameNode chooses the DataNodes. For each block of the file, the NameNode returns the list of DataNodes that will store a replica. The choice takes racks into account: here, one DataNode on the same rack as the application and the others on another rack.
- Data goes to the first DataNode. The client writes only to the first DataNode in the list, without going through the NameNode. When the file is created, the client also computes a checksum of each block and stores it in a hidden file in the same namespace.
- Each DataNode forwards to the next. The first DataNode receives the data in portions, writes each portion locally, and forwards it to the second, which does the same with the third. Each one receives from the previous and sends to the next at the same time.
- The DataNodes report to the NameNode. Each DataNode periodically sends the NameNode a heartbeat, a signal that it is working, and a block report, the list of blocks it stores. This is how the NameNode knows where the replicas are.
- On read, the NameNode says where the blocks are. To read the file, the client makes a first request to the NameNode and receives the location of the blocks. Metadata comes from the NameNode. Data does not.
- The read comes from the closest replica. The client reads each block from the closest replica, preferably on the same rack, and checks the content against the stored checksum. If it does not match, the client fetches the block from another DataNode that has a replica.
Architecture
Metadata lives on the NameNode. Data lives on the DataNodes.
What the figure shows:
- The clients are the HDFS Client (Java API and FS shell), the NFS Gateway (NFSv3 mount), and the cluster services, such as Hive, Spark, and HBase. They query the active NameNode for metadata and read and write directly on the DataNodes.
- The NameNodes are the master servers: they manage the namespace and regulate client access to files. Each one stores the namespace, the block map, the EditLog, and the FsImage. With high availability, there is more than one NameNode: the active one serves the clients and the others, in standby, follow the active one.
- The JournalNodes form the edit quorum: the active NameNode records each edit of the namespace in this quorum, and the standby NameNode reads the edits from there to stay in sync.
- ZooKeeper and the ZKFC monitor the NameNodes in automatic failover: on each NameNode machine, a ZKFC keeps a session in ZooKeeper, which holds the lock for the election of the active one.
- The Secondary NameNode performs the namespace checkpoints in the topology without high availability.
- The DataNodes, usually one per machine, manage the storage of the machines they run on. They are distributed across racks and store the block replicas, passed from DataNode to DataNode in the replication pipeline. They send heartbeats and block reports to the NameNodes.
From namespace to replica
A path in HDFS, from the broadest level to the most concrete: each level contains the next.
Level 1 of 5
Namespace
The hierarchy of directories and files that HDFS exposes, maintained by the NameNode. Creating, removing, moving, and renaming files are namespace operations, and each change is recorded.
- EditLog and FsImageThe transaction log and the namespace image, on the NameNode disk. At a checkpoint, the log is applied to the image.
- Safe modeOn startup, the NameNode stays in a read-only mode until a configurable fraction of the blocks has enough replicas.
- Namespace. The hierarchy of directories and files that HDFS exposes, maintained by the NameNode. Creating, removing, moving, and renaming files are namespace operations, and each change is recorded.
- EditLog and FsImage. The transaction log and the namespace image, on the NameNode disk. At a checkpoint, the log is applied to the image.
- Safe mode. On startup, the NameNode stays in a read-only mode until a configurable fraction of the blocks has enough replicas.
- Directory. Organizes files and other directories, as in most file systems. Each directory has an owner, a group, and permissions.
- Permissions. On a directory, r lists the contents, w creates or deletes files and directories, and x gives access to the children. The NameNode checks permissions along the path.
- File. A sequence of blocks. The model is write once, read many: after a file is created, written, and closed, it only changes through append or truncate.
- Replication factor. How many copies HDFS keeps of the file. It is set at creation and can change later.
- Block. Each part into which the file is split. All but the last have the same size. The NameNode knows which DataNodes each block goes to.
- Block report. The list of a DataNode's blocks, sent periodically to the NameNode.
- Replica. Each copy of a block, stored on a DataNode as a file in the local file system. The DataNode does not know HDFS files, only blocks.
- Rack awareness. One replica of each block goes to another rack. On read, the replica on the same rack as the reader is preferred.
When a DataNode goes down
In HDFS, hardware failure is the norm, not the exception. The scene shows how the system detects the failure and recreates the replicas.
1 All send heartbeats
Each DataNode periodically sends a heartbeat to the NameNode. Receiving the heartbeat indicates that the DataNode is working.
- All send heartbeats. Each DataNode periodically sends a heartbeat to the NameNode. Receiving the heartbeat indicates that the DataNode is working.
- A DataNode goes silent. A disk fails, the machine goes down, or a network partition isolates the DataNode from the NameNode. The NameNode notices through the absence of heartbeats.
- The NameNode marks it as dead. Without recent heartbeats, the DataNode is marked dead and no longer receives read and write requests. The timeout is conservative, to avoid a replication storm when a DataNode flaps. A shorter interval can mark it as stale earlier, so that reads and writes avoid it.
- Blocks are left under-replicated. The blocks that the DataNode stored are left with fewer replicas than the specified replication factor. The NameNode constantly tracks which blocks need to be replicated.
- The NameNode orders the copy. On the NameNode's instruction, a DataNode that has the replica copies the block to another DataNode, and the block again has the specified number of replicas.
- Other reasons to re-replicate. The same happens when a replica becomes corrupted, a disk on a DataNode fails, or the replication factor of a file increases. On read, a block that does not match the checksum is fetched from another replica.
High availability
One active NameNode, others in standby, and automatic switchover when the active one goes down.
1 The active records every change
The active NameNode serves clients and records every namespace modification on the majority of the JournalNodes.
In the Glossary: NameNode · JournalNodes · Namespace
- The active records every change. The active NameNode serves clients and records every namespace modification on the majority of the JournalNodes.
- The standby keeps up. The standby NameNode reads the edits from the JournalNodes and applies them to its own namespace. It also performs the checkpoints, which is why the Secondary NameNode is not needed in this topology.
- The DataNodes report to all. The DataNodes know all the NameNodes and send each of them the heartbeats and the block locations. This way the standby already knows where each block is and can take over quickly.
- The ZKFCs monitor. Each NameNode machine runs a ZKFC, which periodically checks the health of the local NameNode and keeps a session open in ZooKeeper. The active's ZKFC also holds a lock in ZooKeeper.
- The active goes down. If the active's machine goes down, its session in ZooKeeper expires and the lock is deleted automatically. The other NameNodes learn that a failover is needed.
- The standby takes over. The healthy standby's ZKFC sees that no one holds the lock and acquires it. The former active is fenced, if necessary, and the standby, after reading all the edits from the JournalNodes, becomes active. The JournalNodes only accept one NameNode writing at a time.
With high availability, HDFS is identified by a nameservice, a logical name for the set of NameNodes. Absolute HDFS paths use this name, so switching NameNodes does not change the address that applications use.
Without high availability, there is a single NameNode, and the namespace checkpoints are handled by the Secondary NameNode, which usually runs on another machine.
Why HDFS
Fault tolerance
Detects failures and recovers
In a cluster with many machines, some are always failing. Detecting failures and recovering from them quickly and automatically is a core goal of the architecture.
Large volumes
Tuned for very large files
High aggregate bandwidth, hundreds of nodes in a single cluster, and tens of millions of files in one instance.
Streaming access
Throughput over latency
Designed more for batch processing than for interactive use: the emphasis is high-throughput access to data.
Simple coherency
Write once, read many
A file that is created, written, and closed only changes through append or truncate, which simplifies data coherency and keeps throughput high.
Commodity hardware
Low cost and portable
Designed to run on low-cost hardware and, being written in Java, to be moved from one platform to another.
Multiple access methods
API, shell, web, and NFS
Java FileSystem API, C wrapper, REST API, FS shell, browser, and the NFS Gateway, which mounts HDFS on the client's local file system.
HDFS was created as infrastructure for Apache Nutch, a web search engine project, and is part of Apache Hadoop, alongside YARN and MapReduce.
In the TDP editions
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 3.3.6 | TDP Datacenter components |
In TDP Datacenter
In TDP Datacenter, HDFS is the HDFS service, installed and managed by Ambari.
DATANODE (slave, one or more), HDFS_CLIENT (client, one or more), JOURNALNODE (slave, optional), NAMENODE (master, one or more), NFS_GATEWAY (slave, optional), SECONDARY_NAMENODE (master, one instance) and ZKFC (slave, optional). The JOURNALNODE requires HDFS_CLIENT. The NAMENODE requires ZKFC, ZOOKEEPER_SERVER (ZooKeeper) and JOURNALNODE. The NFS_GATEWAY requires HDFS_CLIENT. Component category.
The directories for NameNode metadata, DataNode blocks, and JournalNode edits are configurable in dfs.namenode.name.dir, dfs.datanode.data.dir, and dfs.journalnode.edits.dir, in the hdfs-site configuration.
The block size and the replication factor of new files are configurable in dfs.blocksize and dfs.replication, and the maximum factor in dfs.replication.max. Rack information comes from the topology script set in net.topology.script.file.name (core-site).
The heartbeat interval is configurable in dfs.heartbeat.interval, and the timeout for a DataNode to be considered stale in dfs.namenode.stale.datanode.interval. Avoiding stale DataNodes on reads and writes can be enabled in dfs.namenode.avoid.read.stale.datanode and dfs.namenode.avoid.write.stale.datanode, and how many failed disks a DataNode tolerates before it stops is configurable in dfs.datanode.failed.volumes.tolerated.
The fraction of blocks that takes the NameNode out of safe mode is configurable in dfs.namenode.safemode.threshold-pct, and the checkpoint frequency in dfs.namenode.checkpoint.period and dfs.namenode.checkpoint.txns.
With the nameservice declared in dfs.nameservices, the NAMENODE requires JOURNALNODE, ZKFC, and the ZooKeeper Server in the cluster. See High availability in TDP Datacenter.
Kerberos authentication is configurable in hadoop.security.authentication, and protocol authorization in hadoop.security.authorization (core-site). Permission checking, ACLs, and the Ranger plugin can be enabled in dfs.permissions.enabled, dfs.namenode.acls.enabled, and ranger-hdfs-plugin-enabled, and the key provider for encryption zones is set in dfs.encryption.key.provider.uri. See Security in TDP Datacenter.
The cluster's default file system is configurable in fs.defaultFS, and the trash in fs.trash.interval (core-site). WebHDFS can be enabled in dfs.webhdfs.enabled, and the hosts that can mount HDFS through the NFS Gateway are configurable in nfs.exports.allowed.hosts.
These services require this one in the cluster: Druid, Flink, HBase, Hive, JupyterLab, Ranger KMS, Solr, Spark, Sqoop, YARN and Zeppelin. The ATLAS_SERVER (Atlas) requires HDFS_CLIENT. The HISTORYSERVER (MapReduce) requires HDFS_CLIENT. The OZONE_MANAGER (Ozone) requires NAMENODE. The TEZ_CLIENT (Tez) requires HDFS_CLIENT.
Next steps
TDP Datacenter
Data and processing
HDFS and YARN on the same machines of the cluster managed by Ambari.
TDP Datacenter
NameNode high availability
Active and standby NameNodes, JournalNodes, and automatic failover in the cluster.
Sources
Apache Hadoop - HDFS Architecture
Apache Hadoop - HDFS Users Guide
Apache Hadoop - HDFS High Availability Using the Quorum Journal Manager
Apache Hadoop - HDFS Permissions Guide