]>
git.proxmox.com Git - ceph.git/blob - 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
4 #include "rgw_obj_manifest.h"
6 #include "rgw_rados.h" // RGW_OBJ_NS_SHADOW and RGW_OBJ_NS_MULTIPART
10 void RGWObjManifest::obj_iterator::operator++()
12 if (manifest
->explicit_objs
) {
15 if (explicit_iter
== manifest
->objs
.end()) {
16 ofs
= manifest
->obj_size
;
21 update_explicit_pos();
27 uint64_t obj_size
= manifest
->get_obj_size();
28 uint64_t head_size
= manifest
->get_head_size();
30 if (ofs
== obj_size
) {
34 if (manifest
->rules
.empty()) {
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
);
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
);
53 const RGWObjManifestRule
*rule
= &rule_iter
->second
;
55 stripe_ofs
+= rule
->stripe_max_size
;
57 ldpp_dout(dpp
, 20) << "RGWObjManifest::operator++(): rule->part_size=" << rule
->part_size
<< " rules.size()=" << manifest
->rules
.size() << dendl
;
59 if (rule
->part_size
> 0) {
60 /* multi part, multi stripes object */
62 ldpp_dout(dpp
, 20) << "RGWObjManifest::operator++(): stripe_ofs=" << stripe_ofs
<< " part_ofs=" << part_ofs
<< " rule->part_size=" << rule
->part_size
<< dendl
;
64 if (stripe_ofs
>= part_ofs
+ rule
->part_size
) {
65 /* moved to the next part */
67 part_ofs
+= rule
->part_size
;
68 stripe_ofs
= part_ofs
;
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());
78 cur_part_id
= rule_iter
->second
.start_part_num
;
83 rule
= &rule_iter
->second
;
86 stripe_size
= std::min(rule
->part_size
- (stripe_ofs
- part_ofs
), rule
->stripe_max_size
);
89 cur_override_prefix
= rule
->override_prefix
;
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
;
102 void RGWObjManifest::obj_iterator::seek(uint64_t o
)
105 if (manifest
->explicit_objs
) {
106 explicit_iter
= manifest
->objs
.upper_bound(ofs
);
107 if (explicit_iter
!= manifest
->objs
.begin()) {
110 if (ofs
< manifest
->obj_size
) {
111 update_explicit_pos();
113 ofs
= manifest
->obj_size
;
118 if (o
< manifest
->get_head_size()) {
119 rule_iter
= manifest
->rules
.begin();
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
;
130 rule_iter
= manifest
->rules
.upper_bound(ofs
);
131 next_rule_iter
= rule_iter
;
132 if (rule_iter
!= manifest
->rules
.begin()) {
136 if (rule_iter
== manifest
->rules
.end()) {
141 const RGWObjManifestRule
& rule
= rule_iter
->second
;
143 if (rule
.part_size
> 0) {
144 cur_part_id
= rule
.start_part_num
+ (ofs
- rule
.start_ofs
) / rule
.part_size
;
146 cur_part_id
= rule
.start_part_num
;
148 part_ofs
= rule
.start_ofs
+ (cur_part_id
- rule
.start_part_num
) * rule
.part_size
;
150 if (rule
.stripe_max_size
> 0) {
151 cur_stripe
= (ofs
- part_ofs
) / rule
.stripe_max_size
;
153 stripe_ofs
= part_ofs
+ cur_stripe
* rule
.stripe_max_size
;
154 if (!cur_part_id
&& manifest
->get_head_size() > 0) {
159 stripe_ofs
= part_ofs
;
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
);
166 uint64_t next
= std::min(stripe_ofs
+ rule
.stripe_max_size
, part_ofs
+ rule
.part_size
);
167 stripe_size
= next
- stripe_ofs
;
170 cur_override_prefix
= rule
.override_prefix
;
175 void RGWObjManifest::obj_iterator::update_explicit_pos()
177 ofs
= explicit_iter
->first
;
180 auto next_iter
= explicit_iter
;
182 if (next_iter
!= manifest
->objs
.end()) {
183 stripe_size
= next_iter
->first
- ofs
;
185 stripe_size
= manifest
->obj_size
- ofs
;
189 void RGWObjManifest::obj_iterator::update_location()
191 if (manifest
->explicit_objs
) {
192 if (manifest
->empty()) {
193 location
= rgw_obj_select
{};
195 location
= explicit_iter
->second
.loc
;
200 if (ofs
< manifest
->get_head_size()) {
201 location
= manifest
->get_obj();
202 location
.set_placement_rule(manifest
->get_head_placement_rule());
206 manifest
->get_implicit_location(cur_part_id
, cur_stripe
, ofs
, &cur_override_prefix
, &location
);
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
214 string
& oid
= loc
.key
.name
;
215 string
& ns
= loc
.key
.ns
;
217 if (!override_prefix
|| override_prefix
->empty()) {
220 oid
= *override_prefix
;
224 if (ofs
< max_head_size
) {
225 location
->set_placement_rule(head_placement_rule
);
230 snprintf(buf
, sizeof(buf
), "%d", (int)cur_stripe
);
232 ns
= RGW_OBJ_NS_SHADOW
;
236 if (cur_stripe
== 0) {
237 snprintf(buf
, sizeof(buf
), ".%d", (int)cur_part_id
);
239 ns
= RGW_OBJ_NS_MULTIPART
;
241 snprintf(buf
, sizeof(buf
), ".%d_%d", (int)cur_part_id
, (int)cur_stripe
);
243 ns
= RGW_OBJ_NS_SHADOW
;
247 if (!tail_placement
.bucket
.name
.empty()) {
248 loc
.bucket
= tail_placement
.bucket
;
250 loc
.bucket
= obj
.bucket
;
253 // Always overwrite instance with tail_instance
254 // to get the right shadow object location
255 loc
.key
.set_instance(tail_instance
);
257 location
->set_placement_rule(tail_placement
.placement_rule
);