前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SSM(HDFS智能存储管理) 系统剖析

SSM(HDFS智能存储管理) 系统剖析

原创
作者头像
Yiwenwu
修改2024-05-05 10:32:38
1530
修改2024-05-05 10:32:38
举报
文章被收录于专栏:大数据&分布式大数据&分布式

背景介绍

Smart Storage Management (SSM) 项目是Intel开源的HDFS存储管理系统,致力于提供HDFS数据的智能管理方案。SSM有如下几个重要的功能:

  • SSM Mover,用于冷热数据分层管理。根据用户定制的SSM规则,SSM区分出冷热数据,将冷热数据分别迁移到合适的存储介质上,合理利用不同的存储设备
  • SSM小文件优化,能将HDFS小文件合并成一个大文件,在合并后,仍然支持对小文件透明的读操作
  • SSM Data Sync,能够将一个HDFS集群中的数据自动同步到另一个集群上
  • SSM EC (Erasure Coding),可将HDFS数据转化成某个EC策略下的数据,能够显著减少占用的存储空间
  • SSM Compression,可按照指定的压缩算法,将HDFS文件压缩

整体架构

SSM整体架构可分为三部分:

  • SSM Metastore:管理和优化存储系统元数据,支持标准SQL,提供查询接口,允许用户和其他系统组件查询元数据信息
  • SSM Server:基于规则策略进行解析执行,下发给agent,获取agent上报的执行结果
  • SSM Agent:接收并执行Server端下发的存储优化任务,向Server上报执行结果和心跳

SSM Server基于线程内置不同任务类型的调度器(Scheduler),主要包括:

  • Mover Scheduler:冷热数据分层处理
  • Copy Scheduler:数据备份
  • EC Scheduler:HDFS EC纠删码存储方式
  • SmallFiles Scheduler:小文件合并

SSM的整体执行流程可以分为四个步骤:Collect → Learn → Perform → Measure

  1. Collect:数据采集,例如,访问请求次数、数据温度、数据权限、系统存储信息、用户预定义规则、计算效率等;
  2. Learn:基于启发式算法分析采集的数据,生成待执行的优化任务
  3. Perform:执行HDFS数据智能管理,例如,缓存热数据,归档冷数据,使用透明压缩,EC纠删码,小文件合并等
  4. Measure:评估智能管理效果,例如,存储使用率,数据访问效率,系统负载优化情况等

各个系统的交互图如下所示:

  • SSM Server单独部署,基于REST API对外提供调用服务
  • SSM Client可与HDFS Client 混合在相同节点部署,便于Client节点执行文件管理任务
  • 不管是Server和Client需要保证与HDFS集群网络可通

数据库设计

数据库主要维护的信息包括:

  • files:文件信息,包括ID、路径、大小、block备份数量、存储策略、所属用户、所属用户组、ec策略、权限信息
  • cached_files:维护加热的缓存文件,并进行热数据命中统计
  • storage_policy:自定义存储策略ID与名称
  • ecpolicy:EC策略
  • owners:维护用户信息
  • groups:维护应用组信息
  • access_count_tables:基于不同的时间维度,统计文件的访问频次

核心类

(1). SmartService

SSM业务实现服务类,主要包括:

  • ActionScheduleService:任务调度服务
  • StateUpdateService:任务状态更新服务
  • CmdletManager:cmd执行管理器
  • RuleManager:规则管理器
  • StatesManager:任务状态管理器,基于FSM(优先状态机)进行状态管理

(2). SmartEngine

