From 0f7aeee1d965f94c9672820dc8a61fe263ddf3d0 Mon Sep 17 00:00:00 2001 From: shawn chen Date: Fri, 3 Jul 2015 11:17:55 +0800 Subject: [PATCH] obj_bencher: check run_name and prefix for empty string instead of NULL change aio_bench and clean_up parameter const char * to const std::string & format. In rest_bench.cc, aio_bench used run_name.c_str(), so this format will always be empty string not NULL, so the condition statement const std::string run_name_meta = (run_name == NULL ? BENCH_LASTRUN_METADATA : std::string(run_name)); is wrong! test fix: before: ./rest-bench --seconds 1 -t 2 -b 100 write --api-host=radosgw.com --bucket=test_rm --access-key=FTL7TSJAGXX5KKDQHMJM --secret=123456879 use s3cmd ls s3://test_rm , we can a lot of objects in this bucket, objects are not cleaned up. after changes, do the same procedure, objects are cleaned up. Signed-off-by: shawn chen --- src/common/obj_bencher.cc | 12 ++++++------ src/common/obj_bencher.h | 4 ++-- src/tools/rest_bench.cc | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/obj_bencher.cc b/src/common/obj_bencher.cc index 20295577650d..a0c28c5a2a58 100644 --- a/src/common/obj_bencher.cc +++ b/src/common/obj_bencher.cc @@ -19,7 +19,7 @@ #include "obj_bencher.h" #include -#include +#include #include @@ -169,7 +169,7 @@ void *ObjBencher::status_printer(void *_bencher) { int ObjBencher::aio_bench( int operation, int secondsToRun, - int concurrentios, int object_size, bool cleanup, const char* run_name, bool no_verify) { + int concurrentios, int object_size, bool cleanup, const std::string& run_name, bool no_verify) { if (concurrentios <= 0) return -EINVAL; @@ -179,7 +179,7 @@ int ObjBencher::aio_bench( int prevPid = 0; // default metadata object is used if user does not specify one - const std::string run_name_meta = (run_name == NULL ? BENCH_LASTRUN_METADATA : std::string(run_name)); + const std::string run_name_meta = (run_name.empty() ? BENCH_LASTRUN_METADATA : run_name); //get data from previous write run, if available if (operation != OP_WRITE) { @@ -906,19 +906,19 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr return r; } -int ObjBencher::clean_up(const char* prefix, int concurrentios, const char* run_name) { +int ObjBencher::clean_up(const std::string& prefix, int concurrentios, const std::string& run_name) { int r = 0; int object_size; int num_objects; int prevPid; // default meta object if user does not specify one - const std::string run_name_meta = (run_name == NULL ? BENCH_LASTRUN_METADATA : std::string(run_name)); + const std::string run_name_meta = (run_name.empty() ? BENCH_LASTRUN_METADATA : run_name); r = fetch_bench_metadata(run_name_meta, &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 != NULL) { + if (r == -ENOENT && prefix != "") { return clean_up_slow(prefix, concurrentios); } else { diff --git a/src/common/obj_bencher.h b/src/common/obj_bencher.h index e1d5e9de7fdd..9ba63ed74a26 100644 --- a/src/common/obj_bencher.h +++ b/src/common/obj_bencher.h @@ -100,8 +100,8 @@ public: virtual ~ObjBencher() {} int aio_bench( int operation, int secondsToRun, - int concurrentios, int op_size, bool cleanup, const char* run_name, bool no_verify=false); - int clean_up(const char* prefix, int concurrentios, const char* run_name); + int concurrentios, int op_size, bool cleanup, const std::string& run_name, bool no_verify=false); + int clean_up(const std::string& prefix, int concurrentios, const std::string& run_name); void set_show_time(bool dt) { show_time = dt; diff --git a/src/tools/rest_bench.cc b/src/tools/rest_bench.cc index 0624114e15ea..9ba868ea9215 100644 --- a/src/tools/rest_bench.cc +++ b/src/tools/rest_bench.cc @@ -785,12 +785,12 @@ int main(int argc, const char **argv) } if (operation == OP_CLEANUP) { - ret = bencher.clean_up(prefix.c_str(), concurrent_ios, run_name.c_str()); + ret = bencher.clean_up(prefix, concurrent_ios, run_name); if (ret != 0) cerr << "error during cleanup: " << ret << std::endl; } else { ret = bencher.aio_bench(operation, seconds, - concurrent_ios, op_size, cleanup, run_name.c_str()); + concurrent_ios, op_size, cleanup, run_name); if (ret != 0) { cerr << "error during benchmark: " << ret << std::endl; } -- 2.47.3