ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

RGW多站点 -- RGWSystemMetaObj

2022-08-15 20:01:14  阅读:146  来源: 互联网

标签:info name RGW -- rgw RGWSystemMetaObj id pool


源码

在多站点中,RGWZoneParamsRGWZoneGroupRGWRealm都直接继承RGWSystemMetaObj。本文主要记录RGWSystemMetaObj往RADOS层写入了哪些对象。
RGWSystemMetaObj

在创建realm、zonegroup及zone时,我们需要指定其name。创建成功后,每一个realm、zonegroup及zone都会有一个id。这个id和name就是有RGWSystemMetaObj负责管理的。

粗略的观察一下SystemMetaObj的部分成员函数:

protected:
  int store_name(bool exclusive);
  int store_info(bool exclusive);
  int read_info(const std::string& obj_id, bool old_format = false);
  int read_id(const std::string& obj_name, std::string& obj_id);
  int read_default(RGWDefaultSystemMetaObjInfo& default_info,
		   const std::string& oid);
  /* read and use default id */
  int use_default(bool old_format = false);
public:
  virtual int create(bool exclusive = true);
  virtual rgw_pool get_pool(CephContext *cct) const = 0;
  virtual const std::string get_default_oid(bool old_format = false) const = 0;
  virtual const std::string& get_names_oid_prefix() const = 0;
  virtual const std::string& get_info_oid_prefix(bool old_format = false) const = 0;
  virtual const std::string& get_predefined_name(CephContext *cct) const = 0;

可以看到,其将id、name抽象为两个部分, name和info,有什么区别呢?

进入两者的实现:

int RGWSystemMetaObj::store_name(bool exclusive) {
  rgw_pool pool(get_pool(cct));
  string oid = get_names_oid_prefix() + name;

  RGWNameToId nameToId;
  nameToId.obj_id = id;

  bufferlist bl;
  using ceph::encode;
  encode(nameToId, bl);
  auto obj_ctx = sysobj_svc->init_obj_ctx();
  auto sysobj = sysobj_svc->get_obj(obj_ctx, rgw_raw_obj(pool, oid));
  return sysobj.wop().set_exclusive(exclusive).write(bl);
}

int RGWSystemMetaObj::store_info(bool exclusive) {
  rgw_pool pool(get_pool(cct));

  string oid = get_info_oid_prefix() + id;

  bufferlist bl;
  using ceph::encode;
  encode(*this, bl);
  auto obj_ctx = sysobj_svc->init_obj_ctx();
  auto sysobj = sysobj_svc->get_obj(obj_ctx, rgw_raw_obj{pool, oid});
  return sysobj.wop().set_exclusive(exclusive).write(bl);
}

可以看到,代码片段基本相似,区别在于 pool name 和 oid 的不同,这两个变量依赖于具体的子类实现。
store_nameRGWNameToId写入到对象, 而store_infoRGWSystemMetaObj写入到对象。

以类图中提到的三个子类为例,其对应的 pool和oid如下:

SubClass type pool oid value
RGWRealm info .rgw.root (rgw_realm_root_pool) realms.{id} RGWSystemMetaObj
-- name .rgw.root realms_names.{name} RGWNameToId
RGWZoneGroup info .rgw.root (rgw_zonegroup_root_pool) zonegroup_info.{id} RGWSystemMetaObj
-- name .rgw.root zonegroups_names.{name} RGWNameToId
RGWZoneParams info .rgw.root (rgw_zone_root_pool) zone_info.{id} RGWSystemMetaObj
-- name .rgw.root zone_names.{name} RGWNameToId

需要注意的时,在代码中,pool默认是 rgw.root,只不过conf中默认是.rgw.root

当我们创建realm、zonegroup或zone时,最终都会调用到RGWSystemMetaObj::create,再通过它间接调用store_infostore_name:

int RGWSystemMetaObj::create(bool exclusive) {
  int ret;

  //对于create,id必然是不存在的,所以需要生成一个id
  ret = read_id(name, id);
  if (id.empty()) {
    /* create unique id */
    uuid_d new_uuid;
    char uuid_str[37];
    new_uuid.generate_random();
    new_uuid.print(uuid_str);
    id = uuid_str;
  }
   
  //创建一个名为 {realms/zonegroup_info/zone_info}.{id}的对象,内容为 RGWSystemMetaObj
  ret = store_info(exclusive);
  if (ret < 0) {
    ldout(cct, 0) << "ERROR:  storing info for " << id << ": "
                  << cpp_strerror(-ret) << dendl;
    return ret;
  }
  //创建一个名为{realms_names/zonegroups_names/zone_names}.{name}的对象,对象内容为 RGWNameToId
  return store_name(exclusive);
}

总结

RGWSystemMetaObj中,info对应的是id,而name则是name。

标签:info,name,RGW,--,rgw,RGWSystemMetaObj,id,pool
来源: https://www.cnblogs.com/liutimo/p/16589451.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有