ceph中的mgr 进程

ceph中的mgr 进程用于显示相关复位的统计信息,兵器额可以通过python提供接口来获取这些统计信息
这个进程的入口函数在C:\Users\Administrator\Desktop\source\ceph-master\ceph-master\src\ceph_mgr.cc 中
int main(int argc, const char **argv)
{
#这个进程的名字就是ceph-mgr,在Linux下可以通过top命令看到这个进程
  ceph_pthread_setname(pthread_self(), "ceph-mgr");
#这个进程的主要作用就是创建一个MgrStandby 类,并分别调用其init和mian函数
  MgrStandby mgr(argc, argv);
  int rc = mgr.init();
  if (rc != 0) {
      std::cerr << "Error in initialization: " << cpp_strerror(rc) << std::endl;
      return rc;
  }

  return mgr.main(args);
}
我们首先看init函数
int MgrStandby::init()
{
#订阅mgrmap更新的信息
  monc.sub_want("mgrmap", 0, 0);
#周期性发送becon message
  tick();

}
void MgrStandby::tick()
{
  dout(10) << __func__ << dendl;
  #发送beacon message
  send_beacon();
  #建立一个time ,这个timer的回调函数是tick()->beacon 也就是周期性发送beacon message
  timer.add_event_after(g_conf->get_val<int64_t>("mgr_tick_period"),
      new FunctionContext([this](int r){
          tick();
      }
  )); 
}
我们再看看main函数都做了啥
int MgrStandby::main(vector<const char *> args)
{
  // Enable signal handlers
  #注册SIGHUP/SIGINT/SIGTERM 这三个signal的处理函数
  signal_mgr = this;
  init_async_signal_handler();
  register_async_signal_handler(SIGHUP, sighup_handler);
  register_async_signal_handler_oneshot(SIGINT, handle_mgr_signal);
  register_async_signal_handler_oneshot(SIGTERM, handle_mgr_signal);
  #让当前进程变成一个deamon 进程
  client_messenger->wait();

  return 0;
}
前面我们见过在这个类中通过monc.sub_want("mgrmap", 0, 0); 来订阅mgrmap的更新,因此当收到更新时会调用这个类中下面的函数来处理

bool MgrStandby::ms_dispatch(Message *m)
{
  #判断是msg map信息
  if (m->get_type() == MSG_MGR_MAP) {
    handle_mgr_map(static_cast<MMgrMap*>(m));
    return true;
  } 
}
void MgrStandby::handle_mgr_map(MMgrMap* mmap)
{
  
  if (active_in_map) {
    if (!active_mgr) {
	#第一次active_mgr 为空,这里会新建一个mgr类来处理,从这里可以知道ceph组件更新的信息都是在mgr这个类中处理的。
      dout(1) << "Activating!" << dendl;
      active_mgr.reset(new Mgr(&monc, map, &py_module_registry,
                               client_messenger.get(), &objecter,
			       &client, clog, audit_clog));
      active_mgr->background_init(new FunctionContext(
            [this](int r){
              // Advertise our active-ness ASAP instead of waiting for
              // next tick.
              Mutex::Locker l(lock);
              send_beacon();
            }));
      dout(1) << "I am now activating" << dendl;
    } else {
      dout(10) << "I was already active" << dendl;
      bool need_respawn = active_mgr->got_mgr_map(map);
      if (need_respawn) {
	respawn();
      }
    }

 }
 最终在mgr类中的ms_dispatch中可以看到mgr对各类map的处理
 bool Mgr::ms_dispatch(Message *m)
{
   switch (m->get_type()) {
    case MSG_MGR_DIGEST:
      handle_mgr_digest(static_cast<MMgrDigest*>(m));
      break;
    case CEPH_MSG_MON_MAP:
      py_module_registry->notify_all("mon_map", "");

    case CEPH_MSG_FS_MAP:
      py_module_registry->notify_all("fs_map", "");
      handle_fs_map((MFSMap*)m);
 
    case CEPH_MSG_OSD_MAP:
      handle_osd_map();

      py_module_registry->notify_all("osd_map", "");

      break;
    case MSG_SERVICE_MAP:
      handle_service_map((MServiceMap*)m);
      py_module_registry->notify_all("service_map", "");
      break;
    case MSG_LOG:
      handle_log(static_cast<MLog *>(m));
      break;

  }
}
从这个函数中可以看到mgr中对mon_map/fs_map/osd_map/service_map 这四个map进行处理

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值