From c99c4c7d0d072899b0546befeee3c151fe55ae33 Mon Sep 17 00:00:00 2001 From: Shilpa Jagannath Date: Tue, 26 Nov 2019 13:33:52 +0530 Subject: [PATCH] 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 nautilus; made the changes manually to src/rgw/rgw_metadata.cc --- src/rgw/rgw_metadata.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index b894bb99aeab2..9741cba9dcbd6 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -541,7 +541,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) { @@ -596,7 +596,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); -- 2.39.5