ifesdjeen commented on code in PR #3506:
URL: https://github.com/apache/cassandra/pull/3506#discussion_r1757224677


##########
src/java/org/apache/cassandra/journal/Segments.java:
##########
@@ -68,27 +71,34 @@ Segments<K, V> withCompletedSegment(ActiveSegment<K, V> 
activeSegment, StaticSeg
         return new Segments<>(newSegments);
     }
 
-    Segments<K, V> withCompactedSegment(StaticSegment<K, V> oldSegment, 
StaticSegment<K, V> newSegment)
+    Segments<K, V> withCompactedSegments(Collection<StaticSegment<K, V>> 
oldSegments, Collection<StaticSegment<K, V>> compactedSegments)
     {
-        Invariants.checkArgument(oldSegment.descriptor.timestamp == 
newSegment.descriptor.timestamp);
-        Invariants.checkArgument(oldSegment.descriptor.generation < 
newSegment.descriptor.generation);
         Long2ObjectHashMap<Segment<K, V>> newSegments = new 
Long2ObjectHashMap<>(segments);
-        Segment<K, V> oldValue = 
newSegments.put(newSegment.descriptor.timestamp, newSegment);
-        Invariants.checkState(oldValue == oldSegment);
+        for (StaticSegment<K, V> oldSegment : oldSegments)
+        {
+            Segment<K, V> oldValue = 
newSegments.remove(oldSegment.descriptor.timestamp);
+            Invariants.checkState(oldValue == oldSegment);
+        }
+
+        for (StaticSegment<K, V> compactedSegment : compactedSegments)
+        {
+            Segment<K, V> oldValue = 
newSegments.put(compactedSegment.descriptor.timestamp, compactedSegment);
+            Invariants.checkState(oldValue == null);
+        }
+
         return new Segments<>(newSegments);
     }
 
-    Segments<K, V> withoutInvalidatedSegment(StaticSegment<K, V> staticSegment)
+    boolean contains(long descriptor)
     {
-        Long2ObjectHashMap<Segment<K, V>> newSegments = new 
Long2ObjectHashMap<>(segments);
-        if (!newSegments.remove(staticSegment.descriptor.timestamp, 
staticSegment))
-            throw new IllegalStateException();
-        return new Segments<>(newSegments);
+        return segments.containsKey(descriptor);
     }
 
     Iterable<Segment<K, V>> all()
     {
-        return segments.values();
+        List<Segment<K, V>> segments = new ArrayList<>(this.segments.values());

Review Comment:
   Made a separate method that allocates and sorts. 



-- 
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