1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2019 Red Hat, Inc.
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
19 #include "rgw_datalog.h"
20 #include "rgw_service.h"
21 #include "rgw_tools.h"
24 #include "svc_rados.h"
25 #include "svc_tier_rados.h"
27 struct rgw_bucket_dir_header
;
29 class RGWSI_BILog_RADOS
;
31 #define RGW_NO_SHARD -1
33 #define RGW_SHARDS_PRIME_0 7877
34 #define RGW_SHARDS_PRIME_1 65521
37 * Defined Bucket Index Namespaces
39 #define RGW_OBJ_NS_MULTIPART "multipart"
40 #define RGW_OBJ_NS_SHADOW "shadow"
42 class RGWSI_BucketIndex_RADOS
: public RGWSI_BucketIndex
44 friend class RGWSI_BILog_RADOS
;
46 int open_pool(const DoutPrefixProvider
*dpp
,
48 RGWSI_RADOS::Pool
*index_pool
,
51 int open_bucket_index_pool(const DoutPrefixProvider
*dpp
,
52 const RGWBucketInfo
& bucket_info
,
53 RGWSI_RADOS::Pool
*index_pool
);
54 int open_bucket_index_base(const DoutPrefixProvider
*dpp
,
55 const RGWBucketInfo
& bucket_info
,
56 RGWSI_RADOS::Pool
*index_pool
,
57 std::string
*bucket_oid_base
);
59 // return the index oid for the given shard id
60 void get_bucket_index_object(const std::string
& bucket_oid_base
,
61 const rgw::bucket_index_normal_layout
& normal
,
62 uint64_t gen_id
, int shard_id
,
63 std::string
* bucket_obj
);
64 // return the index oid and shard id for the given object name
65 int get_bucket_index_object(const std::string
& bucket_oid_base
,
66 const rgw::bucket_index_normal_layout
& normal
,
67 uint64_t gen_id
, const std::string
& obj_key
,
68 std::string
* bucket_obj
, int* shard_id
);
70 int cls_bucket_head(const DoutPrefixProvider
*dpp
,
71 const RGWBucketInfo
& bucket_info
,
72 const rgw::bucket_index_layout_generation
& idx_layout
,
74 std::vector
<rgw_bucket_dir_header
> *headers
,
75 std::map
<int, std::string
> *bucket_instance_ids
,
81 RGWSI_Zone
*zone
{nullptr};
82 RGWSI_RADOS
*rados
{nullptr};
83 RGWSI_BILog_RADOS
*bilog
{nullptr};
84 RGWDataChangesLog
*datalog_rados
{nullptr};
87 RGWSI_BucketIndex_RADOS(CephContext
*cct
);
89 void init(RGWSI_Zone
*zone_svc
,
90 RGWSI_RADOS
*rados_svc
,
91 RGWSI_BILog_RADOS
*bilog_svc
,
92 RGWDataChangesLog
*datalog_rados_svc
);
94 static int shards_max() {
95 return RGW_SHARDS_PRIME_1
;
98 static int shard_id(const std::string
& key
, int max_shards
) {
99 return rgw_shard_id(key
, max_shards
);
102 static uint32_t bucket_shard_index(const std::string
& key
,
104 uint32_t sid
= ceph_str_hash_linux(key
.c_str(), key
.size());
105 uint32_t sid2
= sid
^ ((sid
& 0xFF) << 24);
106 return rgw_shards_mod(sid2
, num_shards
);
109 static uint32_t bucket_shard_index(const rgw_obj_key
& obj_key
,
112 std::string sharding_key
;
113 if (obj_key
.ns
== RGW_OBJ_NS_MULTIPART
) {
115 mp
.from_meta(obj_key
.name
);
116 sharding_key
= mp
.get_key();
118 sharding_key
= obj_key
.name
;
121 return bucket_shard_index(sharding_key
, num_shards
);
124 int init_index(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
,const rgw::bucket_index_layout_generation
& idx_layout
) override
;
125 int clean_index(const DoutPrefixProvider
*dpp
, RGWBucketInfo
& bucket_info
, const rgw::bucket_index_layout_generation
& idx_layout
) override
;
129 int read_stats(const DoutPrefixProvider
*dpp
,
130 const RGWBucketInfo
& bucket_info
,
132 optional_yield y
) override
;
134 int get_reshard_status(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& bucket_info
,
135 std::list
<cls_rgw_bucket_instance_entry
> *status
);
137 int handle_overwrite(const DoutPrefixProvider
*dpp
, const RGWBucketInfo
& info
,
138 const RGWBucketInfo
& orig_info
,
139 optional_yield y
) override
;
141 int open_bucket_index_shard(const DoutPrefixProvider
*dpp
,
142 const RGWBucketInfo
& bucket_info
,
143 const std::string
& obj_key
,
144 RGWSI_RADOS::Obj
*bucket_obj
,
147 int open_bucket_index_shard(const DoutPrefixProvider
*dpp
,
148 const RGWBucketInfo
& bucket_info
,
149 const rgw::bucket_index_layout_generation
& index
,
150 int shard_id
, RGWSI_RADOS::Obj
*bucket_obj
);
152 int open_bucket_index(const DoutPrefixProvider
*dpp
,
153 const RGWBucketInfo
& bucket_info
,
154 RGWSI_RADOS::Pool
*index_pool
,
155 std::string
*bucket_oid
);
157 int open_bucket_index(const DoutPrefixProvider
*dpp
,
158 const RGWBucketInfo
& bucket_info
,
159 std::optional
<int> shard_id
,
160 const rgw::bucket_index_layout_generation
& idx_layout
,
161 RGWSI_RADOS::Pool
*index_pool
,
162 std::map
<int, std::string
> *bucket_objs
,
163 std::map
<int, std::string
> *bucket_instance_ids
);