alluxio源码解析-层次化存储(4)

层次化存储-特性介绍:

https://www.alluxio.org/docs/1.6/cn/Tiered-Storage-on-Alluxio.html

引入分层存储后,Alluxio管理的数据块不只在内存中,可存放于任何可用的存储层。Alluxio使用分配策略和回收策略管理块的存放和移动。Alluxio根据I/O性能的高低从上到下配置存储层。因此,这种配置策略决定了最顶层存储是MEM,然后是SSD,最后是HDD。

可以配置多个存储目录,不同的存储介质

一个存储层至少有一个存储目录。目录是Alluxio数据块存放的文件路径。Alluxio支持单个存储层包含多个目录的配置,允许一个存储层有多个挂载点或存储设备。举例而言,如果Alluxio worker上有5个SSD设备,可以配置Alluxio在SSD层同时使用这5个SSD设备。详细配置请参考下面。分配策略决定数据块文件存放的目录。

写数据

用户写入新数据块时默认写在顶层存储。如果顶层没有足够的空间存放数据块,回收策略会被触发并释放空间给新数据块。如果顶层没有足够的可释放空间,那么写操作会失败。如果文件大小超出了顶层空间,写操作也会失败。
用户还可以通过配置项设置指定写数据默认的层级。
从ReadType.CACHE或ReadType.CACHE_PROMOTE读数据会导致数据被写到Alluxio中。这种情况下,数据被默认写到顶层。
最后,通过load命令可将数据写到Alluxio中。这种情况,数据也会被写到顶层。

读数据

读取分层存储的数据块和标准Alluxio类似。如果数据已经在Alluxio中,Alluxio从存储位置读取数据块。如果Alluxio配置了多层存储,数据块不一定是从顶层读取,因为可能被透明地移到下层存储中。
读取策略为ReadType.CACHE_PROMOTE时,Alluxio会确保数据在读取前先被移动到顶层存储中。通过显式的将热数据移到最高层,该策略也可以用于数据块的管理。

固定文件

 

用户可以通过固定(pin)和取消固定(unpin)来固定和移动该文件。文件被固定时,数据块不会从Alluxio的存储空间中移出。同时用户可以将固定文件的数据块移到顶层存储。
 

分配策略

Alluxio使用分配策略选择新数据块的写入位置。Alluxio定义了分配策略的框架,也内置了几种分配策略。以下是Alluxio已实现的分配策略:
  • 贪心分配策略
    分配新数据块到首个有足够空间的存储目录。
  • 最大剩余空间分配策略
    分配数据块到有最大剩余空间的存储目录。
  • 轮询调度分配策略
    分配数据块到有空间的最高存储层,存储目录通过轮询调度选出。
将来会有更多的分配策略可供选择。由于Alluxio支持自定义分配策略。你可以为自己的应用开发合适的分配策略。

回收策略

Alluxio使用回收策略决定当空间需要释放时,哪些数据块被移到低存储层。Alluxio支持自定义回收策略,已有的实现包括:
  • 贪心回收策略
    移出任意的块直到释放出所需大小的空间。
  • LRU回收策略
    移出最近最少使用的数据块直到释放出所需大小的空间。
  • LRFU回收策略
    基于权重分配的最近最少使用和最不经常使用策略移出数据块。如果权重完全偏向最近最少使用,LRFU回收策略退化为LRU回收策略。
  • 部分LRU回收策略
    基于最近最少使用移出,但是选择有最大剩余空间的存储目录(StorageDir),只从该目录移出数据块。
将来会有更多的回收策略可供选择。由于Alluxio支持自定义回收策略。你也可以为自己的应用开发合适的回收策略。
使用同步移出时,推荐使用较小的块大小配置(64MB左右),以降低块移出的延迟。使用空间预留器时,块大小不会影响移出延迟。
 
 

层次化存储-架构位置

层次化存储是作为分布式缓存的最为核心的特性,加速读取/写入

