首页 > 其他分享 >RGW多站点 -- RGWSystemMetaObj

RGW多站点 -- RGWSystemMetaObj

时间:2022-08-15 20:03:21浏览次数:60  
标签: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
From: https://www.cnblogs.com/liutimo/p/16589451.html

相关文章

  • python连接mysql与redis(ssh方式)
    python如何连接数据库(SSH方式)性能测试时,有个支付订单的场景,需要用到已生成的订单code,如何获取订单code?一,通过Jmeter连接数据库获取。二,直接mysql导出数据我这里是使用......
  • 数论----快速幂
      算法: 1intqmi(inta,intb,intmod)2{3//答案4intres=1;5//乘数6intmul=a;7while(b)8{9......
  • 【git】git切换仓库
    目录方法一、修改本地仓库地址方法二、通过命令先删除再添加远程仓库方法三、修改配置文件方法一、修改本地仓库地址#进入项目根目录gitremoteset-urlorigin[url]......
  • Eureka 服务注册
    1、在pom.yml文件中引入Eureka-client的服务依赖<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-......
  • connect (2)
    Anelectricalconnectorisanelectromechanicaldeviceusedtojoinelectricalconductorsandcreateanelectricalcircuit.Mostelectricalconnectorshaveag......
  • 一文看懂线性回归和非线性回归
    一文看懂线性回归和非线性回归           1.非线性回归           2.线性回归           3.总结1.非线性回归我们首先来看维基百......
  • Cypress自动化测试框架安装与部署
    安装与部署一、npm方式安装:1)安装Node.js   在Node.js官方网站https://nodejs.org/en/直接下载Node.js并双击安装2)设置环境变量,把node.exe所在的目录加入到PATH环境......
  • MySQL的字段语法
    MySQL的存储字符编码与配置文件1.\s#查看数据库基本信息(用户、字符编码)2.my-default.ini#windows下MySQL默认的配置文件拷贝上述文件并重命名为my.ini3.添......
  • 知识回顾(持续更新)
    1.this的目的是:this关键字用来表示当前对象本身,或当前类的一个实例,通过this可以调用本对象的所有方法和属性。成员变量与方法内部的变量重名时,希望在方法内部调用成员......
  • 操作系统学习笔记2 | 操作系统接口
    这部分将讲解上层应用软件如何与操作系统交互,理解操作系统到底发生了什么事情,理解操作系统工作原理,为以后扩充操作系统、设计操作系统铺垫。参考资料:课程:哈工大操作系......