Elffuss BraidHub

kikocis/java-driver public

Make schema agreement wait tuneable (JAVA-507).
Changeset8aa079df356d4d52a1e73fe2143a367a2bc038bde0953c46e428d7f00e224af6
Authorolim7t <omichallat+github@gmail.com> · 2014-10-16 11:47 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-16 11:59 +02:00
Parents2c287791e3c8

Browse the files at this changeset

4 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -18,6 +18,7 @@
1818 - [improvement] Log datacenter name in DCAware policy's init when it is explicitly provided
1919 (JAVA-423)
2020 - [improvement] Shuffle the replicas in TokenAwarePolicy.newQueryPlan (JAVA-504)
21+- [improvement] Make schema agreement wait tuneable (JAVA-507)
2122
2223
2324 2.0.6:
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +21 −2
@@ -538,6 +538,7 @@
538538 private final List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
539539 private final List<InetAddress> rawAddresses = new ArrayList<InetAddress>();
540540 private int port = ProtocolOptions.DEFAULT_PORT;
541+ private int maxSchemaAgreementWaitSeconds = ProtocolOptions.DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS;
541542 private int protocolVersion = -1;
542543 private AuthProvider authProvider = AuthProvider.NONE;
543544
@@ -608,6 +609,24 @@
608609 return this;
609610 }
610611
612+ /**
613+ * Sets the maximum time to wait for schema agreement before returning from a DDL query.
614+ * <p>
615+ * If not set through this method, the default value (10 seconds) will be used.
616+ *
617+ * @param maxSchemaAgreementWaitSeconds the new value to set.
618+ * @return this Builder.
619+ *
620+ * @throws IllegalStateException if the provided value is zero or less.
621+ */
622+ public Builder withMaxSchemaAgreementWaitSeconds(int maxSchemaAgreementWaitSeconds) {
623+ if (maxSchemaAgreementWaitSeconds <= 0)
624+ throw new IllegalArgumentException("Max schema agreement wait must be greater than zero");
625+
626+ this.maxSchemaAgreementWaitSeconds = maxSchemaAgreementWaitSeconds;
627+ return this;
628+ }
629+
611630 /**
612631 * The native protocol version to use.
613632 * <p>
@@ -1012,7 +1031,7 @@
10121031 addressTranslater == null ? Policies.defaultAddressTranslater() : addressTranslater
10131032 );
10141033 return new Configuration(policies,
1015- new ProtocolOptions(port, protocolVersion, sslOptions, authProvider).setCompression(compression),
1034+ new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider).setCompression(compression),
10161035 poolingOptions == null ? new PoolingOptions() : poolingOptions,
10171036 socketOptions == null ? new SocketOptions() : socketOptions,
10181037 metricsEnabled ? new MetricsOptions(jmxEnabled) : null,
@@ -1870,7 +1889,7 @@
18701889 // Before refreshing the schema, wait for schema agreement so
18711890 // that querying a table just after having created it don't fail.
18721891 if (!ControlConnection.waitForSchemaAgreement(connection, Cluster.Manager.this))
1873- logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", ControlConnection.MAX_SCHEMA_AGREEMENT_WAIT_SECONDS);
1892+ logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds());
18741893 ControlConnection.refreshSchema(connection, keyspace, table, Cluster.Manager.this, false);
18751894 } catch (Exception e) {
18761895 logger.error("Error during schema refresh ({}). The schema from Cluster.getMetadata() might appear stale. Asynchronously submitting job to fix.", e.getMessage());
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +2 −4
@@ -36,9 +36,6 @@
3636
3737 private static final Logger logger = LoggerFactory.getLogger(ControlConnection.class);
3838
39- // TODO: we might want to expose that through the API
40- static final int MAX_SCHEMA_AGREEMENT_WAIT_SECONDS = SystemProperties.getInt("com.datastax.driver.MAX_SCHEMA_AGREEMENT_WAIT_SECONDS", 10);
41-
4239 private static final InetAddress bindAllAddress;
4340 static
4441 {
@@ -566,7 +563,8 @@
566563
567564 long start = System.nanoTime();
568565 long elapsed = 0;
569- while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_SECONDS * 1000) {
566+ int maxSchemaAgreementWaitSeconds = cluster.configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds();
567+ while (elapsed < maxSchemaAgreementWaitSeconds * 1000) {
570568
571569 DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_PEERS));
572570 DefaultResultSetFuture localFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_LOCAL));
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolOptions.java +19 −7
@@ -15,16 +15,11 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import org.slf4j.Logger;
19-import org.slf4j.LoggerFactory;
20-
2118 /**
2219 * Options of the Cassandra native binary protocol.
2320 */
2421 public class ProtocolOptions {
2522
26- private static final Logger logger = LoggerFactory.getLogger(ProtocolOptions.class);
27-
2823 /**
2924 * Compression supported by the Cassandra binary protocol.
3025 */
@@ -67,11 +62,18 @@
6762 */
6863 public static final int DEFAULT_PORT = 9042;
6964
65+ /**
66+ * The default value for {@link #getMaxSchemaAgreementWaitSeconds()}: 10.
67+ */
68+ public static final int DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS = 10;
69+
7070 private volatile Cluster.Manager manager;
7171
7272 private final int port;
7373 final int initialProtocolVersion; // What the user asked us. Will be -1 by default.
7474
75+ private final int maxSchemaAgreementWaitSeconds;
76+
7577 private final SSLOptions sslOptions; // null if no SSL
7678 private final AuthProvider authProvider;
7779
@@ -94,7 +96,7 @@
9496 * @param port the port to use for the binary protocol.
9597 */
9698 public ProtocolOptions(int port) {
97- this(port, -1, null, AuthProvider.NONE);
99+ this(port, -1, DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS, null, AuthProvider.NONE);
98100 }
99101
100102 /**
@@ -111,9 +113,10 @@
111113 * @param authProvider the {@code AuthProvider} to use for authentication against
112114 * the Cassandra nodes.
113115 */
114- public ProtocolOptions(int port, int protocolVersion, SSLOptions sslOptions, AuthProvider authProvider) {
116+ public ProtocolOptions(int port, int protocolVersion, int maxSchemaAgreementWaitSeconds, SSLOptions sslOptions, AuthProvider authProvider) {
115117 this.port = port;
116118 this.initialProtocolVersion = protocolVersion;
119+ this.maxSchemaAgreementWaitSeconds = maxSchemaAgreementWaitSeconds;
117120 this.sslOptions = sslOptions;
118121 this.authProvider = authProvider;
119122
@@ -181,6 +184,15 @@
181184 return this;
182185 }
183186
187+ /**
188+ * Returns the maximum time to wait for schema agreement before returning from a DDL query.
189+ *
190+ * @return the time.
191+ */
192+ public int getMaxSchemaAgreementWaitSeconds() {
193+ return maxSchemaAgreementWaitSeconds;
194+ }
195+
184196 /**
185197 * The {@code SSLOptions} used by this cluster.
186198 *