]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
obj_bencher: check run_name and prefix for empty string instead of NULL 5071/head
authorshawn chen <cxwshawn@gmail.com>
Fri, 3 Jul 2015 03:17:55 +0000 (11:17 +0800)
committershawn chen <cxwshawn@gmail.com>
Fri, 3 Jul 2015 03:17:58 +0000 (11:17 +0800)
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 <cxwshawn@gmail.com>
src/common/obj_bencher.cc
src/common/obj_bencher.h
src/tools/rest_bench.cc

index 20295577650d2d0cfc1b41c57d61eeb415d5cc9e..a0c28c5a2a58dfacd28fc6715109a4dc1306167c 100644 (file)
@@ -19,7 +19,7 @@
 #include "obj_bencher.h"
 
 #include <iostream>
-#include <fstream>
+#include <fstream> 
 
 #include <cerrno>
 
@@ -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 {
index e1d5e9de7fdd2d90b70a7ccf4d13621f6ed9249e..9ba63ed74a265243440572f0776f88cd7a1f79d7 100644 (file)
@@ -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;
index 0624114e15ead220f457ec5be434329c0117d181..9ba868ea9215c68eac48c20041201dca2bc03963 100644 (file)
@@ -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;
     }