]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: move sync_status into RGWRemoteMetaLog
authorCasey Bodley <cbodley@redhat.com>
Mon, 30 Nov 2015 21:18:29 +0000 (16:18 -0500)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 18 Feb 2016 22:04:19 +0000 (14:04 -0800)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_sync.cc
src/rgw/rgw_sync.h

index 0a3398a602988ebf7024f79fc32524428977aa36..9c2857b9b7dfa1595a24a4753677c4e85311f3a6 100644 (file)
@@ -4490,7 +4490,7 @@ next:
       return -ret;
     }
 
-    rgw_meta_sync_status& sync_status = sync.get_sync_status();
+    const rgw_meta_sync_status& sync_status = sync.get_sync_status();
 
     formatter->open_object_section("summary");
     encode_json("sync_status", sync_status, formatter);
index 4c7e9961869943202f37d306a0041e2b32283db3..dcaaa177d5fd50b95dfd046122756b7d5e998e88 100644 (file)
@@ -240,7 +240,7 @@ int RGWMetaSyncStatusManager::init()
     return r;
   }
 
-  num_shards = sync_status.sync_info.num_shards;
+  int num_shards = master_log.get_sync_status().sync_info.num_shards;
 
   for (int i = 0; i < num_shards; i++) {
     shard_objs[i] = rgw_obj(store->get_zone_params().log_pool, sync_env.shard_obj_name(i));
@@ -1524,22 +1524,23 @@ void RGWRemoteMetaLog::init_sync_env(RGWMetaSyncEnv *env) {
   env->error_logger = error_logger;
 }
 
-int RGWRemoteMetaLog::read_sync_status(rgw_meta_sync_status *sync_status)
+int RGWRemoteMetaLog::read_sync_status()
 {
   if (store->is_meta_master()) {
     return 0;
   }
 
   RGWObjectCtx obj_ctx(store, NULL);
-  return run(new RGWReadSyncStatusCoroutine(&sync_env, obj_ctx, sync_status));
+  return run(new RGWReadSyncStatusCoroutine(&sync_env, obj_ctx, &sync_status));
 }
 
-int RGWRemoteMetaLog::init_sync_status(int num_shards)
+int RGWRemoteMetaLog::init_sync_status()
 {
   if (store->is_meta_master()) {
     return 0;
   }
 
+  auto num_shards = sync_status.sync_info.num_shards;
   if (!num_shards) {
     rgw_mdlog_info mdlog_info;
     int r = read_log_info(&mdlog_info);
@@ -1551,16 +1552,17 @@ int RGWRemoteMetaLog::init_sync_status(int num_shards)
   }
 
   RGWObjectCtx obj_ctx(store, NULL);
-  return run(new RGWInitSyncStatusCoroutine(&sync_env, obj_ctx, num_shards));
+  return run(new RGWInitSyncStatusCoroutine(&sync_env, obj_ctx,
+                                            sync_status.sync_info.num_shards));
 }
 
-int RGWRemoteMetaLog::set_sync_info(const rgw_meta_sync_info& sync_info)
+int RGWRemoteMetaLog::store_sync_info()
 {
   return run(new RGWSimpleRadosWriteCR<rgw_meta_sync_info>(async_rados, store, store->get_zone_params().log_pool,
-                                sync_env.status_oid(), sync_info));
+                                sync_env.status_oid(), sync_status.sync_info));
 }
 
