From a72094d5040144c3e1680cf6444e73a4532f00c9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 4 Dec 2013 14:41:40 -0800 Subject: [PATCH] osd/HitSet: take Params as const ref to avoid confusion about ownership Signed-off-by: Sage Weil --- src/osd/HitSet.cc | 14 +++++++++----- src/osd/HitSet.h | 5 +++-- src/osd/ReplicatedPG.cc | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/osd/HitSet.cc b/src/osd/HitSet.cc index fb9348c8fb4ef..e38ba549972a2 100644 --- a/src/osd/HitSet.cc +++ b/src/osd/HitSet.cc @@ -16,19 +16,23 @@ // -- HitSet -- -HitSet::HitSet(HitSet::Params *params) +HitSet::HitSet(const HitSet::Params& params) { - switch (params->get_type()) { + switch (params.get_type()) { case TYPE_BLOOM: - impl.reset(new BloomHitSet(static_cast(params->impl.get()))); + { + BloomHitSet::Params *p = + static_cast(params.impl.get()); + impl.reset(new BloomHitSet(p)); + } break; case TYPE_EXPLICIT_HASH: - impl.reset(new ExplicitHashHitSet(static_cast(params->impl.get()))); + impl.reset(new ExplicitHashHitSet(static_cast(params.impl.get()))); break; case TYPE_EXPLICIT_OBJECT: - impl.reset(new ExplicitObjectHitSet(static_cast(params->impl.get()))); + impl.reset(new ExplicitObjectHitSet(static_cast(params.impl.get()))); break; case TYPE_NONE: diff --git a/src/osd/HitSet.h b/src/osd/HitSet.h index bb8fa1ec3be82..ace4d052a1b71 100644 --- a/src/osd/HitSet.h +++ b/src/osd/HitSet.h @@ -115,7 +115,7 @@ public: HitSet() : impl(NULL), sealed(false) {} HitSet(Impl *i) : impl(i), sealed(false) {} - HitSet(HitSet::Params *params); + HitSet(const HitSet::Params& params); HitSet(const HitSet& o) { sealed = o.sealed; @@ -349,7 +349,8 @@ public: uint64_t target_size; ///< number of unique insertions we expect to this HitSet uint64_t seed; ///< seed to use when initializing the bloom filter - Params() : false_positive(0), target_size(0), seed(0) {} + Params() + : false_positive(0), target_size(0), seed(0) {} Params(double fpp, uint64_t t, uint64_t s) : false_positive(fpp), target_size(t), seed(s) {} Params(const Params &o) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index e140f7e86c187..26c0a6cd86417 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -8503,11 +8503,12 @@ void ReplicatedPG::hit_set_create() { utime_t now = ceph_clock_now(NULL); // make a copy of the params to modify - HitSet::Params *params = new HitSet::Params(pool.info.hit_set_params); + HitSet::Params params(pool.info.hit_set_params); if (pool.info.hit_set_params.get_type() == HitSet::TYPE_BLOOM) { BloomHitSet::Params *p = - static_cast(params->impl.get()); + static_cast(params.impl.get()); + dout(20) << __func__ << " " << params << " " << p << dendl; // convert false positive rate so it holds up across the full period p->false_positive = p->false_positive / pool.info.hit_set_count; -- 2.39.5