]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/newstore: clone omap
authorSage Weil <sage@redhat.com>
Tue, 18 Aug 2015 14:10:25 +0000 (10:10 -0400)
committerSage Weil <sage@redhat.com>
Tue, 1 Sep 2015 17:39:35 +0000 (13:39 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/newstore/NewStore.cc

index 67c251bd4f227bd119d2404b5fe682eaf189d747..1f3f62eb2daf23bfdf9c375354397a6b39f46cff 100644 (file)
@@ -304,6 +304,14 @@ void get_omap_key(uint64_t id, const string& key, string *out)
   out->append(key);
 }
 
+void rewrite_omap_key(uint64_t id, string old, string *out)
+{
+  char buf[32];
+  snprintf(buf, sizeof(buf), "%016llx", (unsigned long long)id);
+  *out = buf;
+  out->append(old.substr(16));
+}
+
 void decode_omap_key(const string& key, string *user_key)
 {
   *user_key = key.substr(17);
@@ -486,8 +494,7 @@ NewStore::Collection::Collection(NewStore *ns, coll_t c)
   : store(ns),
     cid(c),
     lock("NewStore::Collection::lock"),
-    onode_map() //store->cct, store->cct->_conf->newstore_onode_map_size)
-#warning fixme size the lru/cache
+    onode_map()
 {
 }
 
@@ -3501,7 +3508,34 @@ int NewStore::_clone(TransContext *txc,
   r = _do_write(txc, newo, 0, oldo->onode.size, bl, 0);
 
   newo->onode.attrs = oldo->onode.attrs;
-  // fixme: omap
+
+  // clone omap
+  if (o->onode.omap_head) {
+    dout(20) << __func__ << " clearing old omap data" << dendl;
+    _do_omap_clear(txc, o->onode.omap_head, true);
+  }
+  if (oldo->onode.omap_head) {
+    dout(20) << __func__ << " copying omap data" << dendl;
+    _get_omap_id(txc, o);
+    KeyValueDB::Iterator it = db->get_iterator(PREFIX_OMAP);
+    string head, tail;
+    get_omap_header(oldo->onode.omap_head, &head);
+    get_omap_tail(oldo->onode.omap_head, &tail);
+    it->lower_bound(head);
+    while (it->valid()) {
+      string key;
+      if (it->key() == tail) {
+       dout(30) << __func__ << "  reached tail" << dendl;
+       break;
+      } else {
+       dout(30) << __func__ << "  got header/data " << it->key() << dendl;
+       assert(it->key() < tail);
+       rewrite_omap_key(o->onode.omap_head, it->key(), &key);
+       txc->t->set(PREFIX_OMAP, key, it->value());
+      }
+      it->next();
+    }
+  }
 
   txc->write_onode(newo);