【osd】PG的生成过程

 PG的生成过程

1. 首先将OSD对象new出来:

 1 osd = new OSD(g_ceph_context,
 2                 store,
 3                 whoami,
 4                 ms_cluster,
 5                 ms_public,
 6                 ms_hb_front_client,
 7                 ms_hb_back_client,
 8                 ms_hb_front_server,
 9                 ms_hb_back_server,
10                 ms_objecter,
11                 &mc,
12                 data_path,
13                 journal_path);

 2. 将osd初始化:

init中会call load_pgs();加载pg,在load_pgs之前有一个非常重要的细节,就是read_superblock,superblock中会保存上次持久化的osdmap epoch。拿到这个epoch之后再到store上去读取相应的osdmap,也就是osd最近一次持久化的osdmap,后面会用到。

int OSD::init()
3121   r = read_superblock();
...
3162   osdmap = get_map(superblock.current_epoch);
...
3235   // load up pgs (as they previously existed)
3236   load_pgs();
...
3397   dout(10) << "ensuring pgs have consumed prior maps" << dendl;
3398   consume_map();
...
3413   start_boot();
3414 
3415   return 0;

 

4. PG* OSD::_make_pg(OSDMapRef createmap, spg_t pgid):创造每个pg的类 pg = new PrimaryLogPG(&service, createmap, pool, ec_profile, pgid);

 

 1 PG::PG(OSDService *o, OSDMapRef curmap,
 2        const PGPool &_pool, spg_t p) :
 3   pg_id(p),
 4   coll(p),
 5   osd(o),
 6   cct(o->cct),
 7   osdmap_ref(curmap),
 8   pool(_pool),
 9   osdriver(osd->store, coll_t(), OSD::make_snapmapper_oid()),
10   snap_mapper(cct,
11               &osdriver,
12               p.ps(),
13               p.get_split_bits(_pool.info.get_pg_num()),
14               _pool.id,
15               p.shard),
16   last_persisted_osdmap(curmap->get_epoch()),
17   deleting(false),
18   trace_endpoint("0.0.0.0", 0, "PG"),
19   dirty_info(false), dirty_big_info(false),
20   info(p),
21   info_struct_v(0),
22   pg_log(cct),
23   pgmeta_oid(p.make_pgmeta_oid()),
24   missing_loc(this),
25   stat_queue_item(this),
26   scrub_queued(false),
27   recovery_queued(false),
28   recovery_ops_active(0),
29   role(-1),
30   state(0),
31   send_notify(false),
32   pg_whoami(osd->whoami, p.shard),
33   need_up_thru(false),
34   last_peering_reset(0),
35   heartbeat_peer_lock("PG::heartbeat_peer_lock"),
36   backfill_reserved(false),
37   backfill_reserving(false),
38   flushes_in_progress(0),
39   pg_stats_publish_lock("PG::pg_stats_publish_lock"),
40   pg_stats_publish_valid(false),
41   finish_sync_event(NULL),
42   backoff_lock("PG::backoff_lock"),
43   scrub_after_recovery(false),
44   save_req_scrub(false),
45   active_pushes(0),
46   recovery_state(this), // 创造状态机
47   peer_features(CEPH_FEATURES_SUPPORTED_DEFAULT),
48   acting_features(CEPH_FEATURES_SUPPORTED_DEFAULT),
49   upacting_features(CEPH_FEATURES_SUPPORTED_DEFAULT),
50   last_epoch(0),
51   last_require_osd_release(curmap->require_osd_release)
52 {
53 #ifdef PG_DEBUG_REFS
54   osd->add_pgid(p, this);
55 #endif
56 #ifdef WITH_BLKIN
57   std::stringstream ss;
58   ss << "PG " << info.pgid;
59   trace_endpoint.copy_name(ss.str());
60 #endif
61 }

 

 

void OSD::handle_pg_create(OpRequestRef op)

 

参考资料

1. osd restart之后pg如何达到active+clean

posted @ 2021-12-13 14:03  苏格拉底的落泪  阅读(254)  评论(0编辑  收藏  举报