]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: simplify orphan command
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 4 May 2015 23:32:57 +0000 (16:32 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 29 Jun 2015 22:09:02 +0000 (15:09 -0700)
No need for --init-search

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_orphan.cc

index 8a081c6efa044e592b56e12734f0583232d164a2..5d9b209326cd004145bfb34a1e42751c0a0f6e81 100644 (file)
@@ -1116,7 +1116,6 @@ int main(int argc, char **argv)
   BIIndexType bi_index_type = PlainIdx;
 
   string job_id;
-  int init_search = false;
   int num_shards = 0;
   int max_concurrent_ios = 32;
   uint64_t orphan_stale_secs = (24 * 3600);
@@ -1281,8 +1280,6 @@ int main(int argc, char **argv)
      // do nothing
     } else if (ceph_argparse_binary_flag(args, i, &include_all, NULL, "--include-all", (char*)NULL)) {
      // do nothing
-    } else if (ceph_argparse_binary_flag(args, i, &init_search, NULL, "--init-search", (char*)NULL)) {
-     // do nothing
     } else if (ceph_argparse_witharg(args, i, &val, "--caps", (char*)NULL)) {
       caps = val;
     } else if (ceph_argparse_witharg(args, i, &val, "-i", "--infile", (char*)NULL)) {
@@ -2563,19 +2560,18 @@ next:
       cerr << "ERROR: --job-id not specified" << std::endl;
       return EINVAL;
     }
-    RGWOrphanSearchInfo info, *pinfo = NULL;
-    if (init_search) {
-      if (pool_name.empty()) {
-        cerr << "ERROR: --pool not specified" << std::endl;
-        return EINVAL;
-      }
-      info.pool = pool_name;
-      info.job_name = job_id;
-      info.num_shards = num_shards;
-      pinfo = &info;
+    if (pool_name.empty()) {
+      cerr << "ERROR: --pool not specified" << std::endl;
+      return EINVAL;
     }
 
-    int ret = search.init(job_id, pinfo);
+    RGWOrphanSearchInfo info;
+
+    info.pool = pool_name;
+    info.job_name = job_id;
+    info.num_shards = num_shards;
+
+    int ret = search.init(job_id, &info);
     if (ret < 0) {
       if (ret == -EEXIST) {
         cerr << "cannot init new search, job already exists" << std::endl;
index 88adb82b90457c7ac3668129cb882aced02fb231..7a23a040add30c8fa4853c8d2ed0b4df4d063959 100644 (file)
@@ -154,34 +154,32 @@ int RGWOrphanSearch::init(const string& job_name, RGWOrphanSearchInfo *info) {
     return r;
   }
 
-  if (info) {
+  RGWOrphanSearchState state;
+  r = orphan_store.read_job(job_name, state);
+  if (r < 0 && r != -ENOENT) {
+    lderr(store->ctx()) << "ERROR: failed to read state ret=" << r << dendl;
+    return r;
+  }
+
+  if (r == 0) {
+    if (info->num_shards != state.info.num_shards) {
+      lderr(store->ctx()) << "ERROR: cannot specify different number of shards for existing job" << dendl;
+      return -EINVAL;
+    }
+    search_info = state.info;
+    search_stage = state.stage;
+  } else { /* r == -ENOENT */
     search_info = *info;
     search_info.job_name = job_name;
     search_info.num_shards = (info->num_shards ? info->num_shards : DEFAULT_NUM_SHARDS);
     search_info.start_time = ceph_clock_now(store->ctx());
     search_stage = RGWOrphanSearchStage(ORPHAN_SEARCH_STAGE_INIT);
 
-    RGWOrphanSearchState state;
-    r = orphan_store.read_job(job_name, state);
-    if (r >= 0) {
-      lderr(store->ctx()) << "ERROR: job already exists" << dendl;
-      return -EEXIST;
-    }
     r = save_state();
     if (r < 0) {
       lderr(store->ctx()) << "ERROR: failed to write state ret=" << r << dendl;
       return r;
     }
-  } else {
-    RGWOrphanSearchState state;
-    r = orphan_store.read_job(job_name, state);
-    if (r < 0) {
-      lderr(store->ctx()) << "ERROR: failed to read state ret=" << r << dendl;
-      return r;
-    }
-
-    search_info = state.info;
-    search_stage = state.stage;
   }
 
   index_objs_prefix = RGW_ORPHAN_INDEX_PREFIX + string(".");