]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_obj_manifest.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / rgw_obj_manifest.cc
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 #include "rgw_obj_manifest.h"
5
6 #include "rgw_rados.h" // RGW_OBJ_NS_SHADOW and RGW_OBJ_NS_MULTIPART
7
8 using namespace std;
9
10 void RGWObjManifest::obj_iterator::operator++()
11 {
12 if (manifest->explicit_objs) {
13 ++explicit_iter;
14
15 if (explicit_iter == manifest->objs.end()) {
16 ofs = manifest->obj_size;
17 stripe_size = 0;
18 return;
19 }
20
21 update_explicit_pos();
22
23 update_location();
24 return;
25 }
26
27 uint64_t obj_size = manifest->get_obj_size();
28 uint64_t head_size = manifest->get_head_size();
29
30 if (ofs == obj_size) {
31 return;
32 }
33
34 if (manifest->rules.empty()) {
35 return;
36 }
37
38 /* are we still pointing at the head? */
39 if (ofs < head_size) {
40 rule_iter = manifest->rules.begin();
41 const RGWObjManifestRule *rule = &rule_iter->second;
42 ofs = std::min(head_size, obj_size);
43 stripe_ofs = ofs;
44 cur_stripe = 1;
45 stripe_size = std::min(obj_size - ofs, rule->stripe_max_size);
46 if (rule->part_size > 0) {
47 stripe_size = std::min(stripe_size, rule->part_size);
48 }
49 update_location();
50 return;
51 }
52
53 const RGWObjManifestRule *rule = &rule_iter->second;
54
55 stripe_ofs += rule->stripe_max_size;
56 cur_stripe++;
57 ldpp_dout(dpp, 20) << "RGWObjManifest::operator++(): rule->part_size=" << rule->part_size << " rules.size()=" << manifest->rules.size() << dendl;
58
59 if (rule->part_size > 0) {
60 /* multi part, multi stripes object */
61
62 ldpp_dout(dpp, 20) << "RGWObjManifest::operator++(): stripe_ofs=" << stripe_ofs << " part_ofs=" << part_ofs << " rule->part_size=" << rule->part_size << dendl;
63
64 if (stripe_ofs >= part_ofs + rule->part_size) {
65 /* moved to the next part */
66 cur_stripe = 0;
67 part_ofs += rule->part_size;
68 stripe_ofs = part_ofs;
69
70 bool last_rule = (next_rule_iter == manifest->rules.end());
71 /* move to the next rule? */
72 if (!last_rule && stripe_ofs >= next_rule_iter->second.start_ofs) {
73 rule_iter = next_rule_iter;
74 last_rule = (next_rule_iter == manifest->rules.end());
75 if (!last_rule) {
76 ++next_rule_iter;
77 }
78 cur_part_id = rule_iter->second.start_part_num;
79 } else {
80 cur_part_id++;
81 }
82
83 rule = &rule_iter->second;
84 }
85
86 stripe_size = std::min(rule->part_size - (stripe_ofs - part_ofs), rule->stripe_max_size);
87 }
88
89 cur_override_prefix = rule->override_prefix;
90
91 ofs = stripe_ofs;
92 if (ofs > obj_size) {
93 ofs = obj_size;
94 stripe_ofs = ofs;
95 stripe_size = 0;
96 }
97
98 ldpp_dout(dpp, 20) << "RGWObjManifest::operator++(): result: ofs=" << ofs << " stripe_ofs=" << stripe_ofs << " part_ofs=" << part_ofs << " rule->part_size=" << rule->part_size << dendl;
99 update_location();
100 }
101
102 void RGWObjManifest::obj_iterator::seek(uint64_t o)
103 {
104 ofs = o;
105 if (manifest->explicit_objs) {
106 explicit_iter = manifest->objs.upper_bound(ofs);
107 if (explicit_iter != manifest->objs.begin()) {
108 --explicit_iter;
109 }
110 if (ofs < manifest->obj_size) {
111 update_explicit_pos();
112 } else {
113 ofs = manifest->obj_size;
114 }
115 update_location();
116 return;
117 }
118 if (o < manifest->get_head_size()) {
119 rule_iter = manifest->rules.begin();
120 stripe_ofs = 0;
121 stripe_size = manifest->get_head_size();
122 if (rule_iter != manifest->rules.end()) {
123 cur_part_id = rule_iter->second.start_part_num;
124 cur_override_prefix = rule_iter->second.override_prefix;
125 }
126 update_location();
127 return;
128 }
129
130 rule_iter = manifest->rules.upper_bound(ofs);
131 next_rule_iter = rule_iter;
132 if (rule_iter != manifest->rules.begin()) {
133 --rule_iter;
134 }
135
136 if (rule_iter == manifest->rules.end()) {
137 update_location();
138 return;
139 }
140
141 const RGWObjManifestRule& rule = rule_iter->second;
142
143 if (rule.part_size > 0) {
144 cur_part_id = rule.start_part_num + (ofs - rule.start_ofs) / rule.part_size;
145 } else {
146 cur_part_id = rule.start_part_num;
147 }
148 part_ofs = rule.start_ofs + (cur_part_id - rule.start_part_num) * rule.part_size;
149
150 if (rule.stripe_max_size > 0) {
151 cur_stripe = (ofs - part_ofs) / rule.stripe_max_size;
152
153 stripe_ofs = part_ofs + cur_stripe * rule.stripe_max_size;
154 if (!cur_part_id && manifest->get_head_size() > 0) {
155 cur_stripe++;
156 }
157 } else {
158 cur_stripe = 0;
159 stripe_ofs = part_ofs;
160 }
161
162 if (!rule.part_size) {
163 stripe_size = rule.stripe_max_size;
164 stripe_size = std::min(manifest->get_obj_size() - stripe_ofs, stripe_size);
165 } else {
166 uint64_t next = std::min(stripe_ofs + rule.stripe_max_size, part_ofs + rule.part_size);
167 stripe_size = next - stripe_ofs;
168 }
169
170 cur_override_prefix = rule.override_prefix;
171
172 update_location();
173 }
174
175 void RGWObjManifest::obj_iterator::update_explicit_pos()
176 {
177 ofs = explicit_iter->first;
178 stripe_ofs = ofs;
179
180 auto next_iter = explicit_iter;
181 ++next_iter;
182 if (next_iter != manifest->objs.end()) {
183 stripe_size = next_iter->first - ofs;
184 } else {
185 stripe_size = manifest->obj_size - ofs;
186 }
187 }
188
189 void RGWObjManifest::obj_iterator::update_location()
190 {
191 if (manifest->explicit_objs) {
192 if (manifest->empty()) {
193 location = rgw_obj_select{};
194 } else {
195 location = explicit_iter->second.loc;
196 }
197 return;
198 }
199
200 if (ofs < manifest->get_head_size()) {
201 location = manifest->get_obj();
202 location.set_placement_rule(manifest->get_head_placement_rule());
203 return;
204 }
205
206 manifest->get_implicit_location(cur_part_id, cur_stripe, ofs, &cur_override_prefix, &location);
207 }
208
209 void RGWObjManifest::get_implicit_location(uint64_t cur_part_id, uint64_t cur_stripe,
210 uint64_t ofs, string *override_prefix, rgw_obj_select *location) const
211 {
212 rgw_obj loc;
213
214 string& oid = loc.key.name;
215 string& ns = loc.key.ns;
216
217 if (!override_prefix || override_prefix->empty()) {
218 oid = prefix;
219 } else {
220 oid = *override_prefix;
221 }
222
223 if (!cur_part_id) {
224 if (ofs < max_head_size) {
225 location->set_placement_rule(head_placement_rule);
226 *location = obj;
227 return;
228 } else {
229 char buf[16];
230 snprintf(buf, sizeof(buf), "%d", (int)cur_stripe);
231 oid += buf;
232 ns = RGW_OBJ_NS_SHADOW;
233 }
234 } else {
235 char buf[32];
236 if (cur_stripe == 0) {
237 snprintf(buf, sizeof(buf), ".%d", (int)cur_part_id);
238 oid += buf;
239 ns= RGW_OBJ_NS_MULTIPART;
240 } else {
241 snprintf(buf, sizeof(buf), ".%d_%d", (int)cur_part_id, (int)cur_stripe);
242 oid += buf;
243 ns = RGW_OBJ_NS_SHADOW;
244 }
245 }
246
247 if (!tail_placement.bucket.name.empty()) {
248 loc.bucket = tail_placement.bucket;
249 } else {
250 loc.bucket = obj.bucket;
251 }
252
253 // Always overwrite instance with tail_instance
254 // to get the right shadow object location
255 loc.key.set_instance(tail_instance);
256
257 location->set_placement_rule(tail_placement.placement_rule);
258 *location = loc;
259 }
260