Hadoop官網翻譯之HDFS Architecture

xiaoliuyiting發表於2019-01-01

原文:http://www.cnblogs.com/simple-focus/p/6117384.html

HDFS Architecture

HDFS Architecture(HDFS 架構)

  • 簡介
  • 假設和目標
    •  硬體故障
    • 支援流式訪問
    • 大資料集
    • 簡單一致性模型
    • 移動計算比移動資料更划算
    • 輕便的跨異構的軟硬體平臺
  • NameNode and DataNodes
  • 檔案系統名稱空間
  • 資料副本
    • 副本選址:第一次小嚐試
    • 副本選擇
    • 安全模式
  • 檔案系統後設資料的持久化
  • 通訊協議
  • 魯棒性
    • 資料磁碟失效、心跳機制和重新複製
    • 叢集調整
    • 資料完整性
    • 後設資料磁碟失效
    • 快照
  • 資料結構
  • 可訪問性
    • FS命令列
    • 使用者管理命令列
    • 瀏覽器介面
  • 空間回收
  • 參考書
 

Introduction

The Hadoop Distributed File System (HDFS) is a distributed file system designed to run on commodity hardware. It has many similarities with existing distributed file systems. However, the differences from other distributed file systems are significant. HDFS is highly fault-tolerant and is designed to be deployed on low-cost hardware. HDFS provides high throughput access to application data and is suitable for applications that have large data sets. HDFS relaxes(放鬆) a few POSIX requirements to enable streaming access to file system data. HDFS was originally built as infrastructure for the Apache Nutch web search engine project. HDFS is part of the Apache Hadoop Core project. The project URL is http://hadoop.apache.org/.

Hadoop分散式檔案系統是一個設計可以執行在廉價硬體的分散式系統。它跟目前存在的分散式系統有很多相似之處。然而,不同之處才是重要的。HDFS是一個高容錯和可部署在廉價機器上的系統。HDFS提供高吞吐資料能力適合處理大量資料。HDFS鬆散了一些需求使得支援流式傳輸。HDFS原本是為Apache Butch的搜尋引擎設計的,現在是Apache Hadoop專案的子專案。

Assumptions (假設)and Goals

Hardware Failure

Hardware failure is the norm(規範) rather than the exception. An HDFS instance may consist of hundreds or thousands of server machines, each storing part of the file system’s data. The fact that there are a huge number of components and that each component has a non-trivial probability of failure means that some component of HDFS is always non-functional. Therefore, detection(檢測) of faults and quick, automatic recovery from them is a core architectural(架構) goal of HDFS.

硬體失效是常態而不是意外。HDFS例項可能包含上百成千個伺服器,每個節點儲存著檔案系統的部分資料。事實是叢集有大量的節點,而每個節點都存在一定的概率失效也就意味著HDFS的一些組成部分經常失效。因此,檢測錯誤、快速和自動恢復是HDFS的核心架構。

Streaming Data Access

Applications that run on HDFS need streaming access to their data sets. They are not general(普通的) purpose applications that typically run on general purpose file systems. HDFS is designed more for batch processing rather than interactive use by users. The emphasis(強調,重點) is on high throughput(吞吐量) of data access rather than low latency of data access. POSIX imposes many hard requirements that are not needed for applications that are targeted for HDFS. POSIX semantics in a few key areas has been traded to increase data throughput rates.

流式訪問

應用執行在HDFS需要允許流式訪問它的資料集。這不是普通的應用程式執行在普通的檔案系統上。HDFS是被設計用於批量處理而非使用者互動。設計的重點是高吞吐量訪問而不是低延遲資料訪問。POSIX語義在一些關鍵領域是用來提高吞吐量。

Large Data Sets

Applications that run on HDFS have large data sets. A typical file in HDFS is gigabytes to terabytes in size. Thus, HDFS is tuned to support large files. It should provide high aggregate data bandwidth and scale(擴充套件) to hundreds of nodes in a single cluster. It should support tens of millions of files in a single instance.

大資料集

執行在HDFS的應用程式有大資料集。一個典型文件在HDFS是GB到TB級別的。因此,HDFS是用來支援大檔案。它應該提供高頻寬和可擴充套件到上百節點在一個叢集中。它應該支援在一個例項中有以千萬計的檔案數。

Simple Coherency Model

HDFS applications need a write-once-read-many access model for files. A file once created, written, and closed need not be changed except for appends and truncates. Appending the content to the end of the files is supported but cannot be updated at arbitrary point. This assumption simplifies data coherency issues and enables high throughput data access. A MapReduce application or a web crawler application fits perfectly with this model.

簡單一致性模型

HDFS應用需要一個一次寫入多次讀取的檔案訪問模型。一個檔案一旦建立,寫入和關係都不需要改變。支援在檔案的末端進行追加資料而不支援在檔案的任意位置進行修改。這個假設簡化了資料一致性問題和支援高吞吐量的訪問。支援在資料尾部增加內容而不支援在任意位置更新。一個Map/Reduce任務或者web爬蟲完美匹配了這個模型。

