From: Shilpa Jagannath Date: Tue, 26 Nov 2019 08:03:52 +0000 (+0530) Subject: rgw: when a period lookup for oldest_realm_epoch returns an ENOENT, X-Git-Tag: v13.2.9~82^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6acc458e59612a9e52fec0e574d2707cba630677;p=ceph.git rgw: when a period lookup for oldest_realm_epoch returns an ENOENT, find the oldest one and update RGWMetadataLogHistory. This is to avoid an empty cursor being passed in to ceph_assert() in PurgePeriodLogsCR::operate() in case of incomplete period history. Fixes: https://tracker.ceph.com/issues/40341 Signed-off-by: Shilpa Jagannath (cherry picked from commit 0ea65d81d4d5431ca22340149dbd714e395ecdc3) Conflicts: src/rgw/services/svc_mdlog.cc - file does not exist in mimic; made the changes manually to src/rgw/rgw_metadata.cc - in mimic, find_oldest_period takes an argument: store - in mimic, write_history takes an additional argument: store --- diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index ed237b9e45d16..4d2c5a2c61da6 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -536,7 +536,7 @@ Cursor find_oldest_period(RGWRados *store) RGWPeriod period; int r = store->period_puller->pull(predecessor, period); if (r < 0) { - return Cursor{r}; + return cursor; } auto prev = store->period_history->insert(std::move(period)); if (!prev) { @@ -568,7 +568,6 @@ Cursor RGWMetadataManager::init_oldest_log_period() if (!cursor) { return cursor; } - // write the initial history state.oldest_realm_epoch = cursor.get_epoch(); state.oldest_period_id = cursor.get_period().get_id(); @@ -591,7 +590,20 @@ Cursor RGWMetadataManager::init_oldest_log_period() auto cursor = store->period_history->lookup(state.oldest_realm_epoch); if (cursor) { return cursor; + } else { + cursor = find_oldest_period(store); + state.oldest_realm_epoch = cursor.get_epoch(); + state.oldest_period_id = cursor.get_period().get_id(); + ldout(cct, 10) << "rewriting mdlog history" << dendl; + ret = write_history(store, state, &objv); + if (ret < 0 && ret != -ECANCELED) { + ldout(cct, 1) << "failed to write mdlog history: " + << cpp_strerror(ret) << dendl; + return Cursor{ret}; + } + return cursor; } + // pull the oldest period by id RGWPeriod period; ret = store->period_puller->pull(state.oldest_period_id, period);