The Hadoop Distributed File System | Shvachko, Kuang, Radia, Chansler

Introduction

Uses the MapReduce paradigm.

"A Hadoop cluster scales computation capacity, storage capacity, and IO bandwidth by simply adding more commodity servers."

Largest cluster in use at Yahoo is 3500 servers.

Hadoop is an open source Apache project. Project components are:

  • HDFS: Distributed file system
  • MapReduce: Distributed computation network
  • HBase: Column-oriented table service
  • Pig: Dataflow language and parallel execution framework
  • Hive: Data warehouse infrastructure
  • ZooKeeper: Distributed coordination service.
  • Chukwa: System for collecting management data
  • Avro: Data serialization system

This paper zooms in on HDFS.

HDFS intro

  • HDFS is built after the UNIX file system, but UNIX standards are sometimes sacrificed in favor of improved performance.
  • Metadata and application data are stored separately in NameNodes and DataNodes respectively.
  • Servers communicate based on TCP-based protocols.
  • Data is made reliable/durable not by data protection mechanisms, but by replicating on various DataNodes. This also allows computation to be localized more easily near the needed data.

Architecture

NameNode

Contains the namespace tree and the mapping of file blocks to DataNodes (physical location of the data). A file block is usually 128 MB but user selectable file-by-file. Each block is independently replicated on multiple DataNodes (usually three).

When reading data, a client contacts the NameNode, which shows the DataNode closest to the client where the data can be read.

When writing, the NameNode chooses a suite of three DataNodes to write to, in a pipeline fashion, concurrently.

The entire namespace is kept in RAM.

Image: "inode data and the list of blocks belonging to each file comprise the meta-data of the name system called the image."

Checkpoint: "Persistent record of the image stored in the local host's native files system"

Journal: "The NameNode also stores the modification log of the image called the journal in the local host's native file system."

The current namespace can be restored on restarts by reading the namespace and then replaying the journal.

Q: Is this a 'git-like' operation where changes are applied? (Rather than storing an absolute file state?)

DataNodes

N.B. block replicas can be relocated and are thus not part of the persistent checkpoint.

Each block on a DataNode contains:

1) The data itself * Block size equals the size of the data, so does not require to be rounded up 2) Metadata * Checksums * Generation stamp - A persistent storage ID (assigned by its NameNode)

Each DataNode needs to connect to a NameNode by performing a handshake. The handshake checks namespace ID and the software version, and shuts down if they are incorrect.

The namespace ID is for preserving the integrity of the system, as DataNodes with other namespace IDs are prohibited from entering a cluster. The same holds for checking the software version, to avoid corruption of data due to incompatibility between versions. The namespace ID is stored persistently after registering with a NameNode. Registering with a NameNode also registers a persistent StorageId for the DataNode.

Block report: Frequent rapport of what replica blocks (with id, generation stamp) are stored on a DataNode.

Communication between DataNodes and NameNodes: through heartbeats

Heartbeats: DataNodes inform NameNode every three seconds they are active. If a heartbeat has been missing for 10 minutes, the DataNode is considered to be inactive and its replicas will be recreated at other DataNodes. However, heartbeats also contain information about 1) total storage capacity, 2) storage in use 3) number of current data transfers. This allows space allocation and load balancing by the NameNode.

The NameNode does not initiate communication with the DataNode, but replies to heartbeats with instructions. Possible instructions are:

1) replicate blocks to other node 2) remove local block replica 3) re-register or shutdown node 4) send immediate block report

Frequent communication through heartbeats is essential to maintain data integrity, even on big clusters.

HDFS Client

Communication between HDFS client and NameNode when writing a file

Noticeable difference: HDFS exposes the locations of file blocks through its API, so that applications (e.g. MapReduce) can directly perform tasks to where the data is located.

It also allows applications to increase the replication rate of a file.

Image and Journal

For each transaction that the client starts, the journal records the made changes and then flushes and updates the journal file before the change is committed and confirmed to the client.

On startup NameNodes create their namespace by replaying the changes recorded in the journal with respect to the last checkpoint.

