device-mapper-persistent-data/0016-thin_repair-thin_dump-Fix-sorting-of-data-mapping-ca.patch
2021-11-05 22:26:12 +01:00

73 lines
2.3 KiB
Diff

From 9388ab17da885dbd99d8b68217b282646ce9d73d Mon Sep 17 00:00:00 2001
From: Ming-Hung Tsai <mtsai@redhat.com>
Date: Mon, 16 Aug 2021 18:16:29 +0800
Subject: [PATCH 1/3] [thin_repair/thin_dump] Fix sorting of data mapping
candidates
- Fix the references for sorting. The timestamp statistics is stored
in node_info corresponding to the second element.
- Fix the timestamp comparison routine. The mapping root with more recent
blocks should have higher priority.
(cherry picked from commit 371df963113e7af7b97d2158757e35c44804ccb4)
---
thin-provisioning/metadata_dumper.cc | 37 +++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc
index 665c762..37c6969 100644
--- a/thin-provisioning/metadata_dumper.cc
+++ b/thin-provisioning/metadata_dumper.cc
@@ -252,26 +252,33 @@ namespace {
bool cmp_time_counts(pair<node_info, node_info> const &lhs_pair,
pair<node_info, node_info> const &rhs_pair) {
- auto const &lhs = lhs_pair.first.time_counts;
- auto const &rhs = rhs_pair.first.time_counts;
+ auto const &lhs = lhs_pair.second.time_counts;
+ auto const &rhs = rhs_pair.second.time_counts;
- for (auto lhs_it = lhs.crbegin(); lhs_it != lhs.crend(); lhs_it++) {
- for (auto rhs_it = rhs.crbegin(); rhs_it != rhs.crend(); rhs_it++) {
- if (lhs_it->first > rhs_it->first)
- return true;
- else if (rhs_it->first > lhs_it->first)
- return false;
+ auto lhs_it = lhs.crbegin();
+ auto rhs_it = rhs.crbegin();
+ while (lhs_it != lhs.crend() && rhs_it != rhs.crend()) {
- else if (lhs_it->second > rhs_it->second)
- return true;
+ auto lhs_time = lhs_it->first;
+ auto rhs_time = rhs_it->first;
+ auto lhs_count = lhs_it->second;
+ auto rhs_count = rhs_it->second;
- else if (rhs_it->second > lhs_it->second)
- return false;
- }
- }
+ if (lhs_time > rhs_time)
+ return true;
+ else if (rhs_time > lhs_time)
+ return false;
+ else if (lhs_count > rhs_count)
+ return true;
+ else if (rhs_count > lhs_count)
+ return false;
+
+ lhs_it++;
+ rhs_it++;
+ }
- return true;
+ return (lhs_it != lhs.crend()) ? true : false;
}
class gatherer {
--
1.8.3.1