/
rgw_rados.cc
10435 lines (8738 loc) · 301 KB
/
rgw_rados.cc
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
#include "include/compat.h"
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <boost/algorithm/string.hpp>
#include <string_view>
#include <boost/container/flat_set.hpp>
#include <boost/format.hpp>
#include <boost/optional.hpp>
#include <boost/utility/in_place_factory.hpp>
#include "common/ceph_json.h"
#include "common/errno.h"
#include "common/Formatter.h"
#include "common/Throttle.h"
#include "rgw_rados.h"
#include "rgw_zone.h"
#include "rgw_cache.h"
#include "rgw_acl.h"
#include "rgw_acl_s3.h" /* for dumping s3policy in debug log */
#include "rgw_aio_throttle.h"
#include "rgw_bucket.h"
#include "rgw_rest_conn.h"
#include "rgw_cr_rados.h"
#include "rgw_cr_rest.h"
#include "rgw_putobj_processor.h"
#include "cls/rgw/cls_rgw_ops.h"
#include "cls/rgw/cls_rgw_client.h"
#include "cls/rgw/cls_rgw_const.h"
#include "cls/refcount/cls_refcount_client.h"
#include "cls/version/cls_version_client.h"
#include "cls/log/cls_log_client.h"
#include "cls/timeindex/cls_timeindex_client.h"
#include "cls/lock/cls_lock_client.h"
#include "cls/user/cls_user_client.h"
#include "cls/otp/cls_otp_client.h"
#include "osd/osd_types.h"
#include "rgw_tools.h"
#include "rgw_coroutine.h"
#include "rgw_compression.h"
#undef fork // fails to compile RGWPeriod::fork() below
#include "common/Clock.h"
using namespace librados;
#include <string>
#include <iostream>
#include <vector>
#include <atomic>
#include <list>
#include <map>
#include "include/random.h"
#include "rgw_gc.h"
#include "rgw_lc.h"
#include "rgw_object_expirer_core.h"
#include "rgw_sync.h"
#include "rgw_sync_counters.h"
#include "rgw_sync_trace.h"
#include "rgw_data_sync.h"
#include "rgw_realm_watcher.h"
#include "rgw_reshard.h"
#include "services/svc_zone.h"
#include "services/svc_zone_utils.h"
#include "services/svc_quota.h"
#include "services/svc_sync_modules.h"
#include "services/svc_sys_obj.h"
#include "services/svc_sys_obj_cache.h"
#include "compressor/Compressor.h"
#ifdef WITH_LTTNG
#define TRACEPOINT_DEFINE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#include "tracing/rgw_rados.h"
#undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#undef TRACEPOINT_DEFINE
#else
#define tracepoint(...)
#endif
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rgw
static string shadow_ns = "shadow";
static string dir_oid_prefix = ".dir.";
static string default_bucket_index_pool_suffix = "rgw.buckets.index";
static string default_storage_extra_pool_suffix = "rgw.buckets.non-ec";
static string log_lock_name = "rgw_log_lock";
static RGWObjCategory main_category = RGWObjCategory::Main;
#define RGW_USAGE_OBJ_PREFIX "usage."
#define dout_subsys ceph_subsys_rgw
const std::string MP_META_SUFFIX = ".meta";
static bool rgw_get_obj_data_pool(const RGWZoneGroup& zonegroup, const RGWZoneParams& zone_params,
const rgw_placement_rule& head_placement_rule,
const rgw_obj& obj, rgw_pool *pool)
{
if (!zone_params.get_head_data_pool(head_placement_rule, obj, pool)) {
RGWZonePlacementInfo placement;
if (!zone_params.get_placement(zonegroup.default_placement.name, &placement)) {
return false;
}
if (!obj.in_extra_data) {
*pool = placement.get_data_pool(zonegroup.default_placement.storage_class);
} else {
*pool = placement.get_data_extra_pool();
}
}
return true;
}
static bool rgw_obj_to_raw(const RGWZoneGroup& zonegroup, const RGWZoneParams& zone_params,
const rgw_placement_rule& head_placement_rule,
const rgw_obj& obj, rgw_raw_obj *raw_obj)
{
get_obj_bucket_and_oid_loc(obj, raw_obj->oid, raw_obj->loc);
return rgw_get_obj_data_pool(zonegroup, zone_params, head_placement_rule, obj, &raw_obj->pool);
}
rgw_raw_obj rgw_obj_select::get_raw_obj(const RGWZoneGroup& zonegroup, const RGWZoneParams& zone_params) const
{
if (!is_raw) {
rgw_raw_obj r;
rgw_obj_to_raw(zonegroup, zone_params, placement_rule, obj, &r);
return r;
}
return raw_obj;
}
rgw_raw_obj rgw_obj_select::get_raw_obj(RGWRados *store) const
{
if (!is_raw) {
rgw_raw_obj r;
store->obj_to_raw(placement_rule, obj, &r);
return r;
}
return raw_obj;
}
void RGWObjVersionTracker::prepare_op_for_read(ObjectReadOperation *op)
{
obj_version *check_objv = version_for_check();
if (check_objv) {
cls_version_check(*op, *check_objv, VER_COND_EQ);
}
cls_version_read(*op, &read_version);
}
void RGWObjVersionTracker::prepare_op_for_write(ObjectWriteOperation *op)
{
obj_version *check_objv = version_for_check();
obj_version *modify_version = version_for_write();
if (check_objv) {
cls_version_check(*op, *check_objv, VER_COND_EQ);
}
if (modify_version) {
cls_version_set(*op, *modify_version);
} else {
cls_version_inc(*op);
}
}
void RGWObjManifest::obj_iterator::operator++()
{
if (manifest->explicit_objs) {
++explicit_iter;
update_explicit_pos();
update_location();
return;
}
uint64_t obj_size = manifest->get_obj_size();
uint64_t head_size = manifest->get_head_size();
if (ofs == obj_size) {
return;
}
if (manifest->rules.empty()) {
return;
}
/* are we still pointing at the head? */
if (ofs < head_size) {
rule_iter = manifest->rules.begin();
RGWObjManifestRule *rule = &rule_iter->second;
ofs = std::min(head_size, obj_size);
stripe_ofs = ofs;
cur_stripe = 1;
stripe_size = std::min(obj_size - ofs, rule->stripe_max_size);
if (rule->part_size > 0) {
stripe_size = std::min(stripe_size, rule->part_size);
}
update_location();
return;
}
RGWObjManifestRule *rule = &rule_iter->second;
stripe_ofs += rule->stripe_max_size;
cur_stripe++;
dout(20) << "RGWObjManifest::operator++(): rule->part_size=" << rule->part_size << " rules.size()=" << manifest->rules.size() << dendl;
if (rule->part_size > 0) {
/* multi part, multi stripes object */
dout(20) << "RGWObjManifest::operator++(): stripe_ofs=" << stripe_ofs << " part_ofs=" << part_ofs << " rule->part_size=" << rule->part_size << dendl;
if (stripe_ofs >= part_ofs + rule->part_size) {
/* moved to the next part */
cur_stripe = 0;
part_ofs += rule->part_size;
stripe_ofs = part_ofs;
bool last_rule = (next_rule_iter == manifest->rules.end());
/* move to the next rule? */
if (!last_rule && stripe_ofs >= next_rule_iter->second.start_ofs) {
rule_iter = next_rule_iter;
last_rule = (next_rule_iter == manifest->rules.end());
if (!last_rule) {
++next_rule_iter;
}
cur_part_id = rule_iter->second.start_part_num;
} else {
cur_part_id++;
}
rule = &rule_iter->second;
}
stripe_size = std::min(rule->part_size - (stripe_ofs - part_ofs), rule->stripe_max_size);
}
cur_override_prefix = rule->override_prefix;
ofs = stripe_ofs;
if (ofs > obj_size) {
ofs = obj_size;
stripe_ofs = ofs;
stripe_size = 0;
}
dout(20) << "RGWObjManifest::operator++(): result: ofs=" << ofs << " stripe_ofs=" << stripe_ofs << " part_ofs=" << part_ofs << " rule->part_size=" << rule->part_size << dendl;
update_location();
}
int RGWObjManifest::generator::create_begin(CephContext *cct, RGWObjManifest *_m,
const rgw_placement_rule& head_placement_rule,
const rgw_placement_rule *tail_placement_rule,
const rgw_bucket& _b, const rgw_obj& _obj)
{
manifest = _m;
if (!tail_placement_rule) {
manifest->set_tail_placement(head_placement_rule, _b);
} else {
rgw_placement_rule new_tail_rule = *tail_placement_rule;
new_tail_rule.inherit_from(head_placement_rule);
manifest->set_tail_placement(new_tail_rule, _b);
}
manifest->set_head(head_placement_rule, _obj, 0);
last_ofs = 0;
if (manifest->get_prefix().empty()) {
char buf[33];
gen_rand_alphanumeric(cct, buf, sizeof(buf) - 1);
string oid_prefix = ".";
oid_prefix.append(buf);
oid_prefix.append("_");
manifest->set_prefix(oid_prefix);
}
bool found = manifest->get_rule(0, &rule);
if (!found) {
derr << "ERROR: manifest->get_rule() could not find rule" << dendl;
return -EIO;
}
uint64_t head_size = manifest->get_head_size();
if (head_size > 0) {
cur_stripe_size = head_size;
} else {
cur_stripe_size = rule.stripe_max_size;
}
cur_part_id = rule.start_part_num;
manifest->get_implicit_location(cur_part_id, cur_stripe, 0, NULL, &cur_obj);
// Normal object which not generated through copy operation
manifest->set_tail_instance(_obj.key.instance);
manifest->update_iterators();
return 0;
}
int RGWObjManifest::generator::create_next(uint64_t ofs)
{
if (ofs < last_ofs) /* only going forward */
return -EINVAL;
uint64_t max_head_size = manifest->get_max_head_size();
if (ofs < max_head_size) {
manifest->set_head_size(ofs);
}
if (ofs >= max_head_size) {
manifest->set_head_size(max_head_size);
cur_stripe = (ofs - max_head_size) / rule.stripe_max_size;
cur_stripe_size = rule.stripe_max_size;
if (cur_part_id == 0 && max_head_size > 0) {
cur_stripe++;
}
}
last_ofs = ofs;
manifest->set_obj_size(ofs);
manifest->get_implicit_location(cur_part_id, cur_stripe, ofs, NULL, &cur_obj);
manifest->update_iterators();
return 0;
}
const RGWObjManifest::obj_iterator& RGWObjManifest::obj_begin()
{
return begin_iter;
}
const RGWObjManifest::obj_iterator& RGWObjManifest::obj_end()
{
return end_iter;
}
RGWObjManifest::obj_iterator RGWObjManifest::obj_find(uint64_t ofs)
{
if (ofs > obj_size) {
ofs = obj_size;
}
RGWObjManifest::obj_iterator iter(this);
iter.seek(ofs);
return iter;
}
int RGWObjManifest::append(RGWObjManifest& m, const RGWZoneGroup& zonegroup,
const RGWZoneParams& zone_params)
{
if (explicit_objs || m.explicit_objs) {
return append_explicit(m, zonegroup, zone_params);
}
if (rules.empty()) {
*this = m;
return 0;
}
string override_prefix;
if (prefix.empty()) {
prefix = m.prefix;
}
if (prefix != m.prefix) {
override_prefix = m.prefix;
}
map<uint64_t, RGWObjManifestRule>::iterator miter = m.rules.begin();
if (miter == m.rules.end()) {
return append_explicit(m, zonegroup, zone_params);
}
for (; miter != m.rules.end(); ++miter) {
map<uint64_t, RGWObjManifestRule>::reverse_iterator last_rule = rules.rbegin();
RGWObjManifestRule& rule = last_rule->second;
if (rule.part_size == 0) {
rule.part_size = obj_size - rule.start_ofs;
}
RGWObjManifestRule& next_rule = miter->second;
if (!next_rule.part_size) {
next_rule.part_size = m.obj_size - next_rule.start_ofs;
}
string rule_prefix = prefix;
if (!rule.override_prefix.empty()) {
rule_prefix = rule.override_prefix;
}
string next_rule_prefix = m.prefix;
if (!next_rule.override_prefix.empty()) {
next_rule_prefix = next_rule.override_prefix;
}
if (rule.part_size != next_rule.part_size ||
rule.stripe_max_size != next_rule.stripe_max_size ||
rule_prefix != next_rule_prefix) {
if (next_rule_prefix != prefix) {
append_rules(m, miter, &next_rule_prefix);
} else {
append_rules(m, miter, NULL);
}
break;
}
uint64_t expected_part_num = rule.start_part_num + 1;
if (rule.part_size > 0) {
expected_part_num = rule.start_part_num + (obj_size + next_rule.start_ofs - rule.start_ofs) / rule.part_size;
}
if (expected_part_num != next_rule.start_part_num) {
append_rules(m, miter, NULL);
break;
}
}
set_obj_size(obj_size + m.obj_size);
return 0;
}
int RGWObjManifest::append(RGWObjManifest& m, RGWSI_Zone *zone_svc)
{
return append(m, zone_svc->get_zonegroup(), zone_svc->get_zone_params());
}
void RGWObjManifest::append_rules(RGWObjManifest& m, map<uint64_t, RGWObjManifestRule>::iterator& miter,
string *override_prefix)
{
for (; miter != m.rules.end(); ++miter) {
RGWObjManifestRule rule = miter->second;
rule.start_ofs += obj_size;
if (override_prefix)
rule.override_prefix = *override_prefix;
rules[rule.start_ofs] = rule;
}
}
void RGWObjManifest::convert_to_explicit(const RGWZoneGroup& zonegroup, const RGWZoneParams& zone_params)
{
if (explicit_objs) {
return;
}
obj_iterator iter = obj_begin();
while (iter != obj_end()) {
RGWObjManifestPart& part = objs[iter.get_stripe_ofs()];
const rgw_obj_select& os = iter.get_location();
const rgw_raw_obj& raw_loc = os.get_raw_obj(zonegroup, zone_params);
part.loc_ofs = 0;
uint64_t ofs = iter.get_stripe_ofs();
if (ofs == 0) {
part.loc = obj;
} else {
rgw_raw_obj_to_obj(tail_placement.bucket, raw_loc, &part.loc);
}
++iter;
uint64_t next_ofs = iter.get_stripe_ofs();
part.size = next_ofs - ofs;
}
explicit_objs = true;
rules.clear();
prefix.clear();
}
int RGWObjManifest::append_explicit(RGWObjManifest& m, const RGWZoneGroup& zonegroup, const RGWZoneParams& zone_params)
{
if (!explicit_objs) {
convert_to_explicit(zonegroup, zone_params);
}
if (!m.explicit_objs) {
m.convert_to_explicit(zonegroup, zone_params);
}
map<uint64_t, RGWObjManifestPart>::iterator iter;
uint64_t base = obj_size;
for (iter = m.objs.begin(); iter != m.objs.end(); ++iter) {
RGWObjManifestPart& part = iter->second;
objs[base + iter->first] = part;
}
obj_size += m.obj_size;
return 0;
}
bool RGWObjManifest::get_rule(uint64_t ofs, RGWObjManifestRule *rule)
{
if (rules.empty()) {
return false;
}
map<uint64_t, RGWObjManifestRule>::iterator iter = rules.upper_bound(ofs);
if (iter != rules.begin()) {
--iter;
}
*rule = iter->second;
return true;
}
void RGWObjVersionTracker::generate_new_write_ver(CephContext *cct)
{
write_version.ver = 1;
#define TAG_LEN 24
write_version.tag.clear();
append_rand_alpha(cct, write_version.tag, write_version.tag, TAG_LEN);
}
class RGWMetaNotifierManager : public RGWCoroutinesManager {
RGWRados *store;
RGWHTTPManager http_manager;
public:
RGWMetaNotifierManager(RGWRados *_store) : RGWCoroutinesManager(_store->ctx(), _store->get_cr_registry()), store(_store),
http_manager(store->ctx(), completion_mgr) {
http_manager.start();
}
int notify_all(map<string, RGWRESTConn *>& conn_map, set<int>& shards) {
rgw_http_param_pair pairs[] = { { "type", "metadata" },
{ "notify", NULL },
{ NULL, NULL } };
list<RGWCoroutinesStack *> stacks;
for (map<string, RGWRESTConn *>::iterator iter = conn_map.begin(); iter != conn_map.end(); ++iter) {
RGWRESTConn *conn = iter->second;
RGWCoroutinesStack *stack = new RGWCoroutinesStack(store->ctx(), this);
stack->call(new RGWPostRESTResourceCR<set<int>, int>(store->ctx(), conn, &http_manager, "/admin/log", pairs, shards, NULL));
stacks.push_back(stack);
}
return run(stacks);
}
};
class RGWDataNotifierManager : public RGWCoroutinesManager {
RGWRados *store;
RGWHTTPManager http_manager;
public:
RGWDataNotifierManager(RGWRados *_store) : RGWCoroutinesManager(_store->ctx(), _store->get_cr_registry()), store(_store),
http_manager(store->ctx(), completion_mgr) {
http_manager.start();
}
int notify_all(map<string, RGWRESTConn *>& conn_map, map<int, set<string> >& shards) {
rgw_http_param_pair pairs[] = { { "type", "data" },
{ "notify", NULL },
{ "source-zone", store->svc.zone->get_zone_params().get_id().c_str() },
{ NULL, NULL } };
list<RGWCoroutinesStack *> stacks;
for (map<string, RGWRESTConn *>::iterator iter = conn_map.begin(); iter != conn_map.end(); ++iter) {
RGWRESTConn *conn = iter->second;
RGWCoroutinesStack *stack = new RGWCoroutinesStack(store->ctx(), this);
stack->call(new RGWPostRESTResourceCR<map<int, set<string> >, int>(store->ctx(), conn, &http_manager, "/admin/log", pairs, shards, NULL));
stacks.push_back(stack);
}
return run(stacks);
}
};
/* class RGWRadosThread */
void RGWRadosThread::start()
{
worker = new Worker(cct, this);
worker->create(thread_name.c_str());
}
void RGWRadosThread::stop()
{
down_flag = true;
stop_process();
if (worker) {
worker->signal();
worker->join();
}
delete worker;
worker = NULL;
}
void *RGWRadosThread::Worker::entry() {
uint64_t msec = processor->interval_msec();
utime_t interval = utime_t(msec / 1000, (msec % 1000) * 1000000);
do {
utime_t start = ceph_clock_now();
int r = processor->process();
if (r < 0) {
dout(0) << "ERROR: processor->process() returned error r=" << r << dendl;
}
if (processor->going_down())
break;
utime_t end = ceph_clock_now();
end -= start;
uint64_t cur_msec = processor->interval_msec();
if (cur_msec != msec) { /* was it reconfigured? */
msec = cur_msec;
interval = utime_t(msec / 1000, (msec % 1000) * 1000000);
}
if (cur_msec > 0) {
if (interval <= end)
continue; // next round
utime_t wait_time = interval;
wait_time -= end;
wait_interval(wait_time);
} else {
wait();
}
} while (!processor->going_down());
return NULL;
}
class RGWMetaNotifier : public RGWRadosThread {
RGWMetaNotifierManager notify_mgr;
RGWMetadataLog *const log;
uint64_t interval_msec() override {
return cct->_conf->rgw_md_notify_interval_msec;
}
void stop_process() override {
notify_mgr.stop();
}
public:
RGWMetaNotifier(RGWRados *_store, RGWMetadataLog* log)
: RGWRadosThread(_store, "meta-notifier"), notify_mgr(_store), log(log) {}
int process() override;
};
int RGWMetaNotifier::process()
{
set<int> shards;
log->read_clear_modified(shards);
if (shards.empty()) {
return 0;
}
for (set<int>::iterator iter = shards.begin(); iter != shards.end(); ++iter) {
ldout(cct, 20) << __func__ << "(): notifying mdlog change, shard_id=" << *iter << dendl;
}
notify_mgr.notify_all(store->svc.zone->get_zone_conn_map(), shards);
return 0;
}
class RGWDataNotifier : public RGWRadosThread {
RGWDataNotifierManager notify_mgr;
uint64_t interval_msec() override {
return cct->_conf.get_val<int64_t>("rgw_data_notify_interval_msec");
}
void stop_process() override {
notify_mgr.stop();
}
public:
RGWDataNotifier(RGWRados *_store) : RGWRadosThread(_store, "data-notifier"), notify_mgr(_store) {}
int process() override;
};
int RGWDataNotifier::process()
{
if (!store->data_log) {
return 0;
}
map<int, set<string> > shards;
store->data_log->read_clear_modified(shards);
if (shards.empty()) {
return 0;
}
for (map<int, set<string> >::iterator iter = shards.begin(); iter != shards.end(); ++iter) {
ldout(cct, 20) << __func__ << "(): notifying datalog change, shard_id=" << iter->first << ": " << iter->second << dendl;
}
notify_mgr.notify_all(store->svc.zone->get_zone_data_notify_to_map(), shards);
return 0;
}
class RGWSyncProcessorThread : public RGWRadosThread {
public:
RGWSyncProcessorThread(RGWRados *_store, const string& thread_name = "radosgw") : RGWRadosThread(_store, thread_name) {}
RGWSyncProcessorThread(RGWRados *_store) : RGWRadosThread(_store) {}
~RGWSyncProcessorThread() override {}
int init() override = 0 ;
int process() override = 0;
};
class RGWMetaSyncProcessorThread : public RGWSyncProcessorThread
{
RGWMetaSyncStatusManager sync;
uint64_t interval_msec() override {
return 0; /* no interval associated, it'll run once until stopped */
}
void stop_process() override {
sync.stop();
}
public:
RGWMetaSyncProcessorThread(RGWRados *_store, RGWAsyncRadosProcessor *async_rados)
: RGWSyncProcessorThread(_store, "meta-sync"), sync(_store, async_rados) {}
void wakeup_sync_shards(set<int>& shard_ids) {
for (set<int>::iterator iter = shard_ids.begin(); iter != shard_ids.end(); ++iter) {
sync.wakeup(*iter);
}
}
RGWMetaSyncStatusManager* get_manager() { return &sync; }
int init() override {
int ret = sync.init();
if (ret < 0) {
ldout(store->ctx(), 0) << "ERROR: sync.init() returned " << ret << dendl;
return ret;
}
return 0;
}
int process() override {
sync.run();
return 0;
}
};
class RGWDataSyncProcessorThread : public RGWSyncProcessorThread
{
PerfCountersRef counters;
RGWDataSyncStatusManager sync;
bool initialized;
uint64_t interval_msec() override {
if (initialized) {
return 0; /* no interval associated, it'll run once until stopped */
} else {
#define DATA_SYNC_INIT_WAIT_SEC 20
return DATA_SYNC_INIT_WAIT_SEC * 1000;
}
}
void stop_process() override {
sync.stop();
}
public:
RGWDataSyncProcessorThread(RGWRados *_store, RGWAsyncRadosProcessor *async_rados,
const RGWZone* source_zone)
: RGWSyncProcessorThread(_store, "data-sync"),
counters(sync_counters::build(store->ctx(), std::string("data-sync-from-") + source_zone->name)),
sync(_store, async_rados, source_zone->id, counters.get()),
initialized(false) {}
void wakeup_sync_shards(map<int, set<string> >& shard_ids) {
for (map<int, set<string> >::iterator iter = shard_ids.begin(); iter != shard_ids.end(); ++iter) {
sync.wakeup(iter->first, iter->second);
}
}
RGWDataSyncStatusManager* get_manager() { return &sync; }
int init() override {
return 0;
}
int process() override {
while (!initialized) {
if (going_down()) {
return 0;
}
int ret = sync.init();
if (ret >= 0) {
initialized = true;
break;
}
/* we'll be back! */
return 0;
}
sync.run();
return 0;
}
};
class RGWSyncLogTrimThread : public RGWSyncProcessorThread, DoutPrefixProvider
{
RGWCoroutinesManager crs;
RGWRados *store;
rgw::BucketTrimManager *bucket_trim;
RGWHTTPManager http;
const utime_t trim_interval;
uint64_t interval_msec() override { return 0; }
void stop_process() override { crs.stop(); }
public:
RGWSyncLogTrimThread(RGWRados *store, rgw::BucketTrimManager *bucket_trim,
int interval)
: RGWSyncProcessorThread(store, "sync-log-trim"),
crs(store->ctx(), store->get_cr_registry()), store(store),
bucket_trim(bucket_trim),
http(store->ctx(), crs.get_completion_mgr()),
trim_interval(interval, 0)
{}
int init() override {
return http.start();
}
int process() override {
list<RGWCoroutinesStack*> stacks;
auto meta = new RGWCoroutinesStack(store->ctx(), &crs);
meta->call(create_meta_log_trim_cr(this, store, &http,
cct->_conf->rgw_md_log_max_shards,
trim_interval));
stacks.push_back(meta);
auto data = new RGWCoroutinesStack(store->ctx(), &crs);
data->call(create_data_log_trim_cr(store, &http,
cct->_conf->rgw_data_log_num_shards,
trim_interval));
stacks.push_back(data);
auto bucket = new RGWCoroutinesStack(store->ctx(), &crs);
bucket->call(bucket_trim->create_bucket_trim_cr(&http));
stacks.push_back(bucket);
crs.run(stacks);
return 0;
}
// implements DoutPrefixProvider
CephContext *get_cct() const override { return store->ctx(); }
unsigned get_subsys() const
{
return dout_subsys;
}
std::ostream& gen_prefix(std::ostream& out) const
{
return out << "sync log trim: ";
}
};
void RGWRados::wakeup_meta_sync_shards(set<int>& shard_ids)
{
Mutex::Locker l(meta_sync_thread_lock);
if (meta_sync_processor_thread) {
meta_sync_processor_thread->wakeup_sync_shards(shard_ids);
}
}
void RGWRados::wakeup_data_sync_shards(const string& source_zone, map<int, set<string> >& shard_ids)
{
ldout(ctx(), 20) << __func__ << ": source_zone=" << source_zone << ", shard_ids=" << shard_ids << dendl;
Mutex::Locker l(data_sync_thread_lock);
map<string, RGWDataSyncProcessorThread *>::iterator iter = data_sync_processor_threads.find(source_zone);
if (iter == data_sync_processor_threads.end()) {
ldout(ctx(), 10) << __func__ << ": couldn't find sync thread for zone " << source_zone << ", skipping async data sync processing" << dendl;
return;
}
RGWDataSyncProcessorThread *thread = iter->second;
ceph_assert(thread);
thread->wakeup_sync_shards(shard_ids);
}
RGWMetaSyncStatusManager* RGWRados::get_meta_sync_manager()
{
Mutex::Locker l(meta_sync_thread_lock);
if (meta_sync_processor_thread) {
return meta_sync_processor_thread->get_manager();
}
return nullptr;
}
RGWDataSyncStatusManager* RGWRados::get_data_sync_manager(const std::string& source_zone)
{
Mutex::Locker l(data_sync_thread_lock);
auto thread = data_sync_processor_threads.find(source_zone);
if (thread == data_sync_processor_threads.end()) {
return nullptr;
}
return thread->second->get_manager();
}
int RGWRados::get_required_alignment(const rgw_pool& pool, uint64_t *alignment)
{
IoCtx ioctx;
int r = open_pool_ctx(pool, ioctx, false);
if (r < 0) {
ldout(cct, 0) << "ERROR: open_pool_ctx() returned " << r << dendl;
return r;
}
bool requires;
r = ioctx.pool_requires_alignment2(&requires);
if (r < 0) {
ldout(cct, 0) << "ERROR: ioctx.pool_requires_alignment2() returned "
<< r << dendl;
return r;
}
if (!requires) {
*alignment = 0;
return 0;
}
uint64_t align;
r = ioctx.pool_required_alignment2(&align);
if (r < 0) {
ldout(cct, 0) << "ERROR: ioctx.pool_required_alignment2() returned "
<< r << dendl;
return r;
}
if (align != 0) {
ldout(cct, 20) << "required alignment=" << align << dendl;
}
*alignment = align;
return 0;
}
void RGWRados::get_max_aligned_size(uint64_t size, uint64_t alignment, uint64_t *max_size)
{
if (alignment == 0) {
*max_size = size;
return;
}
if (size <= alignment) {
*max_size = alignment;
return;
}
*max_size = size - (size % alignment);
}
int RGWRados::get_max_chunk_size(const rgw_pool& pool, uint64_t *max_chunk_size, uint64_t *palignment)
{
uint64_t alignment;
int r = get_required_alignment(pool, &alignment);
if (r < 0) {
return r;
}
if (palignment) {
*palignment = alignment;
}