@@ -436,7 +436,8 @@ static int init_target_index(rgw::sal::RadosStore* store,
436436{
437437 int ret = store->svc ()->bi ->init_index (dpp, bucket_info, index, true );
438438 if (ret == -EOPNOTSUPP) {
439- ldpp_dout (dpp, 0 ) << " WARNING: " << " init_index() does not supported logrecord" << dendl;
439+ ldpp_dout (dpp, 0 ) << " WARNING: " << " init_index() does not supported logrecord, "
440+ << " falling back to block reshard mode." << dendl;
440441 support_logrecord = false ;
441442 ret = store->svc ()->bi ->init_index (dpp, bucket_info, index, false );
442443 }
@@ -571,6 +572,25 @@ static int init_target_layout(rgw::sal::RadosStore* store,
571572 store->svc ()->bi ->clean_index (dpp, bucket_info, target);
572573 return ret;
573574 }
575+
576+ // trim the reshard log entries to guarantee that any existing log entries are cleared,
577+ // if there are no reshard log entries, this is a no-op that costs little time
578+ if (support_logrecord) {
579+ ret = store->getRados ()->trim_reshard_log_entries (dpp, bucket_info, null_yield);
580+ if (ret == -EOPNOTSUPP) {
581+ // not an error, logrecord is not supported, change to block reshard
582+ ldpp_dout (dpp, 0 ) << " WARNING: " << " trim_reshard_log_entries() does not supported"
583+ << " logrecord, falling back to block reshard mode." << dendl;
584+ bucket_info.layout .resharding = rgw::BucketReshardState::InProgress;
585+ support_logrecord = false ;
586+ return 0 ;
587+ }
588+ if (ret < 0 ) {
589+ ldpp_dout (dpp, 0 ) << " ERROR: " << __func__ << " failed to trim reshard log entries: "
590+ << cpp_strerror (ret) << dendl;
591+ return ret;
592+ }
593+ }
574594 return 0 ;
575595} // init_target_layout
576596
@@ -591,6 +611,13 @@ static int revert_target_layout(rgw::sal::RadosStore* store,
591611 " target index with: " << cpp_strerror (ret) << dendl;
592612 ret = 0 ; // non-fatal error
593613 }
614+ // trim the reshard log entries written in logrecord state
615+ ret = store->getRados ()->trim_reshard_log_entries (dpp, bucket_info, null_yield);
616+ if (ret < 0 ) {
617+ ldpp_dout (dpp, 1 ) << " WARNING: " << __func__ << " failed to trim "
618+ " reshard log entries: " << cpp_strerror (ret) << dendl;
619+ ret = 0 ; // non-fatal error
620+ }
594621
595622 // retry in case of racing writes to the bucket instance metadata
596623 static constexpr auto max_retries = 10 ;
@@ -677,7 +704,9 @@ static int init_reshard(rgw::sal::RadosStore* store,
677704 }
678705 if (ret == -EOPNOTSUPP) {
679706 ldpp_dout (dpp, 0 ) << " WARNING: " << " set_resharding_status()"
680- << " doesn't support logrecords" << dendl;
707+ << " doesn't support logrecords,"
708+ << " fallback to blocking mode." << dendl;
709+ bucket_info.layout .resharding = rgw::BucketReshardState::InProgress;
681710 support_logrecord = false ;
682711 }
683712 }
@@ -1251,15 +1280,24 @@ int RGWBucketReshard::do_reshard(const rgw::bucket_index_layout_generation& curr
12511280 if (ret < 0 ) {
12521281 return ret;
12531282 }
1254- }
12551283
1256- // block the client op and complete the resharding
1257- ceph_assert (bucket_info.layout .resharding == rgw::BucketReshardState::InProgress);
1258- int ret = reshard_process (current, max_op_entries, target_shards_mgr, verbose_json_out, out,
1259- formatter, bucket_info.layout .resharding , dpp, y);
1260- if (ret < 0 ) {
1261- ldpp_dout (dpp, 0 ) << __func__ << " : failed in progress state of reshard ret = " << ret << dendl;
1262- return ret;
1284+ // block the client op and complete the resharding
1285+ ceph_assert (bucket_info.layout .resharding == rgw::BucketReshardState::InProgress);
1286+ ret = reshard_process (current, max_op_entries, target_shards_mgr, verbose_json_out, out,
1287+ formatter, bucket_info.layout .resharding , dpp, y);
1288+ if (ret < 0 ) {
1289+ ldpp_dout (dpp, 0 ) << __func__ << " : failed in progress state of reshard ret = " << ret << dendl;
1290+ return ret;
1291+ }
1292+ } else {
1293+ // setting InProgress state, but doing InLogrecord state
1294+ ceph_assert (bucket_info.layout .resharding == rgw::BucketReshardState::InProgress);
1295+ int ret = reshard_process (current, max_op_entries, target_shards_mgr, verbose_json_out, out,
1296+ formatter, rgw::BucketReshardState::InLogrecord, dpp, y);
1297+ if (ret < 0 ) {
1298+ ldpp_dout (dpp, 0 ) << __func__ << " : failed in logrecord state of reshard ret = " << ret << dendl;
1299+ return ret;
1300+ }
12631301 }
12641302 return 0 ;
12651303} // RGWBucketReshard::do_reshard
0 commit comments