1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RGWRADOS_H
5 #define CEPH_RGWRADOS_H
9 #include "include/rados/librados.hpp"
10 #include "include/Context.h"
11 #include "common/RefCountedObj.h"
12 #include "common/RWLock.h"
13 #include "common/ceph_time.h"
14 #include "common/lru_map.h"
15 #include "rgw_common.h"
16 #include "cls/rgw/cls_rgw_types.h"
17 #include "cls/version/cls_version_types.h"
18 #include "cls/log/cls_log_types.h"
19 #include "cls/statelog/cls_statelog_types.h"
20 #include "cls/timeindex/cls_timeindex_types.h"
22 #include "rgw_metadata.h"
23 #include "rgw_meta_sync_status.h"
24 #include "rgw_period_puller.h"
25 #include "rgw_sync_module.h"
31 class RGWMetaNotifier
;
32 class RGWDataNotifier
;
34 class RGWObjectExpirer
;
35 class RGWMetaSyncProcessorThread
;
36 class RGWDataSyncProcessorThread
;
37 class RGWSyncLogTrimThread
;
44 /* flags for put_obj_meta() */
45 #define PUT_OBJ_CREATE 0x01
46 #define PUT_OBJ_EXCL 0x02
47 #define PUT_OBJ_CREATE_EXCL (PUT_OBJ_CREATE | PUT_OBJ_EXCL)
49 #define RGW_OBJ_NS_MULTIPART "multipart"
50 #define RGW_OBJ_NS_SHADOW "shadow"
52 #define RGW_BUCKET_INSTANCE_MD_PREFIX ".bucket.meta."
54 #define RGW_NO_SHARD -1
56 #define RGW_SHARDS_PRIME_0 7877
57 #define RGW_SHARDS_PRIME_1 65521
59 static inline int rgw_shards_mod(unsigned hval
, int max_shards
)
61 if (max_shards
<= RGW_SHARDS_PRIME_0
) {
62 return hval
% RGW_SHARDS_PRIME_0
% max_shards
;
64 return hval
% RGW_SHARDS_PRIME_1
% max_shards
;
67 static inline int rgw_shards_hash(const string
& key
, int max_shards
)
69 return rgw_shards_mod(ceph_str_hash_linux(key
.c_str(), key
.size()), max_shards
);
72 static inline int rgw_shards_max()
74 return RGW_SHARDS_PRIME_1
;
77 static inline void prepend_bucket_marker(const rgw_bucket
& bucket
, const string
& orig_oid
, string
& oid
)
79 if (bucket
.marker
.empty() || orig_oid
.empty()) {
88 static inline void get_obj_bucket_and_oid_loc(const rgw_obj
& obj
, string
& oid
, string
& locator
)
90 const rgw_bucket
& bucket
= obj
.bucket
;
91 prepend_bucket_marker(bucket
, obj
.get_oid(), oid
);
92 const string
& loc
= obj
.key
.get_loc();
94 prepend_bucket_marker(bucket
, loc
, locator
);
100 int rgw_init_ioctx(librados::Rados
*rados
, const rgw_pool
& pool
, librados::IoCtx
& ioctx
, bool create
= false);
102 int rgw_policy_from_attrset(CephContext
*cct
, map
<string
, bufferlist
>& attrset
, RGWAccessControlPolicy
*policy
);
104 static inline bool rgw_raw_obj_to_obj(const rgw_bucket
& bucket
, const rgw_raw_obj
& raw_obj
, rgw_obj
*obj
)
106 ssize_t pos
= raw_obj
.oid
.find('_');
111 if (!rgw_obj_key::parse_raw_oid(raw_obj
.oid
.substr(pos
+ 1), &obj
->key
)) {
114 obj
->bucket
= bucket
;
119 struct rgw_bucket_placement
{
120 string placement_rule
;
123 void dump(Formatter
*f
) const;
126 class rgw_obj_select
{
127 string placement_rule
;
133 rgw_obj_select() : is_raw(false) {}
134 rgw_obj_select(const rgw_obj
& _obj
) : obj(_obj
), is_raw(false) {}
135 rgw_obj_select(const rgw_raw_obj
& _raw_obj
) : raw_obj(_raw_obj
), is_raw(true) {}
136 rgw_obj_select(const rgw_obj_select
& rhs
) {
137 placement_rule
= rhs
.placement_rule
;
140 raw_obj
= rhs
.raw_obj
;
146 rgw_raw_obj
get_raw_obj(const RGWZoneGroup
& zonegroup
, const RGWZoneParams
& zone_params
) const;
147 rgw_raw_obj
get_raw_obj(RGWRados
*store
) const;
149 rgw_obj_select
& operator=(const rgw_obj
& rhs
) {
155 rgw_obj_select
& operator=(const rgw_raw_obj
& rhs
) {
161 void set_placement_rule(const string
& rule
) {
162 placement_rule
= rule
;
166 struct compression_block
{
171 void encode(bufferlist
& bl
) const {
172 ENCODE_START(1, 1, bl
);
173 ::encode(old_ofs
, bl
);
174 ::encode(new_ofs
, bl
);
179 void decode(bufferlist::iterator
& bl
) {
181 ::decode(old_ofs
, bl
);
182 ::decode(new_ofs
, bl
);
187 WRITE_CLASS_ENCODER(compression_block
)
189 struct RGWCompressionInfo
{
190 string compression_type
;
192 vector
<compression_block
> blocks
;
194 RGWCompressionInfo() : compression_type("none"), orig_size(0) {}
195 RGWCompressionInfo(const RGWCompressionInfo
& cs_info
) : compression_type(cs_info
.compression_type
),
196 orig_size(cs_info
.orig_size
),
197 blocks(cs_info
.blocks
) {}
199 void encode(bufferlist
& bl
) const {
200 ENCODE_START(1, 1, bl
);
201 ::encode(compression_type
, bl
);
202 ::encode(orig_size
, bl
);
203 ::encode(blocks
, bl
);
207 void decode(bufferlist::iterator
& bl
) {
209 ::decode(compression_type
, bl
);
210 ::decode(orig_size
, bl
);
211 ::decode(blocks
, bl
);
215 WRITE_CLASS_ENCODER(RGWCompressionInfo
)
217 int rgw_compression_info_from_attrset(map
<string
, bufferlist
>& attrs
, bool& need_decompress
, RGWCompressionInfo
& cs_info
);
223 RGWOLHInfo() : removed(false) {}
225 void encode(bufferlist
& bl
) const {
226 ENCODE_START(1, 1, bl
);
227 ::encode(target
, bl
);
228 ::encode(removed
, bl
);
232 void decode(bufferlist::iterator
& bl
) {
234 ::decode(target
, bl
);
235 ::decode(removed
, bl
);
238 static void generate_test_instances(list
<RGWOLHInfo
*>& o
);
239 void dump(Formatter
*f
) const;
241 WRITE_CLASS_ENCODER(RGWOLHInfo
)
243 struct RGWOLHPendingInfo
{
244 ceph::real_time time
;
246 RGWOLHPendingInfo() {}
248 void encode(bufferlist
& bl
) const {
249 ENCODE_START(1, 1, bl
);
254 void decode(bufferlist::iterator
& bl
) {
260 void dump(Formatter
*f
) const;
262 WRITE_CLASS_ENCODER(RGWOLHPendingInfo
)
264 struct RGWUsageBatch
{
265 map
<ceph::real_time
, rgw_usage_log_entry
> m
;
267 void insert(ceph::real_time
& t
, rgw_usage_log_entry
& entry
, bool *account
) {
268 bool exists
= m
.find(t
) != m
.end();
270 m
[t
].aggregate(entry
);
274 struct RGWUsageIter
{
278 RGWUsageIter() : index(0) {}
283 uint64_t extra_data_len
;
285 virtual int handle_data(bufferlist
& bl
, off_t bl_ofs
, off_t bl_len
) = 0;
286 RGWGetDataCB() : extra_data_len(0) {}
287 virtual ~RGWGetDataCB() {}
288 virtual void set_extra_data_len(uint64_t len
) {
289 extra_data_len
= len
;
292 * Flushes any cached data. Used by RGWGetObjFilter.
293 * Return logic same as handle_data.
295 virtual int flush() {
299 * Allows to extend fetch range of RGW object. Used by RGWGetObjFilter.
301 virtual int fixup_range(off_t
& bl_ofs
, off_t
& bl_end
) {
306 class RGWAccessListFilter
{
308 virtual ~RGWAccessListFilter() {}
309 virtual bool filter(string
& name
, string
& key
) = 0;
312 struct RGWCloneRangeInfo
{
319 struct RGWObjManifestPart
{
320 rgw_obj loc
; /* the object where the data is located */
321 uint64_t loc_ofs
; /* the offset at that object where the data is located */
322 uint64_t size
; /* the part size */
324 RGWObjManifestPart() : loc_ofs(0), size(0) {}
326 void encode(bufferlist
& bl
) const {
327 ENCODE_START(2, 2, bl
);
329 ::encode(loc_ofs
, bl
);
334 void decode(bufferlist::iterator
& bl
) {
335 DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl
);
337 ::decode(loc_ofs
, bl
);
342 void dump(Formatter
*f
) const;
343 static void generate_test_instances(list
<RGWObjManifestPart
*>& o
);
345 WRITE_CLASS_ENCODER(RGWObjManifestPart
)
348 The manifest defines a set of rules for structuring the object parts.
349 There are a few terms to note:
350 - head: the head part of the object, which is the part that contains
351 the first chunk of data. An object might not have a head (as in the
352 case of multipart-part objects).
353 - stripe: data portion of a single rgw object that resides on a single
355 - part: a collection of stripes that make a contiguous part of an
356 object. A regular object will only have one part (although might have
357 many stripes), a multipart object might have many parts. Each part
358 has a fixed stripe size, although the last stripe of a part might
359 be smaller than that. Consecutive parts may be merged if their stripe
363 struct RGWObjManifestRule
{
364 uint32_t start_part_num
;
366 uint64_t part_size
; /* each part size, 0 if there's no part size, meaning it's unlimited */
367 uint64_t stripe_max_size
; /* underlying obj max size */
368 string override_prefix
;
370 RGWObjManifestRule() : start_part_num(0), start_ofs(0), part_size(0), stripe_max_size(0) {}
371 RGWObjManifestRule(uint32_t _start_part_num
, uint64_t _start_ofs
, uint64_t _part_size
, uint64_t _stripe_max_size
) :
372 start_part_num(_start_part_num
), start_ofs(_start_ofs
), part_size(_part_size
), stripe_max_size(_stripe_max_size
) {}
374 void encode(bufferlist
& bl
) const {
375 ENCODE_START(2, 1, bl
);
376 ::encode(start_part_num
, bl
);
377 ::encode(start_ofs
, bl
);
378 ::encode(part_size
, bl
);
379 ::encode(stripe_max_size
, bl
);
380 ::encode(override_prefix
, bl
);
384 void decode(bufferlist::iterator
& bl
) {
386 ::decode(start_part_num
, bl
);
387 ::decode(start_ofs
, bl
);
388 ::decode(part_size
, bl
);
389 ::decode(stripe_max_size
, bl
);
391 ::decode(override_prefix
, bl
);
394 void dump(Formatter
*f
) const;
396 WRITE_CLASS_ENCODER(RGWObjManifestRule
)
398 class RGWObjManifest
{
400 bool explicit_objs
; /* old manifest? */
401 map
<uint64_t, RGWObjManifestPart
> objs
;
407 string head_placement_rule
;
409 uint64_t max_head_size
;
411 rgw_bucket_placement tail_placement
; /* might be different than the original bucket,
412 as object might have been copied across pools */
413 map
<uint64_t, RGWObjManifestRule
> rules
;
415 string tail_instance
; /* tail object's instance */
417 void convert_to_explicit(const RGWZoneGroup
& zonegroup
, const RGWZoneParams
& zone_params
);
418 int append_explicit(RGWObjManifest
& m
, const RGWZoneGroup
& zonegroup
, const RGWZoneParams
& zone_params
);
419 void append_rules(RGWObjManifest
& m
, map
<uint64_t, RGWObjManifestRule
>::iterator
& iter
, string
*override_prefix
);
421 void update_iterators() {
423 end_iter
.seek(obj_size
);
427 RGWObjManifest() : explicit_objs(false), obj_size(0), head_size(0), max_head_size(0),
428 begin_iter(this), end_iter(this) {}
429 RGWObjManifest(const RGWObjManifest
& rhs
) {
432 RGWObjManifest
& operator=(const RGWObjManifest
& rhs
) {
433 explicit_objs
= rhs
.explicit_objs
;
435 obj_size
= rhs
.obj_size
;
437 head_size
= rhs
.head_size
;
438 max_head_size
= rhs
.max_head_size
;
440 tail_placement
= rhs
.tail_placement
;
442 tail_instance
= rhs
.tail_instance
;
444 begin_iter
.set_manifest(this);
445 end_iter
.set_manifest(this);
447 begin_iter
.seek(rhs
.begin_iter
.get_ofs());
448 end_iter
.seek(rhs
.end_iter
.get_ofs());
453 map
<uint64_t, RGWObjManifestPart
>& get_explicit_objs() {
458 void set_explicit(uint64_t _size
, map
<uint64_t, RGWObjManifestPart
>& _objs
) {
459 explicit_objs
= true;
464 void get_implicit_location(uint64_t cur_part_id
, uint64_t cur_stripe
, uint64_t ofs
, string
*override_prefix
, rgw_obj_select
*location
);
466 void set_trivial_rule(uint64_t tail_ofs
, uint64_t stripe_max_size
) {
467 RGWObjManifestRule
rule(0, tail_ofs
, 0, stripe_max_size
);
469 max_head_size
= tail_ofs
;
472 void set_multipart_part_rule(uint64_t stripe_max_size
, uint64_t part_num
) {
473 RGWObjManifestRule
rule(0, 0, 0, stripe_max_size
);
474 rule
.start_part_num
= part_num
;
479 void encode(bufferlist
& bl
) const {
480 ENCODE_START(7, 6, bl
);
481 ::encode(obj_size
, bl
);
483 ::encode(explicit_objs
, bl
);
485 ::encode(head_size
, bl
);
486 ::encode(max_head_size
, bl
);
487 ::encode(prefix
, bl
);
489 bool encode_tail_bucket
= !(tail_placement
.bucket
== obj
.bucket
);
490 ::encode(encode_tail_bucket
, bl
);
491 if (encode_tail_bucket
) {
492 ::encode(tail_placement
.bucket
, bl
);
494 bool encode_tail_instance
= (tail_instance
!= obj
.key
.instance
);
495 ::encode(encode_tail_instance
, bl
);
496 if (encode_tail_instance
) {
497 ::encode(tail_instance
, bl
);
499 ::encode(head_placement_rule
, bl
);
500 ::encode(tail_placement
.placement_rule
, bl
);
504 void decode(bufferlist::iterator
& bl
) {
505 DECODE_START_LEGACY_COMPAT_LEN_32(7, 2, 2, bl
);
506 ::decode(obj_size
, bl
);
509 ::decode(explicit_objs
, bl
);
511 ::decode(head_size
, bl
);
512 ::decode(max_head_size
, bl
);
513 ::decode(prefix
, bl
);
516 explicit_objs
= true;
518 map
<uint64_t, RGWObjManifestPart
>::iterator iter
= objs
.begin();
519 obj
= iter
->second
.loc
;
520 head_size
= iter
->second
.size
;
521 max_head_size
= head_size
;
525 if (explicit_objs
&& head_size
> 0 && !objs
.empty()) {
526 /* patch up manifest due to issue 16435:
527 * the first object in the explicit objs list might not be the one we need to access, use the
528 * head object instead if set. This would happen if we had an old object that was created
529 * when the explicit objs manifest was around, and it got copied.
531 rgw_obj
& obj_0
= objs
[0].loc
;
532 if (!obj_0
.get_oid().empty() && obj_0
.key
.ns
.empty()) {
534 objs
[0].size
= head_size
;
540 ::decode(tail_placement
.bucket
, bl
);
543 ::decode(need_to_decode
, bl
);
544 if (need_to_decode
) {
545 ::decode(tail_placement
.bucket
, bl
);
547 tail_placement
.bucket
= obj
.bucket
;
554 ::decode(tail_instance
, bl
);
557 ::decode(need_to_decode
, bl
);
558 if (need_to_decode
) {
559 ::decode(tail_instance
, bl
);
561 tail_instance
= obj
.key
.instance
;
564 } else { // old object created before 'tail_instance' field added to manifest
565 tail_instance
= obj
.key
.instance
;
569 ::decode(head_placement_rule
, bl
);
570 ::decode(tail_placement
.placement_rule
, bl
);
577 void dump(Formatter
*f
) const;
578 static void generate_test_instances(list
<RGWObjManifest
*>& o
);
580 int append(RGWObjManifest
& m
, RGWZoneGroup
& zonegroup
, RGWZoneParams
& zone_params
);
581 int append(RGWObjManifest
& m
, RGWRados
*store
);
583 bool get_rule(uint64_t ofs
, RGWObjManifestRule
*rule
);
588 return rules
.empty();
591 bool has_explicit_objs() {
592 return explicit_objs
;
597 if (objs
.size() == 1) {
598 map
<uint64_t, RGWObjManifestPart
>::iterator iter
= objs
.begin();
599 rgw_obj
& o
= iter
->second
.loc
;
602 return (objs
.size() >= 2);
604 return (obj_size
> head_size
);
607 void set_head(const string
& placement_rule
, const rgw_obj
& _o
, uint64_t _s
) {
608 head_placement_rule
= placement_rule
;
612 if (explicit_objs
&& head_size
> 0) {
614 objs
[0].size
= head_size
;
618 const rgw_obj
& get_obj() {
622 void set_tail_placement(const string
& placement_rule
, const rgw_bucket
& _b
) {
623 tail_placement
.placement_rule
= placement_rule
;
624 tail_placement
.bucket
= _b
;
627 const rgw_bucket_placement
& get_tail_placement() {
628 return tail_placement
;
631 const string
& get_head_placement_rule() {
632 return head_placement_rule
;
635 void set_prefix(const string
& _p
) {
639 const string
& get_prefix() {
643 void set_tail_instance(const string
& _ti
) {
647 const string
& get_tail_instance() {
648 return tail_instance
;
651 void set_head_size(uint64_t _s
) {
655 void set_obj_size(uint64_t s
) {
661 uint64_t get_obj_size() {
665 uint64_t get_head_size() {
669 void set_max_head_size(uint64_t s
) {
673 uint64_t get_max_head_size() {
674 return max_head_size
;
678 RGWObjManifest
*manifest
;
679 uint64_t part_ofs
; /* where current part starts */
680 uint64_t stripe_ofs
; /* where current stripe starts */
681 uint64_t ofs
; /* current position within the object */
682 uint64_t stripe_size
; /* current part size */
686 string cur_override_prefix
;
688 rgw_obj_select location
;
690 map
<uint64_t, RGWObjManifestRule
>::iterator rule_iter
;
691 map
<uint64_t, RGWObjManifestRule
>::iterator next_rule_iter
;
693 map
<uint64_t, RGWObjManifestPart
>::iterator explicit_iter
;
704 void update_explicit_pos();
709 void set_manifest(RGWObjManifest
*m
) {
714 obj_iterator() : manifest(NULL
) {
717 explicit obj_iterator(RGWObjManifest
*_m
) : manifest(_m
) {
719 if (!manifest
->empty()) {
723 obj_iterator(RGWObjManifest
*_m
, uint64_t _ofs
) : manifest(_m
) {
725 if (!manifest
->empty()) {
729 void seek(uint64_t ofs
);
732 bool operator==(const obj_iterator
& rhs
) {
733 return (ofs
== rhs
.ofs
);
735 bool operator!=(const obj_iterator
& rhs
) {
736 return (ofs
!= rhs
.ofs
);
738 const rgw_obj_select
& get_location() {
742 /* start of current stripe */
743 uint64_t get_stripe_ofs() {
744 if (manifest
->explicit_objs
) {
745 return explicit_iter
->first
;
750 /* current ofs relative to start of rgw object */
751 uint64_t get_ofs() const {
756 int get_cur_stripe() const {
760 /* current stripe size */
761 uint64_t get_stripe_size() {
762 if (manifest
->explicit_objs
) {
763 return explicit_iter
->second
.size
;
768 /* offset where data starts within current stripe */
769 uint64_t location_ofs() {
770 if (manifest
->explicit_objs
) {
771 return explicit_iter
->second
.loc_ofs
;
773 return 0; /* all stripes start at zero offset */
776 void update_location();
778 friend class RGWObjManifest
;
781 const obj_iterator
& obj_begin();
782 const obj_iterator
& obj_end();
783 obj_iterator
obj_find(uint64_t ofs
);
785 obj_iterator begin_iter
;
786 obj_iterator end_iter
;
789 * simple object generator. Using a simple single rule manifest.
792 RGWObjManifest
*manifest
;
794 uint64_t cur_part_ofs
;
797 uint64_t cur_stripe_size
;
802 rgw_obj_select cur_obj
;
804 RGWObjManifestRule rule
;
807 generator() : manifest(NULL
), last_ofs(0), cur_part_ofs(0), cur_part_id(0),
808 cur_stripe(0), cur_stripe_size(0) {}
809 int create_begin(CephContext
*cct
, RGWObjManifest
*manifest
, const string
& placement_rule
, rgw_bucket
& bucket
, rgw_obj
& obj
);
811 int create_next(uint64_t ofs
);
813 rgw_raw_obj
get_cur_obj(RGWZoneGroup
& zonegroup
, RGWZoneParams
& zone_params
) { return cur_obj
.get_raw_obj(zonegroup
, zone_params
); }
814 rgw_raw_obj
get_cur_obj(RGWRados
*store
) { return cur_obj
.get_raw_obj(store
); }
816 /* total max size of current stripe (including head obj) */
817 uint64_t cur_stripe_max_size() {
818 return cur_stripe_size
;
822 WRITE_CLASS_ENCODER(RGWObjManifest
)
824 struct RGWUploadPartInfo
{
827 uint64_t accounted_size
{0};
829 ceph::real_time modified
;
830 RGWObjManifest manifest
;
831 RGWCompressionInfo cs_info
;
833 RGWUploadPartInfo() : num(0), size(0) {}
835 void encode(bufferlist
& bl
) const {
836 ENCODE_START(4, 2, bl
);
840 ::encode(modified
, bl
);
841 ::encode(manifest
, bl
);
842 ::encode(cs_info
, bl
);
843 ::encode(accounted_size
, bl
);
846 void decode(bufferlist::iterator
& bl
) {
847 DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl
);
851 ::decode(modified
, bl
);
853 ::decode(manifest
, bl
);
855 ::decode(cs_info
, bl
);
856 ::decode(accounted_size
, bl
);
858 accounted_size
= size
;
862 void dump(Formatter
*f
) const;
863 static void generate_test_instances(list
<RGWUploadPartInfo
*>& o
);
865 WRITE_CLASS_ENCODER(RGWUploadPartInfo
)
872 uint64_t size
; //< size of raw object
873 uint64_t accounted_size
{0}; //< size before compression, encryption
874 ceph::real_time mtime
;
879 RGWObjManifest manifest
;
889 uint32_t zone_short_id
;
891 /* important! don't forget to update copy constructor */
893 RGWObjVersionTracker objv_tracker
;
895 map
<string
, bufferlist
> attrset
;
896 RGWObjState() : is_atomic(false), has_attrs(0), exists(false),
897 size(0), epoch(0), fake_tag(false), has_manifest(false),
898 has_data(false), prefetch_data(false), keep_tail(false), is_olh(false),
899 pg_ver(0), zone_short_id(0) {}
900 RGWObjState(const RGWObjState
& rhs
) : obj (rhs
.obj
) {
901 is_atomic
= rhs
.is_atomic
;
902 has_attrs
= rhs
.has_attrs
;
905 accounted_size
= rhs
.accounted_size
;
908 if (rhs
.obj_tag
.length()) {
909 obj_tag
= rhs
.obj_tag
;
911 write_tag
= rhs
.write_tag
;
912 fake_tag
= rhs
.fake_tag
;
913 if (rhs
.has_manifest
) {
914 manifest
= rhs
.manifest
;
916 has_manifest
= rhs
.has_manifest
;
917 shadow_obj
= rhs
.shadow_obj
;
918 has_data
= rhs
.has_data
;
919 if (rhs
.data
.length()) {
922 prefetch_data
= rhs
.prefetch_data
;
923 keep_tail
= rhs
.keep_tail
;
925 objv_tracker
= rhs
.objv_tracker
;
929 bool get_attr(string name
, bufferlist
& dest
) {
930 map
<string
, bufferlist
>::iterator iter
= attrset
.find(name
);
931 if (iter
!= attrset
.end()) {
939 struct RGWRawObjState
{
941 bool has_attrs
{false};
944 ceph::real_time mtime
;
947 bool has_data
{false};
949 bool prefetch_data
{false};
952 /* important! don't forget to update copy constructor */
954 RGWObjVersionTracker objv_tracker
;
956 map
<string
, bufferlist
> attrset
;
958 RGWRawObjState(const RGWRawObjState
& rhs
) : obj (rhs
.obj
) {
959 has_attrs
= rhs
.has_attrs
;
964 if (rhs
.obj_tag
.length()) {
965 obj_tag
= rhs
.obj_tag
;
967 has_data
= rhs
.has_data
;
968 if (rhs
.data
.length()) {
971 prefetch_data
= rhs
.prefetch_data
;
973 objv_tracker
= rhs
.objv_tracker
;
977 struct RGWPoolIterCtx
{
978 librados::IoCtx io_ctx
;
979 librados::NObjectIterator iter
;
982 struct RGWListRawObjsCtx
{
984 RGWPoolIterCtx iter_ctx
;
986 RGWListRawObjsCtx() : initialized(false) {}
989 struct RGWDefaultSystemMetaObjInfo
{
992 void encode(bufferlist
& bl
) const {
993 ENCODE_START(1, 1, bl
);
994 ::encode(default_id
, bl
);
998 void decode(bufferlist::iterator
& bl
) {
1000 ::decode(default_id
, bl
);
1004 void dump(Formatter
*f
) const;
1005 void decode_json(JSONObj
*obj
);
1007 WRITE_CLASS_ENCODER(RGWDefaultSystemMetaObjInfo
)
1009 struct RGWNameToId
{
1012 void encode(bufferlist
& bl
) const {
1013 ENCODE_START(1, 1, bl
);
1014 ::encode(obj_id
, bl
);
1018 void decode(bufferlist::iterator
& bl
) {
1019 DECODE_START(1, bl
);
1020 ::decode(obj_id
, bl
);
1024 void dump(Formatter
*f
) const;
1025 void decode_json(JSONObj
*obj
);
1027 WRITE_CLASS_ENCODER(RGWNameToId
)
1029 class RGWSystemMetaObj
{
1037 int store_name(bool exclusive
);
1038 int store_info(bool exclusive
);
1039 int read_info(const string
& obj_id
, bool old_format
= false);
1040 int read_id(const string
& obj_name
, string
& obj_id
);
1041 int read_default(RGWDefaultSystemMetaObjInfo
& default_info
,
1043 /* read and use default id */
1044 int use_default(bool old_format
= false);
1047 RGWSystemMetaObj() : cct(NULL
), store(NULL
) {}
1048 RGWSystemMetaObj(const string
& _name
): name(_name
), cct(NULL
), store(NULL
) {}
1049 RGWSystemMetaObj(const string
& _id
, const string
& _name
) : id(_id
), name(_name
), cct(NULL
), store(NULL
) {}
1050 RGWSystemMetaObj(CephContext
*_cct
, RGWRados
*_store
): cct(_cct
), store(_store
){}
1051 RGWSystemMetaObj(const string
& _name
, CephContext
*_cct
, RGWRados
*_store
): name(_name
), cct(_cct
), store(_store
){}
1052 const string
& get_name() const { return name
; }
1053 const string
& get_id() const { return id
; }
1055 void set_name(const string
& _name
) { name
= _name
;}
1056 void set_id(const string
& _id
) { id
= _id
;}
1057 void clear_id() { id
.clear(); }
1059 virtual ~RGWSystemMetaObj() {}
1061 virtual void encode(bufferlist
& bl
) const {
1062 ENCODE_START(1, 1, bl
);
1068 virtual void decode(bufferlist::iterator
& bl
) {
1069 DECODE_START(1, bl
);
1075 void reinit_instance(CephContext
*_cct
, RGWRados
*_store
) {
1079 int init(CephContext
*_cct
, RGWRados
*_store
, bool setup_obj
= true, bool old_format
= false);
1080 virtual int read_default_id(string
& default_id
, bool old_format
= false);
1081 virtual int set_as_default(bool exclusive
= false);
1082 int delete_default();
1083 virtual int create(bool exclusive
= true);
1084 int delete_obj(bool old_format
= false);
1085 int rename(const string
& new_name
);
1086 int update() { return store_info(false);}
1087 int update_name() { return store_name(false);}
1089 int write(bool exclusive
);
1091 virtual rgw_pool
get_pool(CephContext
*cct
) = 0;
1092 virtual const string
get_default_oid(bool old_format
= false) = 0;
1093 virtual const string
& get_names_oid_prefix() = 0;
1094 virtual const string
& get_info_oid_prefix(bool old_format
= false) = 0;
1095 virtual const string
& get_predefined_name(CephContext
*cct
) = 0;
1097 void dump(Formatter
*f
) const;
1098 void decode_json(JSONObj
*obj
);
1100 WRITE_CLASS_ENCODER(RGWSystemMetaObj
)
1102 struct RGWZonePlacementInfo
{
1103 rgw_pool index_pool
;
1105 rgw_pool data_extra_pool
; /* if not set we should use data_pool */
1106 RGWBucketIndexType index_type
;
1107 std::string compression_type
;
1109 RGWZonePlacementInfo() : index_type(RGWBIType_Normal
) {}
1111 void encode(bufferlist
& bl
) const {
1112 ENCODE_START(6, 1, bl
);
1113 ::encode(index_pool
.to_str(), bl
);
1114 ::encode(data_pool
.to_str(), bl
);
1115 ::encode(data_extra_pool
.to_str(), bl
);
1116 ::encode((uint32_t)index_type
, bl
);
1117 ::encode(compression_type
, bl
);
1121 void decode(bufferlist::iterator
& bl
) {
1122 DECODE_START(6, bl
);
1123 string index_pool_str
;
1124 string data_pool_str
;
1125 ::decode(index_pool_str
, bl
);
1126 index_pool
= rgw_pool(index_pool_str
);
1127 ::decode(data_pool_str
, bl
);
1128 data_pool
= rgw_pool(data_pool_str
);
1129 if (struct_v
>= 4) {
1130 string data_extra_pool_str
;
1131 ::decode(data_extra_pool_str
, bl
);
1132 data_extra_pool
= rgw_pool(data_extra_pool_str
);
1134 if (struct_v
>= 5) {
1137 index_type
= (RGWBucketIndexType
)it
;
1139 if (struct_v
>= 6) {
1140 ::decode(compression_type
, bl
);
1144 const rgw_pool
& get_data_extra_pool() const {
1145 if (data_extra_pool
.empty()) {
1148 return data_extra_pool
;
1150 void dump(Formatter
*f
) const;
1151 void decode_json(JSONObj
*obj
);
1153 WRITE_CLASS_ENCODER(RGWZonePlacementInfo
)
1155 struct RGWZoneParams
: RGWSystemMetaObj
{
1156 rgw_pool domain_root
;
1157 rgw_pool metadata_heap
;
1158 rgw_pool control_pool
;
1162 rgw_pool intent_log_pool
;
1163 rgw_pool usage_log_pool
;
1165 rgw_pool user_keys_pool
;
1166 rgw_pool user_email_pool
;
1167 rgw_pool user_swift_pool
;
1168 rgw_pool user_uid_pool
;
1169 rgw_pool roles_pool
;
1170 rgw_pool reshard_pool
;
1172 RGWAccessKey system_key
;
1174 map
<string
, RGWZonePlacementInfo
> placement_pools
;
1178 map
<string
, string
, ltstr_nocase
> tier_config
;
1180 RGWZoneParams() : RGWSystemMetaObj() {}
1181 RGWZoneParams(const string
& name
) : RGWSystemMetaObj(name
){}
1182 RGWZoneParams(const string
& id
, const string
& name
) : RGWSystemMetaObj(id
, name
) {}
1183 RGWZoneParams(const string
& id
, const string
& name
, const string
& _realm_id
)
1184 : RGWSystemMetaObj(id
, name
), realm_id(_realm_id
) {}
1186 rgw_pool
get_pool(CephContext
*cct
);
1187 const string
get_default_oid(bool old_format
= false) override
;
1188 const string
& get_names_oid_prefix() override
;
1189 const string
& get_info_oid_prefix(bool old_format
= false) override
;
1190 const string
& get_predefined_name(CephContext
*cct
) override
;
1192 int init(CephContext
*_cct
, RGWRados
*_store
, bool setup_obj
= true,
1193 bool old_format
= false);
1194 using RGWSystemMetaObj::init
;
1195 int read_default_id(string
& default_id
, bool old_format
= false) override
;
1196 int set_as_default(bool exclusive
= false) override
;
1197 int create_default(bool old_format
= false);
1198 int create(bool exclusive
= true) override
;
1199 int fix_pool_names();
1201 const string
& get_compression_type(const string
& placement_rule
) const;
1203 void encode(bufferlist
& bl
) const override
{
1204 ENCODE_START(10, 1, bl
);
1205 ::encode(domain_root
, bl
);
1206 ::encode(control_pool
, bl
);
1207 ::encode(gc_pool
, bl
);
1208 ::encode(log_pool
, bl
);
1209 ::encode(intent_log_pool
, bl
);
1210 ::encode(usage_log_pool
, bl
);
1211 ::encode(user_keys_pool
, bl
);
1212 ::encode(user_email_pool
, bl
);
1213 ::encode(user_swift_pool
, bl
);
1214 ::encode(user_uid_pool
, bl
);
1215 RGWSystemMetaObj::encode(bl
);
1216 ::encode(system_key
, bl
);
1217 ::encode(placement_pools
, bl
);
1218 ::encode(metadata_heap
, bl
);
1219 ::encode(realm_id
, bl
);
1220 ::encode(lc_pool
, bl
);
1221 ::encode(tier_config
, bl
);
1222 ::encode(roles_pool
, bl
);
1223 ::encode(reshard_pool
, bl
);
1227 void decode(bufferlist::iterator
& bl
) override
{
1228 DECODE_START(10, bl
);
1229 ::decode(domain_root
, bl
);
1230 ::decode(control_pool
, bl
);
1231 ::decode(gc_pool
, bl
);
1232 ::decode(log_pool
, bl
);
1233 ::decode(intent_log_pool
, bl
);
1234 ::decode(usage_log_pool
, bl
);
1235 ::decode(user_keys_pool
, bl
);
1236 ::decode(user_email_pool
, bl
);
1237 ::decode(user_swift_pool
, bl
);
1238 ::decode(user_uid_pool
, bl
);
1239 if (struct_v
>= 6) {
1240 RGWSystemMetaObj::decode(bl
);
1241 } else if (struct_v
>= 2) {
1246 ::decode(system_key
, bl
);
1248 ::decode(placement_pools
, bl
);
1250 ::decode(metadata_heap
, bl
);
1251 if (struct_v
>= 6) {
1252 ::decode(realm_id
, bl
);
1254 if (struct_v
>= 7) {
1255 ::decode(lc_pool
, bl
);
1257 lc_pool
= log_pool
.name
+ ":lc";
1259 if (struct_v
>= 8) {
1260 ::decode(tier_config
, bl
);
1262 if (struct_v
>= 9) {
1263 ::decode(roles_pool
, bl
);
1265 roles_pool
= name
+ ".rgw.meta:roles";
1267 if (struct_v
>= 10) {
1268 ::decode(reshard_pool
, bl
);
1270 reshard_pool
= log_pool
.name
+ ":reshard";
1274 void dump(Formatter
*f
) const;
1275 void decode_json(JSONObj
*obj
);
1276 static void generate_test_instances(list
<RGWZoneParams
*>& o
);
1278 bool get_placement(const string
& placement_id
, RGWZonePlacementInfo
*placement
) const {
1279 auto iter
= placement_pools
.find(placement_id
);
1280 if (iter
== placement_pools
.end()) {
1283 *placement
= iter
->second
;
1288 * return data pool of the head object
1290 bool get_head_data_pool(const string
& placement_id
, const rgw_obj
& obj
, rgw_pool
*pool
) const {
1291 const rgw_data_placement_target
& explicit_placement
= obj
.bucket
.explicit_placement
;
1292 if (!explicit_placement
.data_pool
.empty()) {
1293 if (!obj
.in_extra_data
) {
1294 *pool
= explicit_placement
.data_pool
;
1296 *pool
= explicit_placement
.get_data_extra_pool();
1300 if (placement_id
.empty()) {
1303 auto iter
= placement_pools
.find(placement_id
);
1304 if (iter
== placement_pools
.end()) {
1307 if (!obj
.in_extra_data
) {
1308 *pool
= iter
->second
.data_pool
;
1310 *pool
= iter
->second
.get_data_extra_pool();
1315 WRITE_CLASS_ENCODER(RGWZoneParams
)
1320 list
<string
> endpoints
;
1327 * Represents the number of shards for the bucket index object, a value of zero
1328 * indicates there is no sharding. By default (no sharding, the name of the object
1329 * is '.dir.{marker}', with sharding, the name is '.dir.{marker}.{sharding_id}',
1330 * sharding_id is zero-based value. It is not recommended to set a too large value
1331 * (e.g. thousand) as it increases the cost for bucket listing.
1333 uint32_t bucket_index_max_shards
;
1336 set
<string
> sync_from
; /* list of zones to sync from */
1338 RGWZone() : log_meta(false), log_data(false), read_only(false), bucket_index_max_shards(0),
1339 sync_from_all(true) {}
1341 void encode(bufferlist
& bl
) const {
1342 ENCODE_START(6, 1, bl
);
1344 ::encode(endpoints
, bl
);
1345 ::encode(log_meta
, bl
);
1346 ::encode(log_data
, bl
);
1347 ::encode(bucket_index_max_shards
, bl
);
1349 ::encode(read_only
, bl
);
1350 ::encode(tier_type
, bl
);
1351 ::encode(sync_from_all
, bl
);
1352 ::encode(sync_from
, bl
);
1356 void decode(bufferlist::iterator
& bl
) {
1357 DECODE_START(6, bl
);
1362 ::decode(endpoints
, bl
);
1363 if (struct_v
>= 2) {
1364 ::decode(log_meta
, bl
);
1365 ::decode(log_data
, bl
);
1367 if (struct_v
>= 3) {
1368 ::decode(bucket_index_max_shards
, bl
);
1370 if (struct_v
>= 4) {
1372 ::decode(read_only
, bl
);
1374 if (struct_v
>= 5) {
1375 ::decode(tier_type
, bl
);
1377 if (struct_v
>= 6) {
1378 ::decode(sync_from_all
, bl
);
1379 ::decode(sync_from
, bl
);
1383 void dump(Formatter
*f
) const;
1384 void decode_json(JSONObj
*obj
);
1385 static void generate_test_instances(list
<RGWZone
*>& o
);
1387 bool is_read_only() { return read_only
; }
1389 bool syncs_from(const string
& zone_id
) {
1390 return (sync_from_all
|| sync_from
.find(zone_id
) != sync_from
.end());
1393 WRITE_CLASS_ENCODER(RGWZone
)
1395 struct RGWDefaultZoneGroupInfo
{
1396 string default_zonegroup
;
1398 void encode(bufferlist
& bl
) const {
1399 ENCODE_START(1, 1, bl
);
1400 ::encode(default_zonegroup
, bl
);
1404 void decode(bufferlist::iterator
& bl
) {
1405 DECODE_START(1, bl
);
1406 ::decode(default_zonegroup
, bl
);
1409 void dump(Formatter
*f
) const;
1410 void decode_json(JSONObj
*obj
);
1411 //todo: implement ceph-dencoder
1413 WRITE_CLASS_ENCODER(RGWDefaultZoneGroupInfo
)
1415 struct RGWZoneGroupPlacementTarget
{
1419 bool user_permitted(list
<string
>& user_tags
) const {
1423 for (auto& rule
: user_tags
) {
1424 if (tags
.find(rule
) != tags
.end()) {
1431 void encode(bufferlist
& bl
) const {
1432 ENCODE_START(1, 1, bl
);
1438 void decode(bufferlist::iterator
& bl
) {
1439 DECODE_START(1, bl
);
1444 void dump(Formatter
*f
) const;
1445 void decode_json(JSONObj
*obj
);
1447 WRITE_CLASS_ENCODER(RGWZoneGroupPlacementTarget
)
1450 struct RGWZoneGroup
: public RGWSystemMetaObj
{
1452 list
<string
> endpoints
;
1456 map
<string
, RGWZone
> zones
;
1458 map
<string
, RGWZoneGroupPlacementTarget
> placement_targets
;
1459 string default_placement
;
1461 list
<string
> hostnames
;
1462 list
<string
> hostnames_s3website
;
1463 // TODO: Maybe convert hostnames to a map<string,list<string>> for
1464 // endpoint_type->hostnames
1466 20:05 < _robbat21irssi> maybe I do someting like: if (hostname_map.empty()) { populate all map keys from hostnames; };
1467 20:05 < _robbat21irssi> but that's a later compatability migration planning bit
1468 20:06 < yehudasa> more like if (!hostnames.empty()) {
1469 20:06 < yehudasa> for (list<string>::iterator iter = hostnames.begin(); iter != hostnames.end(); ++iter) {
1470 20:06 < yehudasa> hostname_map["s3"].append(iter->second);
1471 20:07 < yehudasa> hostname_map["s3website"].append(iter->second);
1472 20:07 < yehudasa> s/append/push_back/g
1473 20:08 < _robbat21irssi> inner loop over APIs
1474 20:08 < yehudasa> yeah, probably
1475 20:08 < _robbat21irssi> s3, s3website, swift, swith_auth, swift_website
1477 map
<string
, list
<string
> > api_hostname_map
;
1478 map
<string
, list
<string
> > api_endpoints_map
;
1482 RGWZoneGroup(): is_master(false){}
1483 RGWZoneGroup(const std::string
&id
, const std::string
&name
):RGWSystemMetaObj(id
, name
) {}
1484 RGWZoneGroup(const std::string
&_name
):RGWSystemMetaObj(_name
) {}
1485 RGWZoneGroup(const std::string
&_name
, bool _is_master
, CephContext
*cct
, RGWRados
* store
,
1486 const string
& _realm_id
, const list
<string
>& _endpoints
)
1487 : RGWSystemMetaObj(_name
, cct
, store
), endpoints(_endpoints
), is_master(_is_master
),
1488 realm_id(_realm_id
) {}
1490 bool is_master_zonegroup() const { return is_master
;}
1491 void update_master(bool _is_master
) {
1492 is_master
= _is_master
;
1493 post_process_params();
1495 void post_process_params();
1497 void encode(bufferlist
& bl
) const override
{
1498 ENCODE_START(4, 1, bl
);
1500 ::encode(api_name
, bl
);
1501 ::encode(is_master
, bl
);
1502 ::encode(endpoints
, bl
);
1503 ::encode(master_zone
, bl
);
1504 ::encode(zones
, bl
);
1505 ::encode(placement_targets
, bl
);
1506 ::encode(default_placement
, bl
);
1507 ::encode(hostnames
, bl
);
1508 ::encode(hostnames_s3website
, bl
);
1509 RGWSystemMetaObj::encode(bl
);
1510 ::encode(realm_id
, bl
);
1514 void decode(bufferlist::iterator
& bl
) override
{
1515 DECODE_START(4, bl
);
1517 ::decode(api_name
, bl
);
1518 ::decode(is_master
, bl
);
1519 ::decode(endpoints
, bl
);
1520 ::decode(master_zone
, bl
);
1521 ::decode(zones
, bl
);
1522 ::decode(placement_targets
, bl
);
1523 ::decode(default_placement
, bl
);
1524 if (struct_v
>= 2) {
1525 ::decode(hostnames
, bl
);
1527 if (struct_v
>= 3) {
1528 ::decode(hostnames_s3website
, bl
);
1530 if (struct_v
>= 4) {
1531 RGWSystemMetaObj::decode(bl
);
1532 ::decode(realm_id
, bl
);
1539 int read_default_id(string
& default_id
, bool old_format
= false) override
;
1540 int set_as_default(bool exclusive
= false) override
;
1541 int create_default(bool old_format
= false);
1542 int equals(const string
& other_zonegroup
) const;
1543 int add_zone(const RGWZoneParams
& zone_params
, bool *is_master
, bool *read_only
,
1544 const list
<string
>& endpoints
, const string
*ptier_type
,
1545 bool *psync_from_all
, list
<string
>& sync_from
, list
<string
>& sync_from_rm
);
1546 int remove_zone(const std::string
& zone_id
);
1547 int rename_zone(const RGWZoneParams
& zone_params
);
1548 rgw_pool
get_pool(CephContext
*cct
);
1549 const string
get_default_oid(bool old_region_format
= false) override
;
1550 const string
& get_info_oid_prefix(bool old_region_format
= false) override
;
1551 const string
& get_names_oid_prefix() override
;
1552 const string
& get_predefined_name(CephContext
*cct
) override
;
1554 void dump(Formatter
*f
) const;
1555 void decode_json(JSONObj
*obj
);
1556 static void generate_test_instances(list
<RGWZoneGroup
*>& o
);
1558 WRITE_CLASS_ENCODER(RGWZoneGroup
)
1563 map
<string
, RGWZoneGroup
> zonegroups
;
1564 map
<string
, RGWZoneGroup
> zonegroups_by_api
;
1565 map
<string
, uint32_t> short_zone_ids
;
1567 string master_zonegroup
;
1569 void encode(bufferlist
& bl
) const;
1570 void decode(bufferlist::iterator
& bl
);
1572 int update(const RGWZoneGroup
& zonegroup
, CephContext
*cct
);
1574 void dump(Formatter
*f
) const;
1575 void decode_json(JSONObj
*obj
);
1579 zonegroups_by_api
.clear();
1580 master_zonegroup
.clear();
1583 uint32_t get_zone_short_id(const string
& zone_id
) const;
1585 WRITE_CLASS_ENCODER(RGWPeriodMap
)
1587 struct RGWPeriodConfig
1589 RGWQuotaInfo bucket_quota
;
1590 RGWQuotaInfo user_quota
;
1592 void encode(bufferlist
& bl
) const {
1593 ENCODE_START(1, 1, bl
);
1594 ::encode(bucket_quota
, bl
);
1595 ::encode(user_quota
, bl
);
1599 void decode(bufferlist::iterator
& bl
) {
1600 DECODE_START(1, bl
);
1601 ::decode(bucket_quota
, bl
);
1602 ::decode(user_quota
, bl
);
1606 void dump(Formatter
*f
) const;
1607 void decode_json(JSONObj
*obj
);
1609 // the period config must be stored in a local object outside of the period,
1610 // so that it can be used in a default configuration where no realm/period
1612 int read(RGWRados
*store
, const std::string
& realm_id
);
1613 int write(RGWRados
*store
, const std::string
& realm_id
);
1615 static std::string
get_oid(const std::string
& realm_id
);
1616 static rgw_pool
get_pool(CephContext
*cct
);
1618 WRITE_CLASS_ENCODER(RGWPeriodConfig
)
1620 /* for backward comaptability */
1621 struct RGWRegionMap
{
1623 map
<string
, RGWZoneGroup
> regions
;
1625 string master_region
;
1627 RGWQuotaInfo bucket_quota
;
1628 RGWQuotaInfo user_quota
;
1630 void encode(bufferlist
& bl
) const;
1631 void decode(bufferlist::iterator
& bl
);
1633 void dump(Formatter
*f
) const;
1634 void decode_json(JSONObj
*obj
);
1636 WRITE_CLASS_ENCODER(RGWRegionMap
)
1638 struct RGWZoneGroupMap
{
1640 map
<string
, RGWZoneGroup
> zonegroups
;
1641 map
<string
, RGWZoneGroup
> zonegroups_by_api
;
1643 string master_zonegroup
;
1645 RGWQuotaInfo bucket_quota
;
1646 RGWQuotaInfo user_quota
;
1648 /* constract the map */
1649 int read(CephContext
*cct
, RGWRados
*store
);
1651 void encode(bufferlist
& bl
) const;
1652 void decode(bufferlist::iterator
& bl
);
1654 void dump(Formatter
*f
) const;
1655 void decode_json(JSONObj
*obj
);
1657 WRITE_CLASS_ENCODER(RGWZoneGroupMap
)
1661 struct objexp_hint_entry
{
1665 rgw_obj_key obj_key
;
1666 ceph::real_time exp_time
;
1668 void encode(bufferlist
& bl
) const {
1669 ENCODE_START(2, 1, bl
);
1670 ::encode(bucket_name
, bl
);
1671 ::encode(bucket_id
, bl
);
1672 ::encode(obj_key
, bl
);
1673 ::encode(exp_time
, bl
);
1674 ::encode(tenant
, bl
);
1678 void decode(bufferlist::iterator
& bl
) {
1679 // XXX Do we want DECODE_START_LEGACY_COMPAT_LEN(2, 1, 1, bl); ?
1680 DECODE_START(2, bl
);
1681 ::decode(bucket_name
, bl
);
1682 ::decode(bucket_id
, bl
);
1683 ::decode(obj_key
, bl
);
1684 ::decode(exp_time
, bl
);
1685 if (struct_v
>= 2) {
1686 ::decode(tenant
, bl
);
1693 WRITE_CLASS_ENCODER(objexp_hint_entry
)
1697 class RGWRealm
: public RGWSystemMetaObj
1699 string current_period
;
1700 epoch_t epoch
{0}; //< realm epoch, incremented for each new period
1702 int create_control(bool exclusive
);
1703 int delete_control();
1706 RGWRealm(const string
& _id
, const string
& _name
= "") : RGWSystemMetaObj(_id
, _name
) {}
1707 RGWRealm(CephContext
*_cct
, RGWRados
*_store
): RGWSystemMetaObj(_cct
, _store
) {}
1708 RGWRealm(const string
& _name
, CephContext
*_cct
, RGWRados
*_store
): RGWSystemMetaObj(_name
, _cct
, _store
){}
1710 void encode(bufferlist
& bl
) const override
{
1711 ENCODE_START(1, 1, bl
);
1712 RGWSystemMetaObj::encode(bl
);
1713 ::encode(current_period
, bl
);
1714 ::encode(epoch
, bl
);
1718 void decode(bufferlist::iterator
& bl
) override
{
1719 DECODE_START(1, bl
);
1720 RGWSystemMetaObj::decode(bl
);
1721 ::decode(current_period
, bl
);
1722 ::decode(epoch
, bl
);
1726 int create(bool exclusive
= true) override
;
1728 rgw_pool
get_pool(CephContext
*cct
);
1729 const string
get_default_oid(bool old_format
= false) override
;
1730 const string
& get_names_oid_prefix() override
;
1731 const string
& get_info_oid_prefix(bool old_format
= false) override
;
1732 const string
& get_predefined_name(CephContext
*cct
) override
;
1734 using RGWSystemMetaObj::read_id
; // expose as public for radosgw-admin
1736 void dump(Formatter
*f
) const;
1737 void decode_json(JSONObj
*obj
);
1739 const string
& get_current_period() const {
1740 return current_period
;
1742 int set_current_period(RGWPeriod
& period
);
1743 void clear_current_period_and_epoch() {
1744 current_period
.clear();
1747 epoch_t
get_epoch() const { return epoch
; }
1749 string
get_control_oid();
1750 /// send a notify on the realm control object
1751 int notify_zone(bufferlist
& bl
);
1752 /// notify the zone of a new period
1753 int notify_new_period(const RGWPeriod
& period
);
1755 WRITE_CLASS_ENCODER(RGWRealm
)
1757 struct RGWPeriodLatestEpochInfo
{
1760 void encode(bufferlist
& bl
) const {
1761 ENCODE_START(1, 1, bl
);
1762 ::encode(epoch
, bl
);
1766 void decode(bufferlist::iterator
& bl
) {
1767 DECODE_START(1, bl
);
1768 ::decode(epoch
, bl
);
1772 void dump(Formatter
*f
) const;
1773 void decode_json(JSONObj
*obj
);
1775 WRITE_CLASS_ENCODER(RGWPeriodLatestEpochInfo
)
1781 string predecessor_uuid
;
1782 std::vector
<std::string
> sync_status
;
1783 RGWPeriodMap period_map
;
1784 RGWPeriodConfig period_config
;
1785 string master_zonegroup
;
1790 epoch_t realm_epoch
{1}; //< realm epoch when period was made current
1796 int read_latest_epoch(RGWPeriodLatestEpochInfo
& epoch_info
,
1797 RGWObjVersionTracker
*objv
= nullptr);
1798 int use_latest_epoch();
1799 int use_current_period();
1801 const string
get_period_oid();
1802 const string
get_period_oid_prefix();
1804 // gather the metadata sync status for each shard; only for use on master zone
1805 int update_sync_status(const RGWPeriod
¤t_period
,
1806 std::ostream
& error_stream
, bool force_if_stale
);
1809 RGWPeriod() : epoch(0), cct(NULL
), store(NULL
) {}
1811 RGWPeriod(const string
& period_id
, epoch_t _epoch
= 0)
1812 : id(period_id
), epoch(_epoch
),
1813 cct(NULL
), store(NULL
) {}
1815 const string
& get_id() const { return id
; }
1816 epoch_t
get_epoch() const { return epoch
; }
1817 epoch_t
get_realm_epoch() const { return realm_epoch
; }
1818 const string
& get_predecessor() const { return predecessor_uuid
; }
1819 const string
& get_master_zone() const { return master_zone
; }
1820 const string
& get_master_zonegroup() const { return master_zonegroup
; }
1821 const string
& get_realm() const { return realm_id
; }
1822 const RGWPeriodMap
& get_map() const { return period_map
; }
1823 RGWPeriodConfig
& get_config() { return period_config
; }
1824 const RGWPeriodConfig
& get_config() const { return period_config
; }
1825 const std::vector
<std::string
>& get_sync_status() const { return sync_status
; }
1826 rgw_pool
get_pool(CephContext
*cct
);
1827 const string
& get_latest_epoch_oid();
1828 const string
& get_info_oid_prefix();
1830 void set_user_quota(RGWQuotaInfo
& user_quota
) {
1831 period_config
.user_quota
= user_quota
;
1834 void set_bucket_quota(RGWQuotaInfo
& bucket_quota
) {
1835 period_config
.bucket_quota
= bucket_quota
;
1838 void set_id(const string
& id
) {
1842 void set_epoch(epoch_t epoch
) { this->epoch
= epoch
; }
1843 void set_realm_epoch(epoch_t epoch
) { realm_epoch
= epoch
; }
1845 void set_predecessor(const string
& predecessor
)
1847 predecessor_uuid
= predecessor
;
1850 void set_realm_id(const string
& _realm_id
) {
1851 realm_id
= _realm_id
;
1856 int get_zonegroup(RGWZoneGroup
& zonegroup
,
1857 const string
& zonegroup_id
);
1859 bool is_single_zonegroup()
1861 return (period_map
.zonegroups
.size() == 1);
1865 returns true if there are several zone groups with a least one zone
1867 bool is_multi_zonegroups_with_zones()
1870 for (const auto& zg
: period_map
.zonegroups
) {
1871 if (zg
.second
.zones
.size() > 0) {
1880 int get_latest_epoch(epoch_t
& epoch
);
1881 int set_latest_epoch(epoch_t epoch
, bool exclusive
= false,
1882 RGWObjVersionTracker
*objv
= nullptr);
1883 // update latest_epoch if the given epoch is higher, else return -EEXIST
1884 int update_latest_epoch(epoch_t epoch
);
1886 int init(CephContext
*_cct
, RGWRados
*_store
, const string
&period_realm_id
, const string
&period_realm_name
= "",
1887 bool setup_obj
= true);
1888 int init(CephContext
*_cct
, RGWRados
*_store
, bool setup_obj
= true);
1890 int create(bool exclusive
= true);
1892 int store_info(bool exclusive
);
1893 int add_zonegroup(const RGWZoneGroup
& zonegroup
);
1898 // commit a staging period; only for use on master zone
1899 int commit(RGWRealm
& realm
, const RGWPeriod
¤t_period
,
1900 std::ostream
& error_stream
, bool force_if_stale
= false);
1902 void encode(bufferlist
& bl
) const {
1903 ENCODE_START(1, 1, bl
);
1905 ::encode(epoch
, bl
);
1906 ::encode(realm_epoch
, bl
);
1907 ::encode(predecessor_uuid
, bl
);
1908 ::encode(sync_status
, bl
);
1909 ::encode(period_map
, bl
);
1910 ::encode(master_zone
, bl
);
1911 ::encode(master_zonegroup
, bl
);
1912 ::encode(period_config
, bl
);
1913 ::encode(realm_id
, bl
);
1914 ::encode(realm_name
, bl
);
1918 void decode(bufferlist::iterator
& bl
) {
1919 DECODE_START(1, bl
);
1921 ::decode(epoch
, bl
);
1922 ::decode(realm_epoch
, bl
);
1923 ::decode(predecessor_uuid
, bl
);
1924 ::decode(sync_status
, bl
);
1925 ::decode(period_map
, bl
);
1926 ::decode(master_zone
, bl
);
1927 ::decode(master_zonegroup
, bl
);
1928 ::decode(period_config
, bl
);
1929 ::decode(realm_id
, bl
);
1930 ::decode(realm_name
, bl
);
1933 void dump(Formatter
*f
) const;
1934 void decode_json(JSONObj
*obj
);
1936 static string
get_staging_id(const string
& realm_id
) {
1937 return realm_id
+ ":staging";
1940 WRITE_CLASS_ENCODER(RGWPeriod
)
1942 class RGWDataChangesLog
;
1943 class RGWMetaSyncStatusManager
;
1944 class RGWDataSyncStatusManager
;
1945 class RGWReplicaLogger
;
1946 class RGWCoroutinesManagerRegistry
;
1953 void oid_str(int shard
, string
& oid
);
1954 int get_shard_num(const string
& object
);
1955 string
get_oid(const string
& object
);
1956 int open_ioctx(librados::IoCtx
& ioctx
);
1966 list_state() : cur_shard(0), max_shard(0) {}
1970 virtual bool dump_entry_internal(const cls_statelog_entry
& entry
, Formatter
*f
) {
1975 RGWStateLog(RGWRados
*_store
, int _num_shards
, const string
& _module_name
) :
1976 store(_store
), num_shards(_num_shards
), module_name(_module_name
) {}
1977 virtual ~RGWStateLog() {}
1979 int store_entry(const string
& client_id
, const string
& op_id
, const string
& object
,
1980 uint32_t state
, bufferlist
*bl
, uint32_t *check_state
);
1982 int remove_entry(const string
& client_id
, const string
& op_id
, const string
& object
);
1984 void init_list_entries(const string
& client_id
, const string
& op_id
, const string
& object
,
1987 int list_entries(void *handle
, int max_entries
, list
<cls_statelog_entry
>& entries
, bool *done
);
1989 void finish_list_entries(void *handle
);
1991 virtual void dump_entry(const cls_statelog_entry
& entry
, Formatter
*f
);
1995 * state transitions:
1997 * unknown -> in-progress -> complete
2000 * user can try setting the 'abort' state, and it can only succeed if state is
2003 * state renewal cannot switch state (stays in the same state)
2005 * rgw can switch from in-progress to complete
2006 * rgw can switch from in-progress to error
2008 * rgw can switch from abort to cancelled
2012 class RGWOpState
: public RGWStateLog
{
2014 bool dump_entry_internal(const cls_statelog_entry
& entry
, Formatter
*f
) override
;
2018 OPSTATE_UNKNOWN
= 0,
2019 OPSTATE_IN_PROGRESS
= 1,
2020 OPSTATE_COMPLETE
= 2,
2023 OPSTATE_CANCELLED
= 5,
2026 explicit RGWOpState(RGWRados
*_store
);
2028 int state_from_str(const string
& s
, OpState
*state
);
2029 int set_state(const string
& client_id
, const string
& op_id
, const string
& object
, OpState state
);
2030 int renew_state(const string
& client_id
, const string
& op_id
, const string
& object
, OpState state
);
2033 class RGWOpStateSingleOp
2042 RGWOpState::OpState cur_state
;
2043 ceph::real_time last_update
;
2046 RGWOpStateSingleOp(RGWRados
*store
, const string
& cid
, const string
& oid
, const string
& obj
);
2048 int set_state(RGWOpState::OpState state
);
2052 class RGWGetBucketStats_CB
: public RefCountedObject
{
2055 map
<RGWObjCategory
, RGWStorageStats
> *stats
;
2057 explicit RGWGetBucketStats_CB(const rgw_bucket
& _bucket
) : bucket(_bucket
), stats(NULL
) {}
2058 ~RGWGetBucketStats_CB() override
{}
2059 virtual void handle_response(int r
) = 0;
2060 virtual void set_response(map
<RGWObjCategory
, RGWStorageStats
> *_stats
) {
2065 class RGWGetUserStats_CB
: public RefCountedObject
{
2068 RGWStorageStats stats
;
2070 explicit RGWGetUserStats_CB(const rgw_user
& _user
) : user(_user
) {}
2071 ~RGWGetUserStats_CB() override
{}
2072 virtual void handle_response(int r
) = 0;
2073 virtual void set_response(RGWStorageStats
& _stats
) {
2078 class RGWGetDirHeader_CB
;
2079 class RGWGetUserHeader_CB
;
2081 struct rgw_rados_ref
{
2085 librados::IoCtx ioctx
;
2088 class RGWChainedCache
{
2090 virtual ~RGWChainedCache() {}
2091 virtual void chain_cb(const string
& key
, void *data
) = 0;
2092 virtual void invalidate(const string
& key
) = 0;
2093 virtual void invalidate_all() = 0;
2096 RGWChainedCache
*cache
;
2100 Entry(RGWChainedCache
*_c
, const string
& _k
, void *_d
) : cache(_c
), key(_k
), data(_d
) {}
2104 template <class T
, class S
>
2105 class RGWObjectCtxImpl
{
2107 std::map
<T
, S
> objs_state
;
2111 RGWObjectCtxImpl(RGWRados
*_store
) : store(_store
), lock("RGWObjectCtxImpl") {}
2113 S
*get_state(const T
& obj
) {
2115 typename
std::map
<T
, S
>::iterator iter
;
2117 assert (!obj
.empty());
2118 iter
= objs_state
.find(obj
);
2119 if (iter
!= objs_state
.end()) {
2120 result
= &iter
->second
;
2125 result
= &objs_state
[obj
];
2131 void set_atomic(T
& obj
) {
2132 RWLock::WLocker
wl(lock
);
2133 assert (!obj
.empty());
2134 objs_state
[obj
].is_atomic
= true;
2136 void set_prefetch_data(T
& obj
) {
2137 RWLock::WLocker
wl(lock
);
2138 assert (!obj
.empty());
2139 objs_state
[obj
].prefetch_data
= true;
2141 void invalidate(T
& obj
) {
2142 RWLock::WLocker
wl(lock
);
2143 auto iter
= objs_state
.find(obj
);
2144 if (iter
== objs_state
.end()) {
2147 bool is_atomic
= iter
->second
.is_atomic
;
2148 bool prefetch_data
= iter
->second
.prefetch_data
;
2150 objs_state
.erase(iter
);
2152 if (is_atomic
|| prefetch_data
) {
2153 auto& s
= objs_state
[obj
];
2154 s
.is_atomic
= is_atomic
;
2155 s
.prefetch_data
= prefetch_data
;
2161 void RGWObjectCtxImpl
<rgw_obj
, RGWObjState
>::invalidate(rgw_obj
& obj
);
2164 void RGWObjectCtxImpl
<rgw_raw_obj
, RGWRawObjState
>::invalidate(rgw_raw_obj
& obj
);
2166 struct RGWObjectCtx
{
2170 RGWObjectCtxImpl
<rgw_obj
, RGWObjState
> obj
;
2171 RGWObjectCtxImpl
<rgw_raw_obj
, RGWRawObjState
> raw
;
2173 explicit RGWObjectCtx(RGWRados
*_store
) : store(_store
), user_ctx(NULL
), obj(store
), raw(store
) { }
2174 RGWObjectCtx(RGWRados
*_store
, void *_user_ctx
) : store(_store
), user_ctx(_user_ctx
), obj(store
), raw(store
) { }
2178 class RGWAsyncRadosProcessor
;
2181 class RGWChainedCacheImpl
;
2183 struct bucket_info_entry
{
2186 map
<string
, bufferlist
> attrs
;
2189 struct tombstone_entry
{
2190 ceph::real_time mtime
;
2191 uint32_t zone_short_id
;
2194 tombstone_entry() = default;
2195 tombstone_entry(const RGWObjState
& state
)
2196 : mtime(state
.mtime
), zone_short_id(state
.zone_short_id
),
2197 pg_ver(state
.pg_ver
) {}
2200 class RGWIndexCompletionManager
;
2205 friend class RGWMetaNotifier
;
2206 friend class RGWDataNotifier
;
2208 friend class RGWObjectExpirer
;
2209 friend class RGWMetaSyncProcessorThread
;
2210 friend class RGWDataSyncProcessorThread
;
2211 friend class RGWStateLog
;
2212 friend class RGWReplicaLogger
;
2213 friend class RGWReshard
;
2214 friend class RGWBucketReshard
;
2215 friend class BucketIndexLockGuard
;
2216 friend class RGWCompleteMultipart
;
2218 /** Open the pool used as root for this gateway */
2219 int open_root_pool_ctx();
2220 int open_gc_pool_ctx();
2221 int open_lc_pool_ctx();
2222 int open_objexp_pool_ctx();
2223 int open_reshard_pool_ctx();
2225 int open_pool_ctx(const rgw_pool
& pool
, librados::IoCtx
& io_ctx
);
2226 int open_bucket_index_ctx(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
);
2227 int open_bucket_index(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
, string
& bucket_oid
);
2228 int open_bucket_index_base(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
,
2229 string
& bucket_oid_base
);
2230 int open_bucket_index_shard(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
,
2231 const string
& obj_key
, string
*bucket_obj
, int *shard_id
);
2232 int open_bucket_index_shard(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
,
2233 int shard_id
, string
*bucket_obj
);
2234 int open_bucket_index(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
,
2235 map
<int, string
>& bucket_objs
, int shard_id
= -1, map
<int, string
> *bucket_instance_ids
= NULL
);
2236 template<typename T
>
2237 int open_bucket_index(const RGWBucketInfo
& bucket_info
, librados::IoCtx
& index_ctx
,
2238 map
<int, string
>& oids
, map
<int, T
>& bucket_objs
,
2239 int shard_id
= -1, map
<int, string
> *bucket_instance_ids
= NULL
);
2240 void build_bucket_index_marker(const string
& shard_id_str
, const string
& shard_marker
,
2243 void get_bucket_instance_ids(const RGWBucketInfo
& bucket_info
, int shard_id
, map
<int, string
> *result
);
2245 std::atomic
<int64_t> max_req_id
= { 0 };
2247 Mutex watchers_lock
;
2252 RGWObjectExpirer
*obj_expirer
;
2256 bool run_sync_thread
;
2257 bool run_reshard_thread
;
2259 RGWAsyncRadosProcessor
* async_rados
;
2261 RGWMetaNotifier
*meta_notifier
;
2262 RGWDataNotifier
*data_notifier
;
2263 RGWMetaSyncProcessorThread
*meta_sync_processor_thread
;
2264 map
<string
, RGWDataSyncProcessorThread
*> data_sync_processor_threads
;
2266 RGWSyncLogTrimThread
*sync_log_trimmer
{nullptr};
2268 Mutex meta_sync_thread_lock
;
2269 Mutex data_sync_thread_lock
;
2272 RGWWatcher
**watchers
;
2273 std::set
<int> watchers_set
;
2274 librados::IoCtx root_pool_ctx
; // .rgw
2275 librados::IoCtx control_pool_ctx
; // .rgw.control
2276 bool watch_initialized
;
2278 friend class RGWWatcher
;
2280 Mutex bucket_id_lock
;
2282 // This field represents the number of bucket index object shards
2283 uint32_t bucket_index_max_shards
;
2285 int get_obj_head_ioctx(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, librados::IoCtx
*ioctx
);
2286 int get_obj_head_ref(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, rgw_rados_ref
*ref
);
2287 int get_system_obj_ref(const rgw_raw_obj
& obj
, rgw_rados_ref
*ref
);
2288 uint64_t max_bucket_id
;
2290 int get_olh_target_state(RGWObjectCtx
& rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
2291 RGWObjState
*olh_state
, RGWObjState
**target_state
);
2292 int get_system_obj_state_impl(RGWObjectCtx
*rctx
, rgw_raw_obj
& obj
, RGWRawObjState
**state
, RGWObjVersionTracker
*objv_tracker
);
2293 int get_obj_state_impl(RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWObjState
**state
,
2294 bool follow_olh
, bool assume_noent
= false);
2295 int append_atomic_test(RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
2296 librados::ObjectOperation
& op
, RGWObjState
**state
);
2298 int update_placement_map();
2299 int store_bucket_info(RGWBucketInfo
& info
, map
<string
, bufferlist
> *pattrs
, RGWObjVersionTracker
*objv_tracker
, bool exclusive
);
2301 void remove_rgw_head_obj(librados::ObjectWriteOperation
& op
);
2302 void cls_obj_check_prefix_exist(librados::ObjectOperation
& op
, const string
& prefix
, bool fail_if_exist
);
2303 void cls_obj_check_mtime(librados::ObjectOperation
& op
, const real_time
& mtime
, bool high_precision_time
, RGWCheckMTimeType type
);
2307 std::vector
<librados::Rados
> rados
;
2308 uint32_t next_rados_handle
;
2310 std::map
<pthread_t
, int> rados_map
;
2312 using RGWChainedCacheImpl_bucket_info_entry
= RGWChainedCacheImpl
<bucket_info_entry
>;
2313 RGWChainedCacheImpl_bucket_info_entry
*binfo_cache
;
2315 using tombstone_cache_t
= lru_map
<rgw_obj
, tombstone_entry
>;
2316 tombstone_cache_t
*obj_tombstone_cache
;
2318 librados::IoCtx gc_pool_ctx
; // .rgw.gc
2319 librados::IoCtx lc_pool_ctx
; // .rgw.lc
2320 librados::IoCtx objexp_pool_ctx
;
2321 librados::IoCtx reshard_pool_ctx
;
2323 bool pools_initialized
;
2325 string trans_id_suffix
;
2327 RGWQuotaHandler
*quota_handler
;
2331 RGWCoroutinesManagerRegistry
*cr_registry
;
2333 RGWSyncModulesManager
*sync_modules_manager
{nullptr};
2334 RGWSyncModuleInstanceRef sync_module
;
2335 bool writeable_zone
{false};
2337 RGWZoneGroup zonegroup
;
2338 RGWZone zone_public_config
; /* external zone params, e.g., entrypoints, log flags, etc. */
2339 RGWZoneParams zone_params
; /* internal zone params, e.g., rados pools */
2340 uint32_t zone_short_id
;
2342 RGWPeriod current_period
;
2344 RGWIndexCompletionManager
*index_completion_manager
{nullptr};
2346 RGWRados() : lock("rados_timer_lock"), watchers_lock("watchers_lock"), timer(NULL
),
2347 gc(NULL
), lc(NULL
), obj_expirer(NULL
), use_gc_thread(false), use_lc_thread(false), quota_threads(false),
2348 run_sync_thread(false), run_reshard_thread(false), async_rados(nullptr), meta_notifier(NULL
),
2349 data_notifier(NULL
), meta_sync_processor_thread(NULL
),
2350 meta_sync_thread_lock("meta_sync_thread_lock"), data_sync_thread_lock("data_sync_thread_lock"),
2351 num_watchers(0), watchers(NULL
),
2352 watch_initialized(false),
2353 bucket_id_lock("rados_bucket_id"),
2354 bucket_index_max_shards(0),
2355 max_bucket_id(0), cct(NULL
),
2356 next_rados_handle(0),
2357 handle_lock("rados_handle_lock"),
2358 binfo_cache(NULL
), obj_tombstone_cache(nullptr),
2359 pools_initialized(false),
2360 quota_handler(NULL
),
2364 rest_master_conn(NULL
),
2365 meta_mgr(NULL
), data_log(NULL
), reshard(NULL
) {}
2367 uint64_t get_new_req_id() {
2368 return ++max_req_id
;
2371 librados::IoCtx
* get_lc_pool_ctx() {
2372 return &lc_pool_ctx
;
2374 void set_context(CephContext
*_cct
) {
2379 * AmazonS3 errors contain a HostId string, but is an opaque base64 blob; we
2380 * try to be more transparent. This has a wrapper so we can update it when zonegroup/zone are changed.
2382 void init_host_id() {
2383 /* uint64_t needs 16, two '-' separators and a trailing null */
2384 const string
& zone_name
= get_zone().name
;
2385 const string
& zonegroup_name
= zonegroup
.get_name();
2386 char charbuf
[16 + zone_name
.size() + zonegroup_name
.size() + 2 + 1];
2387 snprintf(charbuf
, sizeof(charbuf
), "%llx-%s-%s", (unsigned long long)instance_id(), zone_name
.c_str(), zonegroup_name
.c_str());
2396 RGWRESTConn
*rest_master_conn
;
2397 map
<string
, RGWRESTConn
*> zone_conn_map
;
2398 map
<string
, RGWRESTConn
*> zone_data_sync_from_map
;
2399 map
<string
, RGWRESTConn
*> zone_data_notify_to_map
;
2400 map
<string
, RGWRESTConn
*> zonegroup_conn_map
;
2402 map
<string
, string
> zone_id_by_name
;
2403 map
<string
, RGWZone
> zone_by_id
;
2405 RGWRESTConn
*get_zone_conn_by_id(const string
& id
) {
2406 auto citer
= zone_conn_map
.find(id
);
2407 if (citer
== zone_conn_map
.end()) {
2411 return citer
->second
;
2414 RGWRESTConn
*get_zone_conn_by_name(const string
& name
) {
2415 auto i
= zone_id_by_name
.find(name
);
2416 if (i
== zone_id_by_name
.end()) {
2420 return get_zone_conn_by_id(i
->second
);
2423 bool find_zone_id_by_name(const string
& name
, string
*id
) {
2424 auto i
= zone_id_by_name
.find(name
);
2425 if (i
== zone_id_by_name
.end()) {
2432 int get_zonegroup(const string
& id
, RGWZoneGroup
& zonegroup
) {
2434 if (id
== get_zonegroup().get_id()) {
2435 zonegroup
= get_zonegroup();
2436 } else if (!current_period
.get_id().empty()) {
2437 ret
= current_period
.get_zonegroup(zonegroup
, id
);
2442 RGWRealm
& get_realm() {
2446 RGWZoneParams
& get_zone_params() { return zone_params
; }
2447 RGWZoneGroup
& get_zonegroup() {
2450 RGWZone
& get_zone() {
2451 return zone_public_config
;
2454 bool zone_is_writeable() {
2455 return writeable_zone
&& !get_zone().is_read_only();
2458 uint32_t get_zone_short_id() const {
2459 return zone_short_id
;
2462 bool zone_syncs_from(RGWZone
& target_zone
, RGWZone
& source_zone
);
2464 const RGWQuotaInfo
& get_bucket_quota() {
2465 return current_period
.get_config().bucket_quota
;
2468 const RGWQuotaInfo
& get_user_quota() {
2469 return current_period
.get_config().user_quota
;
2472 const string
& get_current_period_id() {
2473 return current_period
.get_id();
2476 bool has_zonegroup_api(const std::string
& api
) const {
2477 if (!current_period
.get_id().empty()) {
2478 const auto& zonegroups_by_api
= current_period
.get_map().zonegroups_by_api
;
2479 if (zonegroups_by_api
.find(api
) != zonegroups_by_api
.end())
2485 // pulls missing periods for period_history
2486 std::unique_ptr
<RGWPeriodPuller
> period_puller
;
2487 // maintains a connected history of periods
2488 std::unique_ptr
<RGWPeriodHistory
> period_history
;
2490 RGWAsyncRadosProcessor
* get_async_rados() const { return async_rados
; };
2492 RGWMetadataManager
*meta_mgr
;
2494 RGWDataChangesLog
*data_log
;
2496 RGWReshard
*reshard
;
2497 std::shared_ptr
<RGWReshardWait
> reshard_wait
;
2499 virtual ~RGWRados() = default;
2501 tombstone_cache_t
*get_tombstone_cache() {
2502 return obj_tombstone_cache
;
2505 RGWSyncModulesManager
*get_sync_modules_manager() {
2506 return sync_modules_manager
;
2508 const RGWSyncModuleInstanceRef
& get_sync_module() {
2512 int get_required_alignment(const rgw_pool
& pool
, uint64_t *alignment
);
2513 int get_max_chunk_size(const rgw_pool
& pool
, uint64_t *max_chunk_size
);
2514 int get_max_chunk_size(const string
& placement_rule
, const rgw_obj
& obj
, uint64_t *max_chunk_size
);
2516 uint32_t get_max_bucket_shards() {
2517 return rgw_shards_max();
2520 int get_raw_obj_ref(const rgw_raw_obj
& obj
, rgw_rados_ref
*ref
);
2522 int list_raw_objects(const rgw_pool
& pool
, const string
& prefix_filter
, int max
,
2523 RGWListRawObjsCtx
& ctx
, list
<string
>& oids
,
2524 bool *is_truncated
);
2526 int list_raw_prefixed_objs(const rgw_pool
& pool
, const string
& prefix
, list
<string
>& result
);
2527 int list_zonegroups(list
<string
>& zonegroups
);
2528 int list_regions(list
<string
>& regions
);
2529 int list_zones(list
<string
>& zones
);
2530 int list_realms(list
<string
>& realms
);
2531 int list_periods(list
<string
>& periods
);
2532 int list_periods(const string
& current_period
, list
<string
>& periods
);
2535 CephContext
*ctx() { return cct
; }
2536 /** do all necessary setup of the storage device */
2537 int initialize(CephContext
*_cct
, bool _use_gc_thread
, bool _use_lc_thread
, bool _quota_threads
, bool _run_sync_thread
, bool _run_reshard_thread
) {
2539 use_gc_thread
= _use_gc_thread
;
2540 use_lc_thread
= _use_lc_thread
;
2541 quota_threads
= _quota_threads
;
2542 run_sync_thread
= _run_sync_thread
;
2543 run_reshard_thread
= _run_reshard_thread
;
2544 return initialize();
2546 /** Initialize the RADOS instance and prepare to do other ops */
2547 virtual int init_rados();
2548 int init_zg_from_period(bool *initialized
);
2549 int init_zg_from_local(bool *creating_defaults
);
2550 int init_complete();
2551 int replace_region_with_zonegroup();
2552 int convert_regionmap();
2556 int register_to_service_map(const string
& daemon_type
, const map
<string
, string
>& meta
);
2558 void schedule_context(Context
*c
);
2560 /** set up a bucket listing. handle is filled in. */
2561 int list_buckets_init(RGWAccessHandle
*handle
);
2563 * get the next bucket in the listing. obj is filled in,
2564 * handle is updated.
2566 int list_buckets_next(rgw_bucket_dir_entry
& obj
, RGWAccessHandle
*handle
);
2569 int log_list_init(const string
& prefix
, RGWAccessHandle
*handle
);
2570 int log_list_next(RGWAccessHandle handle
, string
*name
);
2573 int log_remove(const string
& name
);
2576 int log_show_init(const string
& name
, RGWAccessHandle
*handle
);
2577 int log_show_next(RGWAccessHandle handle
, rgw_log_entry
*entry
);
2579 // log bandwidth info
2580 int log_usage(map
<rgw_user_bucket
, RGWUsageBatch
>& usage_info
);
2581 int read_usage(const rgw_user
& user
, uint64_t start_epoch
, uint64_t end_epoch
, uint32_t max_entries
,
2582 bool *is_truncated
, RGWUsageIter
& read_iter
, map
<rgw_user_bucket
, rgw_usage_log_entry
>& usage
);
2583 int trim_usage(rgw_user
& user
, uint64_t start_epoch
, uint64_t end_epoch
);
2585 int create_pool(const rgw_pool
& pool
);
2587 int init_bucket_index(RGWBucketInfo
& bucket_info
, int num_shards
);
2588 int select_bucket_placement(RGWUserInfo
& user_info
, const string
& zonegroup_id
, const string
& rule
,
2589 string
*pselected_rule_name
, RGWZonePlacementInfo
*rule_info
);
2590 int select_legacy_bucket_placement(RGWZonePlacementInfo
*rule_info
);
2591 int select_new_bucket_location(RGWUserInfo
& user_info
, const string
& zonegroup_id
, const string
& rule
,
2592 string
*pselected_rule_name
, RGWZonePlacementInfo
*rule_info
);
2593 int select_bucket_location_by_rule(const string
& location_rule
, RGWZonePlacementInfo
*rule_info
);
2594 void create_bucket_id(string
*bucket_id
);
2596 bool get_obj_data_pool(const string
& placement_rule
, const rgw_obj
& obj
, rgw_pool
*pool
);
2597 bool obj_to_raw(const string
& placement_rule
, const rgw_obj
& obj
, rgw_raw_obj
*raw_obj
);
2599 int create_bucket(RGWUserInfo
& owner
, rgw_bucket
& bucket
,
2600 const string
& zonegroup_id
,
2601 const string
& placement_rule
,
2602 const string
& swift_ver_location
,
2603 const RGWQuotaInfo
* pquota_info
,
2604 map
<std::string
,bufferlist
>& attrs
,
2605 RGWBucketInfo
& bucket_info
,
2607 obj_version
*pep_objv
,
2608 ceph::real_time creation_time
,
2609 rgw_bucket
*master_bucket
,
2610 uint32_t *master_num_shards
,
2611 bool exclusive
= true);
2612 int add_bucket_placement(const rgw_pool
& new_pool
);
2613 int remove_bucket_placement(const rgw_pool
& new_pool
);
2614 int list_placement_set(set
<rgw_pool
>& names
);
2615 int create_pools(vector
<rgw_pool
>& pools
, vector
<int>& retcodes
);
2617 RGWCoroutinesManagerRegistry
*get_cr_registry() { return cr_registry
; }
2619 class SystemObject
{
2627 int get_state(RGWRawObjState
**pstate
, RGWObjVersionTracker
*objv_tracker
);
2630 SystemObject(RGWRados
*_store
, RGWObjectCtx
& _ctx
, rgw_raw_obj
& _obj
) : store(_store
), ctx(_ctx
), obj(_obj
), state(NULL
) {}
2632 void invalidate_state();
2634 RGWRados
*get_store() { return store
; }
2635 rgw_raw_obj
& get_obj() { return obj
; }
2636 RGWObjectCtx
& get_ctx() { return ctx
; }
2639 RGWRados::SystemObject
*source
;
2641 struct GetObjState
{
2643 bool has_ref
{false};
2644 uint64_t last_ver
{0};
2648 int get_ref(RGWRados
*store
, rgw_raw_obj
& obj
, rgw_rados_ref
**pref
);
2652 ceph::real_time
*lastmod
;
2654 map
<string
, bufferlist
> *attrs
;
2656 StatParams() : lastmod(NULL
), obj_size(NULL
), attrs(NULL
) {}
2660 rgw_cache_entry_info
*cache_info
{nullptr};
2661 map
<string
, bufferlist
> *attrs
;
2663 ReadParams() : attrs(NULL
) {}
2666 explicit Read(RGWRados::SystemObject
*_source
) : source(_source
) {}
2668 int stat(RGWObjVersionTracker
*objv_tracker
);
2669 int read(int64_t ofs
, int64_t end
, bufferlist
& bl
, RGWObjVersionTracker
*objv_tracker
);
2670 int get_attr(const char *name
, bufferlist
& dest
);
2674 struct BucketShard
{
2678 librados::IoCtx index_ctx
;
2681 explicit BucketShard(RGWRados
*_store
) : store(_store
), shard_id(-1) {}
2682 int init(const rgw_bucket
& _bucket
, const rgw_obj
& obj
);
2683 int init(const rgw_bucket
& _bucket
, int sid
);
2688 RGWBucketInfo bucket_info
;
2696 bool versioning_disabled
;
2698 bool bs_initialized
;
2701 int get_state(RGWObjState
**pstate
, bool follow_olh
, bool assume_noent
= false);
2702 void invalidate_state();
2704 int prepare_atomic_modification(librados::ObjectWriteOperation
& op
, bool reset_obj
, const string
*ptag
,
2705 const char *ifmatch
, const char *ifnomatch
, bool removal_op
);
2706 int complete_atomic_modification();
2709 Object(RGWRados
*_store
, const RGWBucketInfo
& _bucket_info
, RGWObjectCtx
& _ctx
, const rgw_obj
& _obj
) : store(_store
), bucket_info(_bucket_info
),
2710 ctx(_ctx
), obj(_obj
), bs(store
),
2711 state(NULL
), versioning_disabled(false),
2712 bs_initialized(false) {}
2714 RGWRados
*get_store() { return store
; }
2715 rgw_obj
& get_obj() { return obj
; }
2716 RGWObjectCtx
& get_ctx() { return ctx
; }
2717 RGWBucketInfo
& get_bucket_info() { return bucket_info
; }
2718 int get_manifest(RGWObjManifest
**pmanifest
);
2720 int get_bucket_shard(BucketShard
**pbs
) {
2721 if (!bs_initialized
) {
2722 int r
= bs
.init(bucket_info
.bucket
, obj
);
2726 bs_initialized
= true;
2732 void set_versioning_disabled(bool status
) {
2733 versioning_disabled
= status
;
2736 bool versioning_enabled() {
2737 return (!versioning_disabled
&& bucket_info
.versioning_enabled());
2741 RGWRados::Object
*source
;
2743 struct GetObjState
{
2744 librados::IoCtx io_ctx
;
2746 rgw_raw_obj head_obj
;
2749 struct ConditionParams
{
2750 const ceph::real_time
*mod_ptr
;
2751 const ceph::real_time
*unmod_ptr
;
2752 bool high_precision_time
;
2753 uint32_t mod_zone_id
;
2754 uint64_t mod_pg_ver
;
2755 const char *if_match
;
2756 const char *if_nomatch
;
2759 mod_ptr(NULL
), unmod_ptr(NULL
), high_precision_time(false), mod_zone_id(0), mod_pg_ver(0),
2760 if_match(NULL
), if_nomatch(NULL
) {}
2764 ceph::real_time
*lastmod
;
2766 map
<string
, bufferlist
> *attrs
;
2768 Params() : lastmod(NULL
), obj_size(NULL
), attrs(NULL
) {}
2771 explicit Read(RGWRados::Object
*_source
) : source(_source
) {}
2774 static int range_to_ofs(uint64_t obj_size
, int64_t &ofs
, int64_t &end
);
2775 int read(int64_t ofs
, int64_t end
, bufferlist
& bl
);
2776 int iterate(int64_t ofs
, int64_t end
, RGWGetDataCB
*cb
);
2777 int get_attr(const char *name
, bufferlist
& dest
);
2781 RGWRados::Object
*target
;
2784 ceph::real_time
*mtime
;
2785 map
<std::string
, bufferlist
>* rmattrs
;
2786 const bufferlist
*data
;
2787 RGWObjManifest
*manifest
;
2789 list
<rgw_obj_index_key
> *remove_objs
;
2790 ceph::real_time set_mtime
;
2792 RGWObjCategory category
;
2794 const char *if_match
;
2795 const char *if_nomatch
;
2797 ceph::real_time delete_at
;
2799 const string
*user_data
;
2800 rgw_zone_set
*zones_trace
;
2802 MetaParams() : mtime(NULL
), rmattrs(NULL
), data(NULL
), manifest(NULL
), ptag(NULL
),
2803 remove_objs(NULL
), category(RGW_OBJ_CATEGORY_MAIN
), flags(0),
2804 if_match(NULL
), if_nomatch(NULL
), olh_epoch(0), canceled(false), user_data(nullptr), zones_trace(nullptr) {}
2807 explicit Write(RGWRados::Object
*_target
) : target(_target
) {}
2809 int _do_write_meta(uint64_t size
, uint64_t accounted_size
,
2810 map
<std::string
, bufferlist
>& attrs
,
2813 int write_meta(uint64_t size
, uint64_t accounted_size
,
2814 map
<std::string
, bufferlist
>& attrs
);
2815 int write_data(const char *data
, uint64_t ofs
, uint64_t len
, bool exclusive
);
2819 RGWRados::Object
*target
;
2821 struct DeleteParams
{
2822 rgw_user bucket_owner
;
2823 int versioning_status
;
2824 ACLOwner obj_owner
; /* needed for creation of deletion marker */
2826 string marker_version_id
;
2827 uint32_t bilog_flags
;
2828 list
<rgw_obj_index_key
> *remove_objs
;
2829 ceph::real_time expiration_time
;
2830 ceph::real_time unmod_since
;
2831 ceph::real_time mtime
; /* for setting delete marker mtime */
2832 bool high_precision_time
;
2833 rgw_zone_set
*zones_trace
;
2835 DeleteParams() : versioning_status(0), olh_epoch(0), bilog_flags(0), remove_objs(NULL
), high_precision_time(false), zones_trace(nullptr) {}
2838 struct DeleteResult
{
2842 DeleteResult() : delete_marker(false) {}
2845 explicit Delete(RGWRados::Object
*_target
) : target(_target
) {}
2851 RGWRados::Object
*source
;
2855 RGWObjManifest manifest
;
2858 struct timespec mtime
;
2859 map
<string
, bufferlist
> attrs
;
2861 Result() : has_manifest(false), size(0) {}
2865 librados::IoCtx io_ctx
;
2866 librados::AioCompletion
*completion
;
2869 State() : completion(NULL
), ret(0) {}
2873 explicit Stat(RGWRados::Object
*_source
) : source(_source
) {}
2885 RGWBucketInfo bucket_info
;
2890 Bucket(RGWRados
*_store
, const RGWBucketInfo
& _bucket_info
) : store(_store
), bucket_info(_bucket_info
), bucket(bucket_info
.bucket
),
2891 shard_id(RGW_NO_SHARD
) {}
2892 RGWRados
*get_store() { return store
; }
2893 rgw_bucket
& get_bucket() { return bucket
; }
2894 RGWBucketInfo
& get_bucket_info() { return bucket_info
; }
2896 int update_bucket_id(const string
& new_bucket_id
);
2898 int get_shard_id() { return shard_id
; }
2899 void set_shard_id(int id
) {
2904 RGWRados::Bucket
*target
;
2907 uint16_t bilog_flags
{0};
2909 bool bs_initialized
{false};
2911 bool prepared
{false};
2912 rgw_zone_set
*zones_trace
{nullptr};
2915 int r
= bs
.init(target
->get_bucket(), obj
);
2919 bs_initialized
= true;
2923 void invalidate_bs() {
2924 bs_initialized
= false;
2927 int guard_reshard(BucketShard
**pbs
, std::function
<int(BucketShard
*)> call
);
2930 UpdateIndex(RGWRados::Bucket
*_target
, const rgw_obj
& _obj
) : target(_target
), obj(_obj
),
2931 bs(target
->get_store()) {
2932 blind
= (target
->get_bucket_info().index_type
== RGWBIType_Indexless
);
2935 int get_bucket_shard(BucketShard
**pbs
) {
2936 if (!bs_initialized
) {
2946 void set_bilog_flags(uint16_t flags
) {
2947 bilog_flags
= flags
;
2950 void set_zones_trace(rgw_zone_set
*_zones_trace
) {
2951 zones_trace
= _zones_trace
;
2954 int prepare(RGWModifyOp
, const string
*write_tag
);
2955 int complete(int64_t poolid
, uint64_t epoch
, uint64_t size
,
2956 uint64_t accounted_size
, ceph::real_time
& ut
,
2957 const string
& etag
, const string
& content_type
,
2958 bufferlist
*acl_bl
, RGWObjCategory category
,
2959 list
<rgw_obj_index_key
> *remove_objs
, const string
*user_data
= nullptr);
2960 int complete_del(int64_t poolid
, uint64_t epoch
,
2961 ceph::real_time
& removed_mtime
, /* mtime of removed object */
2962 list
<rgw_obj_index_key
> *remove_objs
);
2965 const string
*get_optag() { return &optag
; }
2967 bool is_prepared() { return prepared
; }
2971 RGWRados::Bucket
*target
;
2972 rgw_obj_key next_marker
;
2978 rgw_obj_key end_marker
;
2981 RGWAccessListFilter
*filter
;
2984 Params() : enforce_ns(true), filter(NULL
), list_versions(false) {}
2988 explicit List(RGWRados::Bucket
*_target
) : target(_target
) {}
2990 int list_objects(int64_t max
, vector
<rgw_bucket_dir_entry
> *result
, map
<string
, bool> *common_prefixes
, bool *is_truncated
);
2991 rgw_obj_key
& get_next_marker() {
2997 /** Write/overwrite an object to the bucket storage. */
2998 virtual int put_system_obj_impl(rgw_raw_obj
& obj
, uint64_t size
, ceph::real_time
*mtime
,
2999 map
<std::string
, bufferlist
>& attrs
, int flags
,
3001 RGWObjVersionTracker
*objv_tracker
,
3002 ceph::real_time set_mtime
/* 0 for don't set */);
3004 virtual int put_system_obj_data(void *ctx
, rgw_raw_obj
& obj
, bufferlist
& bl
,
3005 off_t ofs
, bool exclusive
,
3006 RGWObjVersionTracker
*objv_tracker
= nullptr);
3007 int aio_put_obj_data(void *ctx
, rgw_raw_obj
& obj
, bufferlist
& bl
,
3008 off_t ofs
, bool exclusive
, void **handle
);
3010 int put_system_obj(void *ctx
, rgw_raw_obj
& obj
, const char *data
, size_t len
, bool exclusive
,
3011 ceph::real_time
*mtime
, map
<std::string
, bufferlist
>& attrs
, RGWObjVersionTracker
*objv_tracker
,
3012 ceph::real_time set_mtime
) {
3014 bl
.append(data
, len
);
3015 int flags
= PUT_OBJ_CREATE
;
3017 flags
|= PUT_OBJ_EXCL
;
3019 return put_system_obj_impl(obj
, len
, mtime
, attrs
, flags
, bl
, objv_tracker
, set_mtime
);
3021 int aio_wait(void *handle
);
3022 bool aio_completed(void *handle
);
3024 int on_last_entry_in_listing(RGWBucketInfo
& bucket_info
,
3025 const std::string
& obj_prefix
,
3026 const std::string
& obj_delim
,
3027 std::function
<int(const rgw_bucket_dir_entry
&)> handler
);
3029 bool swift_versioning_enabled(const RGWBucketInfo
& bucket_info
) const {
3030 return bucket_info
.has_swift_versioning() &&
3031 bucket_info
.swift_ver_location
.size();
3034 int swift_versioning_copy(RGWObjectCtx
& obj_ctx
, /* in/out */
3035 const rgw_user
& user
, /* in */
3036 RGWBucketInfo
& bucket_info
, /* in */
3037 rgw_obj
& obj
); /* in */
3038 int swift_versioning_restore(RGWObjectCtx
& obj_ctx
, /* in/out */
3039 const rgw_user
& user
, /* in */
3040 RGWBucketInfo
& bucket_info
, /* in */
3041 rgw_obj
& obj
, /* in */
3042 bool& restored
); /* out */
3043 int copy_obj_to_remote_dest(RGWObjState
*astate
,
3044 map
<string
, bufferlist
>& src_attrs
,
3045 RGWRados::Object::Read
& read_op
,
3046 const rgw_user
& user_id
,
3048 ceph::real_time
*mtime
);
3052 ATTRSMOD_REPLACE
= 1,
3056 int rewrite_obj(RGWBucketInfo
& dest_bucket_info
, rgw_obj
& obj
);
3058 int stat_remote_obj(RGWObjectCtx
& obj_ctx
,
3059 const rgw_user
& user_id
,
3060 const string
& client_id
,
3062 const string
& source_zone
,
3064 RGWBucketInfo
& src_bucket_info
,
3065 real_time
*src_mtime
,
3067 const real_time
*mod_ptr
,
3068 const real_time
*unmod_ptr
,
3069 bool high_precision_time
,
3070 const char *if_match
,
3071 const char *if_nomatch
,
3072 map
<string
, bufferlist
> *pattrs
,
3077 int fetch_remote_obj(RGWObjectCtx
& obj_ctx
,
3078 const rgw_user
& user_id
,
3079 const string
& client_id
,
3080 const string
& op_id
,
3081 bool record_op_state
,
3083 const string
& source_zone
,
3086 RGWBucketInfo
& dest_bucket_info
,
3087 RGWBucketInfo
& src_bucket_info
,
3088 ceph::real_time
*src_mtime
,
3089 ceph::real_time
*mtime
,
3090 const ceph::real_time
*mod_ptr
,
3091 const ceph::real_time
*unmod_ptr
,
3092 bool high_precision_time
,
3093 const char *if_match
,
3094 const char *if_nomatch
,
3097 map
<string
, bufferlist
>& attrs
,
3098 RGWObjCategory category
,
3100 ceph::real_time delete_at
,
3103 ceph::buffer::list
*petag
,
3104 void (*progress_cb
)(off_t
, void *),
3105 void *progress_data
,
3106 rgw_zone_set
*zones_trace
= nullptr);
3109 * dest_obj: the object to copy into
3110 * src_obj: the object to copy from
3111 * attrs: usage depends on attrs_mod parameter
3112 * attrs_mod: the modification mode of the attrs, may have the following values:
3113 * ATTRSMOD_NONE - the attributes of the source object will be
3114 * copied without modifications, attrs parameter is ignored;
3115 * ATTRSMOD_REPLACE - new object will have the attributes provided by attrs
3116 * parameter, source object attributes are not copied;
3117 * ATTRSMOD_MERGE - any conflicting meta keys on the source object's attributes
3118 * are overwritten by values contained in attrs parameter.
3119 * Returns: 0 on success, -ERR# otherwise.
3121 int copy_obj(RGWObjectCtx
& obj_ctx
,
3122 const rgw_user
& user_id
,
3123 const string
& client_id
,
3124 const string
& op_id
,
3126 const string
& source_zone
,
3129 RGWBucketInfo
& dest_bucket_info
,
3130 RGWBucketInfo
& src_bucket_info
,
3131 ceph::real_time
*src_mtime
,
3132 ceph::real_time
*mtime
,
3133 const ceph::real_time
*mod_ptr
,
3134 const ceph::real_time
*unmod_ptr
,
3135 bool high_precision_time
,
3136 const char *if_match
,
3137 const char *if_nomatch
,
3140 map
<std::string
, bufferlist
>& attrs
,
3141 RGWObjCategory category
,
3143 ceph::real_time delete_at
,
3146 ceph::buffer::list
*petag
,
3147 void (*progress_cb
)(off_t
, void *),
3148 void *progress_data
);
3150 int copy_obj_data(RGWObjectCtx
& obj_ctx
,
3151 RGWBucketInfo
& dest_bucket_info
,
3152 RGWRados::Object::Read
& read_op
, off_t end
,
3155 uint64_t max_chunk_size
,
3156 ceph::real_time
*mtime
,
3157 ceph::real_time set_mtime
,
3158 map
<string
, bufferlist
>& attrs
,
3159 RGWObjCategory category
,
3161 ceph::real_time delete_at
,
3164 ceph::buffer::list
*petag
);
3166 int check_bucket_empty(RGWBucketInfo
& bucket_info
);
3170 * bucket: the name of the bucket to delete
3171 * Returns 0 on success, -ERR# otherwise.
3173 int delete_bucket(RGWBucketInfo
& bucket_info
, RGWObjVersionTracker
& objv_tracker
, bool check_empty
= true);
3175 bool is_meta_master();
3178 * Check to see if the bucket metadata is synced
3180 bool is_syncing_bucket_meta(const rgw_bucket
& bucket
);
3181 void wakeup_meta_sync_shards(set
<int>& shard_ids
);
3182 void wakeup_data_sync_shards(const string
& source_zone
, map
<int, set
<string
> >& shard_ids
);
3184 RGWMetaSyncStatusManager
* get_meta_sync_manager();
3185 RGWDataSyncStatusManager
* get_data_sync_manager(const std::string
& source_zone
);
3187 int set_bucket_owner(rgw_bucket
& bucket
, ACLOwner
& owner
);
3188 int set_buckets_enabled(std::vector
<rgw_bucket
>& buckets
, bool enabled
);
3189 int bucket_suspended(rgw_bucket
& bucket
, bool *suspended
);
3191 /** Delete an object.*/
3192 int delete_obj(RGWObjectCtx
& obj_ctx
,
3193 const RGWBucketInfo
& bucket_owner
,
3194 const rgw_obj
& src_obj
,
3195 int versioning_status
,
3196 uint16_t bilog_flags
= 0,
3197 const ceph::real_time
& expiration_time
= ceph::real_time(),
3198 rgw_zone_set
*zones_trace
= nullptr);
3200 /** Delete a raw object.*/
3201 int delete_raw_obj(const rgw_raw_obj
& obj
);
3203 /* Delete a system object */
3204 virtual int delete_system_obj(rgw_raw_obj
& src_obj
, RGWObjVersionTracker
*objv_tracker
= NULL
);
3206 /** Remove an object from the bucket index */
3207 int delete_obj_index(const rgw_obj
& obj
);
3210 * Get an attribute for a system object.
3211 * obj: the object to get attr
3212 * name: name of the attr to retrieve
3213 * dest: bufferlist to store the result in
3214 * Returns: 0 on success, -ERR# otherwise.
3216 virtual int system_obj_get_attr(rgw_raw_obj
& obj
, const char *name
, bufferlist
& dest
);
3218 int system_obj_set_attr(void *ctx
, rgw_raw_obj
& obj
, const char *name
, bufferlist
& bl
,
3219 RGWObjVersionTracker
*objv_tracker
);
3220 virtual int system_obj_set_attrs(void *ctx
, rgw_raw_obj
& obj
,
3221 map
<string
, bufferlist
>& attrs
,
3222 map
<string
, bufferlist
>* rmattrs
,
3223 RGWObjVersionTracker
*objv_tracker
);
3226 * Set an attr on an object.
3227 * bucket: name of the bucket holding the object
3228 * obj: name of the object to set the attr on
3229 * name: the attr to set
3230 * bl: the contents of the attr
3231 * Returns: 0 on success, -ERR# otherwise.
3233 int set_attr(void *ctx
, const RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, const char *name
, bufferlist
& bl
);
3235 int set_attrs(void *ctx
, const RGWBucketInfo
& bucket_info
, rgw_obj
& obj
,
3236 map
<string
, bufferlist
>& attrs
,
3237 map
<string
, bufferlist
>* rmattrs
);
3239 int get_system_obj_state(RGWObjectCtx
*rctx
, rgw_raw_obj
& obj
, RGWRawObjState
**state
, RGWObjVersionTracker
*objv_tracker
);
3240 int get_obj_state(RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWObjState
**state
,
3241 bool follow_olh
, bool assume_noent
= false);
3242 int get_obj_state(RGWObjectCtx
*rctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWObjState
**state
) {
3243 return get_obj_state(rctx
, bucket_info
, obj
, state
, true);
3246 virtual int stat_system_obj(RGWObjectCtx
& obj_ctx
,
3247 RGWRados::SystemObject::Read::GetObjState
& state
,
3249 map
<string
, bufferlist
> *attrs
,
3250 ceph::real_time
*lastmod
,
3252 RGWObjVersionTracker
*objv_tracker
);
3254 virtual int get_system_obj(RGWObjectCtx
& obj_ctx
, RGWRados::SystemObject::Read::GetObjState
& read_state
,
3255 RGWObjVersionTracker
*objv_tracker
, rgw_raw_obj
& obj
,
3256 bufferlist
& bl
, off_t ofs
, off_t end
,
3257 map
<string
, bufferlist
> *attrs
,
3258 rgw_cache_entry_info
*cache_info
);
3260 virtual void register_chained_cache(RGWChainedCache
*cache
) {}
3261 virtual bool chain_cache_entry(list
<rgw_cache_entry_info
*>& cache_info_entries
, RGWChainedCache::Entry
*chained_entry
) { return false; }
3263 int iterate_obj(RGWObjectCtx
& ctx
,
3264 const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
3265 off_t ofs
, off_t end
,
3266 uint64_t max_chunk_size
,
3267 int (*iterate_obj_cb
)(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, const rgw_raw_obj
&, off_t
, off_t
, off_t
, bool, RGWObjState
*, void *),
3270 int flush_read_list(struct get_obj_data
*d
);
3272 int get_obj_iterate_cb(RGWObjectCtx
*ctx
, RGWObjState
*astate
,
3273 const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
3274 const rgw_raw_obj
& read_obj
,
3275 off_t obj_ofs
, off_t read_ofs
, off_t len
,
3276 bool is_head_obj
, void *arg
);
3278 void get_obj_aio_completion_cb(librados::completion_t cb
, void *arg
);
3281 * a simple object read without keeping state
3284 virtual int raw_obj_stat(rgw_raw_obj
& obj
, uint64_t *psize
, ceph::real_time
*pmtime
, uint64_t *epoch
,
3285 map
<string
, bufferlist
> *attrs
, bufferlist
*first_chunk
,
3286 RGWObjVersionTracker
*objv_tracker
);
3288 int obj_operate(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, librados::ObjectWriteOperation
*op
);
3289 int obj_operate(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, librados::ObjectReadOperation
*op
);
3291 int guard_reshard(BucketShard
*bs
, const rgw_obj
& obj_instance
, std::function
<int(BucketShard
*)> call
);
3292 int block_while_resharding(RGWRados::BucketShard
*bs
, string
*new_bucket_id
);
3294 void bucket_index_guard_olh_op(RGWObjState
& olh_state
, librados::ObjectOperation
& op
);
3295 int olh_init_modification(const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& olh_obj
, string
*op_tag
);
3296 int olh_init_modification_impl(const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& olh_obj
, string
*op_tag
);
3297 int bucket_index_link_olh(const RGWBucketInfo
& bucket_info
, RGWObjState
& olh_state
,
3298 const rgw_obj
& obj_instance
, bool delete_marker
,
3299 const string
& op_tag
, struct rgw_bucket_dir_entry_meta
*meta
,
3301 ceph::real_time unmod_since
, bool high_precision_time
, rgw_zone_set
*zones_trace
= nullptr);
3302 int bucket_index_unlink_instance(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj_instance
, const string
& op_tag
, const string
& olh_tag
, uint64_t olh_epoch
, rgw_zone_set
*zones_trace
= nullptr);
3303 int bucket_index_read_olh_log(const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& obj_instance
, uint64_t ver_marker
,
3304 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> > *log
, bool *is_truncated
);
3305 int bucket_index_trim_olh_log(const RGWBucketInfo
& bucket_info
, RGWObjState
& obj_state
, const rgw_obj
& obj_instance
, uint64_t ver
);
3306 int bucket_index_clear_olh(const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& obj_instance
);
3307 int apply_olh_log(RGWObjectCtx
& ctx
, RGWObjState
& obj_state
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
,
3308 bufferlist
& obj_tag
, map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >& log
,
3309 uint64_t *plast_ver
, rgw_zone_set
*zones_trace
= nullptr);
3310 int update_olh(RGWObjectCtx
& obj_ctx
, RGWObjState
*state
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, rgw_zone_set
*zones_trace
= nullptr);
3311 int set_olh(RGWObjectCtx
& obj_ctx
, RGWBucketInfo
& bucket_info
, const rgw_obj
& target_obj
, bool delete_marker
, rgw_bucket_dir_entry_meta
*meta
,
3312 uint64_t olh_epoch
, ceph::real_time unmod_since
, bool high_precision_time
, rgw_zone_set
*zones_trace
= nullptr);
3313 int unlink_obj_instance(RGWObjectCtx
& obj_ctx
, RGWBucketInfo
& bucket_info
, const rgw_obj
& target_obj
,
3314 uint64_t olh_epoch
, rgw_zone_set
*zones_trace
= nullptr);
3316 void check_pending_olh_entries(map
<string
, bufferlist
>& pending_entries
, map
<string
, bufferlist
> *rm_pending_entries
);
3317 int remove_olh_pending_entries(const RGWBucketInfo
& bucket_info
, RGWObjState
& state
, const rgw_obj
& olh_obj
, map
<string
, bufferlist
>& pending_attrs
);
3318 int follow_olh(const RGWBucketInfo
& bucket_info
, RGWObjectCtx
& ctx
, RGWObjState
*state
, const rgw_obj
& olh_obj
, rgw_obj
*target
);
3319 int get_olh(const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
, RGWOLHInfo
*olh
);
3321 void gen_rand_obj_instance_name(rgw_obj
*target
);
3323 int omap_get_vals(rgw_raw_obj
& obj
, bufferlist
& header
, const std::string
& marker
, uint64_t count
, std::map
<string
, bufferlist
>& m
);
3324 int omap_get_all(rgw_raw_obj
& obj
, bufferlist
& header
, std::map
<string
, bufferlist
>& m
);
3325 int omap_set(rgw_raw_obj
& obj
, const std::string
& key
, bufferlist
& bl
);
3326 int omap_set(rgw_raw_obj
& obj
, map
<std::string
, bufferlist
>& m
);
3327 int omap_del(rgw_raw_obj
& obj
, const std::string
& key
);
3328 int update_containers_stats(map
<string
, RGWBucketEnt
>& m
);
3329 int append_async(rgw_raw_obj
& obj
, size_t size
, bufferlist
& bl
);
3331 int watch(const string
& oid
, uint64_t *watch_handle
, librados::WatchCtx2
*ctx
);
3332 int unwatch(uint64_t watch_handle
);
3333 void add_watcher(int i
);
3334 void remove_watcher(int i
);
3335 virtual bool need_watch_notify() { return false; }
3337 void finalize_watch();
3338 int distribute(const string
& key
, bufferlist
& bl
);
3339 virtual int watch_cb(uint64_t notify_id
,
3341 uint64_t notifier_id
,
3342 bufferlist
& bl
) { return 0; }
3343 void pick_control_oid(const string
& key
, string
& notify_oid
);
3345 virtual void set_cache_enabled(bool state
) {}
3347 void set_atomic(void *ctx
, rgw_obj
& obj
) {
3348 RGWObjectCtx
*rctx
= static_cast<RGWObjectCtx
*>(ctx
);
3349 rctx
->obj
.set_atomic(obj
);
3351 void set_prefetch_data(void *ctx
, rgw_obj
& obj
) {
3352 RGWObjectCtx
*rctx
= static_cast<RGWObjectCtx
*>(ctx
);
3353 rctx
->obj
.set_prefetch_data(obj
);
3355 void set_prefetch_data(void *ctx
, rgw_raw_obj
& obj
) {
3356 RGWObjectCtx
*rctx
= static_cast<RGWObjectCtx
*>(ctx
);
3357 rctx
->raw
.set_prefetch_data(obj
);
3360 int decode_policy(bufferlist
& bl
, ACLOwner
*owner
);
3361 int get_bucket_stats(RGWBucketInfo
& bucket_info
, int shard_id
, string
*bucket_ver
, string
*master_ver
,
3362 map
<RGWObjCategory
, RGWStorageStats
>& stats
, string
*max_marker
, bool* syncstopped
= NULL
);
3363 int get_bucket_stats_async(RGWBucketInfo
& bucket_info
, int shard_id
, RGWGetBucketStats_CB
*cb
);
3364 int get_user_stats(const rgw_user
& user
, RGWStorageStats
& stats
);
3365 int get_user_stats_async(const rgw_user
& user
, RGWGetUserStats_CB
*cb
);
3366 void get_bucket_instance_obj(const rgw_bucket
& bucket
, rgw_raw_obj
& obj
);
3367 void get_bucket_meta_oid(const rgw_bucket
& bucket
, string
& oid
);
3369 int put_bucket_entrypoint_info(const string
& tenant_name
, const string
& bucket_name
, RGWBucketEntryPoint
& entry_point
,
3370 bool exclusive
, RGWObjVersionTracker
& objv_tracker
, ceph::real_time mtime
,
3371 map
<string
, bufferlist
> *pattrs
);
3372 int put_bucket_instance_info(RGWBucketInfo
& info
, bool exclusive
, ceph::real_time mtime
, map
<string
, bufferlist
> *pattrs
);
3373 int get_bucket_entrypoint_info(RGWObjectCtx
& obj_ctx
, const string
& tenant_name
, const string
& bucket_name
,
3374 RGWBucketEntryPoint
& entry_point
, RGWObjVersionTracker
*objv_tracker
,
3375 ceph::real_time
*pmtime
, map
<string
, bufferlist
> *pattrs
, rgw_cache_entry_info
*cache_info
= NULL
);
3376 int get_bucket_instance_info(RGWObjectCtx
& obj_ctx
, const string
& meta_key
, RGWBucketInfo
& info
, ceph::real_time
*pmtime
, map
<string
, bufferlist
> *pattrs
);
3377 int get_bucket_instance_info(RGWObjectCtx
& obj_ctx
, const rgw_bucket
& bucket
, RGWBucketInfo
& info
, ceph::real_time
*pmtime
, map
<string
, bufferlist
> *pattrs
);
3378 int get_bucket_instance_from_oid(RGWObjectCtx
& obj_ctx
, const string
& oid
, RGWBucketInfo
& info
, ceph::real_time
*pmtime
, map
<string
, bufferlist
> *pattrs
,
3379 rgw_cache_entry_info
*cache_info
= NULL
);
3381 int convert_old_bucket_info(RGWObjectCtx
& obj_ctx
, const string
& tenant_name
, const string
& bucket_name
);
3382 static void make_bucket_entry_name(const string
& tenant_name
, const string
& bucket_name
, string
& bucket_entry
);
3383 int get_bucket_info(RGWObjectCtx
& obj_ctx
,
3384 const string
& tenant_name
, const string
& bucket_name
,
3385 RGWBucketInfo
& info
,
3386 ceph::real_time
*pmtime
, map
<string
, bufferlist
> *pattrs
= NULL
);
3387 int put_linked_bucket_info(RGWBucketInfo
& info
, bool exclusive
, ceph::real_time mtime
, obj_version
*pep_objv
,
3388 map
<string
, bufferlist
> *pattrs
, bool create_entry_point
);
3390 int cls_rgw_init_index(librados::IoCtx
& io_ctx
, librados::ObjectWriteOperation
& op
, string
& oid
);
3391 int cls_obj_prepare_op(BucketShard
& bs
, RGWModifyOp op
, string
& tag
, rgw_obj
& obj
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
3392 int cls_obj_complete_op(BucketShard
& bs
, const rgw_obj
& obj
, RGWModifyOp op
, string
& tag
, int64_t pool
, uint64_t epoch
,
3393 rgw_bucket_dir_entry
& ent
, RGWObjCategory category
, list
<rgw_obj_index_key
> *remove_objs
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
3394 int cls_obj_complete_add(BucketShard
& bs
, const rgw_obj
& obj
, string
& tag
, int64_t pool
, uint64_t epoch
, rgw_bucket_dir_entry
& ent
,
3395 RGWObjCategory category
, list
<rgw_obj_index_key
> *remove_objs
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
3396 int cls_obj_complete_del(BucketShard
& bs
, string
& tag
, int64_t pool
, uint64_t epoch
, rgw_obj
& obj
,
3397 ceph::real_time
& removed_mtime
, list
<rgw_obj_index_key
> *remove_objs
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
3398 int cls_obj_complete_cancel(BucketShard
& bs
, string
& tag
, rgw_obj
& obj
, uint16_t bilog_flags
, rgw_zone_set
*zones_trace
= nullptr);
3399 int cls_obj_set_bucket_tag_timeout(RGWBucketInfo
& bucket_info
, uint64_t timeout
);
3400 int cls_bucket_list(RGWBucketInfo
& bucket_info
, int shard_id
, rgw_obj_index_key
& start
, const string
& prefix
,
3401 uint32_t num_entries
, bool list_versions
, map
<string
, rgw_bucket_dir_entry
>& m
,
3402 bool *is_truncated
, rgw_obj_index_key
*last_entry
,
3403 bool (*force_check_filter
)(const string
& name
) = NULL
);
3404 int cls_bucket_head(const RGWBucketInfo
& bucket_info
, int shard_id
, map
<string
, struct rgw_bucket_dir_header
>& headers
, map
<int, string
> *bucket_instance_ids
= NULL
);
3405 int cls_bucket_head_async(const RGWBucketInfo
& bucket_info
, int shard_id
, RGWGetDirHeader_CB
*ctx
, int *num_aio
);
3406 int list_bi_log_entries(RGWBucketInfo
& bucket_info
, int shard_id
, string
& marker
, uint32_t max
, std::list
<rgw_bi_log_entry
>& result
, bool *truncated
);
3407 int trim_bi_log_entries(RGWBucketInfo
& bucket_info
, int shard_id
, string
& marker
, string
& end_marker
);
3408 int resync_bi_log_entries(RGWBucketInfo
& bucket_info
, int shard_id
);
3409 int stop_bi_log_entries(RGWBucketInfo
& bucket_info
, int shard_id
);
3410 int get_bi_log_status(RGWBucketInfo
& bucket_info
, int shard_id
, map
<int, string
>& max_marker
);
3412 int bi_get_instance(const RGWBucketInfo
& bucket_info
, rgw_obj
& obj
, rgw_bucket_dir_entry
*dirent
);
3413 int bi_get(rgw_bucket
& bucket
, rgw_obj
& obj
, BIIndexType index_type
, rgw_cls_bi_entry
*entry
);
3414 void bi_put(librados::ObjectWriteOperation
& op
, BucketShard
& bs
, rgw_cls_bi_entry
& entry
);
3415 int bi_put(BucketShard
& bs
, rgw_cls_bi_entry
& entry
);
3416 int bi_put(rgw_bucket
& bucket
, rgw_obj
& obj
, rgw_cls_bi_entry
& entry
);
3417 int bi_list(rgw_bucket
& bucket
, int shard_id
, const string
& filter_obj
, const string
& marker
, uint32_t max
, list
<rgw_cls_bi_entry
> *entries
, bool *is_truncated
);
3418 int bi_list(BucketShard
& bs
, const string
& filter_obj
, const string
& marker
, uint32_t max
, list
<rgw_cls_bi_entry
> *entries
, bool *is_truncated
);
3419 int bi_list(rgw_bucket
& bucket
, const string
& obj_name
, const string
& marker
, uint32_t max
,
3420 list
<rgw_cls_bi_entry
> *entries
, bool *is_truncated
);
3421 int bi_remove(BucketShard
& bs
);
3423 int cls_obj_usage_log_add(const string
& oid
, rgw_usage_log_info
& info
);
3424 int cls_obj_usage_log_read(string
& oid
, string
& user
, uint64_t start_epoch
, uint64_t end_epoch
, uint32_t max_entries
,
3425 string
& read_iter
, map
<rgw_user_bucket
, rgw_usage_log_entry
>& usage
, bool *is_truncated
);
3426 int cls_obj_usage_log_trim(string
& oid
, string
& user
, uint64_t start_epoch
, uint64_t end_epoch
);
3428 int key_to_shard_id(const string
& key
, int max_shards
);
3429 void shard_name(const string
& prefix
, unsigned max_shards
, const string
& key
, string
& name
, int *shard_id
);
3430 void shard_name(const string
& prefix
, unsigned max_shards
, const string
& section
, const string
& key
, string
& name
);
3431 void shard_name(const string
& prefix
, unsigned shard_id
, string
& name
);
3432 int get_target_shard_id(const RGWBucketInfo
& bucket_info
, const string
& obj_key
, int *shard_id
);
3433 void time_log_prepare_entry(cls_log_entry
& entry
, const ceph::real_time
& ut
, const string
& section
, const string
& key
, bufferlist
& bl
);
3434 int time_log_add_init(librados::IoCtx
& io_ctx
);
3435 int time_log_add(const string
& oid
, list
<cls_log_entry
>& entries
,
3436 librados::AioCompletion
*completion
, bool monotonic_inc
= true);
3437 int time_log_add(const string
& oid
, const ceph::real_time
& ut
, const string
& section
, const string
& key
, bufferlist
& bl
);
3438 int time_log_list(const string
& oid
, const ceph::real_time
& start_time
, const ceph::real_time
& end_time
,
3439 int max_entries
, list
<cls_log_entry
>& entries
,
3440 const string
& marker
, string
*out_marker
, bool *truncated
);
3441 int time_log_info(const string
& oid
, cls_log_header
*header
);
3442 int time_log_info_async(librados::IoCtx
& io_ctx
, const string
& oid
, cls_log_header
*header
, librados::AioCompletion
*completion
);
3443 int time_log_trim(const string
& oid
, const ceph::real_time
& start_time
, const ceph::real_time
& end_time
,
3444 const string
& from_marker
, const string
& to_marker
,
3445 librados::AioCompletion
*completion
= nullptr);
3447 string
objexp_hint_get_shardname(int shard_num
);
3448 int objexp_key_shard(const rgw_obj_index_key
& key
);
3449 void objexp_get_shard(int shard_num
,
3450 string
& shard
); /* out */
3451 int objexp_hint_add(const ceph::real_time
& delete_at
,
3452 const string
& tenant_name
,
3453 const string
& bucket_name
,
3454 const string
& bucket_id
,
3455 const rgw_obj_index_key
& obj_key
);
3456 int objexp_hint_list(const string
& oid
,
3457 const ceph::real_time
& start_time
,
3458 const ceph::real_time
& end_time
,
3459 const int max_entries
,
3460 const string
& marker
,
3461 list
<cls_timeindex_entry
>& entries
, /* out */
3462 string
*out_marker
, /* out */
3463 bool *truncated
); /* out */
3464 int objexp_hint_parse(cls_timeindex_entry
&ti_entry
,
3465 objexp_hint_entry
& hint_entry
); /* out */
3466 int objexp_hint_trim(const string
& oid
,
3467 const ceph::real_time
& start_time
,
3468 const ceph::real_time
& end_time
,
3469 const string
& from_marker
= std::string(),
3470 const string
& to_marker
= std::string());
3472 int lock_exclusive(rgw_pool
& pool
, const string
& oid
, ceph::timespan
& duration
, string
& zone_id
, string
& owner_id
);
3473 int unlock(rgw_pool
& pool
, const string
& oid
, string
& zone_id
, string
& owner_id
);
3475 void update_gc_chain(rgw_obj
& head_obj
, RGWObjManifest
& manifest
, cls_rgw_obj_chain
*chain
);
3476 int send_chain_to_gc(cls_rgw_obj_chain
& chain
, const string
& tag
, bool sync
);
3477 int gc_operate(string
& oid
, librados::ObjectWriteOperation
*op
);
3478 int gc_aio_operate(string
& oid
, librados::ObjectWriteOperation
*op
);
3479 int gc_operate(string
& oid
, librados::ObjectReadOperation
*op
, bufferlist
*pbl
);
3481 int list_gc_objs(int *index
, string
& marker
, uint32_t max
, bool expired_only
, std::list
<cls_rgw_gc_obj_info
>& result
, bool *truncated
);
3483 int process_expire_objects();
3484 int defer_gc(void *ctx
, const RGWBucketInfo
& bucket_info
, const rgw_obj
& obj
);
3487 int list_lc_progress(const string
& marker
, uint32_t max_entries
, map
<string
, int> *progress_map
);
3489 int bucket_check_index(RGWBucketInfo
& bucket_info
,
3490 map
<RGWObjCategory
, RGWStorageStats
> *existing_stats
,
3491 map
<RGWObjCategory
, RGWStorageStats
> *calculated_stats
);
3492 int bucket_rebuild_index(RGWBucketInfo
& bucket_info
);
3493 int bucket_set_reshard(RGWBucketInfo
& bucket_info
, const cls_rgw_bucket_instance_entry
& entry
);
3494 int remove_objs_from_index(RGWBucketInfo
& bucket_info
, list
<rgw_obj_index_key
>& oid_list
);
3495 int move_rados_obj(librados::IoCtx
& src_ioctx
,
3496 const string
& src_oid
, const string
& src_locator
,
3497 librados::IoCtx
& dst_ioctx
,
3498 const string
& dst_oid
, const string
& dst_locator
);
3499 int fix_head_obj_locator(const RGWBucketInfo
& bucket_info
, bool copy_obj
, bool remove_bad
, rgw_obj_key
& key
);
3500 int fix_tail_obj_locator(const RGWBucketInfo
& bucket_info
, rgw_obj_key
& key
, bool fix
, bool *need_fix
);
3502 int cls_user_get_header(const string
& user_id
, cls_user_header
*header
);
3503 int cls_user_get_header_async(const string
& user_id
, RGWGetUserHeader_CB
*ctx
);
3504 int cls_user_sync_bucket_stats(rgw_raw_obj
& user_obj
, const RGWBucketInfo
& bucket_info
);
3505 int cls_user_list_buckets(rgw_raw_obj
& obj
,
3506 const string
& in_marker
,
3507 const string
& end_marker
,
3509 list
<cls_user_bucket_entry
>& entries
,
3512 int cls_user_add_bucket(rgw_raw_obj
& obj
, const cls_user_bucket_entry
& entry
);
3513 int cls_user_update_buckets(rgw_raw_obj
& obj
, list
<cls_user_bucket_entry
>& entries
, bool add
);
3514 int cls_user_complete_stats_sync(rgw_raw_obj
& obj
);
3515 int complete_sync_user_stats(const rgw_user
& user_id
);
3516 int cls_user_add_bucket(rgw_raw_obj
& obj
, list
<cls_user_bucket_entry
>& entries
);
3517 int cls_user_remove_bucket(rgw_raw_obj
& obj
, const cls_user_bucket
& bucket
);
3518 int cls_user_get_bucket_stats(const rgw_bucket
& bucket
, cls_user_bucket_entry
& entry
);
3520 int check_quota(const rgw_user
& bucket_owner
, rgw_bucket
& bucket
,
3521 RGWQuotaInfo
& user_quota
, RGWQuotaInfo
& bucket_quota
, uint64_t obj_size
);
3523 int check_bucket_shards(const RGWBucketInfo
& bucket_info
, const rgw_bucket
& bucket
,
3524 RGWQuotaInfo
& bucket_quota
);
3526 int add_bucket_to_reshard(const RGWBucketInfo
& bucket_info
, uint32_t new_num_shards
);
3528 uint64_t instance_id();
3529 const string
& zone_name() {
3530 return get_zone_params().get_name();
3532 const string
& zone_id() {
3533 return get_zone_params().get_id();
3535 string
unique_id(uint64_t unique_num
) {
3537 snprintf(buf
, sizeof(buf
), ".%llu.%llu", (unsigned long long)instance_id(), (unsigned long long)unique_num
);
3538 string s
= get_zone_params().get_id() + buf
;
3542 void init_unique_trans_id_deps() {
3543 char buf
[16 + 2 + 1]; /* uint64_t needs 16, 2 hyphens add further 2 */
3545 snprintf(buf
, sizeof(buf
), "-%llx-", (unsigned long long)instance_id());
3546 url_encode(string(buf
) + get_zone_params().get_name(), trans_id_suffix
);
3549 /* In order to preserve compability with Swift API, transaction ID
3550 * should contain at least 32 characters satisfying following spec:
3551 * - first 21 chars must be in range [0-9a-f]. Swift uses this
3552 * space for storing fragment of UUID obtained through a call to
3553 * uuid4() function of Python's uuid module;
3554 * - char no. 22 must be a hyphen;
3555 * - at least 10 next characters constitute hex-formatted timestamp
3556 * padded with zeroes if necessary. All bytes must be in [0-9a-f]
3558 * - last, optional part of transaction ID is any url-encoded string
3559 * without restriction on length. */
3560 string
unique_trans_id(const uint64_t unique_num
) {
3561 char buf
[41]; /* 2 + 21 + 1 + 16 (timestamp can consume up to 16) + 1 */
3562 time_t timestamp
= time(NULL
);
3564 snprintf(buf
, sizeof(buf
), "tx%021llx-%010llx",
3565 (unsigned long long)unique_num
,
3566 (unsigned long long)timestamp
);
3568 return string(buf
) + trans_id_suffix
;
3571 void get_log_pool(rgw_pool
& pool
) {
3572 pool
= get_zone_params().log_pool
;
3575 bool need_to_log_data() {
3576 return get_zone().log_data
;
3579 bool need_to_log_metadata() {
3580 return is_meta_master() &&
3581 (get_zonegroup().zones
.size() > 1 || current_period
.is_multi_zonegroups_with_zones());
3584 librados::Rados
* get_rados_handle();
3586 int delete_raw_obj_aio(const rgw_raw_obj
& obj
, list
<librados::AioCompletion
*>& handles
);
3587 int delete_obj_aio(const rgw_obj
& obj
, RGWBucketInfo
& info
, RGWObjState
*astate
,
3588 list
<librados::AioCompletion
*>& handles
, bool keep_index_consistent
);
3591 * This is a helper method, it generates a list of bucket index objects with the given
3592 * bucket base oid and number of shards.
3594 * bucket_oid_base [in] - base name of the bucket index object;
3595 * num_shards [in] - number of bucket index object shards.
3596 * bucket_objs [out] - filled by this method, a list of bucket index objects.
3598 void get_bucket_index_objects(const string
& bucket_oid_base
, uint32_t num_shards
,
3599 map
<int, string
>& bucket_objs
, int shard_id
= -1);
3602 * Get the bucket index object with the given base bucket index object and object key,
3603 * and the number of bucket index shards.
3605 * bucket_oid_base [in] - bucket object base name.
3606 * obj_key [in] - object key.
3607 * num_shards [in] - number of bucket index shards.
3608 * hash_type [in] - type of hash to find the shard ID.
3609 * bucket_obj [out] - the bucket index object for the given object.
3611 * Return 0 on success, a failure code otherwise.
3613 int get_bucket_index_object(const string
& bucket_oid_base
, const string
& obj_key
,
3614 uint32_t num_shards
, RGWBucketInfo::BIShardsHashType hash_type
, string
*bucket_obj
, int *shard
);
3616 void get_bucket_index_object(const string
& bucket_oid_base
, uint32_t num_shards
,
3617 int shard_id
, string
*bucket_obj
);
3620 * Check the actual on-disk state of the object specified
3621 * by list_state, and fill in the time and size of object.
3622 * Then append any changes to suggested_updates for
3623 * the rgw class' dir_suggest_changes function.
3625 * Note that this can maul list_state; don't use it afterwards. Also
3626 * it expects object to already be filled in from list_state; it only
3627 * sets the size and mtime.
3629 * Returns 0 on success, -ENOENT if the object doesn't exist on disk,
3630 * and -errno on other failures. (-ENOENT is not a failure, and it
3631 * will encode that info as a suggested update.)
3633 int check_disk_state(librados::IoCtx io_ctx
,
3634 const RGWBucketInfo
& bucket_info
,
3635 rgw_bucket_dir_entry
& list_state
,
3636 rgw_bucket_dir_entry
& object
,
3637 bufferlist
& suggested_updates
);
3640 * Init pool iteration
3641 * pool: pool to use for the ctx initialization
3642 * ctx: context object to use for the iteration
3643 * Returns: 0 on success, -ERR# otherwise.
3645 int pool_iterate_begin(const rgw_pool
& pool
, RGWPoolIterCtx
& ctx
);
3648 * Iterate over pool return object names, use optional filter
3649 * ctx: iteration context, initialized with pool_iterate_begin()
3650 * num: max number of objects to return
3651 * objs: a vector that the results will append into
3652 * is_truncated: if not NULL, will hold true iff iteration is complete
3653 * filter: if not NULL, will be used to filter returned objects
3654 * Returns: 0 on success, -ERR# otherwise.
3656 int pool_iterate(RGWPoolIterCtx
& ctx
, uint32_t num
, vector
<rgw_bucket_dir_entry
>& objs
,
3657 bool *is_truncated
, RGWAccessListFilter
*filter
);
3659 uint64_t next_bucket_id();
3662 class RGWStoreManager
{
3664 RGWStoreManager() {}
3665 static RGWRados
*get_storage(CephContext
*cct
, bool use_gc_thread
, bool use_lc_thread
, bool quota_threads
, bool run_sync_thread
, bool run_reshard_thread
) {
3666 RGWRados
*store
= init_storage_provider(cct
, use_gc_thread
, use_lc_thread
, quota_threads
, run_sync_thread
,
3667 run_reshard_thread
);
3670 static RGWRados
*get_raw_storage(CephContext
*cct
) {
3671 RGWRados
*store
= init_raw_storage_provider(cct
);
3674 static RGWRados
*init_storage_provider(CephContext
*cct
, bool use_gc_thread
, bool use_lc_thread
, bool quota_threads
, bool run_sync_thread
, bool run_reshard_thread
);
3675 static RGWRados
*init_raw_storage_provider(CephContext
*cct
);
3676 static void close_storage(RGWRados
*store
);
3681 class RGWChainedCacheImpl
: public RGWChainedCache
{
3684 map
<string
, T
> entries
;
3687 RGWChainedCacheImpl() : lock("RGWChainedCacheImpl::lock") {}
3689 void init(RGWRados
*store
) {
3690 store
->register_chained_cache(this);
3693 bool find(const string
& key
, T
*entry
) {
3694 RWLock::RLocker
rl(lock
);
3695 typename map
<string
, T
>::iterator iter
= entries
.find(key
);
3696 if (iter
== entries
.end()) {
3700 *entry
= iter
->second
;
3704 bool put(RGWRados
*store
, const string
& key
, T
*entry
, list
<rgw_cache_entry_info
*>& cache_info_entries
) {
3705 Entry
chain_entry(this, key
, entry
);
3707 /* we need the store cache to call us under its lock to maintain lock ordering */
3708 return store
->chain_cache_entry(cache_info_entries
, &chain_entry
);
3711 void chain_cb(const string
& key
, void *data
) override
{
3712 T
*entry
= static_cast<T
*>(data
);
3713 RWLock::WLocker
wl(lock
);
3714 entries
[key
] = *entry
;
3717 void invalidate(const string
& key
) override
{
3718 RWLock::WLocker
wl(lock
);
3722 void invalidate_all() override
{
3723 RWLock::WLocker
wl(lock
);
3726 }; /* RGWChainedCacheImpl */
3729 * Base of PUT operation.
3730 * Allow to create chained data transformers like compresors and encryptors.
3732 class RGWPutObjDataProcessor
3735 RGWPutObjDataProcessor(){}
3736 virtual ~RGWPutObjDataProcessor(){}
3737 virtual int handle_data(bufferlist
& bl
, off_t ofs
, void **phandle
, rgw_raw_obj
*pobj
, bool *again
) = 0;
3738 virtual int throttle_data(void *handle
, const rgw_raw_obj
& obj
, uint64_t size
, bool need_to_wait
) = 0;
3739 }; /* RGWPutObjDataProcessor */
3742 class RGWPutObjProcessor
: public RGWPutObjDataProcessor
3746 RGWObjectCtx
& obj_ctx
;
3748 RGWBucketInfo bucket_info
;
3751 virtual int do_complete(size_t accounted_size
, const string
& etag
,
3752 ceph::real_time
*mtime
, ceph::real_time set_mtime
,
3753 map
<string
, bufferlist
>& attrs
, ceph::real_time delete_at
,
3754 const char *if_match
, const char *if_nomatch
, const string
*user_data
,
3755 rgw_zone_set
* zones_trace
= nullptr) = 0;
3758 RGWPutObjProcessor(RGWObjectCtx
& _obj_ctx
, RGWBucketInfo
& _bi
) : store(NULL
),
3763 ~RGWPutObjProcessor() override
{}
3764 virtual int prepare(RGWRados
*_store
, string
*oid_rand
) {
3769 int complete(size_t accounted_size
, const string
& etag
,
3770 ceph::real_time
*mtime
, ceph::real_time set_mtime
,
3771 map
<string
, bufferlist
>& attrs
, ceph::real_time delete_at
,
3772 const char *if_match
= NULL
, const char *if_nomatch
= NULL
, const string
*user_data
= nullptr,
3773 rgw_zone_set
*zones_trace
= nullptr);
3777 bool is_canceled() { return canceled
; }
3778 }; /* RGWPutObjProcessor */
3780 struct put_obj_aio_info
{
3786 #define RGW_PUT_OBJ_MIN_WINDOW_SIZE_DEFAULT (16 * 1024 * 1024)
3788 class RGWPutObjProcessor_Aio
: public RGWPutObjProcessor
3790 list
<struct put_obj_aio_info
> pending
;
3791 uint64_t window_size
{RGW_PUT_OBJ_MIN_WINDOW_SIZE_DEFAULT
};
3792 uint64_t pending_size
{0};
3794 struct put_obj_aio_info
pop_pending();
3795 int wait_pending_front();
3796 bool pending_has_completed();
3798 rgw_raw_obj last_written_obj
;
3801 uint64_t obj_len
{0};
3803 set
<rgw_raw_obj
> written_objs
;
3806 void add_written_obj(const rgw_raw_obj
& obj
) {
3807 written_objs
.insert(obj
);
3810 int drain_pending();
3811 int handle_obj_data(rgw_raw_obj
& obj
, bufferlist
& bl
, off_t ofs
, off_t abs_ofs
, void **phandle
, bool exclusive
);
3814 int prepare(RGWRados
*store
, string
*oid_rand
) override
;
3815 int throttle_data(void *handle
, const rgw_raw_obj
& obj
, uint64_t size
, bool need_to_wait
) override
;
3817 RGWPutObjProcessor_Aio(RGWObjectCtx
& obj_ctx
, RGWBucketInfo
& bucket_info
) : RGWPutObjProcessor(obj_ctx
, bucket_info
) {}
3818 ~RGWPutObjProcessor_Aio() override
;
3819 }; /* RGWPutObjProcessor_Aio */
3821 class RGWPutObjProcessor_Atomic
: public RGWPutObjProcessor_Aio
3823 bufferlist first_chunk
;
3826 off_t next_part_ofs
;
3830 bufferlist pending_data_bl
;
3831 uint64_t max_chunk_size
;
3833 bool versioned_object
;
3843 rgw_raw_obj cur_obj
;
3844 RGWObjManifest manifest
;
3845 RGWObjManifest::generator manifest_gen
;
3847 int write_data(bufferlist
& bl
, off_t ofs
, void **phandle
, rgw_raw_obj
*pobj
, bool exclusive
);
3848 int do_complete(size_t accounted_size
, const string
& etag
,
3849 ceph::real_time
*mtime
, ceph::real_time set_mtime
,
3850 map
<string
, bufferlist
>& attrs
, ceph::real_time delete_at
,
3851 const char *if_match
, const char *if_nomatch
, const string
*user_data
, rgw_zone_set
*zones_trace
) override
;
3853 int prepare_next_part(off_t ofs
);
3854 int complete_parts();
3855 int complete_writing_data();
3857 int prepare_init(RGWRados
*store
, string
*oid_rand
);
3860 ~RGWPutObjProcessor_Atomic() override
{}
3861 RGWPutObjProcessor_Atomic(RGWObjectCtx
& obj_ctx
, RGWBucketInfo
& bucket_info
,
3862 rgw_bucket
& _b
, const string
& _o
, uint64_t _p
, const string
& _t
, bool versioned
) :
3863 RGWPutObjProcessor_Aio(obj_ctx
, bucket_info
),
3870 versioned_object(versioned
),
3875 int prepare(RGWRados
*store
, string
*oid_rand
) override
;
3876 virtual bool immutable_head() { return false; }
3877 int handle_data(bufferlist
& bl
, off_t ofs
, void **phandle
, rgw_raw_obj
*pobj
, bool *again
) override
;
3879 void set_olh_epoch(uint64_t epoch
) {
3883 void set_version_id(const string
& vid
) {
3886 }; /* RGWPutObjProcessor_Atomic */
3888 #define MP_META_SUFFIX ".meta"
3897 RGWMPObj(const string
& _oid
, const string
& _upload_id
) {
3898 init(_oid
, _upload_id
, _upload_id
);
3900 void init(const string
& _oid
, const string
& _upload_id
) {
3901 init(_oid
, _upload_id
, _upload_id
);
3903 void init(const string
& _oid
, const string
& _upload_id
, const string
& part_unique_str
) {
3909 upload_id
= _upload_id
;
3911 meta
= prefix
+ upload_id
+ MP_META_SUFFIX
;
3912 prefix
.append(part_unique_str
);
3914 string
& get_meta() { return meta
; }
3915 string
get_part(int num
) {
3917 snprintf(buf
, 16, ".%d", num
);
3922 string
get_part(string
& part
) {
3928 string
& get_upload_id() {
3934 bool from_meta(string
& meta
) {
3935 int end_pos
= meta
.rfind('.'); // search for ".meta"
3938 int mid_pos
= meta
.rfind('.', end_pos
- 1); // <key>.<upload_id>
3941 oid
= meta
.substr(0, mid_pos
);
3942 upload_id
= meta
.substr(mid_pos
+ 1, end_pos
- mid_pos
- 1);
3943 init(oid
, upload_id
, upload_id
);
3954 class RGWPutObjProcessor_Multipart
: public RGWPutObjProcessor_Atomic
3962 int prepare(RGWRados
*store
, string
*oid_rand
);
3963 int do_complete(size_t accounted_size
, const string
& etag
,
3964 ceph::real_time
*mtime
, ceph::real_time set_mtime
,
3965 map
<string
, bufferlist
>& attrs
, ceph::real_time delete_at
,
3966 const char *if_match
, const char *if_nomatch
, const string
*user_data
,
3967 rgw_zone_set
*zones_trace
) override
;
3969 bool immutable_head() { return true; }
3970 RGWPutObjProcessor_Multipart(RGWObjectCtx
& obj_ctx
, RGWBucketInfo
& bucket_info
, uint64_t _p
, req_state
*_s
) :
3971 RGWPutObjProcessor_Atomic(obj_ctx
, bucket_info
, _s
->bucket
, _s
->object
.name
, _p
, _s
->req_id
, false), s(_s
) {}
3972 void get_mp(RGWMPObj
** _mp
);
3973 }; /* RGWPutObjProcessor_Multipart */