溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Migrator類怎么用

發(fā)布時(shí)間:2021-12-18 16:58:48 來(lái)源:億速云 閱讀:156 作者:小新 欄目:云計(jì)算

這篇文章主要介紹了Migrator類怎么用,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Migrator類說(shuō)明:

class Migrator {
     MDSRank *mds;          記錄mds信息
     MDCache *cache;          記錄MDCache信息
     struct export_state_t {
          int state;                    記錄export的當(dāng)前狀態(tài)
          mds_rank_t peer;          記錄export到對(duì)端mds rank信息
          uint64_t tid;                    記錄export到對(duì)端的session id信息
          set<mds_rank_t> warning_ack_waiting;     等待warning ack的mds集合
          set<mds_rank_t> notify_ack_waiting;          等待notify ack的mds集合
          map<inodeno_t, map<client_t, Capability::Import>> peer_imported;     記錄export對(duì)端信息
          list<MDSInternalContextBase*> waiting_for_finish;                              記錄等待finish的集合
          MutationRef                     mut;      MutationImpl對(duì)象引用
          utime_t last_cum_auth_pins_change;
          int last_cum_auth_pins;
          int num_remote_waiters;              遠(yuǎn)程auth pin waiters
     };
     map<CDir*, export_state_t> export_state;          export的狀態(tài)集合
     list<pair<dirfrag_t, mds_rank_t>> export_queue;     export隊(duì)列
     struct import_state_t {
          int state;
          mds_rank_t peer;
          uint64_t tid;
          set<mds_rank_t> bystanders;
          list<dirfrag_t> bound_ls;
          list<ScatterLock*> updated_scatterlocks;
          map<client_t, entity_inst_t> client_map;
          map<CInode*, map<client_t, Capability::Export>> peer_exports;
          MutationRef mut;
     };
     map<dirfrag_t, import_state_t> import_state;
};

Migrator類方法:

Migrator::dispatch(m)                              核心分發(fā)處理函數(shù)

|__根據(jù)m的類型決定后續(xù)的處理過(guò)程

     |__類型是MSG_MDS_EXPORTDIRDISCOVER

          |__調(diào)用handle_export_discover(MExportDirDiscover* m)

     |__類型是MSG_MDS_EXPORTDIRPREP

          |__調(diào)用handle_export_prep(MExportDirPrep* m)

     |__類型是MSG_MDS_EXPORTDIR

          |__調(diào)用handle_export_dir(MExportDir* m)

     |__類型是MSG_MDS_EXPORTDIRFINISH

          |__調(diào)用handle_export_finsih(MExportDirFinish* m)

     |__類型是MSG_MDS_EXPORTDIRCANCEL

          |__調(diào)用handle_export_cancel(MExportDirCancel* m)

     |__類型是MSG_MDS_EXPORTDIRDISCOVERACK

          |__調(diào)用handle_export_discover_ack(MExportDirDiscoverAck* m)

     |__類型是MSG_MDS_EXPORTDIRPREACK

          |__調(diào)用handle_export_prep_ack(MExportDirPrepAck* m)

     |__類型是MSG_MDS_EXPORTDIRACK

          |__調(diào)用handle_export_ack(MExportDirAck* m)

     |__類型是MSG_MDS_EXPORTDIRNOTIFYACK

          |__調(diào)用handle_export_notify_ack(MExportDirNotifyAck* m)

     |__類型是MSG_MDS_EXPORTDIRNOTIFY

          |__調(diào)用handle_export_dir_notify(MExportDirNotify* m)

     |__類型是MSG_MDS_EXPORTCAPS

          |__調(diào)用handle_export_caps(MExportCaps* m)

     |__類型是MSG_MDS_GATHERCAPS     

          |__調(diào)用handle_gather_caps(MGatherCaps* m)

Migrator::export_empty_import(dir)

|__dir對(duì)應(yīng)的inode節(jié)點(diǎn)是auth的

     |__直接返回

|__dir是auth的

     |__直接返回

|__dir是freezing或frozen

     |__直接返回

