From: Yehuda Sadeh Date: Wed, 4 Sep 2019 09:22:51 +0000 (-0700) Subject: rgw: add sync policy to zonegroup X-Git-Tag: v15.1.0~22^2~108 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1ca8ec9852734daeb8caad405021de5a097eda02;p=ceph.git rgw: add sync policy to zonegroup and move code around Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index b9325dc7181d..4d8af33f3cc1 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -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" diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index 9a3e16b3dabe..416e35dd9f30 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -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 directional; - std::optional > 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 *sources, std::set *targets) const; -}; -WRITE_CLASS_ENCODER(rgw_sync_flow_rule) - -struct rgw_sync_source { - string id; - string type; - std::optional zone; - std::optional 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 flow_rules; /* flow rules for trivial sources */ - std::set zones; /* target zones. Can be wildcard */ - /* FIXME: add config */ - - std::vector sources; /* non-trivial sources */ - std::optional 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 > flow_rules; - std::optional > sources; - std::optional > 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; diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 3b7369bac8c3..af8ce07910e2 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -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 index 000000000000..4acbafb72559 --- /dev/null +++ b/src/rgw/rgw_sync_policy.h @@ -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 directional; + std::optional > 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 *sources, std::set *targets) const; +}; +WRITE_CLASS_ENCODER(rgw_sync_flow_rule) + +struct rgw_sync_source { + string id; + string type; + std::optional zone; + std::optional 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 flow_rules; /* flow rules for trivial sources */ + std::set zones; /* target zones. Can be wildcard */ + /* FIXME: add config */ + + std::vector sources; /* non-trivial sources */ + std::optional 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 > flow_rules; + std::optional > sources; + std::optional > 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) + + diff --git a/src/rgw/rgw_zone.h b/src/rgw/rgw_zone.h index 9731891343b8..9c1f018cda98 100644 --- a/src/rgw/rgw_zone.h +++ b/src/rgw/rgw_zone.h @@ -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) {}