kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | fa4284d473f7fbb0912a2a37ecbe1e4e2bfa2b92c83da5e9b572e801797d2453 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-04-04 16:05 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-04-26 14:12 +02:00 |
| Parents | b3b954dfe91c |
3 files changed
modified changelog/README.md +1 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | - [improvement] JAVA-1065: Add method to create token from partition key values. |
| 12 | 12 | - [improvement] JAVA-1136: Enable JDK signature check in module driver-extras. |
| 13 | 13 | - [improvement] JAVA-866: Support tuple notation in QueryBuilder.eq/in. |
| 14 | +- [bug] JAVA-1140: Use same connection to check for schema agreement after a DDL query. | |
| 14 | 15 | |
| 15 | 16 | Merged from 2.1 branch: |
| 16 | 17 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +2 −2
| @@ -2156,7 +2156,7 @@ | ||
| 2156 | 2156 | : reusedConnection; |
| 2157 | 2157 | |
| 2158 | 2158 | try { |
| 2159 | - controlConnection.waitForSchemaAgreement(); | |
| 2159 | + ControlConnection.waitForSchemaAgreement(connection, this); | |
| 2160 | 2160 | } catch (ExecutionException e) { |
| 2161 | 2161 | // As below, just move on |
| 2162 | 2162 | } |
| @@ -2261,7 +2261,7 @@ | ||
| 2261 | 2261 | try { |
| 2262 | 2262 | // Before refreshing the schema, wait for schema agreement so |
| 2263 | 2263 | // that querying a table just after having created it don't fail. |
| 2264 | - schemaInAgreement = controlConnection.waitForSchemaAgreement(); | |
| 2264 | + schemaInAgreement = ControlConnection.waitForSchemaAgreement(connection, Cluster.Manager.this); | |
| 2265 | 2265 | if (!schemaInAgreement) |
| 2266 | 2266 | logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds()); |
| 2267 | 2267 |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +10 −7
| @@ -684,13 +684,13 @@ | ||
| 684 | 684 | sb.append(", ").append(columnName).append("=null"); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - boolean waitForSchemaAgreement() throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { | |
| 687 | + static boolean waitForSchemaAgreement(Connection connection, Cluster.Manager cluster) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException { | |
| 688 | 688 | long start = System.nanoTime(); |
| 689 | 689 | long elapsed = 0; |
| 690 | 690 | int maxSchemaAgreementWaitSeconds = cluster.configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds(); |
| 691 | 691 | while (elapsed < maxSchemaAgreementWaitSeconds * 1000) { |
| 692 | 692 | |
| 693 | - if (checkSchemaAgreement()) | |
| 693 | + if (checkSchemaAgreement(connection, cluster)) | |
| 694 | 694 | return true; |
| 695 | 695 | |
| 696 | 696 | // let's not flood the node too much |
| @@ -702,11 +702,7 @@ | ||
| 702 | 702 | return false; |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - boolean checkSchemaAgreement() throws ConnectionException, BusyConnectionException, InterruptedException, ExecutionException { | |
| 706 | - Connection connection = connectionRef.get(); | |
| 707 | - if (connection == null || connection.isClosed()) | |
| 708 | - return false; | |
| 709 | - | |
| 705 | + private static boolean checkSchemaAgreement(Connection connection, Cluster.Manager cluster) throws InterruptedException, ExecutionException { | |
| 710 | 706 | DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_PEERS)); |
| 711 | 707 | DefaultResultSetFuture localFuture = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_LOCAL)); |
| 712 | 708 | connection.write(peersFuture); |
| @@ -732,6 +728,13 @@ | ||
| 732 | 728 | return versions.size() <= 1; |
| 733 | 729 | } |
| 734 | 730 | |
| 731 | + boolean checkSchemaAgreement() throws ConnectionException, BusyConnectionException, InterruptedException, ExecutionException { | |
| 732 | + Connection connection = connectionRef.get(); | |
| 733 | + return connection != null && | |
| 734 | + !connection.isClosed() && | |
| 735 | + checkSchemaAgreement(connection, cluster); | |
| 736 | + } | |
| 737 | + | |
| 735 | 738 | boolean isOpen() { |
| 736 | 739 | Connection c = connectionRef.get(); |
| 737 | 740 | return c != null && !c.isClosed(); |