]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: Support --all for rados bench cleanup
authorDavid Zafman <dzafman@redhat.com>
Fri, 1 Apr 2016 02:59:21 +0000 (19:59 -0700)
committerBoris Ranto <branto@redhat.com>
Fri, 6 May 2016 11:44:16 +0000 (13:44 +0200)
Remove duplicate code in generate_object_name()
Need to handle multiple different pids during cleanup
Add same message from clean_up_slow() in clean_up()

Signed-off-by: David Zafman <dzafman@redhat.com>
src/common/obj_bencher.cc
src/tools/rados/rados.cc

index b0f3ee7c506f327675f6310e1c504f8a8a1cd42b..443a98a920a610770eb9f7ed1ad2622583042169 100644 (file)
@@ -45,11 +45,10 @@ static std::string generate_object_prefix_nopid() {
 }
 
 static std::string generate_object_prefix(int pid = 0) {
-  if (!cached_pid) {
-    if (!pid)
-      pid = getpid();
+  if (pid)
     cached_pid = pid;
-  }
+  else if (!cached_pid)
+    cached_pid = getpid();
 
   std::ostringstream oss;
   oss << generate_object_prefix_nopid() << "_" << cached_pid;
@@ -58,19 +57,9 @@ static std::string generate_object_prefix(int pid = 0) {
 
 static std::string generate_object_name(int objnum, int pid = 0)
 {
-  if (cached_hostname[0] == 0) {
-    gethostname(cached_hostname, sizeof(cached_hostname)-1);
-    cached_hostname[sizeof(cached_hostname)-1] = 0;
-  }
-  if (!cached_pid) {
-    if (!pid)
-      pid = getpid();
-    cached_pid = pid;
-  }
-
-  char name[1024];
-  size_t l = sprintf(&name[0], "%s_%s_%d_object%d", BENCH_PREFIX.c_str(), cached_hostname, cached_pid, objnum);
-  return string(&name[0], l);
+  std::ostringstream oss;
+  oss << generate_object_prefix(pid) << "_object" << objnum;
+  return oss.str();
 }
 
 static void sanitize_object_contents (bench_data *data, size_t length) {
@@ -1095,29 +1084,57 @@ int ObjBencher::clean_up(const std::string& orig_prefix, int concurrentios, cons
   size_t op_size, object_size;
   int num_objects;
   int prevPid;
-  std::string prefix = orig_prefix;
 
   // default meta object if user does not specify one
   const std::string run_name_meta = (run_name.empty() ? BENCH_LASTRUN_METADATA : run_name);
+  const std::string prefix = (orig_prefix.empty() ? generate_object_prefix_nopid() : orig_prefix);
+
+  std::list<Object> unfiltered_objects;
+  std::set<std::string> meta_namespaces, all_namespaces;
 
-  r = fetch_bench_metadata(run_name_meta, &op_size, &object_size, &num_objects, &prevPid);
-  if (r < 0) {
-    // if the metadata file is not found we should try to do a linear search on the prefix
-    if (r == -ENOENT) {
-      if (prefix == "")
-       prefix = generate_object_prefix_nopid();
-      return clean_up_slow(prefix, concurrentios);
+  // If caller set all_nspaces this will be searching
+  // across multiple namespaces.
+  while (true) {
+    bool objects_remain = get_objects(&unfiltered_objects, 20);
+    if (!objects_remain)
+      break;
+
+    std::list<Object>::const_iterator i = unfiltered_objects.begin();
+    for ( ; i != unfiltered_objects.end(); ++i) {
+      if (i->first == run_name_meta) {
+        meta_namespaces.insert(i->second);
+      }
+      if (i->first.substr(0, prefix.length()) == prefix) {
+        all_namespaces.insert(i->second);
+      }
     }
-    else {
+  }
+
+  std::set<std::string>::const_iterator i = all_namespaces.begin();
+  for ( ; i != all_namespaces.end(); ++i) {
+    set_namespace(*i);
+
+    // if no metadata file found we should try to do a linear search on the prefix
+    if (meta_namespaces.find(*i) == meta_namespaces.end()) {
+      int r = clean_up_slow(prefix, concurrentios);
+      if (r < 0) {
+        cerr << "clean_up_slow error r= " << r << std::endl;
+        return r;
+      }
+      continue;
+    }
+
+    r = fetch_bench_metadata(run_name_meta, &op_size, &object_size, &num_objects, &prevPid);
+    if (r < 0) {
       return r;
     }
-  }
 
-  r = clean_up(num_objects, prevPid, concurrentios);
-  if (r != 0) return r;
+    r = clean_up(num_objects, prevPid, concurrentios);
+    if (r != 0) return r;
 
-  r = sync_remove(run_name_meta);
-  if (r != 0) return r;
+    r = sync_remove(run_name_meta);
+    if (r != 0) return r;
+  }
 
   return 0;
 }
@@ -1241,6 +1258,8 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
 
   completions_done();
 
+  out(cout) << "Removed " << data.finished << " object" << (data.finished != 1 ? "s" : "") << std::endl;
+
   return 0;
 
  ERR:
index 3fe6fdf086b72c35ae03527fd882510e4c057362..a3962c6837fdc42f1a881f82763d86fbd6ccba01 100644 (file)
@@ -2816,6 +2816,8 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
   else if (strcmp(nargs[0], "cleanup") == 0) {
     if (!pool_name)
       usage_exit();
+    if (wildcard)
+      io_ctx.set_namespace(all_nspaces);
     RadosBencher bencher(g_ceph_context, rados, io_ctx);
     ret = bencher.clean_up(prefix, concurrent_ios, run_name);
     if (ret != 0)