[1/2] cassandra git commit: Fix MV replica filtering for non-NetworkTopologyStrategy

2015-11-05 Thread aleksey
Repository: cassandra
Updated Branches:
  refs/heads/trunk c3678f6b6 -> bc674c1c8


Fix MV replica filtering for non-NetworkTopologyStrategy

patch by Joel Knighton; reviewed by Carl Yeksigian for CASSANDRA-10634


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

Branch: refs/heads/trunk
Commit: 1bd2c94252b52d99b0c49257d2365f7c85935dcd
Parents: 4db577a
Author: Joel Knighton 
Authored: Mon Nov 2 15:21:11 2015 -0600
Committer: Aleksey Yeschenko 
Committed: Thu Nov 5 23:04:20 2015 +

--
 CHANGES.txt |  1 +
 .../org/apache/cassandra/db/view/ViewUtils.java | 31 
 2 files changed, 19 insertions(+), 13 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1bd2c942/CHANGES.txt
--
diff --git a/CHANGES.txt b/CHANGES.txt
index b469594..ce24c2b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0
+ * Fix MV replica filtering for non-NetworkTopologyStrategy (CASSANDRA-10634)
  * (Hadoop) fix CIF describeSplits() not handling 0 size estimates 
(CASSANDRA-10600)
  * Fix reading of legacy sstables (CASSANDRA-10590)
  * Use CQL type names in schema metadata tables (CASSANDRA-10365)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1bd2c942/src/java/org/apache/cassandra/db/view/ViewUtils.java
--
diff --git a/src/java/org/apache/cassandra/db/view/ViewUtils.java 
b/src/java/org/apache/cassandra/db/view/ViewUtils.java
index ebbae65..089a3b7 100644
--- a/src/java/org/apache/cassandra/db/view/ViewUtils.java
+++ b/src/java/org/apache/cassandra/db/view/ViewUtils.java
@@ -26,6 +26,7 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.Keyspace;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
+import org.apache.cassandra.locator.NetworkTopologyStrategy;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
 
@@ -38,9 +39,10 @@ public final class ViewUtils
 /**
  * Calculate the natural endpoint for the view.
  *
- * The view natural endpoint is the endpint which has the same cardinality 
as this node in the replication factor.
+ * The view natural endpoint is the endpoint which has the same 
cardinality as this node in the replication factor.
  * The cardinality is the number at which this node would store a piece of 
data, given the change in replication
- * factor.
+ * factor. If the keyspace's replication strategy is a 
NetworkTopologyStrategy, we filter the ring to contain only
+ * nodes in the local datacenter when calculating cardinality.
  *
  * For example, if we have the following ring:
  *   A, T1 -> B, T2 -> C, T3 -> A
@@ -61,12 +63,14 @@ public final class ViewUtils
 AbstractReplicationStrategy replicationStrategy = 
Keyspace.open(keyspaceName).getReplicationStrategy();
 
 String localDataCenter = 
DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
-List localBaseEndpoints = new ArrayList<>();
-List localViewEndpoints = new ArrayList<>();
+List baseEndpoints = new ArrayList<>();
+List viewEndpoints = new ArrayList<>();
 for (InetAddress baseEndpoint : 
replicationStrategy.getNaturalEndpoints(baseToken))
 {
-if 
(DatabaseDescriptor.getEndpointSnitch().getDatacenter(baseEndpoint).equals(localDataCenter))
-localBaseEndpoints.add(baseEndpoint);
+// An endpoint is local if we're not using Net
+if (!(replicationStrategy instanceof NetworkTopologyStrategy) ||
+
DatabaseDescriptor.getEndpointSnitch().getDatacenter(baseEndpoint).equals(localDataCenter))
+baseEndpoints.add(baseEndpoint);
 }
 
 for (InetAddress viewEndpoint : 
replicationStrategy.getNaturalEndpoints(viewToken))
@@ -77,17 +81,18 @@ public final class ViewUtils
 
 // We have to remove any endpoint which is shared between the base 
and the view, as it will select itself
 // and throw off the counts otherwise.
-if (localBaseEndpoints.contains(viewEndpoint))
-localBaseEndpoints.remove(viewEndpoint);
-else if 
(DatabaseDescriptor.getEndpointSnitch().getDatacenter(viewEndpoint).equals(localDataCenter))
-localViewEndpoints.add(viewEndpoint);
+if 

cassandra git commit: Fix MV replica filtering for non-NetworkTopologyStrategy

2015-11-05 Thread aleksey
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 4db577abf -> 1bd2c9425


Fix MV replica filtering for non-NetworkTopologyStrategy

patch by Joel Knighton; reviewed by Carl Yeksigian for CASSANDRA-10634


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

Branch: refs/heads/cassandra-3.0
Commit: 1bd2c94252b52d99b0c49257d2365f7c85935dcd
Parents: 4db577a
Author: Joel Knighton 
Authored: Mon Nov 2 15:21:11 2015 -0600
Committer: Aleksey Yeschenko 
Committed: Thu Nov 5 23:04:20 2015 +

--
 CHANGES.txt |  1 +
 .../org/apache/cassandra/db/view/ViewUtils.java | 31 
 2 files changed, 19 insertions(+), 13 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1bd2c942/CHANGES.txt
--
diff --git a/CHANGES.txt b/CHANGES.txt
index b469594..ce24c2b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0
+ * Fix MV replica filtering for non-NetworkTopologyStrategy (CASSANDRA-10634)
  * (Hadoop) fix CIF describeSplits() not handling 0 size estimates 
(CASSANDRA-10600)
  * Fix reading of legacy sstables (CASSANDRA-10590)
  * Use CQL type names in schema metadata tables (CASSANDRA-10365)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1bd2c942/src/java/org/apache/cassandra/db/view/ViewUtils.java
--
diff --git a/src/java/org/apache/cassandra/db/view/ViewUtils.java 
b/src/java/org/apache/cassandra/db/view/ViewUtils.java
index ebbae65..089a3b7 100644
--- a/src/java/org/apache/cassandra/db/view/ViewUtils.java
+++ b/src/java/org/apache/cassandra/db/view/ViewUtils.java
@@ -26,6 +26,7 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.Keyspace;
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
+import org.apache.cassandra.locator.NetworkTopologyStrategy;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
 
@@ -38,9 +39,10 @@ public final class ViewUtils
 /**
  * Calculate the natural endpoint for the view.
  *
- * The view natural endpoint is the endpint which has the same cardinality 
as this node in the replication factor.
+ * The view natural endpoint is the endpoint which has the same 
cardinality as this node in the replication factor.
  * The cardinality is the number at which this node would store a piece of 
data, given the change in replication
- * factor.
+ * factor. If the keyspace's replication strategy is a 
NetworkTopologyStrategy, we filter the ring to contain only
+ * nodes in the local datacenter when calculating cardinality.
  *
  * For example, if we have the following ring:
  *   A, T1 -> B, T2 -> C, T3 -> A
@@ -61,12 +63,14 @@ public final class ViewUtils
 AbstractReplicationStrategy replicationStrategy = 
Keyspace.open(keyspaceName).getReplicationStrategy();
 
 String localDataCenter = 
DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
-List localBaseEndpoints = new ArrayList<>();
-List localViewEndpoints = new ArrayList<>();
+List baseEndpoints = new ArrayList<>();
+List viewEndpoints = new ArrayList<>();
 for (InetAddress baseEndpoint : 
replicationStrategy.getNaturalEndpoints(baseToken))
 {
-if 
(DatabaseDescriptor.getEndpointSnitch().getDatacenter(baseEndpoint).equals(localDataCenter))
-localBaseEndpoints.add(baseEndpoint);
+// An endpoint is local if we're not using Net
+if (!(replicationStrategy instanceof NetworkTopologyStrategy) ||
+
DatabaseDescriptor.getEndpointSnitch().getDatacenter(baseEndpoint).equals(localDataCenter))
+baseEndpoints.add(baseEndpoint);
 }
 
 for (InetAddress viewEndpoint : 
replicationStrategy.getNaturalEndpoints(viewToken))
@@ -77,17 +81,18 @@ public final class ViewUtils
 
 // We have to remove any endpoint which is shared between the base 
and the view, as it will select itself
 // and throw off the counts otherwise.
-if (localBaseEndpoints.contains(viewEndpoint))
-localBaseEndpoints.remove(viewEndpoint);
-else if 
(DatabaseDescriptor.getEndpointSnitch().getDatacenter(viewEndpoint).equals(localDataCenter))
-localViewEndpoints.add(viewEndpoint);
+if