From: myoungwon oh Date: Sat, 17 Sep 2022 07:11:49 +0000 (+0900) Subject: ceph_dedup_tool: fix threshold comparison X-Git-Tag: v18.0.0~6^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F45369%2Fhead;p=ceph.git ceph_dedup_tool: fix threshold comparison If threadhold count is 2, existing code always returns true even though reference count is 1 actually because it additionally adds one via ++. Signed-off-by: Myoungwon Oh --- diff --git a/src/tools/ceph_dedup_tool.cc b/src/tools/ceph_dedup_tool.cc index e95aad68aaca..f3c942a97604 100644 --- a/src/tools/ceph_dedup_tool.cc +++ b/src/tools/ceph_dedup_tool.cc @@ -561,13 +561,13 @@ public: bool add(chunk_t& chunk) { std::unique_lock lock(fingerprint_lock); auto found_iter = fp_map.find(chunk.fingerprint); + ssize_t cur_reference = 1; if (found_iter == fp_map.end()) { - auto ret = fp_map.insert({chunk.fingerprint, 1}); - found_iter = ret.first; + fp_map.insert({chunk.fingerprint, 1}); + } else { + cur_reference = ++found_iter->second; } - auto &target = found_iter->second; - target++; - return target >= dedup_threshold && dedup_threshold != -1; + return cur_reference >= dedup_threshold && dedup_threshold != -1; } void init(size_t dedup_threshold_) {