|__dir不是空目錄

     |__直接返回

|__dir是root節(jié)點(diǎn)

     |__直接返回

|__得到export目的dir所在的mds節(jié)點(diǎn),即:dir->inode->authority().first

|__調(diào)用export_dir(dir, dest)               執(zhí)行實(shí)際的export操作

Migrator::export_dir(dir, dest)

|__檢查MDCache是否是readonly(目前尚不支持read-only模式的export)

     |__直接返回

|__檢查mdsmap是否是degraded(cluster處于degraded狀態(tài)則不能export)

     |__直接返回

|__檢查dir的inode是否是system(不能export system dir)

     |__直接返回

|__檢查dir的inode是否是stray

     |__直接返回

|__檢查dir是否處于freezing或frozen

     |__直接返回

|__檢查dir是否處于EXPORTING狀態(tài)

     |__直接返回

|__執(zhí)行dir的auth_pin()

|__設(shè)置dir的當(dāng)前狀態(tài)為EXPORTING,即:dir->state_set(STATE_EXPORTING)

|__從MDCache中得到MDRequestRef類對(duì)象,即:mds->mdcache->request_start_internal(EXPORTDIR)

|__設(shè)置MDRequest類對(duì)象中的_more的export_dir為dir,即:保存待export的dir數(shù)據(jù)

|__從export_state數(shù)組中得到dir為索引對(duì)應(yīng)的export_state_t對(duì)象stat

|__設(shè)置stat的state為EXPORT_LOCKING

|__設(shè)置stat的peer為dest

|__設(shè)置stat的tid為mdr->reqid.tid

|__設(shè)置stat的mut為mdr

|__調(diào)用dispatch_export_dir(mdr)來(lái)發(fā)送export dir請(qǐng)求

Migrator::dispatch_export_dir(mdr)

|__從mdr的_more中得到待export的dir數(shù)據(jù),即:mdr->more()->export_dir

|__從export_state數(shù)組中找到dir對(duì)應(yīng)的export state項(xiàng)

|__設(shè)置export_state_t的當(dāng)前狀態(tài)是EXPORT_DISCOVERING

|__創(chuàng)建MExportDirDiscover類消息

|__將消息發(fā)送給目的MDS進(jìn)程,即:mds->send_message_mds(discover, it->second.peer)

|__設(shè)置export_state_t中的last_cum_auth_pins_change為系統(tǒng)當(dāng)前時(shí)間

|__freeze當(dāng)前dir的tree,即:dir->freeze_tree()

|__添加dir等待WAIT_FROZEN的回調(diào)函數(shù)C_MDC_ExportFreeze(),即:調(diào)用export_frozen()函數(shù)

Migrator::handle_export_discover(MExportDirDiscover *m) (對(duì)端)

|__從消息中得到對(duì)端的mds_rank_t以及dirfrag_t結(jié)構(gòu),即:from=m->get_source_mds()/df = m->get_dirfrag()

|__遍歷import_state數(shù)組

     |__若數(shù)組中沒(méi)有找到對(duì)應(yīng)的項(xiàng)且m->started==false

          |__設(shè)置m->started=true

          |__更新import_state數(shù)組中對(duì)應(yīng)的項(xiàng),即:state=IMPORT_DISCOVERING/peer=from/tid=m->get_tid()

|__從MDCache中得到export的dir的CInode信息,即:in=cache->get_inode(m->get_dirfrag().ino)

|__更新import_state數(shù)組中對(duì)應(yīng)的項(xiàng),即:state==IMPORT_DISCOVERED

|__創(chuàng)建MExportDirDiscoverAck類消息

|__將類消息發(fā)送回給mds進(jìn)程,即:mds->send_message_mds()

Migrator::handle_export_discover_ack(MExportDirDiscoverAck* m)

|__從消息中得到dirfrag,之后從MDCache中得到dirfrag對(duì)應(yīng)的CDir類對(duì)象,即:cache->get_dirfrag(m->get_dirfrag())

|__在export_state數(shù)組中查找dir對(duì)應(yīng)的項(xiàng)

