Migrator類分析

Migrator類說明:node

class Migrator {數組

     MDSRank *mds;          記錄mds信息session

     MDCache *cache;          記錄MDCache信息函數

     struct export_state_t {ui

          int state;                    記錄export的當前狀態spa

          mds_rank_t peer;          記錄export到對端mds rank信息日誌

          uint64_t tid;                    記錄export到對端的session id信息code

          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對端信息

          list<MDSInternalContextBase*> waiting_for_finish;                              記錄等待finish的集合

          MutationRef                     mut;      MutationImpl對象引用

          utime_t last_cum_auth_pins_change;

          int last_cum_auth_pins;

          int num_remote_waiters;              遠程auth pin waiters

     };

     map<CDir*, export_state_t> export_state;          export的狀態集合

     list<pair<dirfrag_t, mds_rank_t>> export_queue;     export隊列

     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)                              核心分發處理函數

|__根據m的類型決定後續的處理過程

     |__類型是MSG_MDS_EXPORTDIRDISCOVER

          |__調用handle_export_discover(MExportDirDiscover* m)

     |__類型是MSG_MDS_EXPORTDIRPREP

          |__調用handle_export_prep(MExportDirPrep* m)

     |__類型是MSG_MDS_EXPORTDIR

          |__調用handle_export_dir(MExportDir* m)

     |__類型是MSG_MDS_EXPORTDIRFINISH

          |__調用handle_export_finsih(MExportDirFinish* m)

     |__類型是MSG_MDS_EXPORTDIRCANCEL

          |__調用handle_export_cancel(MExportDirCancel* m)

     |__類型是MSG_MDS_EXPORTDIRDISCOVERACK

          |__調用handle_export_discover_ack(MExportDirDiscoverAck* m)

     |__類型是MSG_MDS_EXPORTDIRPREACK

          |__調用handle_export_prep_ack(MExportDirPrepAck* m)

     |__類型是MSG_MDS_EXPORTDIRACK

          |__調用handle_export_ack(MExportDirAck* m)

     |__類型是MSG_MDS_EXPORTDIRNOTIFYACK

          |__調用handle_export_notify_ack(MExportDirNotifyAck* m)

     |__類型是MSG_MDS_EXPORTDIRNOTIFY

          |__調用handle_export_dir_notify(MExportDirNotify* m)

     |__類型是MSG_MDS_EXPORTCAPS

          |__調用handle_export_caps(MExportCaps* m)

     |__類型是MSG_MDS_GATHERCAPS     

          |__調用handle_gather_caps(MGatherCaps* m)

 

Migrator::export_empty_import(dir)

|__dir對應的inode節點是auth的

     |__直接返回

|__dir是auth的

     |__直接返回

|__dir是freezing或frozen

     |__直接返回

|__dir不是空目錄

     |__直接返回

|__dir是root節點

     |__直接返回

|__獲得export目的dir所在的mds節點,即:dir->inode->authority().first

|__調用export_dir(dir, dest)               執行實際的export操做

 

Migrator::export_dir(dir, dest)

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

     |__直接返回

|__檢查mdsmap是不是degraded(cluster處於degraded狀態則不能export)

     |__直接返回

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

     |__直接返回

|__檢查dir的inode是不是stray

     |__直接返回

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

     |__直接返回

|__檢查dir是否處於EXPORTING狀態

     |__直接返回

|__執行dir的auth_pin()

|__設置dir的當前狀態爲EXPORTING,即:dir->state_set(STATE_EXPORTING)

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

|__設置MDRequest類對象中的_more的export_dir爲dir,即:保存待export的dir數據

|__從export_state數組中獲得dir爲索引對應的export_state_t對象stat

|__設置stat的state爲EXPORT_LOCKING

|__設置stat的peer爲dest

|__設置stat的tid爲mdr->reqid.tid

|__設置stat的mut爲mdr

|__調用dispatch_export_dir(mdr)來發送export dir請求

 

Migrator::dispatch_export_dir(mdr)

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

|__從export_state數組中找到dir對應的export state項

|__設置export_state_t的當前狀態是EXPORT_DISCOVERING

|__建立MExportDirDiscover類消息

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

|__設置export_state_t中的last_cum_auth_pins_change爲系統當前時間

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

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

 

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

