kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5c835f8a2f895d0760e1500ad9ebc7c0b93d916bdfedbdbe36e3fe8400892603 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-07-17 19:12 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-08-28 16:36 +02:00 |
| Parents | cd08308b3373 |
3 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +11 −7
| @@ -63,6 +63,10 @@ | ||
| 63 | 63 | |
| 64 | 64 | private static final Logger logger = LoggerFactory.getLogger(Cluster.class); |
| 65 | 65 | |
| 66 | + private static final int NEW_NODE_DELAY_SECONDS = SystemProperties.getInt("com.datastax.driver.NEW_NODE_DELAY_SECONDS", 1); | |
| 67 | + private static final int NON_BLOCKING_EXECUTOR_SIZE = SystemProperties.getInt("com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE", | |
| 68 | + Runtime.getRuntime().availableProcessors()); | |
| 69 | + | |
| 66 | 70 | // Some per-JVM number that allows to generate unique cluster names when |
| 67 | 71 | // multiple Cluster instance are created in the same JVM. |
| 68 | 72 | private static final AtomicInteger CLUSTER_ID = new AtomicInteger(0); |
| @@ -1112,7 +1116,7 @@ | ||
| 1112 | 1116 | this.configuration = configuration; |
| 1113 | 1117 | this.configuration.register(this); |
| 1114 | 1118 | |
| 1115 | - this.executor = makeExecutor(Runtime.getRuntime().availableProcessors(), "Cassandra Java Driver worker-%d"); | |
| 1119 | + this.executor = makeExecutor(NON_BLOCKING_EXECUTOR_SIZE, "Cassandra Java Driver worker-%d"); | |
| 1116 | 1120 | this.blockingExecutor = makeExecutor(2, "Cassandra Java Driver blocking tasks worker-%d"); |
| 1117 | 1121 | |
| 1118 | 1122 | this.reaper = new ConnectionReaper(); |
| @@ -1792,7 +1796,7 @@ | ||
| 1792 | 1796 | // Before refreshing the schema, wait for schema agreement so |
| 1793 | 1797 | // that querying a table just after having created it don't fail. |
| 1794 | 1798 | if (!ControlConnection.waitForSchemaAgreement(connection, Cluster.Manager.this)) |
| 1795 | - logger.warn("No schema agreement from live replicas after {} ms. The schema may not be up to date on some nodes.", ControlConnection.MAX_SCHEMA_AGREEMENT_WAIT_MS); | |
| 1799 | + 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); | |
| 1796 | 1800 | ControlConnection.refreshSchema(connection, keyspace, table, Cluster.Manager.this, false); |
| 1797 | 1801 | } catch (Exception e) { |
| 1798 | 1802 | logger.error("Error during schema refresh ({}). The schema from Cluster.getMetadata() might appear stale. Asynchronously submitting job to fix.", e.getMessage()); |
| @@ -1828,9 +1832,9 @@ | ||
| 1828 | 1832 | final Host newHost = metadata.add(tpAddr); |
| 1829 | 1833 | if (newHost != null) { |
| 1830 | 1834 | // Cassandra tends to send notifications for new/up nodes a bit early (it is triggered once |
| 1831 | - // gossip is up, but that is before the client-side server is up), so we add a somewhat random | |
| 1832 | - // 1 second delay (otherwise the connection will likely fail and have to be retry which is | |
| 1833 | - // wasteful). This probably should be fixed C* side, after which we'll be able to remove this. | |
| 1835 | + // gossip is up, but that is before the client-side server is up), so we add a delay | |
| 1836 | + // (otherwise the connection will likely fail and have to be retry which is wasteful). This | |
| 1837 | + // probably should be fixed C* side, after which we'll be able to remove this. | |
| 1834 | 1838 | scheduledTasksExecutor.schedule(new ExceptionCatchingRunnable() { |
| 1835 | 1839 | @Override |
| 1836 | 1840 | public void runMayThrow() throws InterruptedException, ExecutionException { |
| @@ -1842,7 +1846,7 @@ | ||
| 1842 | 1846 | logger.debug("Not enough info for {}, ignoring host", newHost); |
| 1843 | 1847 | } |
| 1844 | 1848 | } |
| 1845 | - }, 1, TimeUnit.SECONDS); | |
| 1849 | + }, NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); | |
| 1846 | 1850 | } |
| 1847 | 1851 | break; |
| 1848 | 1852 | case REMOVED_NODE: |
| @@ -1884,7 +1888,7 @@ | ||
| 1884 | 1888 | logger.debug("Not enough info for {}, ignoring host", h); |
| 1885 | 1889 | } |
| 1886 | 1890 | } |
| 1887 | - }, 1, TimeUnit.SECONDS); | |
| 1891 | + }, NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); | |
| 1888 | 1892 | } else { |
| 1889 | 1893 | executor.submit(new ExceptionCatchingRunnable() { |
| 1890 | 1894 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +3 −3
| @@ -36,8 +36,8 @@ | ||
| 36 | 36 | |
| 37 | 37 | private static final Logger logger = LoggerFactory.getLogger(ControlConnection.class); |
| 38 | 38 | |
| 39 | - // TODO: we might want to make that configurable | |
| 40 | - static final long MAX_SCHEMA_AGREEMENT_WAIT_MS = 10000; | |
| 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 | 41 | |
| 42 | 42 | private static final InetAddress bindAllAddress; |
| 43 | 43 | static |
| @@ -541,7 +541,7 @@ | ||
| 541 | 541 | |
| 542 | 542 | long start = System.nanoTime(); |
| 543 | 543 | long elapsed = 0; |
| 544 | - while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_MS) { | |
| 544 | + while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_SECONDS * 1000) { | |
| 545 | 545 | |
| 546 | 546 | DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_PEERS)); |
| 547 | 547 | DefaultResultSetFuture localFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_LOCAL)); |
added driver-core/src/main/java/com/datastax/driver/core/SystemProperties.java +29 −0
| @@ -0,0 +1,29 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import org.slf4j.Logger; | |
| 4 | +import org.slf4j.LoggerFactory; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Allows overriding internal settings via system properties. | |
| 8 | + * <p> | |
| 9 | + * Warning: this is meant for integration tests only, NOT FOR PRODUCTION USE. | |
| 10 | + */ | |
| 11 | +class SystemProperties { | |
| 12 | + private static final Logger logger = LoggerFactory.getLogger(SystemProperties.class); | |
| 13 | + | |
| 14 | + static int getInt(String key, int defaultValue) { | |
| 15 | + String stringValue = System.getProperty(key); | |
| 16 | + if (stringValue == null) { | |
| 17 | + logger.debug("{} is undefined, using default value {}", key, defaultValue); | |
| 18 | + return defaultValue; | |
| 19 | + } | |
| 20 | + try { | |
| 21 | + int value = Integer.parseInt(stringValue); | |
| 22 | + logger.debug("{} is defined, using value {}", key, value); | |
| 23 | + return value; | |
| 24 | + } catch (NumberFormatException e) { | |
| 25 | + logger.warn("{} is defined but could not parse value {}, using default value {}", key, stringValue, defaultValue); | |
| 26 | + return defaultValue; | |
| 27 | + } | |
| 28 | + } | |
| 29 | +} |