aweisberg commented on code in PR #3754:
URL: https://github.com/apache/cassandra/pull/3754#discussion_r1984159444


##########
src/java/org/apache/cassandra/db/lifecycle/View.java:
##########
@@ -353,4 +361,40 @@ public boolean apply(T t)
             }
         };
     }
+
+    // Match the SSTableReaders from the existing ones to the new one to be 
added (with same ranges)
+    // Returns the map of toRemove <-> toAdd. Return empty map if such 1-1 
replacement doesn't exist
+    private static Map<SSTableReader, SSTableReader> getReplacementMap(final 
Set<SSTableReader> remove, final Iterable<SSTableReader> add)
+    {
+        List<SSTableReader> toAdds = new ArrayList<>();
+        for (SSTableReader s : add)
+            toAdds.add(s);
+
+        if (remove.size() != toAdds.size())
+            return Collections.emptyMap();
+
+        List<SSTableReader> toRemoves = new ArrayList<>(remove);
+        // sort the SSTableReader list by (first, last, descriptor.id). The 
view is per cfs so id will be unique
+        Comparator<SSTableReader> comp = Comparator.comparing((SSTableReader 
s) -> s.first)
+                                                   .thenComparing(s -> s.last)
+                                                   
.thenComparing(SSTableReader.idComparator);
+        toRemoves.sort(comp);
+        toAdds.sort(comp);
+
+        Map<SSTableReader, SSTableReader> replacementMap = new HashMap<>();
+        // toAdd and toRemove have the same size
+        for (int i = 0; i < toAdds.size(); i++)
+        {
+            SSTableReader toRemove = toRemoves.get(i);
+            SSTableReader toAdd = toAdds.get(i);
+            // optimization: here we don't check the descriptor. If we're able 
to match those to be removed with those
+            // to be added, we ensure that the pairs have the same (first, 
last) range
+            if (toRemove.first.equals(toAdd.first) && 
toRemove.last.equals(toAdd.last))

Review Comment:
   How is this optimization safe? Multiple sstables can share the same first 
and last.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to