]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: pg_t::is_split(): make children out param a pointer, and optional
authorSage Weil <sage@newdream.net>
Mon, 27 Feb 2012 22:35:21 +0000 (14:35 -0800)
committerSage Weil <sage@newdream.net>
Mon, 27 Feb 2012 22:35:21 +0000 (14:35 -0800)
Also unit test it.

Signed-off-by: Sage Weil <sage@newdream.net>
src/osd/OSD.cc
src/osd/osd_types.cc
src/osd/osd_types.h
src/test/test_osd_types.cc

index b1f4dabab43c65b55e166487f1bfe375e40201b4..673833b0c364771154660bc6e706edc493087adc 100644 (file)
@@ -3654,7 +3654,7 @@ void OSD::advance_map(ObjectStore::Transaction& t, C_Contexts *tfin)
        pg_t pgid = it->first;
        PG *pg = it->second;
        set<pg_t> children;
-       if (pgid.is_split(p->second, pg->pool->info.pg_num, children)) {
+       if (pgid.is_split(p->second, pg->pool->info.pg_num, &children)) {
          do_split(pg, children, t, tfin);
        }
       }
index 68f3cb45121f841069fa944e3f4da107b7a37fe7..54adcd87ac3d546305e96aa4403cd780178f731d 100644 (file)
@@ -180,12 +180,13 @@ bool pg_t::parse(const char *s)
   return true;
 }
 
-bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t>children) const
+bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *children) const
 {
   assert(m_seed < old_pg_num);
   if (new_pg_num <= old_pg_num)
     return false;
 
+  bool split = false;
   if (true) {
     int old_bits = pg_pool_t::calc_bits_of(old_pg_num);
     int old_mask = (1 << old_bits) - 1;
@@ -197,8 +198,11 @@ bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t>& childre
        continue;
       if (s >= new_pg_num)
        break;
-      if ((unsigned)ceph_stable_mod(s, old_pg_num, old_mask) == m_seed)
-       children.insert(pg_t(s, m_pool, m_preferred));
+      if ((unsigned)ceph_stable_mod(s, old_pg_num, old_mask) == m_seed) {
+       split = true;
+       if (children)
+         children->insert(pg_t(s, m_pool, m_preferred));
+      }
     }
   }
   if (false) {
@@ -207,11 +211,13 @@ bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t>& childre
     int old_mask = (1 << old_bits) - 1;
     for (unsigned x = old_pg_num; x < new_pg_num; ++x) {
       unsigned o = ceph_stable_mod(x, old_pg_num, old_mask);
-      if (o == m_seed)
-       children.insert(pg_t(x, m_pool, m_preferred));
+      if (o == m_seed) {
+       split = true;
+       children->insert(pg_t(x, m_pool, m_preferred));
+      }
     }
   }
-  return !children.empty();
+  return split;
 }
 
 void pg_t::dump(Formatter *f) const
index 281c60f0f3dcfdbddae192046a8841f3a5bc5e3d..667bdb2b49813302a7dba3ac16f57fade22121f2 100644 (file)
@@ -238,7 +238,7 @@ struct pg_t {
   int print(char *o, int maxlen) const;
   bool parse(const char *s);
 
-  bool is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t>children) const;
+  bool is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *pchildren) const;
 
   void encode(bufferlist& bl) const {
     __u8 v = 1;
index 910d822172ce799bbb3a425bb01b87fdafcaaf5a..3d1373e3c5e264bd21183c1515ffda11663846e0 100644 (file)
@@ -30,6 +30,8 @@ TEST(pg_t, split)
   ASSERT_TRUE(!b);
 
   s.clear();
+  b = pgid.is_split(2, 4, NULL);
+  ASSERT_TRUE(b);
   b = pgid.is_split(2, 4, s);
   ASSERT_TRUE(b);
   ASSERT_EQ(1u, s.size());
@@ -50,6 +52,8 @@ TEST(pg_t, split)
   ASSERT_TRUE(s.count(pg_t(4, 0, -1)));
 
   s.clear();
+  b = pgid.is_split(6, 8, NULL);
+  ASSERT_TRUE(!b);
   b = pgid.is_split(6, 8, s);
   ASSERT_TRUE(!b);
   ASSERT_EQ(0u, s.size());