-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
rgw_rados.h
3265 lines (2736 loc) · 106 KB
/
rgw_rados.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_RGWRADOS_H
#define CEPH_RGWRADOS_H
#include <functional>
#include "include/rados/librados.hpp"
#include "include/Context.h"
#include "common/RefCountedObj.h"
#include "common/RWLock.h"
#include "common/ceph_time.h"
#include "common/lru_map.h"
#include "rgw_common.h"
#include "cls/rgw/cls_rgw_types.h"
#include "cls/version/cls_version_types.h"
#include "cls/log/cls_log_types.h"
#include "cls/statelog/cls_statelog_types.h"
#include "cls/timeindex/cls_timeindex_types.h"
#include "rgw_log.h"
#include "rgw_metadata.h"
#include "rgw_meta_sync_status.h"
#include "rgw_period_puller.h"
class RGWWatcher;
class SafeTimer;
class ACLOwner;
class RGWGC;
class RGWMetaNotifier;
class RGWDataNotifier;
class RGWLC;
class RGWObjectExpirer;
class RGWMetaSyncProcessorThread;
class RGWDataSyncProcessorThread;
class RGWRESTConn;
/* flags for put_obj_meta() */
#define PUT_OBJ_CREATE 0x01
#define PUT_OBJ_EXCL 0x02
#define PUT_OBJ_CREATE_EXCL (PUT_OBJ_CREATE | PUT_OBJ_EXCL)
#define RGW_OBJ_NS_MULTIPART "multipart"
#define RGW_OBJ_NS_SHADOW "shadow"
#define RGW_BUCKET_INSTANCE_MD_PREFIX ".bucket.meta."
#define RGW_NO_SHARD -1
static inline void prepend_bucket_marker(rgw_bucket& bucket, const string& orig_oid, string& oid)
{
if (bucket.marker.empty() || orig_oid.empty()) {
oid = orig_oid;
} else {
oid = bucket.marker;
oid.append("_");
oid.append(orig_oid);
}
}
static inline void get_obj_bucket_and_oid_loc(const rgw_obj& obj, rgw_bucket& bucket, string& oid, string& locator)
{
bucket = obj.bucket;
prepend_bucket_marker(bucket, obj.get_object(), oid);
const string& loc = obj.get_loc();
if (!loc.empty()) {
prepend_bucket_marker(bucket, loc, locator);
} else {
locator.clear();
}
}
int rgw_policy_from_attrset(CephContext *cct, map<string, bufferlist>& attrset, RGWAccessControlPolicy *policy);
struct RGWOLHInfo {
rgw_obj target;
bool removed;
RGWOLHInfo() : removed(false) {}
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
::encode(target, bl);
::encode(removed, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
::decode(target, bl);
::decode(removed, bl);
DECODE_FINISH(bl);
}
static void generate_test_instances(list<RGWOLHInfo*>& o);
void dump(Formatter *f) const;
};
WRITE_CLASS_ENCODER(RGWOLHInfo)
struct RGWOLHPendingInfo {
ceph::real_time time;
RGWOLHPendingInfo() {}
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
::encode(time, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
::decode(time, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
};
WRITE_CLASS_ENCODER(RGWOLHPendingInfo)
struct RGWUsageBatch {
map<ceph::real_time, rgw_usage_log_entry> m;
void insert(ceph::real_time& t, rgw_usage_log_entry& entry, bool *account) {
bool exists = m.find(t) != m.end();
*account = !exists;
m[t].aggregate(entry);
}
};
struct RGWUsageIter {
string read_iter;
uint32_t index;
RGWUsageIter() : index(0) {}
};
class RGWGetDataCB {
protected:
uint64_t extra_data_len;
public:
virtual int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) = 0;
RGWGetDataCB() : extra_data_len(0) {}
virtual ~RGWGetDataCB() {}
virtual void set_extra_data_len(uint64_t len) {
extra_data_len = len;
}
};
class RGWAccessListFilter {
public:
virtual ~RGWAccessListFilter() {}
virtual bool filter(string& name, string& key) = 0;
};
struct RGWCloneRangeInfo {
rgw_obj src;
off_t src_ofs;
off_t dst_ofs;
uint64_t len;
};
struct RGWObjManifestPart {
rgw_obj loc; /* the object where the data is located */
uint64_t loc_ofs; /* the offset at that object where the data is located */
uint64_t size; /* the part size */
RGWObjManifestPart() : loc_ofs(0), size(0) {}
void encode(bufferlist& bl) const {
ENCODE_START(2, 2, bl);
::encode(loc, bl);
::encode(loc_ofs, bl);
::encode(size, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl);
::decode(loc, bl);
::decode(loc_ofs, bl);
::decode(size, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<RGWObjManifestPart*>& o);
};
WRITE_CLASS_ENCODER(RGWObjManifestPart)
/*
The manifest defines a set of rules for structuring the object parts.
There are a few terms to note:
- head: the head part of the object, which is the part that contains
the first chunk of data. An object might not have a head (as in the
case of multipart-part objects).
- stripe: data portion of a single rgw object that resides on a single
rados object.
- part: a collection of stripes that make a contiguous part of an
object. A regular object will only have one part (although might have
many stripes), a multipart object might have many parts. Each part
has a fixed stripe size, although the last stripe of a part might
be smaller than that. Consecutive parts may be merged if their stripe
value is the same.
*/
struct RGWObjManifestRule {
uint32_t start_part_num;
uint64_t start_ofs;
uint64_t part_size; /* each part size, 0 if there's no part size, meaning it's unlimited */
uint64_t stripe_max_size; /* underlying obj max size */
string override_prefix;
RGWObjManifestRule() : start_part_num(0), start_ofs(0), part_size(0), stripe_max_size(0) {}
RGWObjManifestRule(uint32_t _start_part_num, uint64_t _start_ofs, uint64_t _part_size, uint64_t _stripe_max_size) :
start_part_num(_start_part_num), start_ofs(_start_ofs), part_size(_part_size), stripe_max_size(_stripe_max_size) {}
void encode(bufferlist& bl) const {
ENCODE_START(2, 1, bl);
::encode(start_part_num, bl);
::encode(start_ofs, bl);
::encode(part_size, bl);
::encode(stripe_max_size, bl);
::encode(override_prefix, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(2, bl);
::decode(start_part_num, bl);
::decode(start_ofs, bl);
::decode(part_size, bl);
::decode(stripe_max_size, bl);
if (struct_v >= 2)
::decode(override_prefix, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
};
WRITE_CLASS_ENCODER(RGWObjManifestRule)
class RGWObjManifest {
protected:
bool explicit_objs; /* old manifest? */
map<uint64_t, RGWObjManifestPart> objs;
uint64_t obj_size;
rgw_obj head_obj;
uint64_t head_size;
uint64_t max_head_size;
string prefix;
rgw_bucket tail_bucket; /* might be different than the original bucket,
as object might have been copied across buckets */
map<uint64_t, RGWObjManifestRule> rules;
void convert_to_explicit();
int append_explicit(RGWObjManifest& m);
void append_rules(RGWObjManifest& m, map<uint64_t, RGWObjManifestRule>::iterator& iter, string *override_prefix);
void update_iterators() {
begin_iter.seek(0);
end_iter.seek(obj_size);
}
public:
RGWObjManifest() : explicit_objs(false), obj_size(0), head_size(0), max_head_size(0),
begin_iter(this), end_iter(this) {}
RGWObjManifest(const RGWObjManifest& rhs) {
*this = rhs;
}
RGWObjManifest& operator=(const RGWObjManifest& rhs) {
explicit_objs = rhs.explicit_objs;
objs = rhs.objs;
obj_size = rhs.obj_size;
head_obj = rhs.head_obj;
head_size = rhs.head_size;
max_head_size = rhs.max_head_size;
prefix = rhs.prefix;
tail_bucket = rhs.tail_bucket;
rules = rhs.rules;
begin_iter.set_manifest(this);
end_iter.set_manifest(this);
begin_iter.seek(rhs.begin_iter.get_ofs());
end_iter.seek(rhs.end_iter.get_ofs());
return *this;
}
map<uint64_t, RGWObjManifestPart>& get_explicit_objs() {
return objs;
}
void set_explicit(uint64_t _size, map<uint64_t, RGWObjManifestPart>& _objs) {
explicit_objs = true;
obj_size = _size;
objs.swap(_objs);
}
void get_implicit_location(uint64_t cur_part_id, uint64_t cur_stripe, uint64_t ofs, string *override_prefix, rgw_obj *location);
void set_trivial_rule(uint64_t tail_ofs, uint64_t stripe_max_size) {
RGWObjManifestRule rule(0, tail_ofs, 0, stripe_max_size);
rules[0] = rule;
max_head_size = tail_ofs;
}
void set_multipart_part_rule(uint64_t stripe_max_size, uint64_t part_num) {
RGWObjManifestRule rule(0, 0, 0, stripe_max_size);
rule.start_part_num = part_num;
rules[0] = rule;
max_head_size = 0;
}
void encode(bufferlist& bl) const {
ENCODE_START(4, 3, bl);
::encode(obj_size, bl);
::encode(objs, bl);
::encode(explicit_objs, bl);
::encode(head_obj, bl);
::encode(head_size, bl);
::encode(max_head_size, bl);
::encode(prefix, bl);
::encode(rules, bl);
::encode(tail_bucket, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START_LEGACY_COMPAT_LEN_32(4, 2, 2, bl);
::decode(obj_size, bl);
::decode(objs, bl);
if (struct_v >= 3) {
::decode(explicit_objs, bl);
::decode(head_obj, bl);
::decode(head_size, bl);
::decode(max_head_size, bl);
::decode(prefix, bl);
::decode(rules, bl);
} else {
explicit_objs = true;
if (!objs.empty()) {
map<uint64_t, RGWObjManifestPart>::iterator iter = objs.begin();
head_obj = iter->second.loc;
head_size = iter->second.size;
max_head_size = head_size;
}
}
if (explicit_objs && head_size > 0 && !objs.empty()) {
/* patch up manifest due to issue 16435:
* the first object in the explicit objs list might not be the one we need to access, use the
* head object instead if set. This would happen if we had an old object that was created
* when the explicit objs manifest was around, and it got copied.
*/
rgw_obj& obj_0 = objs[0].loc;
if (!obj_0.get_object().empty() && obj_0.ns.empty()) {
objs[0].loc = head_obj;
objs[0].size = head_size;
}
}
if (struct_v >= 4) {
::decode(tail_bucket, bl);
}
update_iterators();
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<RGWObjManifest*>& o);
int append(RGWObjManifest& m);
bool get_rule(uint64_t ofs, RGWObjManifestRule *rule);
bool empty() {
if (explicit_objs)
return objs.empty();
return rules.empty();
}
bool has_explicit_objs() {
return explicit_objs;
}
bool has_tail() {
if (explicit_objs) {
if (objs.size() == 1) {
map<uint64_t, RGWObjManifestPart>::iterator iter = objs.begin();
rgw_obj& obj = iter->second.loc;
return !(head_obj == obj);
}
return (objs.size() >= 2);
}
return (obj_size > head_size);
}
void set_head(const rgw_obj& _o, uint64_t _s) {
head_obj = _o;
head_size = _s;
if (explicit_objs && head_size > 0) {
objs[0].loc = head_obj;
objs[0].size = head_size;
}
}
const rgw_obj& get_head() {
return head_obj;
}
void set_tail_bucket(const rgw_bucket& _b) {
tail_bucket = _b;
}
rgw_bucket& get_tail_bucket() {
return tail_bucket;
}
void set_prefix(const string& _p) {
prefix = _p;
}
const string& get_prefix() {
return prefix;
}
void set_head_size(uint64_t _s) {
head_size = _s;
}
void set_obj_size(uint64_t s) {
obj_size = s;
update_iterators();
}
uint64_t get_obj_size() {
return obj_size;
}
uint64_t get_head_size() {
return head_size;
}
void set_max_head_size(uint64_t s) {
max_head_size = s;
}
uint64_t get_max_head_size() {
return max_head_size;
}
class obj_iterator {
RGWObjManifest *manifest;
uint64_t part_ofs; /* where current part starts */
uint64_t stripe_ofs; /* where current stripe starts */
uint64_t ofs; /* current position within the object */
uint64_t stripe_size; /* current part size */
int cur_part_id;
int cur_stripe;
string cur_override_prefix;
rgw_obj location;
map<uint64_t, RGWObjManifestRule>::iterator rule_iter;
map<uint64_t, RGWObjManifestRule>::iterator next_rule_iter;
map<uint64_t, RGWObjManifestPart>::iterator explicit_iter;
void init() {
part_ofs = 0;
stripe_ofs = 0;
ofs = 0;
stripe_size = 0;
cur_part_id = 0;
cur_stripe = 0;
}
void update_explicit_pos();
protected:
void set_manifest(RGWObjManifest *m) {
manifest = m;
}
public:
obj_iterator() : manifest(NULL) {
init();
}
explicit obj_iterator(RGWObjManifest *_m) : manifest(_m) {
init();
if (!manifest->empty()) {
seek(0);
}
}
obj_iterator(RGWObjManifest *_m, uint64_t _ofs) : manifest(_m) {
init();
if (!manifest->empty()) {
seek(_ofs);
}
}
void seek(uint64_t ofs);
void operator++();
bool operator==(const obj_iterator& rhs) {
return (ofs == rhs.ofs);
}
bool operator!=(const obj_iterator& rhs) {
return (ofs != rhs.ofs);
}
const rgw_obj& get_location() {
return location;
}
/* start of current stripe */
uint64_t get_stripe_ofs() {
if (manifest->explicit_objs) {
return explicit_iter->first;
}
return stripe_ofs;
}
/* current ofs relative to start of rgw object */
uint64_t get_ofs() const {
return ofs;
}
/* current stripe size */
uint64_t get_stripe_size() {
if (manifest->explicit_objs) {
return explicit_iter->second.size;
}
return stripe_size;
}
/* offset where data starts within current stripe */
uint64_t location_ofs() {
if (manifest->explicit_objs) {
return explicit_iter->second.loc_ofs;
}
return 0; /* all stripes start at zero offset */
}
void update_location();
friend class RGWObjManifest;
};
const obj_iterator& obj_begin();
const obj_iterator& obj_end();
obj_iterator obj_find(uint64_t ofs);
obj_iterator begin_iter;
obj_iterator end_iter;
/*
* simple object generator. Using a simple single rule manifest.
*/
class generator {
RGWObjManifest *manifest;
uint64_t last_ofs;
uint64_t cur_part_ofs;
int cur_part_id;
int cur_stripe;
uint64_t cur_stripe_size;
string cur_oid;
string oid_prefix;
rgw_obj cur_obj;
rgw_bucket bucket;
RGWObjManifestRule rule;
public:
generator() : manifest(NULL), last_ofs(0), cur_part_ofs(0), cur_part_id(0),
cur_stripe(0), cur_stripe_size(0) {}
int create_begin(CephContext *cct, RGWObjManifest *manifest, rgw_bucket& bucket, rgw_obj& head);
int create_next(uint64_t ofs);
const rgw_obj& get_cur_obj() { return cur_obj; }
/* total max size of current stripe (including head obj) */
uint64_t cur_stripe_max_size() {
return cur_stripe_size;
}
};
};
WRITE_CLASS_ENCODER(RGWObjManifest)
struct RGWUploadPartInfo {
uint32_t num;
uint64_t size;
string etag;
ceph::real_time modified;
RGWObjManifest manifest;
RGWUploadPartInfo() : num(0), size(0) {}
void encode(bufferlist& bl) const {
ENCODE_START(3, 2, bl);
::encode(num, bl);
::encode(size, bl);
::encode(etag, bl);
::encode(modified, bl);
::encode(manifest, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
::decode(num, bl);
::decode(size, bl);
::decode(etag, bl);
::decode(modified, bl);
if (struct_v >= 3)
::decode(manifest, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
static void generate_test_instances(list<RGWUploadPartInfo*>& o);
};
WRITE_CLASS_ENCODER(RGWUploadPartInfo)
struct RGWObjState {
rgw_obj obj;
bool is_atomic;
bool has_attrs;
bool exists;
uint64_t size;
ceph::real_time mtime;
uint64_t epoch;
bufferlist obj_tag;
string write_tag;
bool fake_tag;
RGWObjManifest manifest;
bool has_manifest;
string shadow_obj;
bool has_data;
bufferlist data;
bool prefetch_data;
bool keep_tail;
bool is_olh;
bufferlist olh_tag;
uint64_t pg_ver;
uint32_t zone_short_id;
/* important! don't forget to update copy constructor */
RGWObjVersionTracker objv_tracker;
map<string, bufferlist> attrset;
RGWObjState() : is_atomic(false), has_attrs(0), exists(false),
size(0), epoch(0), fake_tag(false), has_manifest(false),
has_data(false), prefetch_data(false), keep_tail(false), is_olh(false),
pg_ver(0), zone_short_id(0) {}
RGWObjState(const RGWObjState& rhs) : obj (rhs.obj) {
is_atomic = rhs.is_atomic;
has_attrs = rhs.has_attrs;
exists = rhs.exists;
size = rhs.size;
mtime = rhs.mtime;
epoch = rhs.epoch;
if (rhs.obj_tag.length()) {
obj_tag = rhs.obj_tag;
}
write_tag = rhs.write_tag;
fake_tag = rhs.fake_tag;
if (rhs.has_manifest) {
manifest = rhs.manifest;
}
has_manifest = rhs.has_manifest;
shadow_obj = rhs.shadow_obj;
has_data = rhs.has_data;
if (rhs.data.length()) {
data = rhs.data;
}
prefetch_data = rhs.prefetch_data;
keep_tail = rhs.keep_tail;
is_olh = rhs.is_olh;
objv_tracker = rhs.objv_tracker;
pg_ver = rhs.pg_ver;
}
bool get_attr(string name, bufferlist& dest) {
map<string, bufferlist>::iterator iter = attrset.find(name);
if (iter != attrset.end()) {
dest = iter->second;
return true;
}
return false;
}
};
struct RGWPoolIterCtx {
librados::IoCtx io_ctx;
librados::NObjectIterator iter;
};
struct RGWListRawObjsCtx {
bool initialized;
RGWPoolIterCtx iter_ctx;
RGWListRawObjsCtx() : initialized(false) {}
};
struct RGWDefaultSystemMetaObjInfo {
string default_id;
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
::encode(default_id, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
::decode(default_id, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
};
WRITE_CLASS_ENCODER(RGWDefaultSystemMetaObjInfo)
struct RGWNameToId {
string obj_id;
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
::encode(obj_id, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
::decode(obj_id, bl);
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
};
WRITE_CLASS_ENCODER(RGWNameToId)
class RGWSystemMetaObj {
protected:
string id;
string name;
CephContext *cct;
RGWRados *store;
int store_name(bool exclusive);
int store_info(bool exclusive);
int read_info(const string& obj_id, bool old_format = false);
int read_id(const string& obj_name, string& obj_id);
int read_default(RGWDefaultSystemMetaObjInfo& default_info,
const string& oid);
/* read and use default id */
int use_default(bool old_format = false);
public:
RGWSystemMetaObj() {}
RGWSystemMetaObj(const string& _name): name(_name) {}
RGWSystemMetaObj(const string& _id, const string& _name) : id(_id), name(_name) {}
RGWSystemMetaObj(CephContext *_cct, RGWRados *_store): cct(_cct), store(_store){}
RGWSystemMetaObj(const string& _name, CephContext *_cct, RGWRados *_store): name(_name), cct(_cct), store(_store){}
const string& get_name() const { return name; }
const string& get_id() const { return id; }
void set_name(const string& _name) { name = _name;}
void set_id(const string& _id) { id = _id;}
void clear_id() { id.clear(); }
virtual ~RGWSystemMetaObj() {}
virtual void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
::encode(id, bl);
::encode(name, bl);
ENCODE_FINISH(bl);
}
virtual void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
::decode(id, bl);
::decode(name, bl);
DECODE_FINISH(bl);
}
void reinit_instance(CephContext *_cct, RGWRados *_store) {
cct = _cct;
store = _store;
}
int init(CephContext *_cct, RGWRados *_store, bool setup_obj = true, bool old_format = false);
virtual int read_default_id(string& default_id, bool old_format = false);
virtual int set_as_default(bool exclusive = false);
int delete_default();
virtual int create(bool exclusive = true);
int delete_obj(bool old_format = false);
int rename(const string& new_name);
int update() { return store_info(false);}
int update_name() { return store_name(false);}
int read();
int write(bool exclusive);
virtual const string& get_pool_name(CephContext *cct) = 0;
virtual const string get_default_oid(bool old_format = false) = 0;
virtual const string& get_names_oid_prefix() = 0;
virtual const string& get_info_oid_prefix(bool old_format = false) = 0;
virtual const string& get_predefined_name(CephContext *cct) = 0;
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
};
WRITE_CLASS_ENCODER(RGWSystemMetaObj)
struct RGWZoneGroup;
struct RGWZonePlacementInfo {
string index_pool;
string data_pool;
string data_extra_pool; /* if not set we should use data_pool */
RGWBucketIndexType index_type;
RGWZonePlacementInfo() : index_type(RGWBIType_Normal) {}
void encode(bufferlist& bl) const {
ENCODE_START(5, 1, bl);
::encode(index_pool, bl);
::encode(data_pool, bl);
::encode(data_extra_pool, bl);
::encode((uint32_t)index_type, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(5, bl);
::decode(index_pool, bl);
::decode(data_pool, bl);
if (struct_v >= 4) {
::decode(data_extra_pool, bl);
}
if (struct_v >= 5) {
uint32_t it;
::decode(it, bl);
index_type = (RGWBucketIndexType)it;
}
DECODE_FINISH(bl);
}
const string& get_data_extra_pool() {
if (data_extra_pool.empty()) {
return data_pool;
}
return data_extra_pool;
}
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
};
WRITE_CLASS_ENCODER(RGWZonePlacementInfo)
struct RGWZoneParams : RGWSystemMetaObj {
rgw_bucket domain_root;
rgw_bucket metadata_heap;
rgw_bucket control_pool;
rgw_bucket gc_pool;
rgw_bucket lc_pool;
rgw_bucket log_pool;
rgw_bucket intent_log_pool;
rgw_bucket usage_log_pool;
rgw_bucket user_keys_pool;
rgw_bucket user_email_pool;
rgw_bucket user_swift_pool;
rgw_bucket user_uid_pool;
RGWAccessKey system_key;
map<string, RGWZonePlacementInfo> placement_pools;
string realm_id;
RGWZoneParams() : RGWSystemMetaObj() {}
RGWZoneParams(const string& name) : RGWSystemMetaObj(name){}
RGWZoneParams(const string& id, const string& name) : RGWSystemMetaObj(id, name) {}
RGWZoneParams(const string& id, const string& name, const string& _realm_id)
: RGWSystemMetaObj(id, name), realm_id(_realm_id) {}
const string& get_pool_name(CephContext *cct);
const string get_default_oid(bool old_format = false);
const string& get_names_oid_prefix();
const string& get_info_oid_prefix(bool old_format = false);
const string& get_predefined_name(CephContext *cct);
int init(CephContext *_cct, RGWRados *_store, bool setup_obj = true,
bool old_format = false);
using RGWSystemMetaObj::init;
int read_default_id(string& default_id, bool old_format = false);
int set_as_default(bool exclusive = false) override;
int create_default(bool old_format = false);
int create(bool exclusive = true);
int fix_pool_names();
void encode(bufferlist& bl) const {
ENCODE_START(7, 1, bl);
::encode(domain_root, bl);
::encode(control_pool, bl);
::encode(gc_pool, bl);
::encode(log_pool, bl);
::encode(intent_log_pool, bl);
::encode(usage_log_pool, bl);
::encode(user_keys_pool, bl);
::encode(user_email_pool, bl);
::encode(user_swift_pool, bl);
::encode(user_uid_pool, bl);
RGWSystemMetaObj::encode(bl);
::encode(system_key, bl);
::encode(placement_pools, bl);
::encode(metadata_heap, bl);
::encode(realm_id, bl);
::encode(lc_pool, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(7, bl);
::decode(domain_root, bl);
::decode(control_pool, bl);
::decode(gc_pool, bl);
::decode(log_pool, bl);
::decode(intent_log_pool, bl);
::decode(usage_log_pool, bl);
::decode(user_keys_pool, bl);
::decode(user_email_pool, bl);
::decode(user_swift_pool, bl);
::decode(user_uid_pool, bl);
if (struct_v >= 6) {
RGWSystemMetaObj::decode(bl);
} else if (struct_v >= 2) {
::decode(name, bl);
id = name;
}
if (struct_v >= 3)
::decode(system_key, bl);
if (struct_v >= 4)
::decode(placement_pools, bl);
if (struct_v >= 5)
::decode(metadata_heap, bl);
if (struct_v >= 6) {
::decode(realm_id, bl);
}
if (struct_v >= 7) {
::decode(lc_pool, bl);
} else {
lc_pool = name + ".rgw.lc";
}
DECODE_FINISH(bl);
}
void dump(Formatter *f) const;
void decode_json(JSONObj *obj);
static void generate_test_instances(list<RGWZoneParams*>& o);
};
WRITE_CLASS_ENCODER(RGWZoneParams)
struct RGWZone {
string id;
string name;
list<string> endpoints;
bool log_meta;
bool log_data;
bool read_only;
/**
* Represents the number of shards for the bucket index object, a value of zero
* indicates there is no sharding. By default (no sharding, the name of the object
* is '.dir.{marker}', with sharding, the name is '.dir.{markder}.{sharding_id}',
* sharding_id is zero-based value. It is not recommended to set a too large value
* (e.g. thousand) as it increases the cost for bucket listing.
*/
uint32_t bucket_index_max_shards;
RGWZone() : log_meta(false), log_data(false), read_only(false), bucket_index_max_shards(0) {}
void encode(bufferlist& bl) const {
ENCODE_START(4, 1, bl);
::encode(name, bl);
::encode(endpoints, bl);