You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2013/09/20 18:49:14 UTC

[4/5] git commit: Replace Iterable->Collection in SSTCN

Replace Iterable->Collection in SSTCN

ninja-patch by Aleksey Yeschenko; ninja-reviewed by Jonathan Ellis


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/0d976a8f
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/0d976a8f
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/0d976a8f

Branch: refs/heads/trunk
Commit: 0d976a8fb57d6524e81a6a3033f7672e5b2be2ae
Parents: bcb4da7
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Fri Sep 20 19:43:15 2013 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Fri Sep 20 19:43:15 2013 +0300

----------------------------------------------------------------------
 .../apache/cassandra/db/ColumnFamilyStore.java  |  2 +-
 .../org/apache/cassandra/db/DataTracker.java    | 30 ++++++++------------
 .../db/compaction/LeveledManifest.java          |  8 +++---
 .../SSTableListChangedNotification.java         |  8 ++++--
 4 files changed, 22 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/0d976a8f/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
index 4c9f72d..1ff4832 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -1066,7 +1066,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean
         data.markObsolete(sstables, compactionType);
     }
 
-    public void replaceCompactedSSTables(Collection<SSTableReader> sstables, Iterable<SSTableReader> replacements, OperationType compactionType)
+    public void replaceCompactedSSTables(Collection<SSTableReader> sstables, Collection<SSTableReader> replacements, OperationType compactionType)
     {
         data.replaceCompactedSSTables(sstables, replacements, compactionType);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0d976a8f/src/java/org/apache/cassandra/db/DataTracker.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/DataTracker.java b/src/java/org/apache/cassandra/db/DataTracker.java
index e7d26b0..f30ec1e 100644
--- a/src/java/org/apache/cassandra/db/DataTracker.java
+++ b/src/java/org/apache/cassandra/db/DataTracker.java
@@ -44,14 +44,14 @@ public class DataTracker
 {
     private static final Logger logger = LoggerFactory.getLogger(DataTracker.class);
 
-    public final Collection<INotificationConsumer> subscribers = new CopyOnWriteArrayList<INotificationConsumer>();
+    public final Collection<INotificationConsumer> subscribers = new CopyOnWriteArrayList<>();
     public final ColumnFamilyStore cfstore;
     private final AtomicReference<View> view;
 
     public DataTracker(ColumnFamilyStore cfstore)
     {
         this.cfstore = cfstore;
-        this.view = new AtomicReference<View>();
+        this.view = new AtomicReference<>();
         this.init();
     }
 
@@ -231,7 +231,7 @@ public class DataTracker
         notifySSTablesChanged(sstables, Collections.<SSTableReader>emptyList(), compactionType);
     }
 
-    public void replaceCompactedSSTables(Collection<SSTableReader> sstables, Iterable<SSTableReader> replacements, OperationType compactionType)
+    public void replaceCompactedSSTables(Collection<SSTableReader> sstables, Collection<SSTableReader> replacements, OperationType compactionType)
     {
         replace(sstables, replacements);
         notifySSTablesChanged(sstables, replacements, compactionType);
@@ -285,15 +285,13 @@ public class DataTracker
     void removeUnreadableSSTables(File directory)
     {
         View currentView, newView;
-        List<SSTableReader> remaining = new ArrayList<SSTableReader>();
+        List<SSTableReader> remaining = new ArrayList<>();
         do
         {
             currentView = view.get();
             for (SSTableReader r : currentView.nonCompactingSStables())
-            {
                 if (!r.descriptor.directory.equals(directory))
                     remaining.add(r);
-            }
 
             if (remaining.size() == currentView.nonCompactingSStables().size())
                 return;
@@ -379,9 +377,7 @@ public class DataTracker
     {
         long n = 0;
         for (SSTableReader sstable : getSSTables())
-        {
             n += sstable.estimatedKeys();
-        }
         return n;
     }
 
@@ -415,13 +411,11 @@ public class DataTracker
         return 0;
     }
 
-    public void notifySSTablesChanged(Iterable<SSTableReader> removed, Iterable<SSTableReader> added, OperationType compactionType)
+    public void notifySSTablesChanged(Collection<SSTableReader> removed, Collection<SSTableReader> added, OperationType compactionType)
     {
+        INotification notification = new SSTableListChangedNotification(added, removed, compactionType);
         for (INotificationConsumer subscriber : subscribers)
-        {
-            INotification notification = new SSTableListChangedNotification(added, removed, compactionType);
             subscriber.handleNotification(notification, this);
-        }
     }
 
     public void notifyAdded(SSTableReader added)
@@ -451,7 +445,7 @@ public class DataTracker
 
     public static SSTableIntervalTree buildIntervalTree(Iterable<SSTableReader> sstables)
     {
-        List<Interval<RowPosition, SSTableReader>> intervals = new ArrayList<Interval<RowPosition, SSTableReader>>(Iterables.size(sstables));
+        List<Interval<RowPosition, SSTableReader>> intervals = new ArrayList<>(Iterables.size(sstables));
         for (SSTableReader sstable : sstables)
             intervals.add(Interval.<RowPosition, SSTableReader>create(sstable.first, sstable.last, sstable));
         return new SSTableIntervalTree(intervals);
@@ -519,8 +513,8 @@ public class DataTracker
         {
             Set<Memtable> newPending = ImmutableSet.copyOf(Sets.difference(memtablesPendingFlush, Collections.singleton(flushedMemtable)));
             Set<SSTableReader> newSSTables = newSSTable == null
-                                            ? sstables
-                                            : newSSTables(newSSTable);
+                                           ? sstables
+                                           : newSSTables(newSSTable);
             SSTableIntervalTree intervalTree = buildIntervalTree(newSSTables);
             return new View(memtable, newPending, newSSTables, compacting, intervalTree);
         }
@@ -556,12 +550,12 @@ public class DataTracker
             ImmutableSet<SSTableReader> oldSet = ImmutableSet.copyOf(oldSSTables);
             int newSSTablesSize = sstables.size() - oldSSTables.size() + Iterables.size(replacements);
             assert newSSTablesSize >= Iterables.size(replacements) : String.format("Incoherent new size %d replacing %s by %s in %s", newSSTablesSize, oldSSTables, replacements, this);
-            Set<SSTableReader> newSSTables = new HashSet<SSTableReader>(newSSTablesSize);
+            Set<SSTableReader> newSSTables = new HashSet<>(newSSTablesSize);
+
             for (SSTableReader sstable : sstables)
-            {
                 if (!oldSet.contains(sstable))
                     newSSTables.add(sstable);
-            }
+
             Iterables.addAll(newSSTables, replacements);
             assert newSSTables.size() == newSSTablesSize : String.format("Expecting new size of %d, got %d while replacing %s by %s in %s", newSSTablesSize, newSSTables.size(), oldSSTables, replacements, this);
             return ImmutableSet.copyOf(newSSTables);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0d976a8f/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java b/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
index bc6824a..82aa2d6 100644
--- a/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
+++ b/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java
@@ -127,9 +127,9 @@ public class LeveledManifest
         return newLevel;
     }
 
-    public synchronized void replace(Iterable<SSTableReader> removed, Iterable<SSTableReader> added)
+    public synchronized void replace(Collection<SSTableReader> removed, Collection<SSTableReader> added)
     {
-        assert !Iterables.isEmpty(removed); // use add() instead of promote when adding new sstables
+        assert !removed.isEmpty(); // use add() instead of promote when adding new sstables
         logDistribution();
         if (logger.isDebugEnabled())
             logger.debug("Replacing [" + toString(removed) + "]");
@@ -140,7 +140,7 @@ public class LeveledManifest
             remove(sstable);
 
         // it's valid to do a remove w/o an add (e.g. on truncate)
-        if (!added.iterator().hasNext())
+        if (added.isEmpty())
             return;
 
         if (logger.isDebugEnabled())
@@ -198,7 +198,7 @@ public class LeveledManifest
         }
     }
 
-    private String toString(Iterable<SSTableReader> sstables)
+    private String toString(Collection<SSTableReader> sstables)
     {
         StringBuilder builder = new StringBuilder();
         for (SSTableReader sstable : sstables)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0d976a8f/src/java/org/apache/cassandra/notifications/SSTableListChangedNotification.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/notifications/SSTableListChangedNotification.java b/src/java/org/apache/cassandra/notifications/SSTableListChangedNotification.java
index ca7ead9..c36583c 100644
--- a/src/java/org/apache/cassandra/notifications/SSTableListChangedNotification.java
+++ b/src/java/org/apache/cassandra/notifications/SSTableListChangedNotification.java
@@ -17,17 +17,19 @@
  */
 package org.apache.cassandra.notifications;
 
+import java.util.Collection;
+
 import org.apache.cassandra.io.sstable.SSTableReader;
 
 import org.apache.cassandra.db.compaction.OperationType;
 
 public class SSTableListChangedNotification implements INotification
 {
-    public final Iterable<SSTableReader> removed;
-    public final Iterable<SSTableReader> added;
+    public final Collection<SSTableReader> removed;
+    public final Collection<SSTableReader> added;
     public final OperationType compactionType;
 
-    public SSTableListChangedNotification(Iterable<SSTableReader> added, Iterable<SSTableReader> removed, OperationType compactionType)
+    public SSTableListChangedNotification(Collection<SSTableReader> added, Collection<SSTableReader> removed, OperationType compactionType)
     {
         this.removed = removed;
         this.added = added;