RGW层读取create-multipart信息:get_multipart_info()

1 概述

static int get_multipart_info()函数的主要功能是获取分段上传的ACL、placement rule以及一些元数据。

首先来看get_multipart_info函数:

cpp 复制代码
static int get_multipart_info(RGWRados *store, struct req_state *s,
			      const string& meta_oid,
                              RGWAccessControlPolicy *policy,
			      map<string, bufferlist> *attrs,
                              multipart_upload_info *upload_info)
{
  map<string, bufferlist>::iterator iter;
  bufferlist header;

  rgw_obj meta_obj;
  meta_obj.init_ns(s->bucket, meta_oid, mp_ns); // mp_ns是RGW_OBJ_NS_MULTIPART,也就是multipart
  meta_obj.set_in_extra_data(true);

  return get_multipart_info(store, s, meta_obj, policy, attrs, upload_info);
}

在执行get_multipart_info函数之前有这一步:

cpp 复制代码
RGWMPObj mp(s->object.name, multipart_upload_id);

op_ret = get_multipart_info(store, s, mp.get_meta(), nullptr, nullptr, &upload_info);

就是将文件名和upload id初始化成了一个RGWMPObj,阅读RGWMPObj的初始化函数可以得知mp.get_meta()的结果就是:oid.upload_id.meta,也就是get_multipart_info函数的meta_oid参数;接着初始化完成一个rgw_obj,接着调用同名重写函数get_multipart_info():

cpp 复制代码
static int get_multipart_info(RGWRados *store, struct req_state *s,
			      const rgw_obj& obj,
                              RGWAccessControlPolicy *policy,
			      map<string, bufferlist> *attrs,
                              multipart_upload_info *upload_info)
{
  ...

  int op_ret = get_obj_head(store, s, obj, attrs, pheadbl);
  ...

  if (upload_info && headbl.length() > 0) {
    auto hiter = headbl.cbegin();
    try {
      decode(*upload_info, hiter);
    } 
    ...
  }

  if (policy && attrs) {
    for (auto& iter : *attrs) {
      string name = iter.first;
      if (name.compare(RGW_ATTR_ACL) == 0) {
        bufferlist& bl = iter.second;
        auto bli = bl.cbegin();
        try {
          decode(*policy, bli);
        }
        ...
      }
    }
  }

  return 0;
}

首先get_obj_head调用了两个主要函数,一个是RGWRados::Object::Read::prepare(),另一个是RGWRados::Object::Read::read(),prepare()函数的主要作用:

  1. 准备要读取的对象名称,在分段上传中就是要读取位于.rgw.non-ec池中的头对象,其名称为"<bucket_id>_" + "multipart" + <key-name> + "." + <upload_id> + ".meta"

  2. 校验一些读条件的header,这些header来自http请求中的If-Match/If-None-Match等等
    这里详细的代码不过多赘述,读者可以自行探究。
    read()函数的作用则是下发一个同步请求读取对象中的内容。

    在get_multipart_info中会将读上来的multipart_upload_info和其他attrs属性的bufferlist依次解析出来,其中multipart_upload_info记录的就是目标对象写入锁遵循的placement rule。

相关推荐
无忧.芙桃14 小时前
C++语言原理与实践(二十三):哈希表的实现
c++·链表·哈希算法·散列表·哈希表
AvocadoZeroOneOI17 小时前
B4500 [GESP202603 三级] 凯撒密码 详细解题报告
c++·算法
whitelbwwww19 小时前
cuBLAS--CUDA高性能线性代数计算库--第一部分
c++·线性代数·gpu算力·cuda c++
eggwyw1 天前
C++设计模式之解释器模式
开发语言·c++
我不会插花弄玉1 天前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴2 天前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus2 天前
C++ explicit 关键字工程实践
开发语言·c++
AIgorithmGEEK2 天前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
一拳一个呆瓜2 天前
【STL】头文件:<cmath>
c++·stl
草莓熊Lotso2 天前
【C++ 基于微服务的即时通讯系统】ElasticSearch 用户数据管理实现
linux·数据库·c++·elasticsearch·微服务·架构