]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados.cc: added listomap and getomap commands
authorEleanor Cawthon <eleanor.cawthon@inktank.com>
Tue, 29 May 2012 18:59:15 +0000 (11:59 -0700)
committerEleanor Cawthon <eleanor.cawthon@inktank.com>
Tue, 29 May 2012 20:33:15 +0000 (13:33 -0700)
Signed-off-by: Eleanor Cawthon <eleanor.cawthon@inktank.com>
src/rados.cc

index 526a9e4e314d93d6faae4fcc496e9864e95509fc..a831260df3c2dc793a5a524c4d170cc1e80a1627 100644 (file)
@@ -37,6 +37,7 @@ using namespace librados;
 #include <errno.h>
 #include <dirent.h>
 #include <stdexcept>
+#include <climits>
 
 #include "common/errno.h"
 
@@ -77,6 +78,8 @@ void usage(ostream& out)
 "   bench <seconds> write|seq|rand [-t concurrent_operations]\n"
 "                                    default is 16 concurrent IOs and 4 MB ops\n"
 "   load-gen [options]               generate load on the cluster\n"
+"   listomap <obj-name>              list the keys in the object map\n"
+"   getomap <obj-name> <key>         show the value for the specified key in the object's object map"
 "\n"
 "IMPORT AND EXPORT\n"
 "   import [options] <local-directory> <rados-pool>\n"
@@ -1343,7 +1346,43 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
     cout << "load-gen will run " << lg.run_length << " seconds" << std::endl;
     lg.run();
     lg.cleanup();
-  }  else {
+  } else if (strcmp(nargs[0], "listomap") == 0) {
+    if (!pool_name || nargs.size() < 2)
+      usage_exit();
+
+    librados::ObjectReadOperation read;
+    set<string> out_keys;
+    read.omap_get_keys("", LONG_MAX, &out_keys, &ret);
+    io_ctx.operate(nargs[1], &read, NULL);
+    if (ret < 0) {
+      cerr << "error getting omap key set " << pool_name << "/" << nargs[1] << ": "
+         << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
+      return 1;
+    }
+
+    for (set<string>::iterator iter = out_keys.begin();
+        iter != out_keys.end(); ++iter) {
+      cout << *iter << std::endl;
+    }
+  } else if (strcmp(nargs[0],"getomap") == 0){
+      if (!pool_name || nargs.size() < 3)
+       usage_exit();
+      librados::ObjectReadOperation read;
+      set<string> in_keys;
+      map<string,bufferlist> out_map;
+      in_keys.insert(nargs[2]);
+      read.omap_get_vals_by_keys(in_keys, &out_map, &ret);
+      io_ctx.operate(nargs[1], &read, NULL);
+      if (ret < 0) {
+       cerr << "error getting omap key set " << pool_name << "/" << nargs[1] << ": "
+           << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
+       return 1;
+      }
+      for (map<string,bufferlist>::iterator iter = out_map.begin();
+              iter != out_map.end(); ++iter) {
+      cout << iter->second <<std::endl;
+      }
+    } else {
     cerr << "unrecognized command " << nargs[0] << std::endl;
     usage_exit();
   }