From: Yan, Zheng Date: Fri, 3 Nov 2017 04:03:44 +0000 (+0800) Subject: mds: optimize import/export state access X-Git-Tag: v12.2.3~15^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=45f4b1a141fe3c3caafaece0e82f2f35d0586030;p=ceph.git mds: optimize import/export state access Signed-off-by: "Yan, Zheng" (cherry picked from commit fb9277c14314aaa6a97ee23da9057ddc3c750408) --- diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index b9c6f63394c8..7b6ca8ab2520 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -321,7 +321,7 @@ void Migrator::export_try_cancel(CDir *dir, bool notify_peer) } if (state == EXPORT_WARNING) { // notify bystanders - export_notify_abort(dir, bounds); + export_notify_abort(dir, it->second, bounds); // process delayed expires cache->process_delayed_expire(dir); } @@ -337,7 +337,7 @@ void Migrator::export_try_cancel(CDir *dir, bool notify_peer) case EXPORT_EXPORTING: dout(10) << "export state=exporting : reversing, and unfreezing" << dendl; it->second.state = EXPORT_CANCELLING; - export_reverse(dir); + export_reverse(dir, it->second); break; case EXPORT_LOGGINGFINISH: @@ -506,7 +506,7 @@ void Migrator::handle_mds_failure_or_stop(mds_rank_t who) case IMPORT_PREPPING: assert(dir); dout(10) << "import state=prepping : unpinning base+bounds " << *dir << dendl; - import_reverse_prepping(dir); + import_reverse_prepping(dir, q->second); break; case IMPORT_PREPPED: @@ -521,7 +521,7 @@ void Migrator::handle_mds_failure_or_stop(mds_rank_t who) cache->adjust_subtree_auth(dir, q->second.peer); // notify bystanders ; wait in aborting state - import_state[df].state = IMPORT_ABORTING; + q->second.state = IMPORT_ABORTING; import_notify_abort(dir, bounds); assert(g_conf->mds_kill_import_at != 10); } @@ -1315,11 +1315,12 @@ public: void Migrator::export_go(CDir *dir) { - assert(export_state.count(dir)); - dout(7) << "export_go " << *dir << " to " << export_state[dir].peer << dendl; + auto it = export_state.find(dir); + assert(it != export_state.end()); + dout(7) << "export_go " << *dir << " to " << it->second.peer << dendl; // first sync log to flush out e.g. any cap imports - mds->mdlog->wait_for_safe(new C_M_ExportGo(this, dir, export_state[dir].tid)); + mds->mdlog->wait_for_safe(new C_M_ExportGo(this, dir, it->second.tid)); mds->mdlog->flush(); } @@ -1723,11 +1724,10 @@ void Migrator::handle_export_ack(MExportDirAck *m) m->put(); } -void Migrator::export_notify_abort(CDir *dir, set& bounds) +void Migrator::export_notify_abort(CDir *dir, export_state_t& stat, set& bounds) { dout(7) << "export_notify_abort " << *dir << dendl; - export_state_t& stat = export_state[dir]; assert(stat.state == EXPORT_CANCELLING); if (stat.notify_ack_waiting.empty()) { @@ -1740,9 +1740,9 @@ void Migrator::export_notify_abort(CDir *dir, set& bounds) for (set::iterator p = stat.notify_ack_waiting.begin(); p != stat.notify_ack_waiting.end(); ++p) { - MExportDirNotify *notify = new MExportDirNotify(dir->dirfrag(),stat.tid, true, - pair(mds->get_nodeid(),stat.peer), - pair(mds->get_nodeid(),CDIR_AUTH_UNKNOWN)); + MExportDirNotify *notify = new MExportDirNotify(dir->dirfrag(), stat.tid, true, + pair(mds->get_nodeid(), stat.peer), + pair(mds->get_nodeid(), CDIR_AUTH_UNKNOWN)); for (set::iterator i = bounds.begin(); i != bounds.end(); ++i) notify->get_bounds().push_back((*i)->dirfrag()); mds->send_message_mds(notify, *p); @@ -1754,7 +1754,7 @@ void Migrator::export_notify_abort(CDir *dir, set& bounds) * that is, we don't know they safely received and logged it, so we reverse our changes * and go on. */ -void Migrator::export_reverse(CDir *dir) +void Migrator::export_reverse(CDir *dir, export_state_t& stat) { dout(7) << "export_reverse " << *dir << dendl; @@ -1786,13 +1786,13 @@ void Migrator::export_reverse(CDir *dir) } // unpin bounds - for (const auto &bd : bounds) { + for (auto bd : bounds) { bd->put(CDir::PIN_EXPORTBOUND); bd->state_clear(CDir::STATE_EXPORTBOUND); } // notify bystanders - export_notify_abort(dir, bounds); + export_notify_abort(dir, stat, bounds); // unfreeze tree, with possible subtree merge. cache->adjust_subtree_auth(dir, mds->get_nodeid(), mds->get_nodeid()); @@ -2050,13 +2050,15 @@ void Migrator::handle_export_discover(MExportDirDiscover *m) } // only start discovering on this message once. + import_state_t *p_state; map::iterator it = import_state.find(df); if (!m->started) { assert(it == import_state.end()); m->started = true; - import_state[df].state = IMPORT_DISCOVERING; - import_state[df].peer = from; - import_state[df].tid = m->get_tid(); + p_state = &import_state[df]; + p_state->state = IMPORT_DISCOVERING; + p_state->peer = from; + p_state->tid = m->get_tid(); } else { // am i retrying after ancient path_traverse results? if (it == import_state.end() || @@ -2067,6 +2069,7 @@ void Migrator::handle_export_discover(MExportDirDiscover *m) return; } assert(it->second.state == IMPORT_DISCOVERING); + p_state = &it->second; } if (!mds->mdcache->is_open()) { @@ -2097,7 +2100,7 @@ void Migrator::handle_export_discover(MExportDirDiscover *m) // yay dout(7) << "handle_export_discover have " << df << " inode " << *in << dendl; - import_state[df].state = IMPORT_DISCOVERED; + p_state->state = IMPORT_DISCOVERED; // pin inode in the cache (for now) assert(in->is_dir()); @@ -2105,7 +2108,7 @@ void Migrator::handle_export_discover(MExportDirDiscover *m) // reply dout(7) << " sending export_discover_ack on " << *in << dendl; - mds->send_message_mds(new MExportDirDiscoverAck(df, m->get_tid()), import_state[df].peer); + mds->send_message_mds(new MExportDirDiscoverAck(df, m->get_tid()), p_state->peer); m->put(); assert (g_conf->mds_kill_import_at != 2); } @@ -2122,10 +2125,10 @@ void Migrator::import_reverse_discovered(dirfrag_t df, CInode *diri) import_state.erase(df); } -void Migrator::import_reverse_prepping(CDir *dir) +void Migrator::import_reverse_prepping(CDir *dir, import_state_t& stat) { set bounds; - cache->map_dirfrag_set(import_state[dir->dirfrag()].bound_ls, bounds); + cache->map_dirfrag_set(stat.bound_ls, bounds); import_remove_pins(dir, bounds); import_reverse_final(dir); } @@ -2147,7 +2150,7 @@ void Migrator::handle_export_cancel(MExportDirCancel *m) } else if (it->second.state == IMPORT_PREPPING) { CDir *dir = mds->mdcache->get_dirfrag(df); assert(dir); - import_reverse_prepping(dir); + import_reverse_prepping(dir, it->second); } else if (it->second.state == IMPORT_PREPPED) { CDir *dir = mds->mdcache->get_dirfrag(df); assert(dir); @@ -2357,7 +2360,7 @@ void Migrator::handle_export_prep(MExportDirPrep *m) } if (!success) - import_reverse_prepping(dir); + import_reverse_prepping(dir, it->second); // ok! dout(7) << " sending export_prep_ack on " << *dir << dendl; diff --git a/src/mds/Migrator.h b/src/mds/Migrator.h index d14561920a41..3db1e557dd16 100644 --- a/src/mds/Migrator.h +++ b/src/mds/Migrator.h @@ -151,8 +151,8 @@ protected: void export_go_synced(CDir *dir, uint64_t tid); void export_try_cancel(CDir *dir, bool notify_peer=true); void export_cancel_finish(CDir *dir); - void export_reverse(CDir *dir); - void export_notify_abort(CDir *dir, set& bounds); + void export_reverse(CDir *dir, export_state_t& stat); + void export_notify_abort(CDir *dir, export_state_t& stat, set& bounds); void handle_export_ack(MExportDirAck *m); void export_logged_finish(CDir *dir); void handle_export_notify_ack(MExportDirNotifyAck *m); @@ -175,7 +175,7 @@ protected: void import_reverse_discovering(dirfrag_t df); void import_reverse_discovered(dirfrag_t df, CInode *diri); - void import_reverse_prepping(CDir *dir); + void import_reverse_prepping(CDir *dir, import_state_t& stat); void import_remove_pins(CDir *dir, set& bounds); void import_reverse_unfreeze(CDir *dir); void import_reverse_final(CDir *dir);