]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: add coll_t::get_temp() helper
authorSage Weil <sage@redhat.com>
Mon, 22 Dec 2014 20:12:35 +0000 (12:12 -0800)
committerSage Weil <sage@redhat.com>
Fri, 19 Jun 2015 00:02:46 +0000 (17:02 -0700)
Generate the temp collection for a pg collection.

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/osd_types.h
src/test/osd/types.cc

index 19d4ff909f6e96ab70292f0cdff92b6e48db1515..13c3931d54a97b7e9a779998f32c069fe09cc6e1 100644 (file)
@@ -513,6 +513,17 @@ public:
     return str != rhs.str;
   }
 
+  // get a TEMP collection that corresponds to the current collection,
+  // which we presume is a pg collection.
+  coll_t get_temp() {
+    spg_t pgid;
+    snapid_t snap;
+    bool foo = is_pg(pgid, snap);
+    assert(foo);
+    assert(snap == CEPH_NOSNAP);
+    return coll_t(str.substr(0, str.length() - 4) + "TEMP");
+  }
+
   void dump(Formatter *f) const;
   static void generate_test_instances(list<coll_t*>& o);
 
index 83d9c0fff479c8eea3d3310421a5324347417ef9..53283eb59aa8e209cea57317afcab97984e37dbd 100644 (file)
@@ -1292,6 +1292,20 @@ TEST(shard_id_t, iostream) {
     ASSERT_EQ(out.str(), "0,1,2");
 }
 
+TEST(coll_t, temp) {
+  spg_t pgid;
+  coll_t foo(pgid);
+  ASSERT_EQ(foo.to_str(), string("0.0_head"));
+
+  coll_t temp = foo.get_temp();
+  ASSERT_EQ(temp.to_str(), string("0.0_TEMP"));
+
+  spg_t pgid2;
+  ASSERT_TRUE(temp.is_temp());
+  ASSERT_TRUE(temp.is_temp(pgid2));
+  ASSERT_EQ(pgid, pgid2);
+}
+
 /*
  * Local Variables:
  * compile-command: "cd ../.. ;