Transcription

The Hadoop Distributed File SystemKonstantin Shvachko, Hairong Kuang, Sanjay Radia, Robert ChanslerYahoo!Sunnyvale, California USA{Shv, Hairong, SRadia, Chansler}@Yahoo-Inc.comAbstract—The Hadoop Distributed File System (HDFS) isdesigned to store very large data sets reliably, and to streamthose data sets at high bandwidth to user applications. In a largecluster, thousands of servers both host directly attached storageand execute user application tasks. By distributing storage andcomputation across many servers, the resource can grow withdemand while remaining economical at every size. We describethe architecture of HDFS and report on experience using HDFSto manage 25 petabytes of enterprise data at Yahoo!.Keywords: Hadoop, HDFS, distributed file systemI.INTRODUCTION AND RELATED WORKHadoop [1][16][19] provides a distributed file system and aframework for the analysis and transformation of very largedata sets using the MapReduce [3] paradigm. An importantcharacteristic of Hadoop is the partitioning of data and computation across many (thousands) of hosts, and executing application computations in parallel close to their data. A Hadoopcluster scales computation capacity, storage capacity and IObandwidth by simply adding commodity servers. Hadoop clusters at Yahoo! span 25 000 servers, and store 25 petabytes ofapplication data, with the largest cluster being 3500 servers.One hundred other organizations worldwide report usingHadoop.HDFSDistributed file systemSubject of this paper!MapReduceDistributed computation frameworkHBaseColumn-oriented table servicePigDataflow language and parallel executionframeworkHiveData warehouse infrastructureZooKeeperDistributed coordination serviceChukwaSystem for collecting management dataAvroData serialization systemTable 1. Hadoop project componentsHadoop is an Apache project; all components are availablevia the Apache open source license. Yahoo! has developed andcontributed to 80% of the core of Hadoop (HDFS and MapReduce). HBase was originally developed at Powerset, now adepartment at Microsoft. Hive [15] was originated and devel-developed at Facebook. Pig [4], ZooKeeper [6], and Chukwawere originated and developed at Yahoo! Avro was originatedat Yahoo! and is being co-developed with Cloudera.HDFS is the file system component of Hadoop. While theinterface to HDFS is patterned after the UNIX file system,faithfulness to standards was sacrificed in favor of improvedperformance for the applications at hand.HDFS stores file system metadata and application dataseparately. As in other distributed file systems, like PVFS[2][14], Lustre [7] and GFS [5][8], HDFS stores metadata on adedicated server, called the NameNode. Application data arestored on other servers called DataNodes. All servers are fullyconnected and communicate with each other using TCP-basedprotocols.Unlike Lustre and PVFS, the DataNodes in HDFS do notuse data protection mechanisms such as RAID to make the datadurable. Instead, like GFS, the file content is replicated on multiple DataNodes for reliability. While ensuring data durability,this strategy has the added advantage that data transfer bandwidth is multiplied, and there are more opportunities for locating computation near the needed data.Several distributed file systems have or are exploring trulydistributed implementations of the namespace. Ceph [17] has acluster of namespace servers (MDS) and uses a dynamic subtree partitioning algorithm in order to map the namespace treeto MDSs evenly. GFS is also evolving into a distributed namespace implementation [8]. The new GFS will have hundreds ofnamespace servers (masters) with 100 million files per master.Lustre [7] has an implementation of clustered namespace on itsroadmap for Lustre 2.2 release. The intent is to stripe a directory over multiple metadata servers (MDS), each of which contains a disjoint portion of the namespace. A file is assigned to aparticular MDS using a hash function on the file name.II.ARCHITECTUREA. NameNodeThe HDFS namespace is a hierarchy of files and directories. Files and directories are represented on the NameNode byinodes, which record attributes like permissions, modificationand access times, namespace and disk space quotas. The filecontent is split into large blocks (typically 128 megabytes, butuser selectable file-by-file) and each block of the file is independently replicated at multiple DataNodes (typically three, butuser selectable file-by-file). The NameNode maintains thenamespace tree and the mapping of file blocks to DataNodes978-1-4244-7153-9/10/ 26.00 2010 IEEE

