Blame SOURCES/0016-thin_repair-thin_dump-Fix-sorting-of-data-mapping-ca.patch

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