kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 8aa079df356d4d52a1e73fe2143a367a2bc038bde0953c46e428d7f00e224af6 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-16 11:47 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-16 11:59 +02:00 |
| Parents | 2c287791e3c8 |
4 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | - [improvement] Log datacenter name in DCAware policy's init when it is explicitly provided |
| 19 | 19 | (JAVA-423) |
| 20 | 20 | - [improvement] Shuffle the replicas in TokenAwarePolicy.newQueryPlan (JAVA-504) |
| 21 | +- [improvement] Make schema agreement wait tuneable (JAVA-507) | |
| 21 | 22 | |
| 22 | 23 | |
| 23 | 24 | 2.0.6: |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +21 −2
| @@ -538,6 +538,7 @@ | ||
| 538 | 538 | private final List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(); |
| 539 | 539 | private final List<InetAddress> rawAddresses = new ArrayList<InetAddress>(); |
| 540 | 540 | private int port = ProtocolOptions.DEFAULT_PORT; |
| 541 | + private int maxSchemaAgreementWaitSeconds = ProtocolOptions.DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS; | |
| 541 | 542 | private int protocolVersion = -1; |
| 542 | 543 | private AuthProvider authProvider = AuthProvider.NONE; |
| 543 | 544 | |
| @@ -608,6 +609,24 @@ | ||
| 608 | 609 | return this; |
| 609 | 610 | } |
| 610 | 611 | |
| 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 | + | |
| 611 | 630 | /** |
| 612 | 631 | * The native protocol version to use. |
| 613 | 632 | * <p> |
| @@ -1012,7 +1031,7 @@ | ||
| 1012 | 1031 | addressTranslater == null ? Policies.defaultAddressTranslater() : addressTranslater |
| 1013 | 1032 | ); |
| 1014 | 1033 | return new Configuration(policies, |
| 1015 | - new ProtocolOptions(port, protocolVersion, sslOptions, authProvider).setCompression(compression), | |
| 1034 | + new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider).setCompression(compression), | |
| 1016 | 1035 | poolingOptions == null ? new PoolingOptions() : poolingOptions, |
| 1017 | 1036 | socketOptions == null ? new SocketOptions() : socketOptions, |
| 1018 | 1037 | metricsEnabled ? new MetricsOptions(jmxEnabled) : null, |
| @@ -1870,7 +1889,7 @@ | ||
| 1870 | 1889 | // Before refreshing the schema, wait for schema agreement so |
| 1871 | 1890 | // that querying a table just after having created it don't fail. |
| 1872 | 1891 | 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()); | |
| 1874 | 1893 | ControlConnection.refreshSchema(connection, keyspace, table, Cluster.Manager.this, false); |
| 1875 | 1894 | } catch (Exception e) { |
| 1876 | 1895 | 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 @@ | ||
| 36 | 36 | |
| 37 | 37 | private static final Logger logger = LoggerFactory.getLogger(ControlConnection.class); |
| 38 | 38 | |
| 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 | - | |
| 42 | 39 | private static final InetAddress bindAllAddress; |
| 43 | 40 | static |
| 44 | 41 | { |
| @@ -566,7 +563,8 @@ | ||
| 566 | 563 | |
| 567 | 564 | long start = System.nanoTime(); |
| 568 | 565 | long elapsed = 0; |
| 569 | - while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_SECONDS * 1000) { | |
| 566 | + int maxSchemaAgreementWaitSeconds = cluster.configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds(); | |
| 567 | + while (elapsed < maxSchemaAgreementWaitSeconds * 1000) { | |
| 570 | 568 | |
| 571 | 569 | DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_PEERS)); |
| 572 | 570 | 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 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import org.slf4j.Logger; | |
| 19 | -import org.slf4j.LoggerFactory; | |
| 20 | - | |
| 21 | 18 | /** |
| 22 | 19 | * Options of the Cassandra native binary protocol. |
| 23 | 20 | */ |
| 24 | 21 | public class ProtocolOptions { |
| 25 | 22 | |
| 26 | - private static final Logger logger = LoggerFactory.getLogger(ProtocolOptions.class); | |
| 27 | - | |
| 28 | 23 | /** |
| 29 | 24 | * Compression supported by the Cassandra binary protocol. |
| 30 | 25 | */ |
| @@ -67,11 +62,18 @@ | ||
| 67 | 62 | */ |
| 68 | 63 | public static final int DEFAULT_PORT = 9042; |
| 69 | 64 | |
| 65 | + /** | |
| 66 | + * The default value for {@link #getMaxSchemaAgreementWaitSeconds()}: 10. | |
| 67 | + */ | |
| 68 | + public static final int DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS = 10; | |
| 69 | + | |
| 70 | 70 | private volatile Cluster.Manager manager; |
| 71 | 71 | |
| 72 | 72 | private final int port; |
| 73 | 73 | final int initialProtocolVersion; // What the user asked us. Will be -1 by default. |
| 74 | 74 | |
| 75 | + private final int maxSchemaAgreementWaitSeconds; | |
| 76 | + | |
| 75 | 77 | private final SSLOptions sslOptions; // null if no SSL |
| 76 | 78 | private final AuthProvider authProvider; |
| 77 | 79 | |
| @@ -94,7 +96,7 @@ | ||
| 94 | 96 | * @param port the port to use for the binary protocol. |
| 95 | 97 | */ |
| 96 | 98 | public ProtocolOptions(int port) { |
| 97 | - this(port, -1, null, AuthProvider.NONE); | |
| 99 | + this(port, -1, DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS, null, AuthProvider.NONE); | |
| 98 | 100 | } |
| 99 | 101 | |
| 100 | 102 | /** |
| @@ -111,9 +113,10 @@ | ||
| 111 | 113 | * @param authProvider the {@code AuthProvider} to use for authentication against |
| 112 | 114 | * the Cassandra nodes. |
| 113 | 115 | */ |
| 114 | - public ProtocolOptions(int port, int protocolVersion, SSLOptions sslOptions, AuthProvider authProvider) { | |
| 116 | + public ProtocolOptions(int port, int protocolVersion, int maxSchemaAgreementWaitSeconds, SSLOptions sslOptions, AuthProvider authProvider) { | |
| 115 | 117 | this.port = port; |
| 116 | 118 | this.initialProtocolVersion = protocolVersion; |
| 119 | + this.maxSchemaAgreementWaitSeconds = maxSchemaAgreementWaitSeconds; | |
| 117 | 120 | this.sslOptions = sslOptions; |
| 118 | 121 | this.authProvider = authProvider; |
| 119 | 122 | |
| @@ -181,6 +184,15 @@ | ||
| 181 | 184 | return this; |
| 182 | 185 | } |
| 183 | 186 | |
| 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 | + | |
| 184 | 196 | /** |
| 185 | 197 | * The {@code SSLOptions} used by this cluster. |
| 186 | 198 | * |