|__在export_state數(shù)組對(duì)應(yīng)的dir項(xiàng)中設(shè)置其狀態(tài)為EXPORT_FREEZING

Migrator::export_frozen(dir, tid)

|__從export_state數(shù)組中查找dir對(duì)應(yīng)的項(xiàng)

|__得到該dir對(duì)應(yīng)的CInode,即:dir->get_inode()

|__創(chuàng)建一個(gè)新的MutationImpl類對(duì)象且將其放入export_state_t的mut中

|__根據(jù)dirfrag和tid創(chuàng)建一個(gè)MExportDirPrep類消息

|__遍歷dir的replicas數(shù)組

     |__將數(shù)組中的成員添加到MExportDirPrep類消息的bystander中

|__將basedir添加到MExportDirPrep類消息的basedir中

|__遍歷bounds數(shù)組

     |__將bounds成員添加到MExportDirPrep類消息的bound中

     |__循環(huán)處理如下內(nèi)容

          |__將bounds成員的inode添加到inodes_added數(shù)組中

          |__遍歷bounds成員的parent目錄

     |__將dirfrag以及start信息序列化到bufferlist中

     |__將bufferlist寫入到MExportDirPrep類消息的trace中

|__設(shè)置export_state_t中的狀態(tài)為EXPORT_PREPPING

|__將MExportDirPrep類消息發(fā)送給目的MDS,即:mds->send_message_mds()

Migrator::handle_export_prep(MExportDirPrep *m)     (對(duì)端)

|__從import_state數(shù)組中找到消息中對(duì)應(yīng)的dirfrag項(xiàng)

|__從MDCache中得到dir和dir對(duì)應(yīng)的CInode

|__遍歷消息中的bounds數(shù)組

     |__將數(shù)組中的內(nèi)容添加到import_bound_fragset數(shù)組中

|__若消息中的did_assim()==false

     |__設(shè)置當(dāng)前import_state數(shù)組中對(duì)應(yīng)項(xiàng)的state為IMPORT_PREPPING

     |__從消息中解析traces數(shù)組

          |__將traces數(shù)組中的內(nèi)容添加到MDCache中

     |__遍歷import_bound_fragset數(shù)組

          |__從數(shù)組成員的inodeno_t的到對(duì)應(yīng)的CInode結(jié)構(gòu)

          |__調(diào)用CInode對(duì)應(yīng)的get_stickydirs()函數(shù)

|__遍歷import_bound_fragset數(shù)組

     |__從數(shù)組成員的inodeno_t的到對(duì)應(yīng)的CInode結(jié)構(gòu)

     |__遍歷數(shù)組成員中fragset_t下所有葉子節(jié)點(diǎn)

          |__根據(jù)葉子節(jié)點(diǎn)得到在MDCache中對(duì)應(yīng)的CDir數(shù)據(jù)

          |__若CDir數(shù)據(jù)不在MDCache中

               |__執(zhí)行MDCache中的open_remote_dirfrag()函數(shù)來(lái)創(chuàng)建這個(gè)CDir

          |__將葉子節(jié)點(diǎn)對(duì)應(yīng)的CDir數(shù)據(jù)插入到import_bounds數(shù)組中

|__設(shè)置import_state數(shù)組指定成員的狀態(tài)為IMPORT_PREPPED

|__創(chuàng)建MExportDirPreAck類消息

|__調(diào)用mds的send_message()方法將類消息發(fā)送給指定的MDS進(jìn)程

Migrator::handle_export_prep_ack(MExportDirPrepAck *m)

|__根據(jù)消息的dirfrag得到對(duì)應(yīng)的CDir類對(duì)象

|__在export_state數(shù)組中查找CDir類對(duì)象對(duì)應(yīng)的項(xiàng)

|__遍歷replicas數(shù)組

     |__將mds_rank_t信息插入到export_state_t結(jié)構(gòu)中的warning_ack_waiting/notify_ack_waiting數(shù)組中

     |__創(chuàng)建MExportDirNotify類消息

     |__將MEXportDirNotify類消息發(fā)送給對(duì)端mds進(jìn)程