负责启动所有注入的`SmartService,主要包括:

  • StatesManager
  • RuleManager
  • CmdletManager
    • AgentExecutorService
    • HazelcastExecutorService

(3). StatesManager

StatesManager会轮询从NameNode采集指标和事件,

  • init 初始化
    • 初始化线程池:拉起信息的`accessEventFetcher`
    • 初始化状态变更服务:`initStatesUpdaterService`
  • start 线程启动
    • AccessEventFetcher.start:启动定时线程任务:`FetchTask`
    • StatesUpdaterService.start
事件采集接口
事件采集接口

(4). RuleManager

用于管理规则和执行策略,`RuleExecutorPlugin`:规则执行器插件,可扩展不同的管理任务,如小文件处理,EC等;

规则执行器插件
规则执行器插件

`RuleExecutor`:策略执行方:

  • init:初始化执行策略`RuleInfo`
  • start:提交需要执行的策略任务

(5). CmdletManager:基于系统CMD脚本方式,真正实现任务执行。策略基于SmartAction执行,SmartAction是Action的基础类,所有的Action都需要运行在cmdlet或web console中。

Action基础类
Action基础类

(6). SmartAgent

执行server下发命令,同时上报对应执行的结果,基于`ActorSystem` 实现的。

实现细节

SSM是典型的主从架构,Server是主节点,Agent是从节点,基于Actor实现Master/Client之间通信。

Smart Server

Fetcher采集

由`StatesManager`触发,支持在Runtime运行时进行配置动态加载。

(1). FileAccessEventSource

通过不同方式获取文件访问事件(file access event),默认实现类:`SmartServerAccessEventSource`:

  • 获取FileAccessEventCollector
  • 接收SmartClient上报信息并保存,便于后续消费执行
代码语言:java
复制
  /**
   * Get a collector what will produce events from this file access event source.
   */
  FileAccessEventCollector getCollector();
  
    /**
   * Insert events generated from the Smart client so that the collector can consume.
   * The actual implementation of FileAccessEventSource doesn't have to support this.
   * @param event The event that generated from Smart client
   */
  void insertEventFromSmartClient(FileAccessEvent event);

(2). FileAccessEventCollector

采集器可生产文件访问事件,封装在队列`LinkedBlockingQueue`中,从队列中生产、消费数据;

  • 获取采集器的所有事件列表
代码语言:java
复制
  /**
   * Collect file access events occured since last calling of this method.
   * @return access events
   * @throws IOException
   */
  List<FileAccessEvent> collect() throws IOException;

(3). AccessEventFetcher

获取所有的FileAccess Event,每个访问时间放在一个聚合窗口中。

(4). StatesUpdateService

对HDFS组件的事件进行更新处理,则基于实现`HdfsStatesUpdateService`,实现包括:

Init初始化:

  • 加载HDFS配置信息
  • 获取NameNodeUri(主NN RPC地址)
  • 获取HDFS提供的调用客户端`DFSClient`
  • 判断操作路径:`/system/mover.id`存在,不存在则新建;
  • 初始化Fetcher对象;
    • CachedListFetcher:缓存列表,以定时任务调度`ScheduledExecutorService`的形式启动线程`FetchTask`,获取HDFS缓存列表信息
    • InotifyEventFetcher:节点变化事件,基于client.getNamenode().getCurrentEditLogTxid() 获取变更信息,基于`NamespaceFetcher`获取文件信息
    • DataNodeInfoFetcher:DN节点信息,获取DN存储容量,`client.getDatanodeStorageReport`,并在DB中更新DN容量信息
    • StorageInfoSampler:存储信息模板

Start操作:

  • 启动Fetcher对象
  • 加载规则插件`RulePlugin`
    • CheckSsdRulePlugin
    • CheckErasureCodingRulePlugin

(5). RulePlugin

规则插件,管理规则生命周期的调用,主要提供以下方法:

  • 新增Rule时的调用执行
  • 完成Rule添加后的调用执行
代码语言:java
复制
void onAddingNewRule(RuleInfo ruleInfo, TranslateResult tr) throws IOException;

void onNewRuleAdded(RuleInfo ruleInfo, TranslateResult tr);

Rule策略

依赖`StatesManager`,`CmdletManager`,创建时依赖`RuleExecutorPlugin`,规则执行插件:

(1). RuleExecutorPlugin

规则执行插件主要提供以下方法:

  • 新规则添加后执行操作
  • 规则执行前自定义操作
  • 提交Cmdlet前的自定义操作
  • 提交CmdletDescriptor前的自定义操作
  • 规则执行退出后的自定义操作
代码语言:java
复制
/**
   * Called just before an RuleExecutor been generated and submitted to
   * thread pool for execution. Only called once per instance.
   *
   * @param ruleInfo
   * @param tResult
   */
  void onNewRuleExecutor(final RuleInfo ruleInfo, TranslateResult tResult);

  /**
   * Called just before rule executor begin to execute rule.
   *
   * @param ruleInfo
   * @param tResult
   * @return continue this execution if true.
   */
  boolean preExecution(final RuleInfo ruleInfo, TranslateResult tResult);

  /**
   * Called after rule condition checked.
   *
   * @param objects the result of checking rule condition.
   * @return object list that will be used for Cmdlet submission.
   */
  List<String> preSubmitCmdlet(final RuleInfo ruleInfo, List<String> objects);

  /**
   * Called right before the CmdletDescriptor been submitted to CmdletManager.
   *
   * @param descriptor
   * @return the descriptor that will be used to submit to CmdletManager
   */
  CmdletDescriptor preSubmitCmdletDescriptor(final RuleInfo ruleInfo, TranslateResult tResult,
      CmdletDescriptor descriptor);

  /**
   * Called when an RuleExecutor exits. Called only once per instance.
   *
   * @param ruleInfo
   */
  void onRuleExecutorExit(final RuleInfo ruleInfo);

已经实现的规则插件包括:

  • FileCopyDrPlugin:`CmdletDescriptor` 描述执行命令的信息,执行备份的操作,对应的Action为`SyncAction`;
  • FileCopy2S3Plugin:将数据备份到S3,对应的Action为`Copy2S3Action`;
  • SmallFilePlugin:小文件合并查件
  • ErasureCodingPlugin:Hadoop3.x支持,对应的Action为`ErasureCodingAction`

(2). SmartRuleStringParser

将字符串规则转换为规则对象,基于`antlr`进行规则转换,`Lexer`进行分析,`Parser`进行解析,`SmartRuleBaseVisitor`转为对象,最为后`TranslateResult`.

代码语言:java
复制
ParseTree tree = parser.ssmrule();

(3). RuleInfoRepo

可以有`RuleInfo`获取,关键方法`launchExecutor`,获取`RuleExecutor`;

(4). RuleManager

规则生命周期管理,关键方法包括:

  • submitRule:提交规则,将任务基于`RuleExecutor`进行调用
  • deleteRule:删除规则
  • activateRule:激活规则
  • disableRule:停止规则使用
  • getRuleInfo:获取指定规则信息
  • listRulesMoveInfo:列出规则移动信息
  • listRulesSyncInfo:列出规则同步信息
  • listRulesInfo:列出规则列表
  • updateRuleInfo:更新规则

(5). RuleExecutor

Server实现下发执行的线程核心类,核心方法`submitCmdlets`,最终由`CmdletManager.submitCmdlet(cmd)` 完成

代码语言:java
复制
RuleManager.start 
    -> RuleExecutor.run() 
        -> CmdletManager.submitCmdlet

Action调度

(1). CmdletManager

CMD执行管理,主要包括

  • submitCmdlet:支持以`CmdletDescriptor`执行执行任务,并获取该执行任务对应的`ActionInfo`列表,将要执行的Action存储到元数据;
  • syncCmdAction:同步执行的cmd信息,在内存中存储;

(2). CmdletDescriptor

CmdletDescriptor生成对应的`CmdletInfo`和对应的执行`ActionInfo`,核心`ScheduleTask` ,执行方法`scheduleCmdletActions`

代码语言:java
复制
CmdletDescriptor
    ->CmdletInfo
    ->List<ActionInfo> actionInfos

(3). ActionScheduler

主要提供Action生命周期相关的调度管理方法:

  • Action提交时自定义执行
  • Action调度时自定义执行
  • Action调度后自定义执行
  • Action在分发执行前的自定义执行
  • Action结束后的自定义执行
代码语言:java
复制
  /**
   * Called when new action submitted to CmdletManager.
   *
   * @param cmdletInfo info about the cmdlet which the action belongs to
   * @param actionInfo
   * @param actionIndex index of the action in cmdlet,
   * @return acceptable if true, or discard
   * @throws IOException
   */
  boolean onSubmit(CmdletInfo cmdletInfo, ActionInfo actionInfo, int actionIndex)
      throws IOException;

  /**
   * Trying to schedule an action for Dispatch.
   *
   * @param cmdletInfo
   * @param actionInfo
   * @param cmdlet
   * @param action
   * @param actionIndex
   * @return
   */
  ScheduleResult onSchedule(CmdletInfo cmdletInfo, ActionInfo actionInfo,
      LaunchCmdlet cmdlet, LaunchAction action, int actionIndex);

  /**
   * Called after and an Cmdlet get scheduled.
   *
   * @param actionInfo
   * @param result
   */
  void postSchedule(CmdletInfo cmdletInfo, ActionInfo actionInfo, int actionIndex,
      ScheduleResult result);

  /**
   *  Called just before dispatch for execution.
   *
   * @param action
   */
  void onPreDispatch(LaunchCmdlet cmdlet, LaunchAction action, int actionIndex);

  /**
   *  Called when action finished execution.
   *
   * @param actionInfo
   */
  void onActionFinished(CmdletInfo cmdletInfo, ActionInfo actionInfo, int actionIndex);

Smart Agent

Agent执行Server下发的命令,Cmdlet:线程类,调用`SmartAction.run` 执行。

总结

HDFS存储管理系统,对于公司内部的数据平台影响价值可能较小,相比于繁杂的系统搭建维护成本,可以选择更直接的人工运维操作来管理存储系统。而对于商业化数据平台,完善的存储管理系统则具备很高的附加值,大数据平台可以封装了整套存储管理能力,让客户开箱即用,减少客户的运维投入。

SSM系统是少有的HDFS存储管理开源系统,主要以线程模式进行轻量化的运维任务调度,目前该项目已停止维护。虽然,SSM开源实现的整体功能并不完善,且设计比较偏复杂,但可以参考借鉴该设计思想简化出更符合使用场景的存储管理系统。

如图展示参考SSM设计思想,简化实现的存储资源&计算资源管理的轻量级任务引擎架构

我正在参与2024腾讯技术创作特训营最新征文,快来和我瓜分大奖!

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 背景介绍
  • 整体架构
  • 数据库设计
  • 核心类
  • 实现细节
    • Smart Server
      • Fetcher采集
      • Rule策略
      • Action调度
    • Smart Agent
    • 总结
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档


    http://www.vxiaotou.com