|__從消息中獲得對端的mds_rank_t以及dirfrag_t結構,即:from=m->get_source_mds()/df = m->get_dirfrag()

|__遍歷import_state數組

     |__若數組中沒有找到對應的項且m->started==false

          |__設置m->started=true

          |__更新import_state數組中對應的項,即:state=IMPORT_DISCOVERING/peer=from/tid=m->get_tid()

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

|__更新import_state數組中對應的項,即:state==IMPORT_DISCOVERED

|__建立MExportDirDiscoverAck類消息

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

 

Migrator::handle_export_discover_ack(MExportDirDiscoverAck* m)

|__從消息中獲得dirfrag,以後從MDCache中獲得dirfrag對應的CDir類對象,即:cache->get_dirfrag(m->get_dirfrag())

|__在export_state數組中查找dir對應的項

|__在export_state數組對應的dir項中設置其狀態爲EXPORT_FREEZING

 

Migrator::export_frozen(dir, tid)

|__從export_state數組中查找dir對應的項

|__獲得該dir對應的CInode,即:dir->get_inode()

|__建立一個新的MutationImpl類對象且將其放入export_state_t的mut中

|__根據dirfrag和tid建立一個MExportDirPrep類消息

|__遍歷dir的replicas數組

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

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

|__遍歷bounds數組

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

     |__循環處理以下內容

          |__將bounds成員的inode添加到inodes_added數組中

          |__遍歷bounds成員的parent目錄

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

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

|__設置export_state_t中的狀態爲EXPORT_PREPPING

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

 

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

|__從import_state數組中找到消息中對應的dirfrag項

|__從MDCache中獲得dir和dir對應的CInode

|__遍歷消息中的bounds數組

     |__將數組中的內容添加到import_bound_fragset數組中

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

     |__設置當前import_state數組中對應項的state爲IMPORT_PREPPING

     |__從消息中解析traces數組

          |__將traces數組中的內容添加到MDCache中

     |__遍歷import_bound_fragset數組

          |__從數組成員的inodeno_t的到對應的CInode結構

          |__調用CInode對應的get_stickydirs()函數

|__遍歷import_bound_fragset數組

     |__從數組成員的inodeno_t的到對應的CInode結構

     |__遍歷數組成員中fragset_t下全部葉子節點

          |__根據葉子節點獲得在MDCache中對應的CDir數據

          |__若CDir數據不在MDCache中

               |__執行MDCache中的open_remote_dirfrag()函數來建立這個CDir

          |__將葉子節點對應的CDir數據插入到import_bounds數組中

|__設置import_state數組指定成員的狀態爲IMPORT_PREPPED

|__建立MExportDirPreAck類消息

|__調用mds的send_message()方法將類消息發送給指定的MDS進程

 

Migrator::handle_export_prep_ack(MExportDirPrepAck *m)

|__根據消息的dirfrag獲得對應的CDir類對象

|__在export_state數組中查找CDir類對象對應的項

|__遍歷replicas數組

     |__將mds_rank_t信息插入到export_state_t結構中的warning_ack_waiting/notify_ack_waiting數組中

     |__建立MExportDirNotify類消息

     |__將MEXportDirNotify類消息發送給對端mds進程

|__設置export_state_t結構中的state爲EXPORT_WARNING

 

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

|__從MDCache中獲得消息中dirfrag對應的CDir類對象

|__建立MExportDirNotifyAck類消息

|__調用mds的send_message_mds()將類消息發送回給mds進程

 

Migrator::handle_export_notify_ack(MExportDirNotifyAck *m)

|__根據消息的dirfrag獲得對應的CDir類對象

|__從消息中獲得對端mds_rank_t信息

|__若在export_state數組中可以找到dir對應的項

     |__若export_state_t的state==EXPORT_WARNING

          |__調用export_go(dir)     執行實際的export操做

     |__若export_state_t的state==EXPORT_NOTIFYING

          |__調用export_finish(dir)

 

Migrator::export_go(dir)

|__調用哦mds中mdlog的wait_for_safe()函數來設置回調函數C_M_ExportGo(),最後執行export_go_synced(dir, tid)

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

 

Migrator::export_go_synced(dir, tid)

