alluxio源码解析-层次化存储(4)
层次化存储-特性介绍:
引⼊分层存储后,Alluxio管理的数据块不只在内存中,可存放于任何可⽤的存储层。Alluxio使⽤分配策略和回收策略管理块的存放和移动。Alluxio根据I/O性能的⾼低从上到下配置存储层。因此,这种配置策略决定了最顶层存储是MEM,然后是SSD,最后是HDD。
可以配置多个存储⽬录,不同的存储介质
⼀个存储层⾄少有⼀个存储⽬录。⽬录是Alluxio数据块存放的⽂件路径。Alluxio⽀持单个存储层包含多个⽬录的配置,允许⼀个存储层有多个挂载点或存储设备。举例⽽⾔,如果Alluxio worker上有5个SSD设备,可以配置Alluxio在SSD层同时使⽤这5个SSD设备。详细配置请参考下⾯。分配策略决定数据块⽂件存放的⽬录。
写数据michelle obama
⽤户写⼊新数据块时默认写在顶层存储。如果顶层没有⾜够的空间存放数据块,回收策略会被触发并释放空间给新数据块。如果顶层没有⾜够的可释放空间,那么写操作会失败。如果⽂件⼤⼩超出了顶层空间,写操作也会失败。
⽤户还可以通过配置项设置指定写数据默认的层级。
从ReadType.CACHE或ReadType.CACHE_PROMOTE读数据会导致数据被写到Alluxio中。这种情况下,数据被默认写到顶层。
最后,通过load命令可将数据写到Alluxio中。这种情况,数据也会被写到顶层。
读数据
读取分层存储的数据块和标准Alluxio类似。如果数据已经在Alluxio中,Alluxio从存储位置读取数据块。如果Alluxio配置了多层存储,数据块不⼀定是从顶层读取,因为可能被透明地移到下层存储中。
读取策略为ReadType.CACHE_PROMOTE时,Alluxio会确保数据在读取前先被移动到顶层存储中。通过显式的将热数据移到最⾼层,该策略也可以⽤于数据块的管理。
固定⽂件single是什么意思
last but not the least
⽤户可以通过固定(pin)和取消固定(unpin)来固定和移动该⽂件。⽂件被固定时,数据块不会从Alluxio的存储空间中移出。同时⽤户可以将固定⽂件的数据块移到顶层存储。
分配策略
Alluxio使⽤分配策略选择新数据块的写⼊位置。Alluxio定义了分配策略的框架,也内置了⼏种分配策略。以下是Alluxio已实现的分配策略:
贪⼼分配策略
分配新数据块到⾸个有⾜够空间的存储⽬录。
最⼤剩余空间分配策略
分配数据块到有最⼤剩余空间的存储⽬录。
轮询调度分配策略
分配数据块到有空间的最⾼存储层,存储⽬录通过轮询调度选出。
将来会有更多的分配策略可供选择。由于Alluxio⽀持⾃定义分配策略。你可以为⾃⼰的应⽤开发合适的分配策略。
回收策略
Alluxio使⽤回收策略决定当空间需要释放时,哪些数据块被移到低存储层。Alluxio⽀持⾃定义回收策
略,已有的实现包括:
黑帮大佬和我的365天未删减中文翻译贪⼼回收策略
移出任意的块直到释放出所需⼤⼩的空间。
LRU回收策略
移出最近最少使⽤的数据块直到释放出所需⼤⼩的空间。
LRFU回收策略
基于权重分配的最近最少使⽤和最不经常使⽤策略移出数据块。如果权重完全偏向最近最少使⽤,LRFU回收策略退化为LRU回收策略。
部分LRU回收策略
基于最近最少使⽤移出,但是选择有最⼤剩余空间的存储⽬录(StorageDir),只从该⽬录移出数据块。
将来会有更多的回收策略可供选择。由于Alluxio⽀持⾃定义回收策略。你也可以为⾃⼰的应⽤开发合适的回收策略。
使⽤同步移出时,推荐使⽤较⼩的块⼤⼩配置(64MB左右),以降低块移出的延迟。使⽤空间预留器时,块⼤⼩不会影响移出延迟。
层次化存储-架构位置
层次化存储是作为分布式缓存的最为核⼼的特性,加速读取/写⼊
层次化存储也是worker组件最重要的功能,同时⽀持横向扩展
层次化存储-代码解析
接上⽂/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列表的任务
deeploveprivate PinListSync mPinListSync;少儿英语培训教材
/** Runnable responsible for clean up potential zombie ssions. */
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 increas metrics counters. */
报告者端午节的由来和习俗
private BlockMetricsReporter mMetricsReporter;
/** Session metadata, ud to keep track of ssion 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提交bolock Id(address)获取workerId
⼼跳类⽅法代码注释
PinListSync Set<Long> pinList = PinList();
mBlockWorker.updatePinList(pinList);更新本地的pin列表
SessionCleaner for (long ssion : TimedOutSessions()) {
for (SessionCleanable sc : mSessionCleanables) {
sc.cleanupSession(ssion);
}
}
清除ssion
SpaceRerver太多各存储层空间检查
BlockMasterSync cmdFromMaster = mMasterClient.(),
handleMasterCommand(cmdFromMaster);
prompt是什么意思向blockmaster发送⼼跳,并处理返回
的消息
TieredBlockStore
该类负责分层存储逻辑,与不同介质的缓存存储模块进⾏交互
维护读写锁,保证block操作的线程安全
该类拥有前⽂提到过得申请和驱逐策略以及 pinned列表
备注:申请和驱逐策略,就是关于不同介质的缓存存储模块如何进⾏分配以及管理的策略//申请策略接⼝
fighter什么意思private final Allocator mAllocator;
//驱逐策略接⼝
private final Evictor mEvictor;
private final Set<Long> mPinnedInodes = new HashSet<>();