From 1e7718c37c5ebbc98d4c3caec91d71a99f5c0982 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 7 Jun 2019 10:57:04 -0500 Subject: [PATCH] mon/OSDMonitor: move (removed, purged) snap update into a helper This is trivial at the moment, but we'll make it clever next. Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 28 +++++++++++++++++++--------- src/mon/OSDMonitor.h | 7 +++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index e7c7aeeb7dc..982b92acfc5 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -1582,21 +1582,18 @@ void OSDMonitor::encode_pending(MonitorDBStore::TransactionRef t) for (auto q = i.second.begin(); q != i.second.end(); ++q) { - bufferlist v; - string k = make_removed_snap_key_value(i.first, q.get_start(), - q.get_len(), pending_inc.epoch, &v); - t->put(OSD_SNAP_PREFIX, k, v); + insert_snap_update(false, i.first, q.get_start(), q.get_end(), + pending_inc.epoch, + t); } } for (auto& i : pending_inc.new_purged_snaps) { for (auto q = i.second.begin(); q != i.second.end(); ++q) { - bufferlist v; - string k = make_snap_purged_key_value(i.first, q.get_start(), - q.get_len(), pending_inc.epoch, - &v); - t->put(OSD_SNAP_PREFIX, k, v); + insert_snap_update(true, i.first, q.get_start(), q.get_end(), + pending_inc.epoch, + t); } } @@ -6271,6 +6268,19 @@ int OSDMonitor::_lookup_snap(bool purged, return 0; } +void OSDMonitor::insert_snap_update( + bool purged, + int64_t pool, + snapid_t start, snapid_t end, + epoch_t epoch, + MonitorDBStore::TransactionRef t) +{ + bufferlist v; + string k = _make_snap_key_value(purged, pool, start, end - start, + pending_inc.epoch, &v); + t->put(OSD_SNAP_PREFIX, k, v); +} + bool OSDMonitor::try_prune_purged_snaps() { if (!mon->mgrstatmon()->is_readable()) { diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index b7e40e2fa98..d797be0f916 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -536,6 +536,13 @@ private: return _lookup_snap(true, pool, snap, begin,end); } + void insert_snap_update( + bool purged, + int64_t pool, + snapid_t start, snapid_t end, + epoch_t epoch, + MonitorDBStore::TransactionRef t); + bool prepare_set_flag(MonOpRequestRef op, int flag); bool prepare_unset_flag(MonOpRequestRef op, int flag);