HDFS概述
1)分布式
2)commodity hardware 硬件
3)fault-tolerant 容错
4)large data sets
分布式文件系统 vs 普通文件系统(单机)
分布式文件系统
能够横跨N个机器
HDFS前提和设计目标(整点掌握四点##)
一.Hardware Failure 硬件错误
##each storing part of the file system’s data.
每个机器只存储文件的部分数据,blocksize=128M
block存放在不同的机器上的,由于容错,HDFS默认采用3副本机制
二.Streaming Data Access 流式数据访问
##The emphasis is on high throughput of data access rather than low latency of data access.
重点是数据访问的高吞吐量,而不是数据访问的低延迟。
三.Large Data Sets 大规模数据集
可存储大文件,(小文件问题后续深入讨论)
四.“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为应用程序提供接口,使它们更接近数据所在的位置。
HDFS架构##
1.NameNode(master) and DataNodes(slave)
2.master/slave架构
3.NN:the file system namespace(文件层级)(1.管理文件系统)
example:/home/hadoop/software
regulates access to files by clients(2.提供客户端对于文件的访问)
4.DN:storage(负责存储)
5.HDFS exposes a file system namespace and allows user data to be stored in files.
HDFS公开文件系统名称空间,并允许将用户数据存储在文件中。
6.a file is split into one or more blocks and these blocks are stored in a set of DataNodes
一个文件被分成一个或多个块,这些块存储在一组DataNodes中(提高容错)
7.NameNode executes file system namespace operations:like opening, closing, and renaming files and directories.
8.determines the mapping of blocks to DataNodes(决定DataNodes和块的映射关系)
比如又一个文件 aa.txt=150M blocksize=128M
aa.txt会拆分成两个block 一个是bl1:128M 一个是bl2:22M
则bl1存放在哪个DN?bl2存放在哪个DN?
client往HDFS上传数据,NameNode会把文件拆开并记录块是哪个文件的
如
aa.txt =150M拆分成:
bl1:128M 存放在192.168.218.1
bl2: 22M 存放在192.168.218.2
当用户取文件的时候(取文件也是通过NN,因为元数据(即是文件拆分后存放的关系)信息是在NN上) get aa.txt :当取文件的时候,就去NN上面找,aa.txt这个文件被拆分成了两个块,则去192.168.218.1上面取到bl1,再到192.168.218.2上面取到bl2,然后合并提取给用户(可以把HDFS想象成一个拆文件和组合文件的一个过程,这个过程对于用户来说是不感知的)
9.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.
datanode负责处理来自文件系统客户机的读和写请求。datanode还根据来自NameNode的指令执行块创建、删除和复制。
10.通常情况下:1个node部署一个组件
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.
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.
HDFS支持传统的分层文件组织。用户或应用程序可以在这些目录中创建目录并存储文件。文件系统名称空间层次结构与大多数现有文件系统相似;可以创建和删除文件,将文件从一个目录移动到另一个目录,或者重命名文件。HDFS支持用户配额和访问权限。HDFS不支持硬链接或软链接。然而,HDFS体系结构并不排除实现这些特性。
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.
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.
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.
HDFS的设计目的是在大型集群中跨机器可靠地存储非常大的文件。它将每个文件存储为块序列。复制文件的块是为了容错。每个文件都可以配置块大小和复制因子。
除了最后一个块之外,文件中的所有块大小都相同,而用户可以在append和hsync中添加了对可变长度块的支持之后,启动一个新块,而不需要将最后一个块填充到所配置的块大小。
应用程序可以指定文件的副本数量。复制因子可以在文件创建时指定,稍后可以更改。HDFS中的文件是写一次的(除了追加和截断),并且任何时候只有一个写器。
NameNode做出关于复制块的所有决策。它定期从集群中的每个数据节点接收心跳和块报告。接收到心跳意味着DataNode正常工作。块报告包含DataNode上的所有块的列表。
假设现在8个节点,假设4和8节点挂掉了即ID2,4,5没有了,但是2,4,5在其他机器上都有副本备份,大大提高了容错性