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

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