]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_bi_rados.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / services / svc_bi_rados.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2019 Red Hat, Inc.
8 *
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.
13 *
14 */
15
16
17 #pragma once
18
19 #include "rgw_datalog.h"
20 #include "rgw_service.h"
21 #include "rgw_tools.h"
22
23 #include "svc_bi.h"
24 #include "svc_rados.h"
25 #include "svc_tier_rados.h"
26
27 struct rgw_bucket_dir_header;
28
29 class RGWSI_BILog_RADOS;
30
31 #define RGW_NO_SHARD -1
32
33 #define RGW_SHARDS_PRIME_0 7877
34 #define RGW_SHARDS_PRIME_1 65521
35
36 /*
37 * Defined Bucket Index Namespaces
38 */
39 #define RGW_OBJ_NS_MULTIPART "multipart"
40 #define RGW_OBJ_NS_SHADOW "shadow"
41
42 class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
43 {
44 friend class RGWSI_BILog_RADOS;
45
46 int open_pool(const DoutPrefixProvider *dpp,
47 const rgw_pool& pool,
48 RGWSI_RADOS::Pool *index_pool,
49 bool mostly_omap);
50
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);
58
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);
69
70 int cls_bucket_head(const DoutPrefixProvider *dpp,
71 const RGWBucketInfo& bucket_info,
72 const rgw::bucket_index_layout_generation& idx_layout,
73 int shard_id,
74 std::vector<rgw_bucket_dir_header> *headers,
75 std::map<int, std::string> *bucket_instance_ids,
76 optional_yield y);
77
78 public:
79
80 struct Svc {
81 RGWSI_Zone *zone{nullptr};
82 RGWSI_RADOS *rados{nullptr};
83 RGWSI_BILog_RADOS *bilog{nullptr};
84 RGWDataChangesLog *datalog_rados{nullptr};
85 } svc;
86
87 RGWSI_BucketIndex_RADOS(CephContext *cct);
88
89 void init(RGWSI_Zone *zone_svc,
90 RGWSI_RADOS *rados_svc,
91 RGWSI_BILog_RADOS *bilog_svc,
92 RGWDataChangesLog *datalog_rados_svc);
93
94 static int shards_max() {
95 return RGW_SHARDS_PRIME_1;
96 }
97
98 static int shard_id(const std::string& key, int max_shards) {
99 return rgw_shard_id(key, max_shards);
100 }
101
102 static uint32_t bucket_shard_index(const std::string& key,
103 int num_shards) {
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);
107 }
108
109 static uint32_t bucket_shard_index(const rgw_obj_key& obj_key,
110 int num_shards)
111 {
112 std::string sharding_key;
113 if (obj_key.ns == RGW_OBJ_NS_MULTIPART) {
114 RGWMPObj mp;
115 mp.from_meta(obj_key.name);
116 sharding_key = mp.get_key();
117 } else {
118 sharding_key = obj_key.name;
119 }
120
121 return bucket_shard_index(sharding_key, num_shards);
122 }
123
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;
126
127 /* RADOS specific */
128
129 int read_stats(const DoutPrefixProvider *dpp,
130 const RGWBucketInfo& bucket_info,
131 RGWBucketEnt *stats,
132 optional_yield y) override;
133
134 int get_reshard_status(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info,
135 std::list<cls_rgw_bucket_instance_entry> *status);
136
137 int handle_overwrite(const DoutPrefixProvider *dpp, const RGWBucketInfo& info,
138 const RGWBucketInfo& orig_info,
139 optional_yield y) override;
140
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,
145 int *shard_id);
146
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);
151
152 int open_bucket_index(const DoutPrefixProvider *dpp,
153 const RGWBucketInfo& bucket_info,
154 RGWSI_RADOS::Pool *index_pool,
155 std::string *bucket_oid);
156
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);
164 };
165
166