]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Fix ObjBencher clean_up when no prefix specified
authorDavid Zafman <dzafman@redhat.com>
Thu, 31 Mar 2016 03:29:22 +0000 (20:29 -0700)
committerBoris Ranto <branto@redhat.com>
Fri, 6 May 2016 11:44:16 +0000 (13:44 +0200)
By default remove all objects named benchmark_data_{hostname} when
there is no benchmark_last_metadata present.

Fixes: http://tracker.ceph.com/issues/15338
Signed-off-by: David Zafman <dzafman@redhat.com>
src/common/obj_bencher.cc

index 9a2215e46162d2787f23d4993c8f0f83acba3228..b0f3ee7c506f327675f6310e1c504f8a8a1cd42b 100644 (file)
@@ -33,12 +33,18 @@ const std::string BENCH_PREFIX = "benchmark_data";
 static char cached_hostname[30] = {0};
 int cached_pid = 0;
 
-static std::string generate_object_prefix(int pid = 0) {
+static std::string generate_object_prefix_nopid() {
   if (cached_hostname[0] == 0) {
     gethostname(cached_hostname, sizeof(cached_hostname)-1);
     cached_hostname[sizeof(cached_hostname)-1] = 0;
   }
 
+  std::ostringstream oss;
+  oss << BENCH_PREFIX << "_" << cached_hostname;
+  return oss.str();
+}
+
+static std::string generate_object_prefix(int pid = 0) {
   if (!cached_pid) {
     if (!pid)
       pid = getpid();
@@ -46,7 +52,7 @@ static std::string generate_object_prefix(int pid = 0) {
   }
 
   std::ostringstream oss;
-  oss << BENCH_PREFIX << "_" << cached_hostname << "_" << cached_pid;
+  oss << generate_object_prefix_nopid() << "_" << cached_pid;
   return oss.str();
 }
 
@@ -1084,11 +1090,12 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
   return r;
 }
 
-int ObjBencher::clean_up(const std::string& prefix, int concurrentios, const std::string& run_name) {
+int ObjBencher::clean_up(const std::string& orig_prefix, int concurrentios, const std::string& run_name) {
   int r = 0;
   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);
@@ -1096,7 +1103,9 @@ int ObjBencher::clean_up(const std::string& prefix, int concurrentios, const std
   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 && prefix != "") {
+    if (r == -ENOENT) {
+      if (prefix == "")
+       prefix = generate_object_prefix_nopid();
       return clean_up_slow(prefix, concurrentios);
     }
     else {