层次化存储也是worker组件最重要的功能,同时支持横向扩展

 

层次化存储-代码解析

接上文https://www.cnblogs.com/victor2302/p/10491974.html,我们讲到了BlockWorker接口

该接口的实现实现类:DefaultBlockWorker

DefaultBlockWorker

主要负责几种功能:

  • PinListSync,定时获取pinned列表
  • BlockMasterSync周期性的工作,例如:与master的心跳交互
  • 报告计量相关指标至master
  • 所有块相关存储操作的逻辑
成员变量如下:
/** Runnable responsible for heartbeating and registration with master. */
和master节点的心跳任务
private BlockMasterSync mBlockMasterSync;

/** Runnable responsible for fetching pinlist from master. */
获取master pin列表的任务
private PinListSync mPinListSync;

/** Runnable responsible for clean up potential zombie sessions. */
private SessionCleaner mSessionCleaner;

/** Client for all block master communication. */
与block master通讯
private final BlockMasterClient mBlockMasterClient;
/**
 * Block master clients. commitBlock is the only reason to keep a pool of block master clients
 * on each worker. We should either improve our RPC model in the master or get rid of the
 * necessity to call commitBlock in the workers.
 */
private final BlockMasterClientPool mBlockMasterClientPool;

/** Client for all file system master communication. */
与file system交互的客户端
private final FileSystemMasterClient mFileSystemMasterClient;

/** Block store delta reporter for master heartbeat. */
报告者
private BlockHeartbeatReporter mHeartbeatReporter;
/** Metrics reporter that listens on block events and increases metrics counters. */
报告者
private BlockMetricsReporter mMetricsReporter;
/** Session metadata, used to keep track of session heartbeats. */
private Sessions mSessions;
/** Block Store manager. */
mBlockStore是TieredBlockStore,为多级存储block存储管理器
private BlockStore mBlockStore;
private WorkerNetAddress mAddress;

/** The under file system block store. */
ufs管理器
private final UnderFileSystemBlockStore mUnderFileSystemBlockStore;

/**
 * The worker ID for this worker. This is initialized in {@link #start(WorkerNetAddress)} and may
 * be updated by the block sync thread if the master requests re-registration.
 */
private AtomicReference<Long> mWorkerId;

 

涉及到交互的方法 代码 注释  
commitBlock blockMasterClient.commitBlock 提交bolock  
start mBlockMasterClient.getId(address) 获取workerId  
       
心跳类方法  代码  注释  
PinListSync
Set<Long> pinList = mMasterClient.getPinList();
mBlockWorker.updatePinList(pinList);
更新本地的pin列表  
SessionCleaner
for (long session : mSessions.getTimedOutSessions()) {
  mSessions.removeSession(session);
  for (SessionCleanable sc : mSessionCleanables) {
    sc.cleanupSession(session);
  }
}
清除session  
SpaceReserver 太多 各存储层空间检查  
BlockMasterSync
cmdFromMaster = mMasterClient.heartbeat(mWorkerId.get(), storeMeta.getUsedBytesOnTiers(),
    blockReport.getRemovedBlocks(), blockReport.getAddedBlocks(), metrics);
handleMasterCommand(cmdFromMaster);
向blockmaster发送心跳,并处理返回的消息  

 

TieredBlockStore

该类负责分层存储逻辑,与不同介质的缓存存储模块进行交互

维护读写锁,保证block操作的线程安全

该类拥有前文提到过得申请和驱逐策略以及 pinned列表

备注:申请和驱逐策略,就是关于不同介质的缓存存储模块如何进行分配以及管理的策略

//申请策略接口
private final Allocator mAllocator;
//驱逐策略接口
private final Evictor mEvictor;

private final Set<Long> mPinnedInodes = new HashSet<>();

 

posted @ 2019-03-11 21:17  聚变归来  阅读(933)  评论(0编辑  收藏  举报