-int RGWRemoteMetaLog::run_sync(int num_shards, rgw_meta_sync_status& sync_status)
+int RGWRemoteMetaLog::run_sync()
 {
   if (store->is_meta_master()) {
     return 0;
@@ -1575,13 +1577,6 @@ int RGWRemoteMetaLog::run_sync(int num_shards, rgw_meta_sync_status& sync_status
     return r;
   }
 
-  if (!num_shards) {
-    num_shards = mdlog_info.num_shards;
-  } else if ((uint32_t)num_shards != mdlog_info.num_shards) {
-    lderr(store->ctx()) << "ERROR: can't sync, mismatch between num shards, master num_shards=" << mdlog_info.num_shards << " local num_shards=" << num_shards << dendl;
-    return r;
-  }
-
   do {
     r = run(new RGWReadSyncStatusCoroutine(&sync_env, obj_ctx, &sync_status));
     if (r < 0 && r != -ENOENT) {
@@ -1591,7 +1586,8 @@ int RGWRemoteMetaLog::run_sync(int num_shards, rgw_meta_sync_status& sync_status
 
     if (sync_status.sync_info.state == rgw_meta_sync_info::StateInit) {
       ldout(store->ctx(), 20) << __func__ << "(): init" << dendl;
-      r = run(new RGWInitSyncStatusCoroutine(&sync_env, obj_ctx, num_shards));
+      r = run(new RGWInitSyncStatusCoroutine(&sync_env, obj_ctx,
+                                             sync_status.sync_info.num_shards));
       if (r == -EBUSY) {
         backoff.backoff_sleep();
         continue;
@@ -1604,6 +1600,12 @@ int RGWRemoteMetaLog::run_sync(int num_shards, rgw_meta_sync_status& sync_status
     }
   } while (sync_status.sync_info.state == rgw_meta_sync_info::StateInit);
 
+  auto num_shards = sync_status.sync_info.num_shards;
+  if (num_shards != mdlog_info.num_shards) {
+    lderr(store->ctx()) << "ERROR: can't sync, mismatch between num shards, master num_shards=" << mdlog_info.num_shards << " local num_shards=" << num_shards << dendl;
+    return r;
+  }
+
   do {
     r = run(new RGWReadSyncStatusCoroutine(&sync_env, obj_ctx, &sync_status));
     if (r < 0 && r != -ENOENT) {
@@ -1626,7 +1628,7 @@ int RGWRemoteMetaLog::run_sync(int num_shards, rgw_meta_sync_status& sync_status
         }
 
         sync_status.sync_info.state = rgw_meta_sync_info::StateSync;
-        r = set_sync_info(sync_status.sync_info);
+        r = store_sync_info();
         if (r < 0) {
           ldout(store->ctx(), 0) << "ERROR: failed to update sync status" << dendl;
           return r;
index e7e6292da75fe6e16dd99ccbfe777e5dd54d2c97..0a6799dbc043f1d5975044192dbbab701805a08f 100644 (file)
@@ -153,8 +153,10 @@ class RGWRemoteMetaLog : public RGWCoroutinesManager {
   RGWSyncBackoff backoff;
 
   RGWMetaSyncEnv sync_env;
+  rgw_meta_sync_status sync_status;
 
   void init_sync_env(RGWMetaSyncEnv *env);
+  int store_sync_info();
 
   atomic_t going_down;
 
@@ -172,16 +174,16 @@ public:
   void finish();
 
   int read_log_info(rgw_mdlog_info *log_info);
-  int read_sync_status(rgw_meta_sync_status *sync_status);
-  int init_sync_status(int num_shards);
-  int set_sync_info(const rgw_meta_sync_info& sync_info);
-  int run_sync(int num_shards, rgw_meta_sync_status& sync_status);
+  int read_sync_status();
+  int init_sync_status();
+  int run_sync();
 
   void wakeup(int shard_id);
 
   RGWMetaSyncEnv& get_sync_env() {
     return sync_env;
   }
+  const rgw_meta_sync_status& get_sync_status() const { return sync_status; }
 };
 
 class RGWMetaSyncStatusManager {
@@ -190,11 +192,8 @@ class RGWMetaSyncStatusManager {
 
   RGWRemoteMetaLog master_log;
 
-  rgw_meta_sync_status sync_status;
   map<int, rgw_obj> shard_objs;
 
-  int num_shards;
-
   struct utime_shard {
     utime_t ts;
     int shard_id;
@@ -216,16 +215,18 @@ class RGWMetaSyncStatusManager {
 public:
   RGWMetaSyncStatusManager(RGWRados *_store, RGWAsyncRadosProcessor *async_rados)
     : store(_store), master_log(store, async_rados, this),
-      num_shards(0), ts_to_shard_lock("ts_to_shard_lock") {}
+      ts_to_shard_lock("ts_to_shard_lock") {}
   int init();
   void finish();
 
-  rgw_meta_sync_status& get_sync_status() { return sync_status; }
+  const rgw_meta_sync_status& get_sync_status() const {
+    return master_log.get_sync_status();
+  }
 
-  int read_sync_status() { return master_log.read_sync_status(&sync_status); }
-  int init_sync_status() { return master_log.init_sync_status(num_shards); }
+  int read_sync_status() { return master_log.read_sync_status(); }
+  int init_sync_status() { return master_log.init_sync_status(); }
 
-  int run() { return master_log.run_sync(num_shards, sync_status); }
+  int run() { return master_log.run_sync(); }
 
   void wakeup(int shard_id) { return master_log.wakeup(shard_id); }
   void stop() {