“Moving Computation is Cheaper than Moving Data”

A computation requested by an application is much more efficient if it is executed near the data it operates on. This is especially true when the size of the data set is huge. This minimizes network congestion and increases the overall throughput of the system. The assumption is that it is often better to migrate the computation closer to where the data is located rather than moving the data to where the application is running. HDFS provides interfaces for applications to move themselves closer to where the data is located.

移動計算比移動資料更划算

如果應用的計算在它要操作的資料附近執行那就會更高效。尤其是資料集非常大的時候。這將最大限度地減少網路擁堵和提高系統的吞吐量。這個假設是在應用執行中經常移動計算到要操作的資料附近比移動資料資料更好HDFS提供介面讓應用去移動計算到資料所在的位置。

Portability Across Heterogeneous Hardware and Software Platforms

HDFS has been designed to be easily portable from one platform to another. This facilitates(促進) widespread(普遍的) adoption of HDFS as a platform of choice for a large set of applications.

輕便的跨異構的軟硬體平臺

HDFS被設計成可輕便從一個平臺跨到另一個平臺。這促使HDFS被廣泛地採用作為應用的大資料集系統。

NameNode and DataNodes

HDFS has a master/slave architecture. An HDFS cluster consists of a single NameNode, a master server that manages the file system namespace and regulates(控制) access to files by clients. In addition, there are a number of DataNodes, usually one per node in the cluster, which manage storage attached to the nodes that they run on. HDFS exposes a file system namespace and allows user data to be stored in files. Internally, a file is split into one or more blocks and these blocks are stored in a set of DataNodes. The NameNode executes file system namespace operations like opening, closing, and renaming files and directories. It also determines(決定) the mapping of blocks to DataNodes. The DataNodes are responsible for serving read and write requests from the file system’s clients. The DataNodes also perform block creation, deletion, and replication upon instruction from the NameNode.

HDFS使用主/從架構。一個HDFS叢集包含一個NameNode,一個伺服器管理系統的名稱空間和並控制客戶端對檔案的訪問。此外,有許多的DataNode,通常是叢集中的每個節點,用來管理它們所執行的節點的記憶體。HDFS暴露檔案系統的名稱空間和允許使用者資料儲存在檔案中。在系統內部,一個檔案被切割成一個或者多個塊而這些塊將儲存在一系列的DataNode中。NameNode執行檔案系統的名稱空間操作例如開啟、關閉和從命名檔案和路徑。它也指定資料塊對應的DataNode。DataNode負責提供客戶端對檔案的讀寫服務。DataNode也負責執行NameNode的建立、刪除和複製指令。

HDFS Architecture

The NameNode and DataNode are pieces of software designed to run on commodity machines. These machines typically run a GNU/Linux operating system (OS). HDFS is built using the Java language; any machine that supports Java can run the NameNode or the DataNode software. Usage of the highly portable(可移植) Java language means that HDFS can be deployed on a wide range of machines. A typical deployment(部署) has a dedicated(專用的) machine that runs only the NameNode software. Each of the other machines in the cluster runs one instance of the DataNode software. The architecture does not preclude running multiple DataNodes on the same machine but in a real deployment that is rarely the case.

NameNode和DatNode是設計執行在商業電腦的軟體框架。這些機器通常是執行著GNU/Linux作業系統。HDFS是用Java語言構建的;任何機器只要支援Java就可以執行NameNode或者DataNode。使用Java這種高可移植性的語言就意味著HDFS可以部署在大範圍的機器上。部署通常是在專用的機器上只執行NameNode軟體。叢集中的其他每個機器執行著單個DaaNode例項。架構並不排除在同一臺機器部署多個DataNode,但是這種情況比較少見。

The existence of a single NameNode in a cluster greatly simplifies the architecture of the system. The NameNode is the arbitrator and repository for all HDFS metadata. The system is designed in such a way that user data never flows through the NameNode.

叢集中只存在一個NameNode例項極大地簡化系統的架構。NameNode是HDFS後設資料的仲裁者和儲存庫。這個系統用這樣的方式保證了資料的流動不能避過NameNode。

The File System Namespace

HDFS supports a traditional hierarchical file organization. A user or an application can create directories and store files inside these directories. The file system namespace hierarchy is similar to most other existing file systems; one can create and remove files, move a file from one directory to another, or rename a file. HDFS supports user quotas and access permissions. HDFS does not support hard links or soft links. However, the HDFS architecture does not preclude implementing these features.

HDFS支援傳統的層級檔案結構。使用者或應用可以建立檔案目錄和儲存檔案在這些目錄下。檔案系統的名稱空間層級跟其他已經在存在的檔案系統很相像;可以建立和刪除檔案,將檔案從一個目錄移動到另一個目錄或者重新命名。HDFS支援使用者限制和訪問許可權。HDFS不支援硬關聯或者軟關聯。然而,HDFS架構不排除實現這些特性。