|__設(shè)置export_state_t結(jié)構(gòu)中的state為EXPORT_WARNING

Migrator::handle_export_notify(MExportDirNotify *m)     (對(duì)端)

|__從MDCache中得到消息中dirfrag對(duì)應(yīng)的CDir類對(duì)象

|__創(chuàng)建MExportDirNotifyAck類消息

|__調(diào)用mds的send_message_mds()將類消息發(fā)送回給mds進(jìn)程

Migrator::handle_export_notify_ack(MExportDirNotifyAck *m)

|__根據(jù)消息的dirfrag得到對(duì)應(yīng)的CDir類對(duì)象

|__從消息中得到對(duì)端mds_rank_t信息

|__若在export_state數(shù)組中能夠找到dir對(duì)應(yīng)的項(xiàng)

     |__若export_state_t的state==EXPORT_WARNING

          |__調(diào)用export_go(dir)     執(zhí)行實(shí)際的export操作

     |__若export_state_t的state==EXPORT_NOTIFYING

          |__調(diào)用export_finish(dir)

Migrator::export_go(dir)

|__調(diào)用哦mds中mdlog的wait_for_safe()函數(shù)來(lái)設(shè)置回調(diào)函數(shù)C_M_ExportGo(),最后執(zhí)行export_go_synced(dir, tid)

|__flush mds的mdlog,即:|mds->mdlog->flush()

Migrator::export_go_synced(dir, tid)

|__在export_state數(shù)組中查找dir對(duì)應(yīng)的項(xiàng)

|__設(shè)置其狀態(tài)為EXPORT_EXPORTING

|__創(chuàng)建MExportDir類消息

|__調(diào)用encode_export_dir()得到export的map信息以及得到exported_inodes數(shù)量

|__將得到的export的map信息序列化到類消息的client_map中

|__遍歷bounds數(shù)組

     |__將數(shù)組中的成員添加到類消息的export數(shù)組中

|__發(fā)送類消息到對(duì)端mds進(jìn)程,即:mds->send_message_mds()

Migrator::handle_export_dir(MExportDir *m)     (對(duì)端)

|__從MDCache中得到消息中dirfrag對(duì)應(yīng)的CDir類對(duì)象

|__從import_state數(shù)組中查到消息中dirfrag對(duì)象的項(xiàng)

|__創(chuàng)建C_MDS_ImportDirLoggedStart回調(diào)函數(shù)類

|__創(chuàng)建EImportStart日志入口

|__調(diào)用MDS的mlog的start_entry()來(lái)啟動(dòng)日志

|__將消息中的client_map信息解析道EImportStart中的imported_client_map中

|__從消息中得到export_data

|__調(diào)用decode_import_dir()函數(shù),將export_data寫入到mdlog對(duì)應(yīng)的current segment里

|__遍歷消息中的bounds數(shù)組

     |__將數(shù)組中dirfrag_t對(duì)應(yīng)的CDir添加到LogSegment中

     |__將數(shù)組中dirfrag_t對(duì)應(yīng)的CDir添加到import_bounds數(shù)組中

|__調(diào)用mds的balancer的add_import()函數(shù)來(lái)平衡查找樹

|__設(shè)置import_state_t中的狀態(tài)為IMPORT_LOGGINGSTART

|__啟動(dòng)mdlog,即:mds->mdlog->submit_entry()/mds->mdlog->flush()

Migrator::import_logged_start()     (對(duì)端)

|__在import_state數(shù)組中查找dirfrag對(duì)應(yīng)的項(xiàng)

|__設(shè)置對(duì)應(yīng)項(xiàng)的state為IMPORT_ACKING

|__創(chuàng)建MExportDirAck類對(duì)象

|__發(fā)送MExportDirAck類對(duì)象到mds進(jìn)程

Migrator::handle_export_ack(MExportDirAck *m)

|__在export_state數(shù)組中查找dirfrag對(duì)應(yīng)的項(xiàng)