|__在export_state數組中查找dir對應的項

|__設置其狀態爲EXPORT_EXPORTING

|__建立MExportDir類消息

|__調用encode_export_dir()獲得export的map信息以及獲得exported_inodes數量

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

|__遍歷bounds數組

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

|__發送類消息到對端mds進程,即:mds->send_message_mds()

 

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

|__從MDCache中獲得消息中dirfrag對應的CDir類對象

|__從import_state數組中查到消息中dirfrag對象的項

|__建立C_MDS_ImportDirLoggedStart回調函數類

|__建立EImportStart日誌入口

|__調用MDS的mlog的start_entry()來啓動日誌

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

|__從消息中獲得export_data

|__調用decode_import_dir()函數,將export_data寫入到mdlog對應的current segment裏

|__遍歷消息中的bounds數組

     |__將數組中dirfrag_t對應的CDir添加到LogSegment中

     |__將數組中dirfrag_t對應的CDir添加到import_bounds數組中

|__調用mds的balancer的add_import()函數來平衡查找樹

|__設置import_state_t中的狀態爲IMPORT_LOGGINGSTART

|__啓動mdlog,即:mds->mdlog->submit_entry()/mds->mdlog->flush()

 

Migrator::import_logged_start()     (對端)

|__在import_state數組中查找dirfrag對應的項

|__設置對應項的state爲IMPORT_ACKING

|__建立MExportDirAck類對象

|__發送MExportDirAck類對象到mds進程

 

Migrator::handle_export_ack(MExportDirAck *m)

|__在export_state數組中查找dirfrag對應的項

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

|__設置對應項的state爲EXPORT_LOGGINGFINISH

|__建立EExport類對象

|__將bounds數組中的內容寫入到EExport類對象的metablob中

|__建立C_MDS_ExportFinishLogged回調函數類

|__啓動mdlog,即:mds->mdlog->submit_entry()/mds->mdlog->flush()

 

Migator::export_logged_finish(dir)

|__查找export_state數組中指定dir的export_state_t項

|__遍歷export_state_t項中的notify_ack_waiting數組

     |__建立MExportDirNotify類消息

     |__發送MExportDirNotify類消息到mds進程

|__設置export_state_t中的狀態爲EXPORT_NOTIFYING

|__建立MExportDirFinish類消息

|__發送MExportDirFinish類消息到mds進程

 

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

|__在import_state數組中找到對應項

|__調用import_finish()函數

 

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

|__從import_state數組中獲得指定dirfrag

|__若state==IMPORT_ACKING

     |__遍歷import_state_t中的peer_exports數組

          |__更新MDCache中的內容

|__若last==false

     |__設置state=IMPORT_FINISHING

     |__直接返回

|__處理MDCache中的內容

 

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

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

|__調用in->export_client_caps()函數,獲得in的client capability map信息

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

|__遍歷in的client_caps數組

     |__從mds的sessionmap中獲得client_caps數組成員對應的信息並寫入到exported_client_map中

 

Migrator::export_caps(CInode *in)

|__從in中獲得受權的mds_rank_t信息,即:in->authority().first

|__建立MExportCaps類消息

|__設置類消息的ino爲in->ino()

|__調用encode_export_inode_caps()

|__調用mds的send_message_mds()函數將MExportCaps消息發送給指定的MDS進程

 

Migrator::handle_export_caps(MExportCaps *ex)

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

|__若in處於frozen狀態

     |__直接返回

|__建立C_M_LoggedImportCaps回調函數類

|__將類消息中的client_map信息寫入到回調函數類的client_map中

|__調用decode_import_inode_caps()函數將類消息中的client caps信息反序列化並保存到peer_exports數組中

|__建立ESession類型的LogEvent類消息(client_map)

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

|__調用mds->mdlog->flush()     刷mdlog日誌

 

Migrator::handle_gather_caps(MGatherCaps *m)

|__從MDCache中獲得類消息對應的CInode信息,即:cache->get_inode(m->ino)

|__若in存在caps而且in不存在auth而且in沒有EXPORTINGCAPS

     |__調用export_caps(in)          將in對應的client maps和client caps map export出去

 

Migrator導入導出狀態機處理過程以下圖所示:

相關文章
相關標籤/搜索