/
rgw_data_sync.cc
6707 lines (5874 loc) · 239 KB
/
rgw_data_sync.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 ft=cpp
#include "common/ceph_json.h"
#include "common/RefCountedObj.h"
#include "common/WorkQueue.h"
#include "common/Throttle.h"
#include "common/errno.h"
#include "rgw_common.h"
#include "rgw_zone.h"
#include "rgw_sync.h"
#include "rgw_data_sync.h"
#include "rgw_rest_conn.h"
#include "rgw_cr_rados.h"
#include "rgw_cr_rest.h"
#include "rgw_cr_tools.h"
#include "rgw_http_client.h"
#include "rgw_bucket.h"
#include "rgw_bucket_sync.h"
#include "rgw_bucket_sync_cache.h"
#include "rgw_datalog.h"
#include "rgw_metadata.h"
#include "rgw_sync_counters.h"
#include "rgw_sync_error_repo.h"
#include "rgw_sync_module.h"
#include "rgw_sal.h"
#include "cls/lock/cls_lock_client.h"
#include "cls/rgw/cls_rgw_client.h"
#include "services/svc_zone.h"
#include "services/svc_sync_modules.h"
#include "include/common_fwd.h"
#include "include/random.h"
#include <boost/asio/yield.hpp>
#include <string_view>
#define dout_subsys ceph_subsys_rgw
#undef dout_prefix
#define dout_prefix (*_dout << "data sync: ")
using namespace std;
static const string datalog_sync_status_oid_prefix = "datalog.sync-status";
static const string datalog_sync_status_shard_prefix = "datalog.sync-status.shard";
static const string datalog_sync_full_sync_index_prefix = "data.full-sync.index";
static const string bucket_full_status_oid_prefix = "bucket.full-sync-status";
static const string bucket_status_oid_prefix = "bucket.sync-status";
static const string object_status_oid_prefix = "bucket.sync-status";
void rgw_datalog_info::decode_json(JSONObj *obj) {
JSONDecoder::decode_json("num_objects", num_shards, obj);
}
void rgw_datalog_entry::decode_json(JSONObj *obj) {
JSONDecoder::decode_json("key", key, obj);
utime_t ut;
JSONDecoder::decode_json("timestamp", ut, obj);
timestamp = ut.to_real_time();
}
void rgw_datalog_shard_data::decode_json(JSONObj *obj) {
JSONDecoder::decode_json("marker", marker, obj);
JSONDecoder::decode_json("truncated", truncated, obj);
JSONDecoder::decode_json("entries", entries, obj);
};
// print a bucket shard with [gen]
std::string to_string(const rgw_bucket_shard& bs, std::optional<uint64_t> gen)
{
constexpr auto digits10 = std::numeric_limits<uint64_t>::digits10;
constexpr auto reserve = 2 + digits10; // [value]
auto str = bs.get_key('/', ':', ':', reserve);
str.append(1, '[');
str.append(std::to_string(gen.value_or(0)));
str.append(1, ']');
return str;
}
class RGWReadDataSyncStatusMarkersCR : public RGWShardCollectCR {
static constexpr int MAX_CONCURRENT_SHARDS = 16;
RGWDataSyncCtx *sc;
RGWDataSyncEnv *env;
const int num_shards;
int shard_id{0};;
map<uint32_t, rgw_data_sync_marker>& markers;
std::vector<RGWObjVersionTracker>& objvs;
int handle_result(int r) override {
if (r == -ENOENT) { // ENOENT is not a fatal error
return 0;
}
if (r < 0) {
ldout(cct, 4) << "failed to read data sync status: "
<< cpp_strerror(r) << dendl;
}
return r;
}
public:
RGWReadDataSyncStatusMarkersCR(RGWDataSyncCtx *sc, int num_shards,
map<uint32_t, rgw_data_sync_marker>& markers,
std::vector<RGWObjVersionTracker>& objvs)
: RGWShardCollectCR(sc->cct, MAX_CONCURRENT_SHARDS),
sc(sc), env(sc->env), num_shards(num_shards), markers(markers), objvs(objvs)
{}
bool spawn_next() override;
};
bool RGWReadDataSyncStatusMarkersCR::spawn_next()
{
if (shard_id >= num_shards) {
return false;
}
using CR = RGWSimpleRadosReadCR<rgw_data_sync_marker>;
spawn(new CR(env->dpp, env->driver,
rgw_raw_obj(env->svc->zone->get_zone_params().log_pool, RGWDataSyncStatusManager::shard_obj_name(sc->source_zone, shard_id)),
&markers[shard_id], true, &objvs[shard_id]),
false);
shard_id++;
return true;
}
class RGWReadDataSyncRecoveringShardsCR : public RGWShardCollectCR {
static constexpr int MAX_CONCURRENT_SHARDS = 16;
RGWDataSyncCtx *sc;
RGWDataSyncEnv *env;
uint64_t max_entries;
int num_shards;
int shard_id{0};
string marker;
std::vector<RGWRadosGetOmapKeysCR::ResultPtr>& omapkeys;
int handle_result(int r) override {
if (r == -ENOENT) { // ENOENT is not a fatal error
return 0;
}
if (r < 0) {
ldout(cct, 4) << "failed to list recovering data sync: "
<< cpp_strerror(r) << dendl;
}
return r;
}
public:
RGWReadDataSyncRecoveringShardsCR(RGWDataSyncCtx *sc, uint64_t _max_entries, int _num_shards,
std::vector<RGWRadosGetOmapKeysCR::ResultPtr>& omapkeys)
: RGWShardCollectCR(sc->cct, MAX_CONCURRENT_SHARDS), sc(sc), env(sc->env),
max_entries(_max_entries), num_shards(_num_shards), omapkeys(omapkeys)
{}
bool spawn_next() override;
};
bool RGWReadDataSyncRecoveringShardsCR::spawn_next()
{
if (shard_id >= num_shards)
return false;
string error_oid = RGWDataSyncStatusManager::shard_obj_name(sc->source_zone, shard_id) + ".retry";
auto& shard_keys = omapkeys[shard_id];
shard_keys = std::make_shared<RGWRadosGetOmapKeysCR::Result>();
spawn(new RGWRadosGetOmapKeysCR(env->driver, rgw_raw_obj(env->svc->zone->get_zone_params().log_pool, error_oid),
marker, max_entries, shard_keys), false);
++shard_id;
return true;
}
class RGWReadDataSyncStatusCoroutine : public RGWCoroutine {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
rgw_data_sync_status *sync_status;
RGWObjVersionTracker* objv_tracker;
std::vector<RGWObjVersionTracker>& objvs;
public:
RGWReadDataSyncStatusCoroutine(RGWDataSyncCtx *_sc,
rgw_data_sync_status *_status,
RGWObjVersionTracker* objv_tracker,
std::vector<RGWObjVersionTracker>& objvs)
: RGWCoroutine(_sc->cct), sc(_sc), sync_env(sc->env), sync_status(_status),
objv_tracker(objv_tracker), objvs(objvs)
{}
int operate(const DoutPrefixProvider *dpp) override;
};
int RGWReadDataSyncStatusCoroutine::operate(const DoutPrefixProvider *dpp)
{
reenter(this) {
// read sync info
using ReadInfoCR = RGWSimpleRadosReadCR<rgw_data_sync_info>;
yield {
bool empty_on_enoent = false; // fail on ENOENT
call(new ReadInfoCR(dpp, sync_env->driver,
rgw_raw_obj(sync_env->svc->zone->get_zone_params().log_pool, RGWDataSyncStatusManager::sync_status_oid(sc->source_zone)),
&sync_status->sync_info, empty_on_enoent, objv_tracker));
}
if (retcode < 0) {
ldpp_dout(dpp, 4) << "failed to read sync status info with "
<< cpp_strerror(retcode) << dendl;
return set_cr_error(retcode);
}
// read shard markers
objvs.resize(sync_status->sync_info.num_shards);
using ReadMarkersCR = RGWReadDataSyncStatusMarkersCR;
yield call(new ReadMarkersCR(sc, sync_status->sync_info.num_shards,
sync_status->sync_markers, objvs));
if (retcode < 0) {
ldpp_dout(dpp, 4) << "failed to read sync status markers with "
<< cpp_strerror(retcode) << dendl;
return set_cr_error(retcode);
}
return set_cr_done();
}
return 0;
}
class RGWReadRemoteDataLogShardInfoCR : public RGWCoroutine {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
RGWRESTReadResource *http_op;
int shard_id;
RGWDataChangesLogInfo *shard_info;
public:
RGWReadRemoteDataLogShardInfoCR(RGWDataSyncCtx *_sc,
int _shard_id, RGWDataChangesLogInfo *_shard_info) : RGWCoroutine(_sc->cct),
sc(_sc),
sync_env(_sc->env),
http_op(NULL),
shard_id(_shard_id),
shard_info(_shard_info) {
}
~RGWReadRemoteDataLogShardInfoCR() override {
if (http_op) {
http_op->put();
}
}
int operate(const DoutPrefixProvider *dpp) override {
reenter(this) {
yield {
char buf[16];
snprintf(buf, sizeof(buf), "%d", shard_id);
rgw_http_param_pair pairs[] = { { "type" , "data" },
{ "id", buf },
{ "info" , NULL },
{ NULL, NULL } };
string p = "/admin/log/";
http_op = new RGWRESTReadResource(sc->conn, p, pairs, NULL, sync_env->http_manager);
init_new_io(http_op);
int ret = http_op->aio_read(dpp);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: failed to read from " << p << dendl;
log_error() << "failed to send http operation: " << http_op->to_str() << " ret=" << ret << std::endl;
return set_cr_error(ret);
}
return io_block(0);
}
yield {
int ret = http_op->wait(shard_info, null_yield);
if (ret < 0) {
return set_cr_error(ret);
}
return set_cr_done();
}
}
return 0;
}
};
struct read_remote_data_log_response {
string marker;
bool truncated;
vector<rgw_data_change_log_entry> entries;
read_remote_data_log_response() : truncated(false) {}
void decode_json(JSONObj *obj) {
JSONDecoder::decode_json("marker", marker, obj);
JSONDecoder::decode_json("truncated", truncated, obj);
JSONDecoder::decode_json("entries", entries, obj);
};
};
class RGWReadRemoteDataLogShardCR : public RGWCoroutine {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
RGWRESTReadResource *http_op = nullptr;
int shard_id;
const std::string& marker;
string *pnext_marker;
vector<rgw_data_change_log_entry> *entries;
bool *truncated;
read_remote_data_log_response response;
std::optional<TOPNSPC::common::PerfGuard> timer;
public:
RGWReadRemoteDataLogShardCR(RGWDataSyncCtx *_sc, int _shard_id,
const std::string& marker, string *pnext_marker,
vector<rgw_data_change_log_entry> *_entries,
bool *_truncated)
: RGWCoroutine(_sc->cct), sc(_sc), sync_env(_sc->env),
shard_id(_shard_id), marker(marker), pnext_marker(pnext_marker),
entries(_entries), truncated(_truncated) {
}
~RGWReadRemoteDataLogShardCR() override {
if (http_op) {
http_op->put();
}
}
int operate(const DoutPrefixProvider *dpp) override {
reenter(this) {
yield {
char buf[16];
snprintf(buf, sizeof(buf), "%d", shard_id);
rgw_http_param_pair pairs[] = { { "type" , "data" },
{ "id", buf },
{ "marker", marker.c_str() },
{ "extra-info", "true" },
{ NULL, NULL } };
string p = "/admin/log/";
http_op = new RGWRESTReadResource(sc->conn, p, pairs, NULL, sync_env->http_manager);
init_new_io(http_op);
if (sync_env->counters) {
timer.emplace(sync_env->counters, sync_counters::l_poll);
}
int ret = http_op->aio_read(dpp);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: failed to read from " << p << dendl;
log_error() << "failed to send http operation: " << http_op->to_str() << " ret=" << ret << std::endl;
if (sync_env->counters) {
sync_env->counters->inc(sync_counters::l_poll_err);
}
return set_cr_error(ret);
}
return io_block(0);
}
yield {
timer.reset();
int ret = http_op->wait(&response, null_yield);
if (ret < 0) {
if (sync_env->counters && ret != -ENOENT) {
sync_env->counters->inc(sync_counters::l_poll_err);
}
return set_cr_error(ret);
}
entries->clear();
entries->swap(response.entries);
*pnext_marker = response.marker;
*truncated = response.truncated;
return set_cr_done();
}
}
return 0;
}
};
class RGWReadRemoteDataLogInfoCR : public RGWShardCollectCR {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
int num_shards;
map<int, RGWDataChangesLogInfo> *datalog_info;
int shard_id;
#define READ_DATALOG_MAX_CONCURRENT 10
int handle_result(int r) override {
if (r == -ENOENT) { // ENOENT is not a fatal error
return 0;
}
if (r < 0) {
ldout(cct, 4) << "failed to fetch remote datalog info: "
<< cpp_strerror(r) << dendl;
}
return r;
}
public:
RGWReadRemoteDataLogInfoCR(RGWDataSyncCtx *_sc,
int _num_shards,
map<int, RGWDataChangesLogInfo> *_datalog_info) : RGWShardCollectCR(_sc->cct, READ_DATALOG_MAX_CONCURRENT),
sc(_sc), sync_env(_sc->env), num_shards(_num_shards),
datalog_info(_datalog_info), shard_id(0) {}
bool spawn_next() override;
};
bool RGWReadRemoteDataLogInfoCR::spawn_next() {
if (shard_id >= num_shards) {
return false;
}
spawn(new RGWReadRemoteDataLogShardInfoCR(sc, shard_id, &(*datalog_info)[shard_id]), false);
shard_id++;
return true;
}
class RGWListRemoteDataLogShardCR : public RGWSimpleCoroutine {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
RGWRESTReadResource *http_op;
int shard_id;
string marker;
uint32_t max_entries;
rgw_datalog_shard_data *result;
public:
RGWListRemoteDataLogShardCR(RGWDataSyncCtx *sc, int _shard_id,
const string& _marker, uint32_t _max_entries,
rgw_datalog_shard_data *_result)
: RGWSimpleCoroutine(sc->cct), sc(sc), sync_env(sc->env), http_op(NULL),
shard_id(_shard_id), marker(_marker), max_entries(_max_entries), result(_result) {}
int send_request(const DoutPrefixProvider *dpp) override {
RGWRESTConn *conn = sc->conn;
char buf[32];
snprintf(buf, sizeof(buf), "%d", shard_id);
char max_entries_buf[32];
snprintf(max_entries_buf, sizeof(max_entries_buf), "%d", (int)max_entries);
const char *marker_key = (marker.empty() ? "" : "marker");
rgw_http_param_pair pairs[] = { { "type", "data" },
{ "id", buf },
{ "max-entries", max_entries_buf },
{ marker_key, marker.c_str() },
{ NULL, NULL } };
string p = "/admin/log/";
http_op = new RGWRESTReadResource(conn, p, pairs, NULL, sync_env->http_manager);
init_new_io(http_op);
int ret = http_op->aio_read(dpp);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: failed to read from " << p << dendl;
log_error() << "failed to send http operation: " << http_op->to_str() << " ret=" << ret << std::endl;
http_op->put();
return ret;
}
return 0;
}
int request_complete() override {
int ret = http_op->wait(result, null_yield);
http_op->put();
if (ret < 0 && ret != -ENOENT) {
ldpp_dout(sync_env->dpp, 0) << "ERROR: failed to list remote datalog shard, ret=" << ret << dendl;
return ret;
}
return 0;
}
};
class RGWListRemoteDataLogCR : public RGWShardCollectCR {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
map<int, string> shards;
int max_entries_per_shard;
map<int, rgw_datalog_shard_data> *result;
map<int, string>::iterator iter;
#define READ_DATALOG_MAX_CONCURRENT 10
int handle_result(int r) override {
if (r == -ENOENT) { // ENOENT is not a fatal error
return 0;
}
if (r < 0) {
ldout(cct, 4) << "failed to list remote datalog: "
<< cpp_strerror(r) << dendl;
}
return r;
}
public:
RGWListRemoteDataLogCR(RGWDataSyncCtx *_sc,
map<int, string>& _shards,
int _max_entries_per_shard,
map<int, rgw_datalog_shard_data> *_result) : RGWShardCollectCR(_sc->cct, READ_DATALOG_MAX_CONCURRENT),
sc(_sc), sync_env(_sc->env), max_entries_per_shard(_max_entries_per_shard),
result(_result) {
shards.swap(_shards);
iter = shards.begin();
}
bool spawn_next() override;
};
bool RGWListRemoteDataLogCR::spawn_next() {
if (iter == shards.end()) {
return false;
}
spawn(new RGWListRemoteDataLogShardCR(sc, iter->first, iter->second, max_entries_per_shard, &(*result)[iter->first]), false);
++iter;
return true;
}
class RGWInitDataSyncStatusCoroutine : public RGWCoroutine {
static constexpr auto lock_name{ "sync_lock"sv };
RGWDataSyncCtx* const sc;
RGWDataSyncEnv* const sync_env{ sc->env };
const uint32_t num_shards;
rgw_data_sync_status* const status;
RGWSyncTraceNodeRef tn;
boost::intrusive_ptr<RGWContinuousLeaseCR> lease_cr;
RGWObjVersionTracker& objv_tracker;
std::vector<RGWObjVersionTracker>& objvs;
const rgw_pool& pool{ sync_env->svc->zone->get_zone_params().log_pool };
const string sync_status_oid{
RGWDataSyncStatusManager::sync_status_oid(sc->source_zone) };
map<int, RGWDataChangesLogInfo> shards_info;
public:
RGWInitDataSyncStatusCoroutine(
RGWDataSyncCtx* _sc, uint32_t num_shards, uint64_t instance_id,
const RGWSyncTraceNodeRef& tn_parent, rgw_data_sync_status* status,
boost::intrusive_ptr<RGWContinuousLeaseCR> lease_cr,
RGWObjVersionTracker& objv_tracker,
std::vector<RGWObjVersionTracker>& objvs)
: RGWCoroutine(_sc->cct), sc(_sc), num_shards(num_shards), status(status),
tn(sync_env->sync_tracer->add_node(tn_parent, "init_data_sync_status")),
lease_cr(std::move(lease_cr)), objv_tracker(objv_tracker), objvs(objvs) {
status->sync_info.instance_id = instance_id;
}
static auto continuous_lease_cr(RGWDataSyncCtx* const sc,
RGWCoroutine* const caller) {
auto lock_duration = sc->cct->_conf->rgw_sync_lease_period;
return new RGWContinuousLeaseCR(
sc->env->async_rados, sc->env->driver,
{ sc->env->svc->zone->get_zone_params().log_pool,
RGWDataSyncStatusManager::sync_status_oid(sc->source_zone) },
string(lock_name), lock_duration, caller, &sc->lcc);
}
int operate(const DoutPrefixProvider *dpp) override {
int ret;
reenter(this) {
if (!lease_cr->is_locked()) {
drain_all();
return set_cr_error(-ECANCELED);
}
using WriteInfoCR = RGWSimpleRadosWriteCR<rgw_data_sync_info>;
yield call(new WriteInfoCR(dpp, sync_env->driver,
rgw_raw_obj{pool, sync_status_oid},
status->sync_info, &objv_tracker));
if (retcode < 0) {
tn->log(0, SSTR("ERROR: failed to write sync status info with " << retcode));
return set_cr_error(retcode);
}
// In the original code we reacquired the lock. Since
// RGWSimpleRadosWriteCR doesn't appear to touch the attributes
// and cls_version works across it, this should be unnecessary.
// Putting a note here just in case. If we see ECANCELED where
// we expect EBUSY, we can revisit this.
/* fetch current position in logs */
yield {
RGWRESTConn *conn = sync_env->svc->zone->get_zone_conn(sc->source_zone);
if (!conn) {
tn->log(0, SSTR("ERROR: connection to zone " << sc->source_zone << " does not exist!"));
return set_cr_error(-EIO);
}
for (uint32_t i = 0; i < num_shards; i++) {
spawn(new RGWReadRemoteDataLogShardInfoCR(sc, i, &shards_info[i]), true);
}
}
while (collect(&ret, NULL)) {
if (ret < 0) {
tn->log(0, SSTR("ERROR: failed to read remote data log shards"));
return set_state(RGWCoroutine_Error);
}
yield;
}
yield {
objvs.resize(num_shards);
for (uint32_t i = 0; i < num_shards; i++) {
RGWDataChangesLogInfo& info = shards_info[i];
auto& marker = status->sync_markers[i];
marker.next_step_marker = info.marker;
marker.timestamp = info.last_update;
const auto& oid = RGWDataSyncStatusManager::shard_obj_name(sc->source_zone, i);
auto& objv = objvs[i];
objv.generate_new_write_ver(cct);
using WriteMarkerCR = RGWSimpleRadosWriteCR<rgw_data_sync_marker>;
spawn(new WriteMarkerCR(dpp, sync_env->driver,
rgw_raw_obj{pool, oid}, marker, &objv), true);
}
}
while (collect(&ret, NULL)) {
if (ret < 0) {
tn->log(0, SSTR("ERROR: failed to write data sync status markers"));
return set_state(RGWCoroutine_Error);
}
yield;
}
status->sync_info.state = rgw_data_sync_info::StateBuildingFullSyncMaps;
yield call(new WriteInfoCR(dpp, sync_env->driver,
rgw_raw_obj{pool, sync_status_oid},
status->sync_info, &objv_tracker));
if (retcode < 0) {
tn->log(0, SSTR("ERROR: failed to write sync status info with " << retcode));
return set_cr_error(retcode);
}
return set_cr_done();
}
return 0;
}
};
RGWRemoteDataLog::RGWRemoteDataLog(const DoutPrefixProvider *dpp,
rgw::sal::RadosStore* driver,
RGWAsyncRadosProcessor *async_rados)
: RGWCoroutinesManager(driver->ctx(), driver->getRados()->get_cr_registry()),
dpp(dpp), driver(driver),
cct(driver->ctx()), cr_registry(driver->getRados()->get_cr_registry()),
async_rados(async_rados),
http_manager(driver->ctx(), completion_mgr),
data_sync_cr(NULL),
initialized(false)
{
}
int RGWRemoteDataLog::read_log_info(const DoutPrefixProvider *dpp, rgw_datalog_info *log_info)
{
rgw_http_param_pair pairs[] = { { "type", "data" },
{ NULL, NULL } };
int ret = sc.conn->get_json_resource(dpp, "/admin/log", pairs, null_yield, *log_info);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: failed to fetch datalog info" << dendl;
return ret;
}
ldpp_dout(dpp, 20) << "remote datalog, num_shards=" << log_info->num_shards << dendl;
return 0;
}
int RGWRemoteDataLog::read_source_log_shards_info(const DoutPrefixProvider *dpp, map<int, RGWDataChangesLogInfo> *shards_info)
{
rgw_datalog_info log_info;
int ret = read_log_info(dpp, &log_info);
if (ret < 0) {
return ret;
}
return run(dpp, new RGWReadRemoteDataLogInfoCR(&sc, log_info.num_shards, shards_info));
}
int RGWRemoteDataLog::read_source_log_shards_next(const DoutPrefixProvider *dpp, map<int, string> shard_markers, map<int, rgw_datalog_shard_data> *result)
{
return run(dpp, new RGWListRemoteDataLogCR(&sc, shard_markers, 1, result));
}
int RGWRemoteDataLog::init(const rgw_zone_id& _source_zone, RGWRESTConn *_conn, RGWSyncErrorLogger *_error_logger,
RGWSyncTraceManager *_sync_tracer, RGWSyncModuleInstanceRef& _sync_module,
PerfCounters* counters)
{
sync_env.init(dpp, cct, driver, driver->svc(), async_rados, &http_manager, _error_logger,
_sync_tracer, _sync_module, counters);
sc.init(&sync_env, _conn, _source_zone);
if (initialized) {
return 0;
}
int ret = http_manager.start();
if (ret < 0) {
ldpp_dout(dpp, 0) << "failed in http_manager.start() ret=" << ret << dendl;
return ret;
}
tn = sync_env.sync_tracer->add_node(sync_env.sync_tracer->root_node, "data");
initialized = true;
return 0;
}
void RGWRemoteDataLog::finish()
{
stop();
}
int RGWRemoteDataLog::read_sync_status(const DoutPrefixProvider *dpp, rgw_data_sync_status *sync_status)
{
// cannot run concurrently with run_sync(), so run in a separate manager
RGWObjVersionTracker objv;
std::vector<RGWObjVersionTracker> shard_objvs;
RGWCoroutinesManager crs(cct, cr_registry);
RGWHTTPManager http_manager(cct, crs.get_completion_mgr());
int ret = http_manager.start();
if (ret < 0) {
ldpp_dout(dpp, 0) << "failed in http_manager.start() ret=" << ret << dendl;
return ret;
}
RGWDataSyncEnv sync_env_local = sync_env;
sync_env_local.http_manager = &http_manager;
RGWDataSyncCtx sc_local = sc;
sc_local.env = &sync_env_local;
ret = crs.run(dpp, new RGWReadDataSyncStatusCoroutine(&sc_local, sync_status,
&objv, shard_objvs));
http_manager.stop();
return ret;
}
int RGWRemoteDataLog::read_recovering_shards(const DoutPrefixProvider *dpp, const int num_shards, set<int>& recovering_shards)
{
// cannot run concurrently with run_sync(), so run in a separate manager
RGWCoroutinesManager crs(cct, cr_registry);
RGWHTTPManager http_manager(cct, crs.get_completion_mgr());
int ret = http_manager.start();
if (ret < 0) {
ldpp_dout(dpp, 0) << "failed in http_manager.start() ret=" << ret << dendl;
return ret;
}
RGWDataSyncEnv sync_env_local = sync_env;
sync_env_local.http_manager = &http_manager;
RGWDataSyncCtx sc_local = sc;
sc_local.env = &sync_env_local;
std::vector<RGWRadosGetOmapKeysCR::ResultPtr> omapkeys;
omapkeys.resize(num_shards);
uint64_t max_entries{1};
ret = crs.run(dpp, new RGWReadDataSyncRecoveringShardsCR(&sc_local, max_entries, num_shards, omapkeys));
http_manager.stop();
if (ret == 0) {
for (int i = 0; i < num_shards; i++) {
if (omapkeys[i]->entries.size() != 0) {
recovering_shards.insert(i);
}
}
}
return ret;
}
namespace RGWRDL {
class DataSyncInitCR : public RGWCoroutine {
RGWDataSyncCtx* const sc;
const uint32_t num_shards;
uint64_t instance_id;
const RGWSyncTraceNodeRef& tn;
rgw_data_sync_status* const sync_status;
std::vector<RGWObjVersionTracker>& objvs;
boost::intrusive_ptr<RGWContinuousLeaseCR> lease_cr;
RGWObjVersionTracker objv_tracker;
public:
DataSyncInitCR(RGWDataSyncCtx* sc, uint32_t num_shards, uint64_t instance_id,
const RGWSyncTraceNodeRef& tn,
rgw_data_sync_status* sync_status,
std::vector<RGWObjVersionTracker>& objvs)
: RGWCoroutine(sc->cct), sc(sc), num_shards(num_shards),
instance_id(instance_id), tn(tn),
sync_status(sync_status), objvs(objvs) {}
~DataSyncInitCR() override {
if (lease_cr) {
lease_cr->abort();
}
}
int operate(const DoutPrefixProvider *dpp) override {
reenter(this) {
lease_cr.reset(
RGWInitDataSyncStatusCoroutine::continuous_lease_cr(sc, this));
yield spawn(lease_cr.get(), false);
while (!lease_cr->is_locked()) {
if (lease_cr->is_done()) {
tn->log(5, "ERROR: failed to take data sync status lease");
set_status("lease lock failed, early abort");
drain_all();
return set_cr_error(lease_cr->get_ret_status());
}
tn->log(5, "waiting on data sync status lease");
yield set_sleeping(true);
}
tn->log(5, "acquired data sync status lease");
objv_tracker.generate_new_write_ver(sc->cct);
yield call(new RGWInitDataSyncStatusCoroutine(sc, num_shards, instance_id,
tn, sync_status, lease_cr,
objv_tracker, objvs));
lease_cr->go_down();
lease_cr.reset();
drain_all();
if (retcode < 0) {
set_cr_error(retcode);
}
return set_cr_done();
}
return 0;
}
};
}
int RGWRemoteDataLog::init_sync_status(const DoutPrefixProvider *dpp, int num_shards)
{
rgw_data_sync_status sync_status;
std::vector<RGWObjVersionTracker> objvs;
sync_status.sync_info.num_shards = num_shards;
RGWCoroutinesManager crs(cct, cr_registry);
RGWHTTPManager http_manager(cct, crs.get_completion_mgr());
int ret = http_manager.start();
if (ret < 0) {
ldpp_dout(dpp, 0) << "failed in http_manager.start() ret=" << ret << dendl;
return ret;
}
RGWDataSyncEnv sync_env_local = sync_env;
sync_env_local.http_manager = &http_manager;
auto instance_id = ceph::util::generate_random_number<uint64_t>();
RGWDataSyncCtx sc_local = sc;
sc_local.env = &sync_env_local;
ret = crs.run(dpp, new RGWRDL::DataSyncInitCR(&sc_local, num_shards,
instance_id, tn, &sync_status, objvs));
http_manager.stop();
return ret;
}
static string full_data_sync_index_shard_oid(const rgw_zone_id& source_zone, int shard_id)
{
char buf[datalog_sync_full_sync_index_prefix.size() + 1 + source_zone.id.size() + 1 + 16];
snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_full_sync_index_prefix.c_str(), source_zone.id.c_str(), shard_id);
return string(buf);
}
struct read_metadata_list {
string marker;
bool truncated;
list<string> keys;
int count;
read_metadata_list() : truncated(false), count(0) {}
void decode_json(JSONObj *obj) {
JSONDecoder::decode_json("marker", marker, obj);
JSONDecoder::decode_json("truncated", truncated, obj);
JSONDecoder::decode_json("keys", keys, obj);
JSONDecoder::decode_json("count", count, obj);
}
};
struct bucket_instance_meta_info {
string key;
obj_version ver;
utime_t mtime;
RGWBucketInstanceMetadataObject data;
bucket_instance_meta_info() {}
void decode_json(JSONObj *obj) {
JSONDecoder::decode_json("key", key, obj);
JSONDecoder::decode_json("ver", ver, obj);
JSONDecoder::decode_json("mtime", mtime, obj);
JSONDecoder::decode_json("data", data, obj);
}
};
class RGWReadRemoteBucketIndexLogInfoCR : public RGWCoroutine {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env;
const string instance_key;
rgw_bucket_index_marker_info *info;
public:
RGWReadRemoteBucketIndexLogInfoCR(RGWDataSyncCtx *_sc,
const rgw_bucket& bucket,
rgw_bucket_index_marker_info *_info)
: RGWCoroutine(_sc->cct), sc(_sc), sync_env(_sc->env),
instance_key(bucket.get_key()), info(_info) {}
int operate(const DoutPrefixProvider *dpp) override {
reenter(this) {
yield {
rgw_http_param_pair pairs[] = { { "type" , "bucket-index" },
{ "bucket-instance", instance_key.c_str() },
{ "info" , NULL },
{ NULL, NULL } };
string p = "/admin/log/";
call(new RGWReadRESTResourceCR<rgw_bucket_index_marker_info>(sync_env->cct, sc->conn, sync_env->http_manager, p, pairs, info));
}
if (retcode < 0) {
return set_cr_error(retcode);
}
return set_cr_done();
}
return 0;
}
};
class RGWListBucketIndexesCR : public RGWCoroutine {
RGWDataSyncCtx *sc;
RGWDataSyncEnv *sync_env = sc->env;
rgw::sal::RadosStore* driver = sync_env->driver;
rgw_data_sync_status *sync_status;
std::vector<RGWObjVersionTracker>& objvs;
int req_ret = 0;
int ret = 0;
list<string>::iterator iter;
unique_ptr<RGWShardedOmapCRManager> entries_index;
string oid_prefix =
datalog_sync_full_sync_index_prefix + "." + sc->source_zone.id;
string path = "/admin/metadata/bucket.instance";
bucket_instance_meta_info meta_info;
string key;
bool failed = false;
bool truncated = false;
read_metadata_list result;
public:
RGWListBucketIndexesCR(RGWDataSyncCtx* sc,
rgw_data_sync_status* sync_status, std::vector<RGWObjVersionTracker>& objvs)
: RGWCoroutine(sc->cct), sc(sc), sync_status(sync_status), objvs(objvs) {}
~RGWListBucketIndexesCR() override { }
int operate(const DoutPrefixProvider *dpp) override {
reenter(this) {
entries_index = std::make_unique<RGWShardedOmapCRManager>(
sync_env->async_rados, driver, this,
cct->_conf->rgw_data_log_num_shards,
sync_env->svc->zone->get_zone_params().log_pool,
oid_prefix);
yield; // yield so OmapAppendCRs can start
do {
yield {
string entrypoint = "/admin/metadata/bucket.instance"s;
rgw_http_param_pair pairs[] = {{"max-entries", "1000"},
{"marker", result.marker.c_str()},
{NULL, NULL}};
call(new RGWReadRESTResourceCR<read_metadata_list>(
sync_env->cct, sc->conn, sync_env->http_manager,
entrypoint, pairs, &result));
}
if (retcode < 0) {
ldpp_dout(dpp, 0)
<< "ERROR: failed to fetch metadata for section bucket.instance"
<< dendl;
return set_cr_error(retcode);
}
for (iter = result.keys.begin(); iter != result.keys.end(); ++iter) {