Skip to main content

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​

Press Play or move forward step by step. Underlined names lead to the Glossary.

ClientApplication on rack 1
HDFS ClientWrites and reads the file
NameNodeKnows where each block is
NameNodeNamespace and block map
Rack 1Same rack as the application
DataNodeFirst in the pipeline
Rack 2Another rack
DataNodeReceives and forwards
DataNodeLast in the pipeline
Step 1 of 8

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.

  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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
Figure 1 - Writing and reading a block in HDFS. The application asks the NameNode where to write and where to read. Data flows directly to and from the DataNodes.

Architecture​

Metadata lives on the NameNode. Data lives on the DataNodes.

HDFS architecture: clients, metadata layer with the NameNodes, and data layer with the DataNodes in racksClients, the NFS Gateway, and the cluster services request metadata from the active NameNode and read and write data directly on the DataNodes. The active NameNode stores the namespace, the block map, the EditLog, and the FsImage, and records each namespace edit in a quorum of JournalNodes, from which the standby NameNode reads the edits. On each NameNode machine, a ZKFC keeps a session in ZooKeeper for the active election. Without high availability, the Secondary NameNode performs the namespace checkpoints. The DataNodes are distributed across racks, store the block replicas, forward each block along the replication pipeline, and send heartbeats and block reports to the NameNodes.ClientsHDFS ClientJava API and FS shellNFS GatewayNFSv3 mountCluster servicesHive, Spark, HBase…Metadata layerActive NameNodeServes the clientsStandby NameNodeFollows the activeNamespaceBlock mapEditLog and FsImageNamespaceBlock mapEditLog and FsImageZKFCZKFCZooKeeperSessions and lockfor the active electionJournalNodesJNJNJNEdit quorumSecondary NameNodeNamespace checkpointsin the non-HA topologyData layerRack 1Rack 2DataNodeDataNodeDataNodeDataNodeBlock BBlock ABlock BBlock ABlock ABlock BMetadata requestsData reads and writesReplication pipelineHeartbeats and block reportsNamespace editsZooKeeper sessions (ZKFC)
Figure 2 - HDFS architecture: clients, the metadata layer with the NameNodes, and the data layer with the DataNodes on racks. Underlined terms lead to the Glossary.

What the figure shows:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. The Secondary NameNode performs the namespace checkpoints in the topology without high availability.
  6. 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.
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
Figure 3 - The levels of data in HDFS. The terms beside each level go with that level.

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.

NameNodeTracks the DataNodes
NameNodeDecides replication
Rack 1DataNodes
DataNodeReplica of block A
DataNodeNo replica of block A
Rack 2DataNodes
DataNodeReplica of block A
DataNodeReplica of block A
Step 1 of 6

1 All send heartbeats

Each DataNode periodically sends a heartbeat to the NameNode. Receiving the heartbeat indicates that the DataNode is working.

  1. All send heartbeats. Each DataNode periodically sends a heartbeat to the NameNode. Receiving the heartbeat indicates that the DataNode is working.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
Figure 4 - Re-replication in HDFS. Without a heartbeat, the DataNode is marked dead, and the NameNode orders the blocks that are left with too few replicas to be copied.

High availability​

One active NameNode, others in standby, and automatic switchover when the active one goes down.

DataNodesWhere the blocks are
DataNodesReport to all NameNodes
NameNodesOne active, others in standby
ZKFCMonitors the active NameNode
NameNodeActive
NameNodeStandby
ZKFCMonitors the standby NameNode
QuorumsZooKeeper and JournalNodes
ZooKeeperSessions and active lock
JournalNodesEach edit goes to the majority
Step 1 of 6

1 The active records every change

The active NameNode serves clients and records every namespace modification on the majority of the JournalNodes.

  1. The active records every change. The active NameNode serves clients and records every namespace modification on the majority of the JournalNodes.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
Figure 5 - NameNode high availability. The JournalNodes store the edits, the ZKFCs monitor the NameNodes, and ZooKeeper drives the election of the new active.

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.

Where it comes from

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​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter3.3.6TDP Datacenter components

In TDP Datacenter​

In TDP Datacenter, HDFS is the HDFS service, installed and managed by Ambari.

Service components

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.

Where data is stored

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.

Blocks and replicas

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).

DataNodes

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.

Safe mode and checkpoints

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.

High availability

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.

Security

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.

Access

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.

Dependencies

Ambari requires in the cluster ZooKeeper and YARN.

Required by

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​

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

Apache Hadoop - Rack Awareness

Apache Hadoop - HDFS NFS Gateway