]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_objectstore_tool: use '_remove' pgmeta omap key to indicate removal too
authorSage Weil <sage@redhat.com>
Fri, 5 Dec 2014 01:15:29 +0000 (17:15 -0800)
committerSage Weil <sage@redhat.com>
Wed, 17 Dec 2014 01:07:58 +0000 (17:07 -0800)
We could conceivably mark the PG for backfill, but to do this correctly
we have to do the log rollback, which uses various methods in PG to update
snap metadata that we simply don't have access to from this tool.

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/PG.cc
src/tools/ceph_objectstore_tool.cc

index b857aaf836f03d679bc0fbaa227502a599e760d1..279c649d3d928d212b42c0880f93a452b3274f78 100644 (file)
@@ -2708,6 +2708,17 @@ bool PG::_has_removal_flag(ObjectStore *store,
                           spg_t pgid)
 {
   coll_t coll(pgid);
+  ghobject_t pgmeta_oid(pgid.make_pgmeta_oid());
+
+  // first try new way
+  set<string> keys;
+  keys.insert("_remove");
+  map<string,bufferlist> values;
+  if (store->omap_get_values(coll, pgmeta_oid, keys, &values) == 0 &&
+      values.size() == 1)
+    return true;
+
+  // try old way
   char val;
   if (store->collection_getattr(coll, "remove", &val, 1) > 0)
     return true;
index 523d3594707f4bd2181d787bce17d6935b40287b..b555774398ff429b9dafee60b8d5c5c57ff06a16 100644 (file)
@@ -707,28 +707,57 @@ int finish_remove_pgs(ObjectStore *store)
   return 0;
 }
 
-int initiate_new_remove_pg(ObjectStore *store, spg_t r_pgid)
+int mark_pg_for_removal(ObjectStore *fs, spg_t pgid, ObjectStore::Transaction *t)
 {
-  ObjectStore::Transaction *rmt = new ObjectStore::Transaction;
+  pg_info_t info(pgid);
+  coll_t coll(pgid);
+  ghobject_t pgmeta_oid(info.pgid.make_pgmeta_oid());
 
-  if (store->collection_exists(coll_t(r_pgid))) {
-    cout << " marking collection for removal" << std::endl;
+  bufferlist bl;
+  PG::peek_map_epoch(fs, pgid, OSD::make_infos_oid(), &bl);
+  map<epoch_t,pg_interval_t> past_intervals;
+  interval_set<snapid_t> snap_collections;
+  __u8 struct_v;
+  int r = PG::read_info(fs, pgid, coll, bl, info, past_intervals,
+                       infos_oid, snap_collections, struct_v);
+  if (r < 0) {
+    cerr << __func__ << " error on read_info " << cpp_strerror(-r) << std::endl;
+    return r;
+  }
+  if (struct_v < 8) {
+    // old xattr
+    cout << "setting legacy 'remove' xattr flag" << std::endl;
     bufferlist one;
     one.append('1');
-    rmt->collection_setattr(coll_t(r_pgid), "remove", one);
+    t->collection_setattr(coll, "remove", one);
+    cout << "remove " << META_COLL << " " << log_oid.hobj.oid << std::endl;
+    t->remove(META_COLL, log_oid);
+    cout << "remove " << META_COLL << " " << biginfo_oid.oid << std::endl;
+    t->remove(META_COLL, biginfo_oid);
   } else {
-    delete rmt;
-    return ENOENT;
+    // new omap key
+    cout << "setting '_remove' omap key" << std::endl;
+    map<string,bufferlist> values;
+    ::encode((char)1, values["_remove"]);
+    t->omap_setkeys(coll, pgmeta_oid, values);
   }
+  return 0;
+}
 
-  cout << "remove " << META_COLL << " " << log_oid.hobj.oid << std::endl;
-  rmt->remove(META_COLL, log_oid);
-  cout << "remove " << META_COLL << " " << biginfo_oid.oid << std::endl;
-  rmt->remove(META_COLL, biginfo_oid);
+int initiate_new_remove_pg(ObjectStore *store, spg_t r_pgid)
+{
+  if (!store->collection_exists(coll_t(r_pgid)))
+    return -ENOENT;
 
+  cout << " marking collection for removal" << std::endl;
+  ObjectStore::Transaction *rmt = new ObjectStore::Transaction;
+  int r = mark_pg_for_removal(store, r_pgid, rmt);
+  if (r < 0) {
+    delete rmt;
+    return r;
+  }
   store->apply_transaction(*rmt);
-
-  return 0;
+  return r;
 }
 
 int header::get_header()
@@ -1583,15 +1612,14 @@ int do_import(ObjectStore *store, OSDSuperblock& sb)
     return 1;
   }
 
-  // mark this coll for removal until we are done
-  bufferlist one;
-  one.append('1');
   ObjectStore::Transaction *t = new ObjectStore::Transaction;
   PG::_create(*t, pgid);
   PG::_init(*t, pgid, NULL);
 
   // mark this coll for removal until we're done
-  t->collection_setattr(coll, "remove", one);
+  map<string,bufferlist> values;
+  ::encode((char)1, values["_remove"]);
+  t->omap_setkeys(coll, pgid.make_pgmeta_oid(), values);
 
   store->apply_transaction(*t);
   delete t;
@@ -1634,9 +1662,11 @@ int do_import(ObjectStore *store, OSDSuperblock& sb)
   }
 
   // done, clear removal flag
-  cout << "done, clearing remove flag" << std::endl;
+  cout << "done, clearing removal flag flag" << std::endl;
   t = new ObjectStore::Transaction;
-  t->collection_rmattr(coll, "remove");
+  set<string> remove;
+  remove.insert("_remove");
+  t->omap_rmkeys(coll, pgid.make_pgmeta_oid(), remove);
   store->apply_transaction(*t);
   delete t;