BigData7:Hadoop之HDFS的租约锁机制和特点总结

租约锁

HDFS的有个内部机制:
不允许客户端的并行写。指的是同一时刻内,不允许多个客户端向一个HDFS上写数据。

所以要实现以上的机制,实现思路就是用互斥锁,但是如果底层要是用简单的互斥锁,可能有与网络问题,造成客户端不释放锁,而造成死锁。所以Hadoop为了避免这种情况产生,引入租约机制。

租约锁本质上就是一个带有租期的互斥锁。
Hadoop的思想来自于Google的论文,3.1
Hadoop 租约锁对应的类:org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease

A Lease governs all the locks held by a single client.
For each client there’s a corresponding lease, whose
timestamp is updated when the client periodically
checks in. If the client dies and allows its lease to
expire, all the corresponding locks can be released.

还有一个租约锁管理者:
org.apache.hadoop.hdfs.server.namenode.LeaseManager

LeaseManager does the lease housekeeping for writing on files.
This class also provides useful static methods for lease recovery.

Lease Recovery Algorithm 1) Namenode retrieves lease information 2)
For each file f in the lease, consider the last block b of f
2.1) Get the datanodes which contains b
2.2) Assign one of the datanodes as the primary datanode p

2.3) p obtains a new generation stamp from the namenode
2.4) p gets the block info from each datanode
2.5) p computes the minimum block length
2.6) p updates the datanodes, which have a valid generation stamp,
with the new generation stamp and the minimum block length
2.7) p acknowledges the namenode the update results

2.8) Namenode updates the BlockInfo
2.9) Namenode removes f from the lease
and removes the lease once all files have been removed
2.10) Namenode commit changes to edit log

HDFS特点总结

1、分布式存储架构,支持海量数据存储。(GB、TB、PB级别数据)
2、高容错性,数据块拥有多个副本(副本冗余机制)。副本丢失后,自动恢复。
3、低成本部署,Hadoop可构建在廉价的服务器上。
4、能够检测和快速应对硬件故障,通过RPC心跳机制来实现。
5、简化的一致性模型,这里指的是用户在使用HDFS时,所有关于文件相关的操作,比如文件切块、块的复制、块的存储等细节并不需要去关注,所有的工作都已被框架封装完毕。用户所需要的做的仅仅是将数据上传到HDFS。这大大简化了分布式文件存储操作的难度和管理的复杂度。
6、HDFS不能做到低延迟的数据访问(毫秒级内给出响应)。但是Hadoop的优势在于它的高吞吐率(吞吐率指的是:单位时间内产生的数据流)。可以说HDFS的设计是牺牲了低延迟的数据访问,而获取的是数据的高吞吐率。如果要想获取低延迟的数据访问,可以通过Hbase框架来实现。
7、HDFS不许修改数据,所以适用场景是:一次写入,多次读取(once-write-many-read)。
注意:HDFS允许追加数据,但不允许修改数据。追加和修改的意义是不同的。
8、HDFS不支持并发写入,一个文件同一个时间只能有一个写入者。
9、HDFS不适合存储海量小文件,因为会浪费namenode服务节点的内存空间

发布了39 篇原创文章 · 获赞 15 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/sinat_35667067/article/details/104262844