ceph pool的創建和刪除過程

ceph pool的刪除過程

命令行

ceph中一個pool的刪除過程如下:
ceph osd pool rm testpool testpool --yes-i-really-really-mean-it

Mon的處理

命令行請求直接發送請求給monitor
monitor接收的請求的處理流程如下:

void Monitor::_ms_dispatch(Message *m){
   ......
   dispatch_op(op);
}
void Monitor::dispatch_op(MonOpRequestRef op){

 switch (op->get_req()->get_type()) {

    // OSDs
    case CEPH_MSG_MON_GET_OSDMAP:
    case CEPH_MSG_POOLOP:
    case MSG_OSD_BEACON:
    case MSG_OSD_MARK_ME_DOWN:
    case MSG_OSD_FULL:
    case MSG_OSD_FAILURE:
    case MSG_OSD_BOOT:
    case MSG_OSD_ALIVE:
    case MSG_OSD_PGTEMP:
    case MSG_OSD_PG_CREATED:
    case MSG_REMOVE_SNAPS:
    case MSG_OSD_PG_READY_TO_MERGE:
      paxos_service[PAXOS_OSDMAP]->dispatch(op);
      return;
}

bool PaxosService::dispatch(MonOpRequestRef op)
      bool OSDMonitor::prepare_update(MonOpRequestRef op)
           bool OSDMonitor::prepare_pool_op(MonOpRequestRef op)
                  bool OSDMonitor::prepare_pool_op_delete(MonOpRequestRef op)
                         int OSDMonitor::_prepare_remove_pool
int OSDMonitor::_prepare_remove_pool(
  int64_t pool, ostream *ss, bool no_fake){
  ......
   // remove
  pending_inc.old_pools.insert(pool);

  // remove any pg_temp mappings for this pool
  ......
  // remove any primary_temp mappings for this pool
  // remove any pg_upmap mappings for this pool
  // remove any pending pg_upmap mappings for this pool
  // remove any pg_upmap_items mappings for this pool
  // remove any pending pg_upmap mappings for this pool
  }

在monitor的處理,主要是在 osdmap中標記

OSD的處理

在osd側,monitor 會更新osdmap,新的osdmap會更新epoch值。同時所有的pg都需要應對osdmap的變化。

boost::statechart::result PG::RecoveryState::Started::react(const AdvMap& advmap)
{
  PG *pg = context< RecoveryMachine >().pg;
  ldout(pg->cct, 10) << "Started advmap" << dendl;
  pg->check_full_transition(advmap.lastmap, advmap.osdmap);
  if (pg->should_restart_peering(
	advmap.up_primary,
	advmap.acting_primary,
	advmap.newup,
	advmap.newacting,
	advmap.lastmap,
	advmap.osdmap)) {
    ldout(pg->cct, 10) << "should_restart_peering, transitioning to Reset"
		       << dendl;
    post_event(advmap);
    return transit< Reset >();
  }
  pg->remove_down_peer_info(advmap.osdmap);
  return discard_event();
}
bool PastIntervals::is_new_interval(
  int old_acting_primary,
  int new_acting_primary,
  const vector<int> &old_acting,
  const vector<int> &new_acting,
  int old_up_primary,
  int new_up_primary,
  const vector<int> &old_up,
  const vector<int> &new_up,
  OSDMapRef osdmap,
  OSDMapRef lastmap,
  pg_t pgid)
{
  const pg_pool_t *plast = lastmap->get_pg_pool(pgid.pool());
  if (!plast) {
    return false; // after pool is deleted there are no more interval changes
  }
  const pg_pool_t *pi = osdmap->get_pg_pool(pgid.pool());
  if (!pi) {
    return true;  // pool was deleted this epoch -> (final!) interval change
  }

在函數is_new_interval裏,比較了lastmap和當前的osdmap中該pool的變化。從而可以確定:如果是在當前的epoch裏刪除了該pool,就返回true,該pg 需要重新 peering過程。

void OSD::handle_osd_map(MOSDMap *m)
    void OSD::_committed_osd_maps(epoch_t first, epoch_t last, MOSDMap *m)
              void OSD::consume_map()
/*-------Stray---*/
PG::RecoveryState::Stray::Stray(my_context ctx)
  : my_base(ctx),
    NamedState(context< RecoveryMachine >().pg, "Started/Stray")
{
  context< RecoveryMachine >().log_enter(state_name);

  PG *pg = context< RecoveryMachine >().pg;
  ceph_assert(!pg->is_peered());
  ceph_assert(!pg->is_peering());
  ceph_assert(!pg->is_primary());

  if (!pg->get_osdmap()->have_pg_pool(pg->get_pgid().pool())) {
    ldout(pg->cct,10) << __func__ << " pool is deleted" << dendl;
    post_event(DeleteStart());
  } else {
    pg->start_flush(context< RecoveryMachine >().get_cur_transaction());
  }
}

在函數_delete_some中實際完成刪除操作
void PG::_delete_some(ObjectStore::Transaction *t)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章