|__將消息中的imported_caps解析到export_state_t中的peer_imported中

|__設(shè)置對(duì)應(yīng)項(xiàng)的state為EXPORT_LOGGINGFINISH

|__創(chuàng)建EExport類對(duì)象

|__將bounds數(shù)組中的內(nèi)容寫入到EExport類對(duì)象的metablob中

|__創(chuàng)建C_MDS_ExportFinishLogged回調(diào)函數(shù)類

|__啟動(dòng)mdlog,即:mds->mdlog->submit_entry()/mds->mdlog->flush()

Migator::export_logged_finish(dir)

|__查找export_state數(shù)組中指定dir的export_state_t項(xiàng)

|__遍歷export_state_t項(xiàng)中的notify_ack_waiting數(shù)組

     |__創(chuàng)建MExportDirNotify類消息

     |__發(fā)送MExportDirNotify類消息到mds進(jìn)程

|__設(shè)置export_state_t中的狀態(tài)為EXPORT_NOTIFYING

|__創(chuàng)建MExportDirFinish類消息

|__發(fā)送MExportDirFinish類消息到mds進(jìn)程

Migrator::handle_export_finish(MExportDirFinish *m)     (對(duì)端)

|__在import_state數(shù)組中找到對(duì)應(yīng)項(xiàng)

|__調(diào)用import_finish()函數(shù)

Migrator::import_finish(dir, notify, last)     (對(duì)端)

|__從import_state數(shù)組中得到指定dirfrag

|__若state==IMPORT_ACKING

     |__遍歷import_state_t中的peer_exports數(shù)組

          |__更新MDCache中的內(nèi)容

|__若last==false

     |__設(shè)置state=IMPORT_FINISHING

     |__直接返回

|__處理MDCache中的內(nèi)容

=======================export client maps and client caps

Migrator::encode_export_inode_caps(in, auth_cap, bl, exported_client_map)     得到client map以及client caps map

|__調(diào)用in->export_client_caps()函數(shù),得到in的client capability map信息

|__將client capability map信息序列化到bl中

|__遍歷in的client_caps數(shù)組

     |__從mds的sessionmap中得到client_caps數(shù)組成員對(duì)應(yīng)的信息并寫入到exported_client_map中

Migrator::export_caps(CInode *in)

|__從in中得到授權(quán)的mds_rank_t信息,即:in->authority().first

|__創(chuàng)建MExportCaps類消息

|__設(shè)置類消息的ino為in->ino()

|__調(diào)用encode_export_inode_caps()

|__調(diào)用mds的send_message_mds()函數(shù)將MExportCaps消息發(fā)送給指定的MDS進(jìn)程

Migrator::handle_export_caps(MExportCaps *ex)

|__從MDCache中得到類消息中的CInode信息,即:in=cache->get_inode(ex->ino)

|__若in處于frozen狀態(tài)

     |__直接返回

|__創(chuàng)建C_M_LoggedImportCaps回調(diào)函數(shù)類

|__將類消息中的client_map信息寫入到回調(diào)函數(shù)類的client_map中

|__調(diào)用decode_import_inode_caps()函數(shù)將類消息中的client caps信息反序列化并保存到peer_exports數(shù)組中

|__創(chuàng)建ESession類型的LogEvent類消息(client_map)

|__寫mdlog日志,即:mds->mdlog->start_submit_entry()

|__調(diào)用mds->mdlog->flush()     刷mdlog日志

Migrator::handle_gather_caps(MGatherCaps *m)

|__從MDCache中得到類消息對(duì)應(yīng)的CInode信息,即:cache->get_inode(m->ino)

|__若in存在caps并且in不存在auth并且in沒(méi)有EXPORTINGCAPS

     |__調(diào)用export_caps(in)          將in對(duì)應(yīng)的client maps和client caps map export出去

Migrator導(dǎo)入導(dǎo)出狀態(tài)機(jī)處理過(guò)程如下圖所示:

Migrator類怎么用

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Migrator類怎么用”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI