bereng commented on a change in pull request #870:
URL: https://github.com/apache/cassandra/pull/870#discussion_r568326365
##########
File path: src/java/org/apache/cassandra/dht/RangeStreamer.java
##########
@@ -353,9 +361,27 @@ public void addRanges(String keyspaceName,
ReplicaCollection<?> replicas)
*/
private boolean useStrictSourcesForRanges(AbstractReplicationStrategy
strat)
{
- return useStrictConsistency
- && tokens != null
- && metadata.getSizeOfAllEndpoints() !=
strat.getReplicationFactor().allReplicas;
+ boolean res = useStrictConsistency && tokens != null;
+
+ if (res)
+ {
+ int nodes = 0;
+
+ if (strat instanceof NetworkTopologyStrategy)
+ {
+ ImmutableMultimap<String, InetAddressAndPort> dc2Nodes =
metadata.getDC2AllEndpoints(snitch);
+
+ NetworkTopologyStrategy ntps = (NetworkTopologyStrategy) strat;
+ for (String dc : dc2Nodes.keySet())
+ nodes += ntps.getReplicationFactor(dc).allReplicas > 0 ?
dc2Nodes.get(dc).size() : 0;
+ }
+ else
+ nodes = metadata.getSizeOfAllEndpoints();
+
+ res = res && nodes > strat.getReplicationFactor().allReplicas;
Review comment:
I was thinking about branch prediction when writing that. Iirc from some
training an early return disables it so accumulating the result to return at
the end is preferable. You'd then want to keep `nodes` declaration inside the
branch to spare that cost when possible as well.
So I am removing the `res &&` bit indeed but the rest sgtm. Does it make
sense or am I being too far reached? This is not in the hot path iiuc so we may
want to favor readability :thinking:
##########
File path:
test/unit/org/apache/cassandra/cql3/validation/operations/CreateTest.java
##########
@@ -365,6 +372,31 @@ public void testKeyspace() throws Throwable
execute("DROP KEYSPACE testXYZ");
}
+ /**
+ * Test a warning is thrown on create keyspace with a RF > number of
nodes.
+ */
+ @Test
+ public void testCreateKeyspaceRFgtNodesWarns() throws Throwable
Review comment:
Ok found it. Without the network the test sees 0 nodes and that has been
short circuited. With the network we see the node and then the test passes. As
the other tests don't rely on the number of nodes to generate a warning they
pass without the network. Also I was using `test` instead of `testsome` ops!
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]