Elffuss BraidHub

kikocis/java-driver public

Wait for binary port on ccm start

Motivation:

CCM checks for certain messages in the cassandra log, such as "Listening
for thrift clients..." on < 2.2 clusters.  It awaits this message or for
the start process to die before proceeding.  In our setup, we disable
thrift explicitly since we don't use it.

This works fine for Apache Cassandra, but not for DataStax Enterprise,
as the start process remains running indefinitely.

Modifications:

Instead of changing CCM, pass the --no-wait flag to CCM and wait for the
binary protocol port to be listening in CCMBridge as a condition to
exiting start.

Result:

DSE clusters less than 5.0 work with the test harness.
Changeset12df520b331ade4fd9d54eefdbdf59b161d11574ff9d5983f450a824b359d100
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-06 20:21 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-14 17:44 -06:00
Parentsded53c12ab71

Browse the files at this changeset

2 files changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +39 −6
@@ -34,8 +34,7 @@
3434 import java.util.regex.Matcher;
3535 import java.util.regex.Pattern;
3636
37-import static com.datastax.driver.core.TestUtils.executeNoFail;
38-import static com.datastax.driver.core.TestUtils.findAvailablePort;
37+import static com.datastax.driver.core.TestUtils.*;
3938
4039 public class CCMBridge implements CCMAccess {
4140
@@ -236,7 +235,9 @@
236235
237236 private boolean closed = false;
238237
239- private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs) {
238+ private final int[] nodes;
239+
240+ private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs, int[] nodes) {
240241 this.clusterName = clusterName;
241242 this.version = version;
242243 this.storagePort = storagePort;
@@ -244,6 +245,7 @@
244245 this.binaryPort = binaryPort;
245246 this.isDSE = isDSE;
246247 this.jvmArgs = jvmArgs;
248+ this.nodes = nodes;
247249 this.ccmDir = Files.createTempDir();
248250 }
249251
@@ -394,6 +396,21 @@
394396 logger.debug("Closed: {}", this);
395397 }
396398
399+ /**
400+ * Based on C* version, return the wait arguments.
401+ *
402+ * @return For C* 1.x, --wait-other-notice otherwise --no-wait
403+ */
404+ private String getStartWaitArguments() {
405+ // make a small exception for C* 1.2 as it has a bug where it starts listening on the binary
406+ // interface slightly before it joins the cluster.
407+ if (getCassandraVersion().startsWith("1.")) {
408+ return " --wait-other-notice";
409+ } else {
410+ return " --no-wait";
411+ }
412+ }
413+
397414 @Override
398415 public synchronized void start() {
399416 if (started)
@@ -401,11 +418,23 @@
401418 if (logger.isDebugEnabled())
402419 logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB());
403420 try {
404- String cmd = CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs;
421+ String cmd = CCM_COMMAND + " start " + jvmArgs + getStartWaitArguments();
405422 if (isWindows() && this.version.compareTo(VersionNumber.parse("2.2.4")) >= 0) {
406423 cmd += " --quiet-windows";
407424 }
408425 execute(cmd);
426+
427+ // Wait for binary interface on each node.
428+ int n = 1;
429+ for (int dc = 1; dc <= nodes.length; dc++) {
430+ int nodesInDc = nodes[dc - 1];
431+ for (int i = 0; i < nodesInDc; i++) {
432+ InetSocketAddress addr = new InetSocketAddress(ipOfNode(n), binaryPort);
433+ logger.debug("Waiting for binary protocol to show up for {}", addr);
434+ TestUtils.waitUntilPortIsUp(addr);
435+ n++;
436+ }
437+ }
409438 } catch (CCMException e) {
410439 logger.error("Could not start " + this, e);
411440 logger.error("CCM output:\n{}", e.getOut());
@@ -463,11 +492,15 @@
463492 public void start(int n) {
464493 logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
465494 try {
466- String cmd = CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs;
495+ String cmd = CCM_COMMAND + " node%d start " + jvmArgs + getStartWaitArguments();
467496 if (isWindows() && this.version.compareTo(VersionNumber.parse("2.2.4")) >= 0) {
468497 cmd += " --quiet-windows";
469498 }
470499 execute(cmd, n);
500+ // Wait for binary interface
501+ InetSocketAddress addr = new InetSocketAddress(ipOfNode(n), binaryPort);
502+ logger.debug("Waiting for binary protocol to show up for {}", addr);
503+ TestUtils.waitUntilPortIsUp(addr);
471504 } catch (CCMException e) {
472505 logger.error(String.format("Could not start node %s in %s", n, this), e);
473506 logger.error("CCM output:\n{}", e.getOut());
@@ -875,7 +908,7 @@
875908 int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString());
876909 int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString());
877910 int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString());
878- final CCMBridge ccm = new CCMBridge(clusterName, dse, version, storagePort, thriftPort, binaryPort, joinJvmArgs());
911+ final CCMBridge ccm = new CCMBridge(clusterName, dse, version, storagePort, thriftPort, binaryPort, joinJvmArgs(), nodes);
879912
880913 Runtime.getRuntime().addShutdownHook(new Thread() {
881914 @Override
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +0 −6
@@ -919,12 +919,6 @@
919919 }
920920 LOGGER.debug("Using {}", ccm);
921921 }
922-
923- // Check to ensure binary protocol is listening before proceeding.
924- for (InetSocketAddress node : getContactPointsWithPorts()) {
925- LOGGER.debug("Waiting for binary protocol to show up for {}", node);
926- TestUtils.waitUntilPortIsUp(node);
927- }
928922 }
929923
930924 protected void initTestCluster(Object testInstance) throws Exception {