Checkpoints of the namespace image are never changed, but replaced completely by the NameNode before the NameNode starts serving clients.

This all means that the namespace can be corrupted both by errors in the checkpoint or namespace. Therefore it is appropriate to store these in multiple storage directories.

"During startup the NameNode initialized the namepsace image from the checkpoint, and then replays changes from the journal until the image is up-to-date with the last state of the file system. A new checkpoint and empty journal are written back to the storage directories before the NameNode starts serving clients."

Checkpoint- and backup nodes

NameNodes can call CheckpointNodes or BackupNodes.

Checkpoint nodes merge the last checkpoint and the journal into a new checkpoint. This allows the tail of the journal to be cut off. This is necessary because longer journals have a higher risk of data corruption, and increase the time of journal replay at start up (Processing a journal of a week takes an hour, so NameNode start up will be extremely slow).

N.B. the CheckpointNode does the same work as a NameNode and thus has similarly high memory requirements. Therefore it is usually ran on a different host than the NameNodes'.

The BackupNode simply updates its own namespace image in memory. It does not require to download checkpoints the whole time, as it just updates its own namespace in memory.

Upgrades and File System Snapshots

I skipped this, as it seems less relevant for me.

File I/O and Replica Management

File read and write

HDFS implements a single-writer, multiple-reader model: only one client can have the lease on a file and write to it. It needs to renew the lease through heartbeats. After a soft limit other clients can take the lease. The lease is closed by HDFS if a hard limit is passed.

Data pipeline for block construction

Packets are written to the next data node without the requirement that the reader is notified that the previous package is successfully written. If this is desired, the hflush operation is available.

When a client reads a file, it requests the list of required blocks and the location of the block replica's. Blocks closer to the client are accessed first; the next block is tried on failure.

Block placement

For efficiency nodes can be placed in racks instead of in a flat topology. Distance between two nodes can be calculated by summing up the distances to their closest common ancestor.

Efficiency: a shorter distance means that a greater bandwidth can be used to transfer data.

The default data rack policy reduces the inter-rack and inter-node write traffic and improves performance.

The default policy summarized (p. 6)

  • No DataNode contains more than one replica of any block
  • No rack contains more than two replicas of the same block, provided there are sufficient racks on the cluster.

Replication Management

Over-replicated blocks are removed by the NameNode, following two heuristics:

1) Do not reduce the amount of racks of the replica 2) Prefer removal at DataNodes with low storage capacity

For under-replicated blocks, the priority is to make a new replicate with low cost. If the block is already represented on multiple racks, then it is not necessary to place the new replica on yet another rack.

Balancer

A cluster is considered to be balanced if the activity of each DataNode (used/capacity) does not differ much from the utilization in the whole cluster (used space/total capacity).

A balancer moves replicas from highly utilized nodes to lower utilized nodes. It strongly prioritizes doing so within racks whenever possible.

"If the balancer decides that a replica A needs to be moved to a different rack and the destination rack happens to have a replica B of the same block, the data will be copied from replica B instead of replica A." (p.7)

Block Scanner

Each DataNode runs a block scanner that verifies all checksums of the block data. If corrupt, the NameNode first commissions a new replica before removing the old one.

Decommissioning

Administrators can remove DataNodes from the cluster in a controlled manner.

1) Stop creating replica's on the target, but still serve read requests. 2) Schedule replication of its blocks to other DataNodes 3) NameNode will remove it when it detects all blocks have been moved.

Practical Remarks from Experience at Yahoo

Durable against uncorrelated data loss due to the replication of blocks.

Correlated data loss is more dangerous.

  • Broken switches make whole racks unavailable
    • Repairing the switch makes the data available again
    • There is always minimally one replica on another rack
  • Loss of power
    • Re-enabling power and a power on restart can lead to the destruction of some nodes, leading to potential data loss.

A main problem is the scalability of the NameNode. Limited heap size limits:

1) the number of files 2) the number of blocks addressable

There are various proposal to deal with this. See paper.

History Β· 4 changes since 2019-02-05

Full changelog