(the physical location of file data). An HDFS client wanting toread a file first contacts the NameNode for the locations of datablocks comprising the file and then reads block contents fromthe DataNode closest to the client. When writing data, the client requests the NameNode to nominate a suite of threeDataNodes to host the block replicas. The client then writesdata to the DataNodes in a pipeline fashion. The current designhas a single NameNode for each cluster. The cluster can havethousands of DataNodes and tens of thousands of HDFS clientsper cluster, as each DataNode may execute multiple applicationtasks concurrently.DataNode when it registers with the NameNode for the firsttime and never changes after that.A DataNode identifies block replicas in its possession to theNameNode by sending a block report. A block report containsthe block id, the generation stamp and the length for each blockreplica the server hosts. The first block report is sent immediately after the DataNode registration. Subsequent block reportsare sent every hour and provide the NameNode with an up-todate view of where block replicas are located on the cluster.During normal operation DataNodes send heartbeats to theNameNode to confirm that the DataNode is operating and theblock replicas it hosts are available. The default heartbeat interval is three seconds. If the NameNode does not receive aheartbeat from a DataNode in ten minutes the NameNode considers the DataNode to be out of service and the block replicashosted by that DataNode to be unavailable. The NameNodethen schedules creation of new replicas of those blocks on otherDataNodes.HDFS keeps the entire namespace in RAM. The inode dataand the list of blocks belonging to each file comprise the metadata of the name system called the image. The persistent recordof the image stored in the local host’s native files system iscalled a checkpoint. The NameNode also stores the modification log of the image called the journal in the local host’s native file system. For improved durability, redundant copies ofthe checkpoint and journal can be made at other servers. During restarts the NameNode restores the namespace by readingthe namespace and replaying the journal. The locations ofblock replicas may change over time and are not part of thepersistent checkpoint.Heartbeats from a DataNode also carry information abouttotal storage capacity, fraction of storage in use, and the number of data transfers currently in progress. These statistics areused for the NameNode’s space allocation and load balancingdecisions.B. DataNodesEach block replica on a DataNode is represented by twofiles in the local host’s native file system. The first file containsthe data itself and the second file is block’s metadata includingchecksums for the block data and the block’s generation stamp.The size of the data file equals the actual length of the blockand does not require extra space to round it up to the nominalblock size as in traditional file systems. Thus, if a block is halffull it needs only half of the space of the full block on the localdrive.The NameNode does not directly call DataNodes. It usesreplies to heartbeats to send instructions to the DataNodes. Theinstructions include commands to: replicate blocks to other nodes;remove local block replicas;re-register or to shut down the node;send an immediate block report.These commands are important for maintaining the overallsystem integrity and therefore it is critical to keep heartbeatsfrequent even on big clusters. The NameNode can processthousands of heartbeats per second without affecting otherNameNode operations.During startup each DataNode connects to the NameNodeand performs a handshake. The purpose of the handshake is toverify the namespace ID and the software version of theDataNode. If either does not match that of the NameNode theDataNode automatically shuts down.C. HDFS ClientUser applications access the file system using the HDFSclient, a code library that exports the HDFS file system interface.The namespace ID is assigned to the file system instancewhen it is formatted. The namespace ID is persistently storedon all nodes of the cluster. Nodes with a different namespaceID will not be able to join the cluster, thus preserving the integrity of the file system.Similar to most conventional file systems, HDFS supportsoperations to read, write and delete files, and operations to create and delete directories. The user references files and directories by paths in the namespace. The user application generallydoes not need to know that file system metadata and storage areon different servers, or that blocks have multiple replicas.The consistency of software versions is important becauseincompatible version may cause data corruption or loss, and onlarge clusters of thousands of machines it is easy to overlooknodes that did not shut down properly prior to the softwareupgrade or were not available during the upgrade.When an application reads a file, the HDFS client first asksthe NameNode for the list of DataNodes that host replicas ofthe blocks of the file. It then contacts a DataNode directly andrequests the transfer of the desired block. When a client writes,it first asks the NameNode to choose DataNodes to host replicas of the first block of the file. The client organizes a pipelinefrom node-to-node and sends the data. When the first block isfilled, the client requests new DataNodes to be chosen to hostreplicas of the next block. A new pipeline is organized, and theA DataNode that is newly initialized and without anynamespace ID is permitted to join the cluster and receive thecluster’s namespace ID.After the handshake the DataNode registers with theNameNode. DataNodes persistently store their unique storageIDs. The storage ID is an internal identifier of the DataNode,which makes it recognizable even if it is restarted with a different IP address or port. The storage ID is assigned to the2

Figure 1. An HDFS client creates a new file by giving its path to the NameNode. For each block of the file, the NameNode returnsa list of DataNodes to host its replicas. The client then pipelines data to the chosen DataNodes, which eventually confirm thecreation of the block replicas to the NameNode.client sends the further bytes of the file. Each choice ofDataNodes is likely to be different. The interactions among theclient, the NameNode and the DataNodes are illustrated inFig. 1.be configured to store the checkpoint and journal in multiplestorage directories. Recommended practice is to place the directories on different volumes, and for one storage directory tobe on a remote NFS server. The first choice prevents loss fromsingle volume failures, and the second choice protects againstfailure of the entire node. If the NameNode encounters an errorwriting the journal to one of the storage directories it automatically excludes that directory from the list of storage directories.The NameNode automatically shuts itself down if no storagedirectory is available.Unlike conventional file systems, HDFS provides an APIthat exposes the locations of a file blocks. This allows applications like the MapReduce framework to schedule a task towhere the data are located, thus improving the read performance. It also allows an application to set the replication factorof a file. By default a file’s replication factor is three. For critical files or files which are accessed very often, having a higherreplication factor improves their tolerance against faults andincrease their read bandwidth.The NameNode is a multithreaded system and processesrequests simultaneously from multiple clients. Saving a transaction to disk becomes a bottleneck since all other threads needto wait until the synchronous flush-and-sync procedure initiated by one of them is complete. In order to optimize thisprocess the NameNode batches multiple transactions initiatedby different clients. When one of the NameNode’s threads initiates a flush-and-sync operation, all transactions batched atthat time are committed together. Remaining threads only needto check that their transactions have been saved and do notneed to initiate a flush-and-sync operation.D. Image and JournalThe namespace image is the file system metadata that describes the organization of application data as directories andfiles. A persistent record of the image written to disk is called acheckpoint. The journal is a write-ahead commit log forchanges to the file system that must be persistent. For eachclient-initiated transaction, the change is recorded in the journal, and the journal file is flushed and synched before thechange is committed to the HDFS client. The checkpoint file isnever changed by the NameNode; it is replaced in its entiretywhen a new checkpoint is created during restart, when requested by the administrator, or by the CheckpointNode described in the next section. During startup the NameNode initializes the namespace image from the checkpoint, and thenreplays changes from the journal until the image is up-to-datewith the last state of the file system. A new checkpoint andempty journal are written back to the storage directories beforethe NameNode starts serving clients.E. CheckpointNodeThe NameNode in HDFS, in addition to its primary roleserving client requests, can alternatively execute either of twoother roles, either a CheckpointNode or a BackupNode. Therole is specifi