ceph rgw:rgw的I/O路径 前篇

导言

radosgw使用OP线程处理外部应用的I/O请求,OP线程由rgw main函数初始化后创建,当rgw的frontend为civetweb时,可以通过修改rgw_thread_pool_size指定OP线程的数目。

OP线程的处理逻辑可分为 HTTP前端、REST API通用处理层、API操作执行层、RADOS接口适配层、librados接口层等几部分。具体的作用会在后面逐步解释。

有关整个I/O路径,可能会分多篇文章来分析,这篇文章不涉及OP线程,从main函数入手,看看rgw初始化的一些工作。

main函数

radosgw代码位于ceph/src/rgw目录下,其main函数位于rgw_main.cc。下面按顺序列出main函数中主要的操作,一些细节暂时忽略。

  • 根据配置确认rgw提供哪一个或哪几个frontends。frontend有civetweb、apache等,在最新版本中,其默认frontend是civetweb。frontend是rgw与外界交互的组件。然后为每个被要求提供的frontend的配置创建一个 RGWFrontendConfig 对象,并写入数据。然后所有的RGWFrontendConfig 存储在一个list中。
    civetweb的官方描述:

CivetWeb can be used by developers as a library, to add web server functionality to an existing application. It can also be used by end users as a stand-alone web server. It is available as single executable, no installation is required.

  • 初始化RGWRados对象,建立起与rados的联系。

  • 从配置中获取要对外提供的apis,并存储在一个 apiname->bool的apis_map中,目前支持的api包括s3、swift、admin等等,要注意的是s3和swift不能同时提供。api的选择通过判断apis_map中是否有对应的apiname来确定。比如s3的判断如下:

  if (apis_map.count("s3") > 0 || s3website_enabled) {
    if (! swift_at_root) {
      rest.register_default_mgr(set_logging(rest_filter(store, RGW_REST_S3,
                                                        new RGWRESTMgr_S3(s3website_enabled))));
    } else {
      derr << "Cannot have the S3 or S3 Website enabled together with "
           << "Swift API placed in the root of hierarchy" << dendl;
      return EINVAL;
    }
  }
  • 初始化与日志服务器的连接

  • 注册必要的信号处理函数

  • 遍历之前创建的RGWFrontendConfig列表,为每个frontend创建对象,比如civetweb对应于RGWCivetWebFrontend类对象,loadgen对应于RGWLoadGenFrontend类对象,这些类都继承了同一个基类RGWFrontend。

class RGWFrontend {
public:
  virtual ~RGWFrontend() {}

  virtual int init() = 0; // 进行对象的初始化

  virtual int run() = 0; // 开始服务,frontend一般作为一个服务器接受请求
  virtual void stop() = 0; // 停止服务
  virtual void join() = 0; // 释放对象前调用

  virtual void pause_for_new_config() = 0; // 当rgw的配置发生改变时,需要暂停服务器
  virtual void unpause_with_new_config(RGWRados* store,
                                       rgw_auth_registry_ptr_t auth_registry) = 0; //取消暂停
};

然后将有关frontend的元数据信息存入service_map_meta,如下,fe_count代表当前是第几个frontend,从0开始计数。

service_map_meta["frontend_type#" + stringify(fe_count)] = framework;
service_map_meta["frontend_config#" + stringify(fe_count)] = config->get_config();

然后调用RGWFrontend的init()函数进行初始化。初始化成功后,调用run()函数在其他线程运行frontend。

做完这一切,将创建并初始化的RGWFrontend对象指针放入一个list,list<RGWFrontend *> fes;

  • 运行时事件,因为rgw需要在运行过程中同时监听一些时间的notify,对指定的notify做对应的处理,比如当配置文件修改时,需要暂停frontend的工作,apply新的配置后然后继续工作。rgw是通过将不同的组件注册到一个RGWRealmWatcher上,然后RGWRealmWatcher会监听外部事件,并将其通知注册的组件。代码如下,去看看这几个类的定义会更容易理解。
  RGWPeriodPusher pusher(store);
  RGWFrontendPauser pauser(fes, &pusher);
  RGWRealmReloader reloader(store, service_map_meta, &pauser);

  RGWRealmWatcher realm_watcher(g_ceph_context, store->realm);
  realm_watcher.add_watcher(RGWRealmNotify::Reload, reloader);
  realm_watcher.add_watcher(RGWRealmNotify::ZonesNeedPeriod, pusher);
  • 等待停止信号,进入阻塞状态。
    当收到停止信号后,遍历RGWFrontend列表,为每个对象调用stop函数,然后再遍历一次,为每个对象调用join函数并delete对象。遍历RGWFrontendConfig列表,delete配置对象。

  • 其他各种资源释放,收尾工作



作者:chnmagnus
链接:https://www.jianshu.com/p/d96c76c41c56
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值