]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add sync policy to zonegroup
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 4 Sep 2019 09:22:51 +0000 (02:22 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 28 Jan 2020 18:20:36 +0000 (10:20 -0800)
and move code around

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_data_sync.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_sync_policy.h [new file with mode: 0644]
src/rgw/rgw_zone.h

index b9325dc7181d25008091ace2cacda7f8a2ab9672..4d8af33f3cc1bc7e3337cb8d0816e15fed32c8e2 100644 (file)
@@ -29,6 +29,7 @@
 #include "include/str_list.h"
 #include "rgw_crypt_sanitize.h"
 #include "rgw_bucket_sync.h"
+#include "rgw_sync_policy.h"
 
 #include "services/svc_zone.h"
 
index 9a3e16b3dabe4189a639cf5c43f104cbc5e5f613..416e35dd9f3026f9168ac6607aea7bdbeff27204 100644 (file)
@@ -269,158 +269,6 @@ struct rgw_bucket_entry_owner {
   void decode_json(JSONObj *obj);
 };
 
-struct rgw_sync_flow_directional_rule {
-  string source_zone;
-  string target_zone;
-
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(source_zone, bl);
-    encode(target_zone, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(source_zone, bl);
-    decode(target_zone, bl);
-    DECODE_FINISH(bl);
-  }
-
-  void dump(ceph::Formatter *f) const;
-  void decode_json(JSONObj *obj);
-};
-WRITE_CLASS_ENCODER(rgw_sync_flow_directional_rule)
-
-struct rgw_sync_flow_rule {
-  string id;
-  std::optional<rgw_sync_flow_directional_rule> directional;
-  std::optional<std::set<string> > symmetrical;
-
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(id, bl);
-    encode(directional, bl);
-    encode(symmetrical, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(id, bl);
-    decode(directional, bl);
-    decode(symmetrical, bl);
-    DECODE_FINISH(bl);
-  }
-
-  void dump(ceph::Formatter *f) const;
-  void decode_json(JSONObj *obj);
-
-  void get_zone_peers(const string& zone_id, std::set<string> *sources, std::set<string> *targets) const;
-};
-WRITE_CLASS_ENCODER(rgw_sync_flow_rule)
-
-struct rgw_sync_source {
-  string id;
-  string type;
-  std::optional<string> zone;
-  std::optional<rgw_bucket> bucket;
-  /* FIXME: config */
-
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(id, bl);
-    encode(type, bl);
-    encode(zone, bl);
-    encode(bucket, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(id, bl);
-    decode(type, bl);
-    decode(zone, bl);
-    decode(bucket, bl);
-    DECODE_FINISH(bl);
-  }
-
-  void dump(ceph::Formatter *f) const;
-  void decode_json(JSONObj *obj);
-};
-WRITE_CLASS_ENCODER(rgw_sync_source)
-
-struct rgw_sync_target {
-  string id;
-  string type;
-  std::vector<rgw_sync_flow_rule> flow_rules; /* flow rules for trivial sources */
-  std::set<string> zones;  /* target zones. Can be wildcard */
-  /* FIXME: add config */
-
-  std::vector<rgw_sync_source> sources; /* non-trivial sources */
-  std::optional<rgw_bucket> bucket; /* can be explicit, or not set. If not set then depending
-                                       on the context */
-  
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(id, bl);
-    encode(type, bl);
-    encode(flow_rules, bl);
-    encode(zones, bl);
-    encode(sources, bl);
-    encode(bucket, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(id, bl);
-    decode(type, bl);
-    decode(flow_rules, bl);
-    decode(zones, bl);
-    decode(sources, bl);
-    decode(bucket, bl);
-    DECODE_FINISH(bl);
-  }
-
-  void dump(ceph::Formatter *f) const;
-  void decode_json(JSONObj *obj);
-};
-WRITE_CLASS_ENCODER(rgw_sync_target)
-
-
-struct rgw_sync_policy_info {
-  std::optional<std::vector<rgw_sync_flow_rule> > flow_rules;
-  std::optional<std::vector<rgw_sync_source> > sources;
-  std::optional<std::vector<rgw_sync_target> > targets;
-
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(flow_rules, bl);
-    encode(sources, bl);
-    encode(targets, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(flow_rules, bl);
-    decode(sources, bl);
-    decode(targets, bl);
-    DECODE_FINISH(bl);
-  }
-
-  void dump(ceph::Formatter *f) const;
-  void decode_json(JSONObj *obj);
-
-  bool empty() const {
-    return (!flow_rules || flow_rules->empty()) &&
-           (!targets || targets->empty());
-  }
-
-};
-WRITE_CLASS_ENCODER(rgw_sync_policy_info)
-
 class RGWSyncErrorLogger;
 class RGWRESTConn;
 class RGWServices;
index 3b7369bac8c38846a0e70244447352f971158326..af8ce07910e250d3fc7fbb97d3fbe99a77a8889e 100644 (file)
@@ -793,6 +793,9 @@ void RGWBucketInfo::dump(Formatter *f) const
   encode_json("mdsearch_config", mdsearch_config, f);
   encode_json("reshard_status", (int)reshard_status, f);
   encode_json("new_bucket_instance_id", new_bucket_instance_id, f);
+  if (!empty_sync_policy()) {
+    encode_json("sync_policy", *sync_policy, f);
+  }
 }
 
 void RGWBucketInfo::decode_json(JSONObj *obj) {
@@ -830,6 +833,12 @@ void RGWBucketInfo::decode_json(JSONObj *obj) {
   int rs;
   JSONDecoder::decode_json("reshard_status", rs, obj);
   reshard_status = (cls_rgw_reshard_status)rs;
+
+  rgw_sync_policy_info sp;
+  JSONDecoder::decode_json("sync_policy", sp, obj);
+  if (!sp.empty()) {
+    set_sync_policy(std::move(sp));
+  }
 }
 
 void rgw_sync_flow_directional_rule::dump(Formatter *f) const
diff --git a/src/rgw/rgw_sync_policy.h b/src/rgw/rgw_sync_policy.h
new file mode 100644 (file)
index 0000000..4acbafb
--- /dev/null
@@ -0,0 +1,173 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#pragma once
+
+#include "rgw_common.h"
+
+
+struct rgw_sync_flow_directional_rule {
+  string source_zone;
+  string target_zone;
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    encode(source_zone, bl);
+    encode(target_zone, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::const_iterator& bl) {
+    DECODE_START(1, bl);
+    decode(source_zone, bl);
+    decode(target_zone, bl);
+    DECODE_FINISH(bl);
+  }
+
+  void dump(ceph::Formatter *f) const;
+  void decode_json(JSONObj *obj);
+};
+WRITE_CLASS_ENCODER(rgw_sync_flow_directional_rule)
+
+struct rgw_sync_flow_rule {
+  string id;
+  std::optional<rgw_sync_flow_directional_rule> directional;
+  std::optional<std::set<string> > symmetrical;
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    encode(id, bl);
+    encode(directional, bl);
+    encode(symmetrical, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::const_iterator& bl) {
+    DECODE_START(1, bl);
+    decode(id, bl);
+    decode(directional, bl);
+    decode(symmetrical, bl);
+    DECODE_FINISH(bl);
+  }
+
+  void dump(ceph::Formatter *f) const;
+  void decode_json(JSONObj *obj);
+
+  void get_zone_peers(const string& zone_id, std::set<string> *sources, std::set<string> *targets) const;
+};
+WRITE_CLASS_ENCODER(rgw_sync_flow_rule)
+
+struct rgw_sync_source {
+  string id;
+  string type;
+  std::optional<string> zone;
+  std::optional<rgw_bucket> bucket;
+  /* FIXME: config */
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    encode(id, bl);
+    encode(type, bl);
+    encode(zone, bl);
+    encode(bucket, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::const_iterator& bl) {
+    DECODE_START(1, bl);
+    decode(id, bl);
+    decode(type, bl);
+    decode(zone, bl);
+    decode(bucket, bl);
+    DECODE_FINISH(bl);
+  }
+
+  void dump(ceph::Formatter *f) const;
+  void decode_json(JSONObj *obj);
+};
+WRITE_CLASS_ENCODER(rgw_sync_source)
+
+struct rgw_sync_target {
+  string id;
+  string type;
+  std::vector<rgw_sync_flow_rule> flow_rules; /* flow rules for trivial sources */
+  std::set<string> zones;  /* target zones. Can be wildcard */
+  /* FIXME: add config */
+
+  std::vector<rgw_sync_source> sources; /* non-trivial sources */
+  std::optional<rgw_bucket> bucket; /* can be explicit, or not set. If not set then depending
+                                       on the context */
+  
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    encode(id, bl);
+    encode(type, bl);
+    encode(flow_rules, bl);
+    encode(zones, bl);
+    encode(sources, bl);
+    encode(bucket, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::const_iterator& bl) {
+    DECODE_START(1, bl);
+    decode(id, bl);
+    decode(type, bl);
+    decode(flow_rules, bl);
+    decode(zones, bl);
+    decode(sources, bl);
+    decode(bucket, bl);
+    DECODE_FINISH(bl);
+  }
+
+  void dump(ceph::Formatter *f) const;
+  void decode_json(JSONObj *obj);
+};
+WRITE_CLASS_ENCODER(rgw_sync_target)
+
+
+struct rgw_sync_policy_info {
+  std::optional<std::vector<rgw_sync_flow_rule> > flow_rules;
+  std::optional<std::vector<rgw_sync_source> > sources;
+  std::optional<std::vector<rgw_sync_target> > targets;
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    encode(flow_rules, bl);
+    encode(sources, bl);
+    encode(targets, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::const_iterator& bl) {
+    DECODE_START(1, bl);
+    decode(flow_rules, bl);
+    decode(sources, bl);
+    decode(targets, bl);
+    DECODE_FINISH(bl);
+  }
+
+  void dump(ceph::Formatter *f) const;
+  void decode_json(JSONObj *obj);
+
+  bool empty() const {
+    return (!flow_rules || flow_rules->empty()) &&
+           (!targets || targets->empty());
+  }
+
+};
+WRITE_CLASS_ENCODER(rgw_sync_policy_info)
+
+
index 9731891343b89aa32c8fbeff60b68943610a2a49..9c1f018cda98142d90e2d274dd97adc8b3a4a1ae 100644 (file)
@@ -5,6 +5,7 @@
 #define CEPH_RGW_ZONE_H
 
 #include "rgw_common.h"
+#include "rgw_sync_policy.h"
 
 namespace rgw_zone_defaults {
 
@@ -721,6 +722,8 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
 
   std::string realm_id;
 
+  rgw_sync_policy_info sync_policy;
+
   RGWZoneGroup(): is_master(false){}
   RGWZoneGroup(const std::string &id, const std::string &name):RGWSystemMetaObj(id, name) {}
   explicit RGWZoneGroup(const std::string &_name):RGWSystemMetaObj(_name) {}