From 970296648f97cbca48ef79b468b2d6e5434f8011 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 29 Oct 2015 13:45:40 -0700 Subject: [PATCH] rgw: error out if failed to build md sync index Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_cr_rados.cc | 9 +++++++-- src/rgw/rgw_cr_rados.h | 22 ++++++++++++++++------ src/rgw/rgw_sync.cc | 34 ++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/rgw/rgw_cr_rados.cc b/src/rgw/rgw_cr_rados.cc index ddee27442501a..d4254f8cfb69a 100644 --- a/src/rgw/rgw_cr_rados.cc +++ b/src/rgw/rgw_cr_rados.cc @@ -364,18 +364,23 @@ void RGWOmapAppend::flush_pending() { num_pending_entries = 0; } -void RGWOmapAppend::append(const string& s) { +bool RGWOmapAppend::append(const string& s) { + if (is_done()) { + return false; + } ++total_entries; pending_entries.push_back(s); if (++num_pending_entries >= OMAP_APPEND_MAX_ENTRIES) { flush_pending(); } + return true; } -void RGWOmapAppend::finish() { +bool RGWOmapAppend::finish() { going_down = true; flush_pending(); set_sleeping(false); + return (!is_done()); } int RGWAsyncGetBucketInstanceInfo::_send_request() diff --git a/src/rgw/rgw_cr_rados.h b/src/rgw/rgw_cr_rados.h index ee0e95941371f..708a174f2cf8a 100644 --- a/src/rgw/rgw_cr_rados.h +++ b/src/rgw/rgw_cr_rados.h @@ -436,8 +436,8 @@ public: RGWOmapAppend(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, rgw_bucket& _pool, const string& _oid); int operate(); void flush_pending(); - void append(const string& s); - void finish(); + bool append(const string& s); + bool finish(); uint64_t get_total_entries() { return total_entries; @@ -518,18 +518,28 @@ public: char buf[oid_prefix.size() + 16]; snprintf(buf, sizeof(buf), "%s.%d", oid_prefix.c_str(), i); RGWOmapAppend *shard = new RGWOmapAppend(async_rados, store, pool, buf); + shard->get(); shards.push_back(shard); op->spawn(shard, false); } } - void append(const string& entry) { + + ~RGWShardedOmapCRManager() { + for (auto shard : shards) { + shard->put(); + } + } + + bool append(const string& entry) { int shard_id = store->key_to_shard_id(entry, shards.size()); - shards[shard_id]->append(entry); + return shards[shard_id]->append(entry); } - void finish() { + bool finish() { + bool success = true; for (vector::iterator iter = shards.begin(); iter != shards.end(); ++iter) { - (*iter)->finish(); + success &= (*iter)->finish(); } + return success; } uint64_t get_total_entries(int shard_id) { diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index b45a322749cf3..f3a6a4f9395db 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -554,6 +554,7 @@ class RGWFetchAllMetaCR : public RGWCoroutine { RGWContinuousLeaseCR *lease_cr; bool lost_lock; + bool failed; map& markers; @@ -561,7 +562,7 @@ public: RGWFetchAllMetaCR(RGWMetaSyncEnv *_sync_env, int _num_shards, map& _markers) : RGWCoroutine(_sync_env->cct), sync_env(_sync_env), num_shards(_num_shards), - req_ret(0), entries_index(NULL), lease_cr(NULL), lost_lock(false), markers(_markers) { + req_ret(0), entries_index(NULL), lease_cr(NULL), lost_lock(false), failed(false), markers(_markers) { } ~RGWFetchAllMetaCR() { @@ -641,7 +642,7 @@ public: return set_state(RGWCoroutine_Error); } iter = result.begin(); - for (list::iterator iter = result.begin(); iter != result.end(); ++iter) { + for (; iter != result.end(); ++iter) { yield { if (!lease_cr->is_locked()) { lost_lock = true; @@ -649,19 +650,25 @@ public: } ldout(cct, 20) << "list metadata: section=" << *sections_iter << " key=" << *iter << dendl; string s = *sections_iter + ":" + *iter; - entries_index->append(s); -#warning error handling of shards + if (!entries_index->append(s)) { + break; + } } } } - yield entries_index->finish(); - - for (map::iterator iter = markers.begin(); iter != markers.end(); ++iter) { - int shard_id = (int)iter->first; - rgw_meta_sync_marker& marker = iter->second; - marker.total_entries = entries_index->get_total_entries(shard_id); - spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, sync_env->store, sync_env->store->get_zone_params().log_pool, - sync_env->shard_obj_name(shard_id), marker), true); + yield { + if (!entries_index->finish()) { + failed = true; + } + } + if (!failed) { + for (map::iterator iter = markers.begin(); iter != markers.end(); ++iter) { + int shard_id = (int)iter->first; + rgw_meta_sync_marker& marker = iter->second; + marker.total_entries = entries_index->get_total_entries(shard_id); + spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, sync_env->store, sync_env->store->get_zone_params().log_pool, + sync_env->shard_obj_name(shard_id), marker), true); + } } drain_all_but(1); /* the lease cr still needs to run */ @@ -675,6 +682,9 @@ public: } yield; } + if (failed) { + yield return set_cr_error(-EIO); + } if (lost_lock) { yield return set_cr_error(-EBUSY); } -- 2.39.5