From: Joshua Blanch Date: Thu, 31 Jul 2025 22:31:37 +0000 (+0000) Subject: rgw: auto-create missing bucket index shards during reindex operations X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F64801%2Fhead;p=ceph.git rgw: auto-create missing bucket index shards during reindex operations When bucket indexes are purged (e.g., via `radosgw-admin bi purge`), reindex operations fail because they attempt to update non-existent bucket index shards. Fixes: https://tracker.ceph.com/issues/68750 Signed-off-by: Joshua Blanch --- diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 4ab7fe06e94f..e3dd956741c0 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -4088,6 +4088,39 @@ int RGWRados::reindex_obj(rgw::sal::Driver* driver, (void) decode_policy(dpp, acl_bl, &owner); } + rgw_rados_ref bucket_ref; + ret = svc.bi_rados->open_bucket_index_shard(dpp, + bucket_info, + head_obj.get_hash_object(), + &bucket_ref, + nullptr); + if (ret < 0) { + ldpp_dout(dpp, 0) << "ERROR: failed to determine bucket index shard" + << dendl; + return ret; + } + + // validate bucket index shard existence before attempting reindex + ret = bucket_ref.ioctx.stat(bucket_ref.obj.oid, NULL, NULL); + if (ret == -ENOENT) { + ldpp_dout(dpp, 10) << "INFO: bucket index shard " << bucket_ref.obj.oid + << " missing, creating..." << dendl; + int create_ret = svc.bi_rados->init_index(dpp, + y, + bucket_info, + bucket_info.layout.current_index, + false); + + if (create_ret < 0) { + ldpp_dout(dpp, 0) << "ERROR: failed to create bucket index" << dendl; + return create_ret; + } + } else if (ret < 0) { + ldpp_dout(dpp, 0) << "ERROR: failed to stat bucket index shard: " + << cpp_strerror(-ret) << dendl; + return ret; + } + Bucket bkt(this, bucket_info); RGWRados::Bucket::UpdateIndex update_idx(&bkt, head_obj);