From: David Zafman Date: Thu, 31 Mar 2016 03:29:22 +0000 (-0700) Subject: common: Fix ObjBencher clean_up when no prefix specified X-Git-Tag: v11.0.0~136^2~16^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4140c320cee3e8fc1f25058ef05ac8fa531ff065;p=ceph.git common: Fix ObjBencher clean_up when no prefix specified 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 --- diff --git a/src/common/obj_bencher.cc b/src/common/obj_bencher.cc index 9a2215e46162..b0f3ee7c506f 100644 --- a/src/common/obj_bencher.cc +++ b/src/common/obj_bencher.cc @@ -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 {