]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: add 'tmap-to-omap' command 671/head
authorSage Weil <sage@inktank.com>
Wed, 2 Oct 2013 00:19:24 +0000 (17:19 -0700)
committerSage Weil <sage@inktank.com>
Wed, 2 Oct 2013 00:21:21 +0000 (17:21 -0700)
Explicitly convert tmap object data to omap keys.  Removes the old tmap
content at the same time.

Signed-off-by: Sage Weil <sage@inktank.com>
qa/workunits/rados/test_tmap_to_omap.sh [new file with mode: 0755]
src/tools/rados/rados.cc

diff --git a/qa/workunits/rados/test_tmap_to_omap.sh b/qa/workunits/rados/test_tmap_to_omap.sh
new file mode 100755 (executable)
index 0000000..76656ad
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh -ex
+
+expect_false()
+{
+       set -x
+       if "$@"; then return 1; else return 0; fi
+}
+
+pool="pool-$$"
+rados mkpool $pool
+
+rados -p $pool tmap set foo key1 value1
+rados -p $pool tmap set foo key2 value2
+rados -p $pool tmap set foo key2 value2
+rados -p $pool tmap dump foo | grep key1
+rados -p $pool tmap dump foo | grep key2
+rados -p $pool tmap-to-omap foo
+expect_false rados -p $pool tmap dump foo
+expect_false rados -p $pool tmap dump foo
+
+rados -p $pool listomapkeys foo | grep key1
+rados -p $pool listomapkeys foo | grep key2
+rados -p $pool getomapval foo key1 | grep value1
+rados -p $pool getomapval foo key2 | grep value2
+
+rados rmpool $pool $pool --yes-i-really-really-mean-it
+
+echo OK
index 009df5cd0af5b3a7ca0923bc86b9655e7c69a2f1..ad8eaa3e1a4a2563acd0dbc03730993a6696b9d6 100644 (file)
@@ -98,6 +98,7 @@ void usage(ostream& out)
 "   rmomapkey <obj-name> <key>\n"
 "   getomapheader <obj-name>\n"
 "   setomapheader <obj-name> <val>\n"
+"   tmap-to-omap <obj-name>          convert tmap keys/values to omap\n"
 "   listwatchers <obj-name>          list the watchers of this object\n"
 "\n"
 "IMPORT AND EXPORT\n"
@@ -1848,6 +1849,50 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
     }
   }
 
+  else if (strcmp(nargs[0], "tmap-to-omap") == 0) {
+    if (!pool_name || nargs.size() < 2)
+      usage_exit();
+    string oid(nargs[1]);
+
+    bufferlist bl;
+    int r = io_ctx.tmap_get(oid, bl);
+    if (r < 0) {
+      ret = r;
+      cerr << "error reading tmap " << pool_name << "/" << oid
+          << ": " << cpp_strerror(ret) << std::endl;
+      goto out;
+    }
+    bufferlist hdr;
+    map<string, bufferlist> kv;
+    bufferlist::iterator p = bl.begin();
+    try {
+      ::decode(hdr, p);
+      ::decode(kv, p);
+    }
+    catch (buffer::error& e) {
+      cerr << "error decoding tmap " << pool_name << "/" << oid << std::endl;
+      ret = -EINVAL;
+      goto out;
+    }
+    if (!p.end()) {
+      cerr << "error decoding tmap (stray trailing data) in " << pool_name << "/" << oid << std::endl;
+      ret = -EINVAL;
+      goto out;
+    }
+    librados::ObjectWriteOperation wr;
+    wr.omap_set_header(hdr);
+    wr.omap_set(kv);
+    wr.truncate(0);  // delete the old tmap data
+    r = io_ctx.operate(oid, &wr);
+    if (r < 0) {
+      ret = r;
+      cerr << "error writing tmap data as omap on " << pool_name << "/" << oid
+          << ": " << cpp_strerror(ret) << std::endl;
+      goto out;
+    }
+    ret = 0;
+  }
+
   else if (strcmp(nargs[0], "mkpool") == 0) {
     int auid = 0;
     __u8 crush_rule = 0;