From c97c14f6de4d1ef0772a1a1e0626e1cc08baf443 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 12 Feb 2012 20:47:02 -0800 Subject: [PATCH] osd: use single helper for pg creation Take a bool so that we initialize the last_epoch_started properly on newly created PGs. This gives us a single code path for all new PGs. We drop the clear_primary_state(), which has no effect, given that this is a newly constructed PG. Signed-off-by: Sage Weil --- src/osd/OSD.cc | 49 +++++++++++++++++++++---------------------------- src/osd/OSD.h | 5 +++-- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 070861fac278f..9f76dbe85dd3a 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1065,29 +1065,30 @@ PG *OSD::_open_lock_pg(pg_t pgid, bool no_lockdep_check) return pg; } -PG *OSD::_create_lock_new_pg(pg_t pgid, vector& acting, ObjectStore::Transaction& t, - pg_history_t history) +PG *OSD::_create_lock_pg(pg_t pgid, bool newly_created, + int role, vector& up, vector& acting, pg_history_t history, + ObjectStore::Transaction& t) { assert(osd_lock.is_locked()); - dout(20) << "_create_lock_new_pg pgid " << pgid << " -> " << acting << dendl; - assert(whoami == acting[0]); - assert(pg_map.count(pgid) == 0); + dout(20) << "_create_lock_pg pgid " << pgid << dendl; PG *pg = _open_lock_pg(pgid, true); assert(!store->collection_exists(coll_t(pgid))); t.create_collection(coll_t(pgid)); - /* This is weird, but all the peering code needs last_epoch_start - * to be less than same_interval_since. Make it so! - * This is easier to deal with if you remember that the PG, while - * now created in memory, still hasn't peered and started -- and - * the map epoch could change before that happens! */ - history.last_epoch_started = history.epoch_created - 1; + if (newly_created) { + /* This is weird, but all the peering code needs last_epoch_start + * to be less than same_interval_since. Make it so! + * This is easier to deal with if you remember that the PG, while + * now created in memory, still hasn't peered and started -- and + * the map epoch could change before that happens! */ + history.last_epoch_started = history.epoch_created - 1; + } - pg->init(0, acting, acting, history, &t); + pg->init(role, acting, acting, history, &t); - dout(7) << "_create_lock_new_pg " << *pg << dendl; + dout(7) << "_create_lock_pg " << *pg << dendl; return pg; } @@ -1230,19 +1231,7 @@ PG *OSD::get_or_create_pg(const pg_info_t& info, epoch_t epoch, int from, int& c // ok, create PG locally using provided Info and History *pt = new ObjectStore::Transaction; *pfin = new C_Contexts(g_ceph_context); - if (create) { - pg = _create_lock_new_pg(info.pgid, acting, **pt, history); - } else { - pg = _open_lock_pg(info.pgid); - - // create collection - assert(!store->collection_exists(coll_t(info.pgid))); - (*pt)->create_collection(coll_t(info.pgid)); - - pg->init(role, up, acting, history, *pt); - - pg->clear_primary_state(); // yep, notably, set hml=false - } + pg = _create_lock_pg(info.pgid, create, role, up, acting, history, **pt); created++; dout(10) << *pg << " is new" << dendl; @@ -4025,7 +4014,9 @@ void OSD::kick_pg_split_queue() history.epoch_created = history.same_up_since = history.same_interval_since = history.same_primary_since = osdmap->get_epoch(); - PG *pg = _create_lock_new_pg(*q, creating_pgs[*q].acting, *t, history); + PG *pg = _create_lock_pg(*q, true, + 0, creating_pgs[*q].acting, creating_pgs[*q].acting, history, + *t); children[*q] = pg; } @@ -4269,7 +4260,9 @@ void OSD::handle_pg_create(OpRequest *op) ObjectStore::Transaction *t = new ObjectStore::Transaction; C_Contexts *fin = new C_Contexts(g_ceph_context); - PG *pg = _create_lock_new_pg(pgid, creating_pgs[pgid].acting, *t, history); + PG *pg = _create_lock_pg(pgid, true, + 0, creating_pgs[pgid].acting, creating_pgs[pgid].acting, history, + *t); creating_pgs.erase(pgid); wake_pg_waiters(pg->info.pgid); diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 2eff15d72e661..356aeab3f95fc 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -443,8 +443,9 @@ protected: bool _have_pg(pg_t pgid); PG *_lookup_lock_pg(pg_t pgid); PG *_open_lock_pg(pg_t pg, bool no_lockdep_check=false); // create new PG (in memory) - PG *_create_lock_new_pg(pg_t pgid, vector& acting, ObjectStore::Transaction& t, - pg_history_t history); + PG *_create_lock_pg(pg_t pgid, bool newly_created, + int role, vector& up, vector& acting, pg_history_t history, + ObjectStore::Transaction& t); PG *lookup_lock_raw_pg(pg_t pgid); -- 2.39.5