The NameNode maintains(維持) the file system namespace. Any change to the file system namespace or its properties is recorded by the NameNode. An application can specify(指定) the number of replicas(副本 of a file that should be maintained by HDFS. The number of copies of a file is called the replication factor of that file. This information is stored by the NameNode.

NameNode維持檔案系統的名稱空間。檔案系統的名稱空間或者它的屬性的任何改變都被NameNode記錄著。應用可以指定HDFS維持多少個檔案副本。檔案的拷貝數目稱為檔案的複製因子。這個資訊將會被NameNode記錄。

Data Replication

HDFS is designed to reliably(可靠地) store very large files across machines in a large cluster. It stores each file as a sequence of blocks. The blocks of a file are replicated(被複制) for fault tolerance(容錯性). The block size and replication factor are configurable per file.

 資料副本

HDFS是被設計成在一個叢集中跨機器可靠地儲存大量檔案。它將每個檔案儲存為一序列的塊。檔案的塊被複制保證容錯。每個檔案塊的大小和複製因子都是可配置的。

All blocks in a file except the last block are the same size, while users can start a new block without filling out the last block to the configured block size after the support for variable length block was added to append and hsync.

一個檔案的所有的塊除了最後一個都是同樣大小的,同時使用者在可以在一個支援可變長度的塊被同步新增之後啟動一個新的塊而沒有配置最後一個塊的大小。

An application can specify the number of replicas of a file. The replication factor can be specified at file creation time and can be changed later. Files in HDFS are write-once (except for appends and truncates) and have strictly one writer at any time.

應用可以指定檔案的副本數目。複製因子可以在檔案建立時指定,在後面時間修改。HDFS中的檔案一旦寫入(除了新增和截斷)就必須在任何時間嚴格遵守一個寫入者。

The NameNode makes all decisions regarding replication of blocks. It periodically receives a Heartbeat and a Blockreport from each of the DataNodes in the cluster. Receipt of a Heartbeat implies that the DataNode is functioning properly. A Blockreport contains a list of all blocks on a DataNode.

NameNode控制著關於blocks複製的所有決定。它週期性地接收叢集中DataNode傳送的心跳和塊報告。收到心跳意味著DataNode在正常地執行著。一個塊報告包含著DataNode上所有塊資訊的集合。

HDFS DataNodes

Replica Placement: The First Baby Steps

The placement(定位) of replicas is critical(關鍵的) to HDFS reliability(可信賴的) and performance(效能). Optimizing (優化)replica placement distinguishes HDFS from most other distributed file systems. This is a feature(特徵) that needs lots of tuning(除錯) and experience. The purpose of a rack-aware replica placement policy is to improve data reliability, availability, and network bandwidth utilization. The current implementation for the replica placement policy is a first effort in this direction. The short-term goals of implementing this policy are to validate it on production systems, learn more about its behavior, and build a foundation to test and research more sophisticated policies.

副本選址:第一次小嚐試

副本的選址對HDFS的可靠性和效能是起到關鍵作用的。優化的副本選址使得HDFS有別於大多數分散式檔案系統。這是一個需要大量除錯和經驗的特性。機架感知副本配置策略的目的是提高可靠性、可用性和網路頻寬的利用率。目前的副本放置策略實現是第一次在這個方向上的努力。這個策略實現的短期目標是在生產環境上驗證,更多地瞭解它的行為表現,建立一個基礎用來測試和研究更好的策略。

Large HDFS instances run on a cluster of computers that commonly spread across many racks. Communication between two nodes in different racks has to go through switches. In most cases, network bandwidth between machines in the same rack is greater than network bandwidth between machines in different racks.

執行在叢集計算機的大型HDFS例項一般是分佈在許多機架上。兩個不同機架上的節點的通訊必須經過交換機。在大多數情況下,同一個機架上的不同機器之間的網路頻寬要優於不同機架上的機器的。

The NameNode determines the rack id each DataNode belongs to via the process outlined in Hadoop Rack Awareness. A simple but non-optimal policy is to place replicas on unique racks. This prevents losing data when an entire rack fails and allows use of bandwidth from multiple racks when reading data. This policy evenly distributes replicas in the cluster which makes it easy to balance load on component failure. However, this policy increases the cost of writes because a write needs to transfer blocks to multiple racks.

NameNode通過在Hadoop Rack Awarenes概述過程來確定每個DataNode屬於哪個機架ID。一個簡單但不是最佳的策略上是將副本部署在不同的機架上。這將避免一個機架失效時丟失資料和允許使用頻寬來跨機架讀取資料。這個策略平衡地將副本分佈在叢集中以平衡元件失效負載。然而,這個策略增加了寫的負擔因為一個塊資料需要在多個機架之間傳輸。

For the common case, when the replication factor is three, HDFS’s placement policy is to put one replica on the local machine if the writer is on a datanode, otherwise on a random datanode, another replica on a node in a different (remote) rack, and the last on a different node in the same remote rack. This policy cuts the inter-rack write traffic which generally improves write performance. The chance of rack failure is far less than that of node failure; this policy does not impact data reliability and availability guarantees. However, it does reduce the aggregate network bandwidth used when reading data since a block is placed in only two unique racks rather than three. With this policy, the replicas of a file do not evenly distribute across the racks. One third of replicas are on one node, two thirds of replicas are on one rack, and the other third are evenly distributed across the remaining racks. This policy improves write performance without compromising data reliability or read performance.

通常情況下,當複製因子為3時,HDFS的副本放置策略是將一個副本放在本機架的一個節點上,將另一個副本放在本機架的另一個節點,最後一個副本放在不同機架的不同節點上。該策略減少機架內部的傳輸以提高寫的效能。機架失效的概率要遠低於節點失效;這個策略不會影響資料可靠性和可用性的保證。然而,它確實會減少資料讀取時網路頻寬的使用因為資料塊只放置在兩個單獨的機架而不是三個。在這個策略當中,副本的分佈不是均勻的。三分一個的副本放置在一個節點上,三分之二的副本放置在一個機架上,而另外三分之一均勻分佈在剩餘的機架上。這個策略提高了寫效能而不影響資料可靠性和讀效能。

The current, default replica placement policy described here is a work in progress.

目前,預設的副本放置策略描述的是正在進行的工作。

Replica Selection

To minimize global bandwidth consumption and read latency, HDFS tries to satisfy a read request from a replica that is closest to the reader. If there exists a replica on the same rack as the reader node, then that replica is preferred to satisfy the read request. If HDFS cluster spans multiple data centers, then a replica that is resident in the local data center is preferred over any remote replica.

副本選擇

為了最大限度地減少全域性頻寬消耗和讀取延遲,HDFS試圖讓讀取者的讀取需求離副本最近。如果存在一個副本在客戶端節點所在的同個機架上,那麼這個副本是滿足讀取需求的首選。如果HDFS叢集橫跨多個資料中心,那麼在本地資料中心的副本將是優先於其他遠端副本。

Safemode

On startup, the NameNode enters a special state called Safemode. Replication of data blocks does not occur when the NameNode is in the Safemode state. The NameNode receives Heartbeat and Blockreport messages from the DataNodes. A Blockreport contains the list of data blocks that a DataNode is hosting. Each block has a specified minimum number of replicas. A block is considered safely replicated when the minimum number of replicas of that data block has checked in with the NameNode. After a configurable percentage of safely replicated data blocks checks in with the NameNode (plus an additional 30 seconds), the NameNode exits the Safemode state. It then determines the list of data blocks (if any) that still have fewer than the specified number of replicas. The NameNode then replicates these blocks to other DataNodes.

安全模式

在啟動時,NameNode進入一個特殊的狀態稱之為安全模式。當NameNode進入安全模式之後資料塊的複製將不會發生。NameNode接收來自DataNode的心跳和資料塊報告。資料塊報告包含正在執行的DataNode上的資料塊資訊集合。每個快都指定了最小副本數。一個資料塊如果被NameNode檢查確保它滿足最小副本數,那麼它被認為是安全的。在NameNode檢查配置的一定比例的資料塊安全性檢查(加上30s),NameNode將會退出安全模式。然後它將確認有一組(如果可能)還沒有達到指定數目副本的資料塊。NameNode將這些資料塊複製到其他DataNode。

The Persistence of File System Metadata

The HDFS namespace is stored by the NameNode. The NameNode uses a transaction log called the EditLog to persistently record every change that occurs to file system metadata. For example, creating a new file in HDFS causes the NameNode to insert a record into the EditLog indicating this. Similarly, changing the replication factor of a file causes a new record to be inserted into the EditLog. The NameNode uses a file in its local host OS file system to store the EditLog. The entire file system namespace, including the mapping of blocks to files and file system properties, is stored in a file called the FsImage. The FsImage is stored as a file in the NameNode’s local file system too.

檔案系統後設資料的永續性

NameNode儲存著HDFS的名稱空間。NmaeNode使用一個稱之為EditLog的事務日誌持續地記錄發生在檔案系統後設資料的每一個改變。例如,HDFS中建立一個檔案會導致NameNode在EditLog中插入一條記錄來表示。相同的,改變一個檔案的複製因子也會導致EditLog中新增一條新的記錄。NameNode在它本地的系統中用一個檔案來儲存EditLog。整個檔案系統名稱空間,包括blocks的對映關係和檔案系統屬性,將儲存在一個叫FsImage的檔案。FsImage也是儲存在NameNode所在的本地檔案系統中。

The NameNode keeps an image of the entire file system namespace and file Blockmap in memory. When the NameNode starts up, or a checkpoint is triggered by a configurable threshold, it reads the FsImage and EditLog from disk, applies all the transactions from the EditLog to the in-memory representation of the FsImage, and flushes out this new version into a new FsImage on disk. It can then truncate the old EditLog because its transactions have been applied to the persistent FsImage. This process is called a checkpoint. The purpose of a checkpoint is to make sure that HDFS has a consistent view of the file system metadata by taking a snapshot of the file system metadata and saving it to FsImage. Even though it is efficient to read a FsImage, it is not efficient to make incremental edits directly to a FsImage. Instead of modifying FsImage for each edit, we persist the edits in the Editlog. During the checkpoint the changes from Editlog are applied to the FsImage. A checkpoint can be triggered at a given time interval (dfs.namenode.checkpoint.period) expressed in seconds, or after a given number of filesystem transactions have accumulated (dfs.namenode.checkpoint.txns). If both of these properties are set, the first threshold to be reached triggers a checkpoint.

NameNode在記憶體中儲存著整個檔案系統名稱空間的影像和檔案對映關係。這個關鍵後設資料項設計緊湊,以致一個有著4GB RAM的NameNode足夠支援大量的檔案和目錄。當NameNode啟動時,它將從磁碟中讀取FsImage和EditLog,將EditLog中所有彙報更新到記憶體中的FsImage中,重新整理輸出一個新版本的FsImage到磁碟中。然後縮短EditLog因為它的事務彙報已經更新到持久化的FsImage中。這個過程稱之為檢查站。在目前這個版本中,只有當NameNode啟動時會執行一次。在不久的將來會在任務執行過程也執行CheckPoint。

The DataNode stores HDFS data in files in its local file system. The DataNode has no knowledge about HDFS files. It stores each block of HDFS data in a separate file in its local file system. The DataNode does not create all files in the same directory. Instead, it uses a heuristic to determine the optimal number of files per directory and creates subdirectories appropriately. It is not optimal to create all local files in the same directory because the local file system might not be able to efficiently support a huge number of files in a single directory. When a DataNode starts up, it scans through its local file system, generates a list of all HDFS data blocks that correspond to each of these local files, and sends this report to the NameNode. The report is called the Blockreport.

DataNode將HDFS資料儲存在他本地的檔案系統中。DataNode對於HDFS檔案一無所知。它將每一塊HDFS資料儲存為單獨的檔案在它的本地檔案系統中。DataNode不會再相同的目錄之下建立所有檔案。相反,使用一個啟發式的方法來確定每個目錄的最優檔案數目和恰當地建立子目錄。在同一個目錄下建立所有本地檔案並不是最優的因為本地文化系統或許不是高效地支援在一個目錄下有大量檔案。當一個DataNode啟動時,它將掃描本地檔案系統,生成一個對應本地檔案的所有HDFS資料塊列表和將它傳送給NameNode,這就是Blockreport。

The Communication Protocols

All HDFS communication protocols are layered on top of the TCP/IP protocol. A client establishes a connection to a configurable TCP port on the NameNode machine. It talks the ClientProtocol with the NameNode. The DataNodes talk to the NameNode using the DataNode Protocol. A Remote Procedure Call (RPC) abstraction wraps both the Client Protocol and the DataNode Protocol. By design, the NameNode never initiates any RPCs. Instead, it only responds to RPC requests issued by DataNodes or clients.

通訊協議

所有的HDFS通訊協議的底層都是TCP/IP協議。客戶端通過NameNode機器上TCP埠與之建立連線。它使用客戶端協議與NameNode通訊。DataNode使用DataNode協議與NameNode通訊。RPC抽象封裝了客戶端協議和DataNode協議。有意地,NameNode從不會主動發起任何RPC,相反,它只回復DatsNodes和客戶端發來的RPC請求。

Robustness

The primary objective of HDFS is to store data reliably even in the presence of failures. The three common types of failures are NameNode failures, DataNode failures and network partitions.

魯棒性

HDFS的主要目標是在失效出現時保證儲存的資料的可靠性。通常有這三種失效,分別為NameNode失效,DataNode失效和網路分裂(一種在系統的任何兩個組之間的所有網路連線同時發生故障後所出現的情況)

Data Disk Failure, Heartbeats and Re-Replication

Each DataNode sends a Heartbeat message to the NameNode periodically. A network partition can cause a subset of DataNodes to lose connectivity with the NameNode. The NameNode detects this condition by the absence of a Heartbeat message. The NameNode marks DataNodes without recent Heartbeats as dead and does not forward any new IO requests to them. Any data that was registered to a dead DataNode is not available to HDFS any more. DataNode death may cause the replication factor of some blocks to fall below their specified value. The NameNode constantly tracks which blocks need to be replicated and initiates replication whenever necessary. The necessity for re-replication may arise due to many reasons: a DataNode may become unavailable, a replica may become corrupted, a hard disk on a DataNode may fail, or the replication factor of a file may be increased.

資料磁碟失效,心跳機制和重新複製

每個節點週期性地傳送心跳資訊給NameNode。網路分裂會導致一部分DataNode失去與NameNode的連線。NameNode通過心跳資訊的丟失發現這個情況。NameNode將最近沒有心跳資訊的DataNode標記為死亡並且不再轉發任何IO請求給他們。在已經死亡的DataNode註冊的任何資料在HDFS將不能再使用。DataNode死亡會導致部分資料塊的複製因子小於指定的數目。NameNode時常地跟蹤資料塊是否需要被複制和當必要的時候啟動複製。重新複製的必要性會因為許多原因而提升:DataNode不可用,一個副本被破壞,DataNode的磁碟失效或者一個檔案的複製因子增加了。

The time-out to mark DataNodes dead is conservatively long (over 10 minutes by default) in order to avoid replication storm caused by state flapping of DataNodes. Users can set shorter interval to mark DataNodes as stale and avoid stale nodes on reading and/or writing by configuration for performance sensitive workloads.

將DatNode標記為死亡的超時時間適當地加長(預設超過10分鐘)是為了避免DataNode狀態改變引起的複製風暴。使用者可以設定更短的時間間隔來標記DataNode為失效和避免失效的節點在讀和/或寫配置效能敏感的工作負載

Cluster Rebalancing

The HDFS architecture is compatible with data rebalancing schemes. A scheme might automatically move data from one DataNode to another if the free space on a DataNode falls below a certain threshold. In the event of a sudden high demand for a particular file, a scheme might dynamically create additional replicas and rebalance other data in the cluster. These types of data rebalancing schemes are not yet implemented.

叢集調整

HDFS架構相容資料調整方案。一個方案可能自動地將資料從一個DataNode移動到另一個距離上限值還有多餘空間的DataNode。對一個特別的檔案突然發生的需求,一個方案可以動態地建立額外的副本和重新調整叢集中的資料。這些型別的調整方案目前還沒有實現。

Data Integrity

It is possible that a block of data fetched from a DataNode arrives corrupted. This corruption can occur because of faults in a storage device, network faults, or buggy software. The HDFS client software implements checksum checking on the contents of HDFS files. When a client creates an HDFS file, it computes a checksum of each block of the file and stores these checksums in a separate hidden file in the same HDFS namespace. When a client retrieves file contents it verifies that the data it received from each DataNode matches the checksum stored in the associated checksum file. If not, then the client can opt to retrieve that block from another DataNode that has a replica of that block.

資料完整性

從一個失效的DataNode取得資料塊是可行的。這種失效會發生是因為儲存裝置故障、網路故障或者軟體bug。HDFS客戶端軟體實現了校驗和用來校驗HDFS檔案的內容。當客戶端建立一個HDFS檔案,他會計算檔案的每一個資料塊的校驗和並且將這些校驗和儲存在HDFS名稱空間中一個單獨的隱藏的檔案當中。當客戶端從DataNode獲得資料時會對對其進行校驗和,並且將之與儲存在相關校驗和檔案中的校驗和進行匹配。如果沒有,客戶端會選擇從另一個擁有該資料塊副本的DataNode上恢復資料。

Metadata Disk Failure

The FsImage and the EditLog are central data structures of HDFS. A corruption of these files can cause the HDFS instance to be non-functional. For this reason, the NameNode can be configured to support maintaining multiple copies of the FsImage and EditLog. Any update to either the FsImage or EditLog causes each of the FsImages and EditLogs to get updated synchronously. This synchronous updating of multiple copies of the FsImage and EditLog may degrade the rate of namespace transactions per second that a NameNode can support. However, this degradation is acceptable because even though HDFS applications are very data intensive in nature, they are not metadata intensive. When a NameNode restarts, it selects the latest consistent FsImage and EditLog to use.

後設資料的磁碟故障

FsImage和EditLog是HDFS架構的中心資料。這些資料的失效會引起HDFS例項失效。因為這個原因,NameNode可以配置用來維持FsImage和EditLog的多個副本。FsImage或EditLog的任何改變會引起每一份FsImage和EditLog同步更新。同步更新多份FsImge和EditLog降低NameNode能支援的每秒更新名稱空間事務的頻率。然而,頻率的降低是可以接受盡管HDFS應用本質上是對資料敏感,而不是對後設資料敏感。當一個NameNode重新啟動,他會選擇最新的FsImage和EditLog來使用。

Another option to increase resilience against failures is to enable High Availability using multiple NameNodes either with a shared storage on NFS or using a distributed edit log (called Journal). The latter is the recommended approach.

Snapshots

Snapshots support storing a copy of data at a particular instant of time. One usage of the snapshot feature may be to roll back a corrupted HDFS instance to a previously known good point in time.

快照

快照支援儲存一個特點時間的的資料副本。一個使用可能快照功能的情況是一個失效的HDFS例項想要回滾到之前一個已知是正確的時間。

Data Organization

Data Blocks

HDFS is designed to support very large files. Applications that are compatible with HDFS are those that deal with large data sets. These applications write their data only once but they read it one or more times and require these reads to be satisfied at streaming speeds. HDFS supports write-once-read-many semantics on files. A typical block size used by HDFS is 128 MB. Thus, an HDFS file is chopped up into 128 MB chunks, and if possible, each chunk will reside on a different DataNode.

資料組織

資料塊 

HDFS是被設計來支援大量檔案的。一個應用相容HDFS是那些處理大資料集的應用。這些應用都是一次寫入資料但可一次或多次讀取和需要這些讀取滿足一定的流式速度。HDFS支援一次寫入多次讀取檔案語義。HDFS中通常的資料塊大小為128M。因此,一個HDFS檔案會被切割成128M大小的塊,如果可以的話,每一個大塊都會分屬於一個不同的DatNode.

Replication Pipelining

When a client is writing data to an HDFS file with a replication factor of three, the NameNode retrieves a list of DataNodes using a replication target choosing algorithm. This list contains the DataNodes that will host a replica of that block. The client then writes to the first DataNode. The first DataNode starts receiving the data in portions, writes each portion to its local repository and transfers that portion to the second DataNode in the list. The second DataNode, in turn starts receiving each portion of the data block, writes that portion to its repository and then flushes that portion to the third DataNode. Finally, the third DataNode writes the data to its local repository. Thus, a DataNode can be receiving data from the previous one in the pipeline and at the same time forwarding data to the next one in the pipeline. Thus, the data is pipelined from one DataNode to the next.

複製管道/複製流水線

當一個客戶端寫入一個HDFS檔案,它的資料首先是寫到它的本地快取當中(這在前面一節已經解釋了)。假設HDFS檔案的複製因子為3。當客戶端累積了大量的使用者資料,客戶端將會從NameNode取得DataNode列表。這個列表包含著該塊的副本宿主DataNode。然偶客戶端會將資料重新整理到第一個DataNode。第一個DataNode接收一小部分資料,將每一小塊資料寫到本地倉庫然後將這小塊資料傳到列表的第二個DataNode。第二個DataNode開始接收每一小塊資料並寫到本地資料倉儲然後將資料傳輸到第三個DataNode,最後,第三個DataNode將資料寫到本地倉庫。因此,一個Dataode能夠在管道中接收到從上一個節點接收到資料並且在同一時間將資料轉發給下一個節點。因此,資料在管道中從一個DataNode傳輸到下一個。

Accessibility

HDFS can be accessed from applications in many different ways. Natively, HDFS provides a FileSystem Java API for applications to use. A C language wrapper for this Java API and REST API is also available. In addition, an HTTP browser and can also be used to browse the files of an HDFS instance. By using NFS gateway, HDFS can be mounted as part of the client’s local file system.

可訪問性

應用可以通過很多方式訪問HDFS。HDFS本身提供FileSystem Java API 給應用使用。C語言封裝JAVA API和REST API也是可以使用。此外,HTTP瀏覽器也可以用來瀏覽HDFS例項的檔案。通過使用NFS閘道器,HDFS能被安裝作為本地檔案系統的一部分。

FS Shell

HDFS allows user data to be organized in the form of files and directories. It provides a commandline interface called FS shell that lets a user interact with the data in HDFS. The syntax of this command set is similar to other shells (e.g. bash, csh) that users are already familiar with. Here are some sample action/command pairs:

HDFS允許使用者資料已檔案盒目錄的形式來組織。他提供稱為FS shell的命令列介面讓使用者與HDFSJ互動資料。這命令列的語法跟其他使用者已經熟悉的shell相似。這裡是一些命令操作的例子

Action Command
Create a directory named /foodir bin/hadoop dfs -mkdir /foodir
Remove a directory named /foodir bin/hadoop fs -rm -R /foodir
View the contents of a file named /foodir/myfile.txt bin/hadoop dfs -cat /foodir/myfile.txt

FS shell is targeted for applications that need a scripting language to interact with the stored data.

FS shell的目標是讓一些使用指令碼的應用能與HDFS進行資料互動。

DFSAdmin

The DFSAdmin command set is used for administering an HDFS cluster. These are commands that are used only by an HDFS administrator. Here are some sample action/command pairs:

DFSAdmin命令集是用來管理HDFS叢集。這些命令只能被HDFS管理員使用,下面是一些例子:

Action Command
Put the cluster in Safemode bin/hdfs dfsadmin -safemode enter
Generate a list of DataNodes bin/hdfs dfsadmin -report
Recommission or decommission DataNode(s) bin/hdfs dfsadmin -refreshNodes

Browser Interface

A typical HDFS install configures a web server to expose the HDFS namespace through a configurable TCP port. This allows a user to navigate the HDFS namespace and view the contents of its files using a web browser.

一個通常的HDFS安裝會配置一個web服務通過一個配置好的TCP埠來暴露HDFS名稱空間。它允許使用者看到HDFS名稱空間的導航和使用web瀏覽器來檢視他的檔案內容。

Space Reclamation

File Deletes and Undeletes

If trash configuration is enabled, files removed by FS Shell is not immediately removed from HDFS. Instead, HDFS moves it to a trash directory (each user has its own trash directory under /user/<username>/.Trash). The file can be restored quickly as long as it remains in trash.

Most recent deleted files are moved to the current trash directory (/user/<username>/.Trash/Current), and in a configurable interval, HDFS creates checkpoints (under /user/<username>/.Trash/<date>) for files in current trash directory and deletes old checkpoints when they are expired. See expunge command of FS shell about checkpointing of trash.

After the expiry of its life in trash, the NameNode deletes the file from the HDFS namespace. The deletion of a file causes the blocks associated with the file to be freed. Note that there could be an appreciable time delay between the time a file is deleted by a user and the time of the corresponding increase in free space in HDFS.

空間回收

檔案的刪除和恢復

如果垃圾相關配置是可用的,通過FS shell移除的檔案將不會直接從HDFS移除。相反的,HDFS將它移動到一個回收目錄(每個使用者在/usr/<username>/.Trash下都擁有它自己的回收站目錄)。一個檔案只要還在回收站那麼就能夠快速恢復。

大部分最近刪除的檔案都將移動到當前的回收站目錄(/user/<username>/.Trash/Current),並且在設定好的時間間隔內,HDFS建立對 /user/<username>/.Trash/<date>目錄下的檔案建立一個檢查點並且當老的檢查點過期的時候刪除他們。檢視expunge command of FS shell 瞭解回收站的檢查點。

當檔案在回收站期滿之後,NameNode將會將檔案從HDFS的名稱空間中刪除。檔案的刪除將導致與該檔案關聯的block被釋放。需要說明的是檔案被使用者刪除的時間和對應的釋放空間的時間之間有一個明顯的時間延遲。

 

Following is an example which will show how the files are deleted from HDFS by FS Shell. We created 2 files (test1 & test2) under the directory delete

接下來是我們展示如何通過FS shel刪除檔案的例子。我們在要刪除的目錄中建立test1和test2兩個檔案

$ hadoop fs -mkdir -p delete/test1
$ hadoop fs -mkdir -p delete/test2
$ hadoop fs -ls delete/
Found 2 items
drwxr-xr-x   - hadoop hadoop          0 2015-05-08 12:39 delete/test1
drwxr-xr-x   - hadoop hadoop          0 2015-05-08 12:40 delete/test2

We are going to remove the file test1. The comment below shows that the file has been moved to Trash directory.

我們來刪除檔案test1.下面的註釋顯示文件被移除到回收站目錄。

$ hadoop fs -rm -r delete/test1
Moved: hdfs://localhost:8020/user/hadoop/delete/test1 to trash at: hdfs://localhost:8020/user/hadoop/.Trash/Current

now we are going to remove the file with skipTrash option, which will not send the file to Trash.It will be completely removed from HDFS.

現在我來執行將檔案刪除跳過回收站選項,檔案則不會轉移到回收站。檔案將完全從HDFS中移除。

$ hadoop fs -rm -r -skipTrash delete/test2
Deleted delete/test2

We can see now that the Trash directory contains only file test1.

我們現在可以看到回收站目錄下只有test1

$ hadoop fs -ls .Trash/Current/user/hadoop/delete/
Found 1 items\
drwxr-xr-x   - hadoop hadoop          0 2015-05-08 12:39 .Trash/Current/user/hadoop/delete/test1

So file test1 goes to Trash and file test2 is deleted permanently.

所以test1去了回收站而test2被永久地刪除了。

Decrease Replication Factor

When the replication factor of a file is reduced, the NameNode selects excess replicas that can be deleted. The next Heartbeat transfers this information to the DataNode. The DataNode then removes the corresponding blocks and the corresponding free space appears in the cluster. Once again, there might be a time delay between the completion of the setReplication API call and the appearance of free space in the cluster.

減少副本因子

當檔案的副本因子減小時,NameNode將在可以刪除的副本中選中多餘的副本。在下一個心跳通訊中將該資訊傳輸給DataNode。然後DataNode移除對應的資料塊並且釋放對應的空間。再重申一遍,在設定副本因子完成和叢集中出現新的空間之間有個時間延遲。

References

Hadoop JavaDoc API.

HDFS source code: http://hadoop.apache.org/version_control.html

相關文章