]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools: add maxread in rados listomapkeys
authorlvshuhua <lvshuhua@cmss.chinamobile.com>
Sun, 29 Sep 2019 11:09:33 +0000 (19:09 +0800)
committerlvshuhua <lvshuhua@cmss.chinamobile.com>
Wed, 9 Oct 2019 03:29:53 +0000 (11:29 +0800)
could avoid a long wait when to search in large omap range

Signed-off-by: lvshuhua <lvshuhua@cmss.chinamobile.com>
src/tools/rados/rados.cc

index c90b3ec7a2b01b38ea721bba92f046eedff46694..3e3cae88bcd3dcfaf1c7540a82472cf93b1ff285 100644 (file)
@@ -407,6 +407,7 @@ void dump_name(Formatter *formatter, const librados::NObjectIterator& i, [[maybe
 } // namespace detail
 
 unsigned default_op_size = 1 << 22;
+static const unsigned MAX_OMAP_BYTES_PER_REQUEST = 1 << 10;
 
 [[noreturn]] static void usage_exit()
 {
@@ -2870,10 +2871,9 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
 
     string oid(nargs[1]);
     string last_read = "";
-    int MAX_READ = 512;
     do {
       map<string, bufferlist> values;
-      ret = io_ctx.omap_get_vals(oid, last_read, MAX_READ, &values);
+      ret = io_ctx.omap_get_vals(oid, last_read, MAX_OMAP_BYTES_PER_REQUEST, &values);
       if (ret < 0) {
        cerr << "error getting omap keys " << pool_name << "/" << oid << ": "
             << cpp_strerror(ret) << std::endl;
@@ -2898,7 +2898,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
        it->second.hexdump(cout);
        cout << std::endl;
       }
-    } while (ret == MAX_READ);
+    } while (ret == MAX_OMAP_BYTES_PER_REQUEST);
     ret = 0;
   }
   else if (strcmp(nargs[0], "cp") == 0) {
@@ -3342,18 +3342,22 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
       return 1;
     }
 
-    set<string> out_keys;
-    ret = io_ctx.omap_get_keys(nargs[1], "", LONG_MAX, &out_keys);
-    if (ret < 0) {
-      cerr << "error getting omap key set " << pool_name << "/"
-          << nargs[1] << ": "  << cpp_strerror(ret) << std::endl;
-      return 1;
-    }
+    string last_read;
+    bool more = true;
+    do {
+      set<string> out_keys;
+      ret = io_ctx.omap_get_keys2(nargs[1], last_read, MAX_OMAP_BYTES_PER_REQUEST, &out_keys, &more);
+      if (ret < 0) {
+        cerr << "error getting omap key set " << pool_name << "/"
+             << nargs[1] << ": "  << cpp_strerror(ret) << std::endl;
+        return 1;
+      }
 
-    for (set<string>::iterator iter = out_keys.begin();
-        iter != out_keys.end(); ++iter) {
-      cout << *iter << std::endl;
-    }
+      for (auto &key : out_keys) {
+        cout << key << std::endl;
+        last_read = std::move(key);
+      }
+    } while (more);
   } else if (strcmp(nargs[0], "lock") == 0) {
     if (!pool_name) {
       usage(cerr);