千家信息网

Migrator类怎么用

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章主要介绍了Migrator类怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。Migrator类说明:class Migra
千家信息网最后更新 2026年10月31日Migrator类怎么用

这篇文章主要介绍了Migrator类怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

Migrator类说明:

class Migrator {     MDSRank *mds;          记录mds信息     MDCache *cache;          记录MDCache信息     struct export_state_t {          int state;                    记录export的当前状态          mds_rank_t peer;          记录export到对端mds rank信息          uint64_t tid;                    记录export到对端的session id信息          set warning_ack_waiting;     等待warning ack的mds集合          set notify_ack_waiting;          等待notify ack的mds集合          map> peer_imported;     记录export对端信息          list 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 export_state;          export的状态集合     list> export_queue;     export队列     struct import_state_t {          int state;          mds_rank_t peer;          uint64_t tid;          set bystanders;          list bound_ls;          list updated_scatterlocks;          map client_map;          map> peer_exports;          MutationRef mut;     };     map 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导入导出状态机处理过程如下图所示:

感谢你能够认真阅读完这篇文章,希望小编分享的"Migrator类怎么用"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!

数组 消息 信息 函数 对象 状态 类型 进程 成员 内容 节点 检查 数据 结构 处理 序列 日志 篇文章 叶子 目的 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广东猪兼强互联网科技有限公司 互联网科技公司起名 中关村互联网 科技集团 深圳互联网络科技有限公司 成都互联网科技公司 广西互联网科技公司 深圳互联网科技怎么样 深圳国际航运科技和互联网 互联网之后的科技是什么 互联网大会黑科技排名 未来五年的互联网科技 电子科技大学互联网创业大赛 广西互联网科技孵化中心 众安科技工业互联网合作 陕西云淼互联网科技公司 新氧科技和美国互联网有关系吗 信承诺互联网科技有限公司 张家口科技产业互联网平台 中国互联网公司的科技投入 互联网企业和网络科技有限公司 沃里互联网科技 互联网金融和金融科技 互联网大会黑科技排名 晓花互联网科技有限公司网址 无锡工业互联网科技有限公司 众安科技工业互联网合作 2021世界互联网领先科技成果发布 互联网时代高科技布局 陕西彩京云互联网科技有限公司 中国主要互联网科技公司
0