Github user jolynch commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/283#discussion_r236763554
--- Diff: test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java ---
@@ -60,57 +130,229 @@ private static EndpointsForRange full(InetAddressAndPort... endpoints)
}
@Test
- public void testSnitch() throws InterruptedException, IOException, ConfigurationException
+ public void testSortedByProximity() throws InterruptedException, IOException, ConfigurationException
{
- // do this because SS needs to be initialized before DES can work properly.
- StorageService.instance.unsafeInitialize();
- SimpleSnitch ss = new SimpleSnitch();
- DynamicEndpointSnitch dsnitch = new DynamicEndpointSnitch(ss, String.valueOf(ss.hashCode()));
- InetAddressAndPort self = FBUtilities.getBroadcastAddressAndPort();
- InetAddressAndPort host1 = InetAddressAndPort.getByName("127.0.0.2");
- InetAddressAndPort host2 = InetAddressAndPort.getByName("127.0.0.3");
- InetAddressAndPort host3 = InetAddressAndPort.getByName("127.0.0.4");
- InetAddressAndPort host4 = InetAddressAndPort.getByName("127.0.0.5");
- List<InetAddressAndPort> hosts = Arrays.asList(host1, host2, host3);
+ InetAddressAndPort self = hosts[0];
+ List<InetAddressAndPort> allHosts = Arrays.asList(hosts[1], hosts[2], hosts[3]);
// first, make all hosts equal
- setScores(dsnitch, 1, hosts, 10, 10, 10);
- EndpointsForRange order = full(host1, host2, host3);
- Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(host1, host2,
host3)));
-
- // make host1 a little worse
- setScores(dsnitch, 1, hosts, 20, 10, 10);
- order = full(host2, host3, host1);
- Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(host1, host2,
host3)));
-
- // make host2 as bad as host1
- setScores(dsnitch, 2, hosts, 15, 20, 10);
- order = full(host3, host1, host2);
- Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(host1, host2,
host3)));
-
- // make host3 the worst
- setScores(dsnitch, 3, hosts, 10, 10, 30);
- order = full(host1, host2, host3);
- Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(host1, host2,
host3)));
-
- // make host3 equal to the others
- setScores(dsnitch, 5, hosts, 10, 10, 10);
- order = full(host1, host2, host3);
- Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(host1, host2,
host3)));
+ setScores(dsnitch, 1, allHosts, 10, 10, 10);
+ EndpointsForRange order = full(hosts[1], hosts[2], hosts[3]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3])));
+
+ // make hosts[1] a little worse
+ setScores(dsnitch, 2, allHosts, 20, 10, 10);
+ order = full(hosts[2], hosts[3], hosts[1]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3])));
+
+ // make hosts[2] as bad as hosts[1]
+ setScores(dsnitch, 4, allHosts, 15, 20, 10);
+ order = full(hosts[3], hosts[1], hosts[2]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3])));
+
+ // make hosts[3] the worst
+ setScores(dsnitch, 10, allHosts, 10, 10, 30);
+ order = full(hosts[1], hosts[2], hosts[3]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3])));
+
+ // make hosts[3] equal to the others
+ setScores(dsnitch, 15, allHosts, 10, 10, 10);
+ order = full(hosts[1], hosts[2], hosts[3]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3])));
/// Tests CASSANDRA-6683 improvements
// make the scores differ enough from the ideal order that we sort by score;
under the old
// dynamic snitch behavior (where we only compared neighbors), these wouldn't
get sorted
- setScores(dsnitch, 20, hosts, 10, 70, 20);
- order = full(host1, host3, host2);
- Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(host1, host2,
host3)));
+ dsnitch.reset();
+ setScores(dsnitch, 20, allHosts, 10, 70, 20);
+ order = full(hosts[1], hosts[3], hosts[2]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3])));
+
+ order = full(hosts[4], hosts[1], hosts[3], hosts[2]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3], hosts[4])));
+
+ setScores(dsnitch, 40, allHosts, 10, 10, 11);
+ order = full(hosts[4], hosts[1], hosts[2], hosts[3]);
+ Util.assertRCEquals(order, dsnitch.sortedByProximity(self, full(hosts[1], hosts[2],
hosts[3], hosts[4])));
+ }
+
+ // CASSANDRA-14459 improvements to add latency probes instead of resets
+ @Test
+ public void testLatencyProbeNeeded()
+ {
+ InetAddressAndPort self = hosts[0];
+
+ // Four hosts, two are very latent, but all are requested for ranking
+ dsnitch.receiveTiming(hosts[1], 20, LatencyMeasurementType.READ);
+ dsnitch.receiveTiming(hosts[2], 10, LatencyMeasurementType.READ);
+ dsnitch.receiveTiming(hosts[3], 1000, LatencyMeasurementType.READ);
+ dsnitch.receiveTiming(hosts[4], 1000, LatencyMeasurementType.READ);
+ dsnitch.updateScores();
+
+ EndpointsForRange orderBefore = full(hosts[2], hosts[1], hosts[3], hosts[4]);
+
+ Map<InetAddressAndPort, DynamicEndpointSnitch.AnnotatedMeasurement> measurements
= dsnitch.getMeasurementsWithPort();
+ // At this point we haven't ranked any of hosts so we should need no probes even
+ DynamicEndpointSnitch.calculateProbes(measurements, dsnitch.dynamicLatencyProbeInterval);
+ assertFalse(measurements.values().stream().anyMatch(m -> m.probeTimerMillis
> 0));
+ assertTrue(measurements.values().stream().allMatch(m -> m.probeFuture == null));
+
+ // Two hosts continue receiving traffic but the last two are always ranked by
the snitch
+ for (int i = 0; i < 10; i++)
+ {
+ dsnitch.receiveTiming(hosts[1], 20, LatencyMeasurementType.READ);
+ dsnitch.receiveTiming(hosts[2], 10, LatencyMeasurementType.READ);
+ Util.assertRCEquals(orderBefore, dsnitch.sortedByProximity(self, full(hosts[1],
hosts[2], hosts[3], hosts[4])));
--- End diff --
It shouldn't change, I'm mostly just calling that for the `sortedByProximity` call (might
as well check the return value while we're calling it).
I added in a call to `dsnitch.updateScores()` after the `receiveTimings` just to double
triple check.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
|