Elffuss BraidHub

kikocis/java-driver public

JAVA-1140: Use same connection to check for schema agreement after a DDL query.
Changesetfa4284d473f7fbb0912a2a37ecbe1e4e2bfa2b92c83da5e9b572e801797d2453
Authorolim7t <omichallat+github@gmail.com> · 2016-04-04 16:05 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2016-04-26 14:12 +02:00
Parentsb3b954dfe91c

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -11,6 +11,7 @@
1111 - [improvement] JAVA-1065: Add method to create token from partition key values.
1212 - [improvement] JAVA-1136: Enable JDK signature check in module driver-extras.
1313 - [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.
1415
1516 Merged from 2.1 branch:
1617
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +2 −2
@@ -2156,7 +2156,7 @@
21562156 : reusedConnection;
21572157
21582158 try {
2159- controlConnection.waitForSchemaAgreement();
2159+ ControlConnection.waitForSchemaAgreement(connection, this);
21602160 } catch (ExecutionException e) {
21612161 // As below, just move on
21622162 }
@@ -2261,7 +2261,7 @@
22612261 try {
22622262 // Before refreshing the schema, wait for schema agreement so
22632263 // that querying a table just after having created it don't fail.
2264- schemaInAgreement = controlConnection.waitForSchemaAgreement();
2264+ schemaInAgreement = ControlConnection.waitForSchemaAgreement(connection, Cluster.Manager.this);
22652265 if (!schemaInAgreement)
22662266 logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds());
22672267
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +10 −7
@@ -684,13 +684,13 @@
684684 sb.append(", ").append(columnName).append("=null");
685685 }
686686
687- boolean waitForSchemaAgreement() throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException {
687+ static boolean waitForSchemaAgreement(Connection connection, Cluster.Manager cluster) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException {
688688 long start = System.nanoTime();
689689 long elapsed = 0;
690690 int maxSchemaAgreementWaitSeconds = cluster.configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds();
691691 while (elapsed < maxSchemaAgreementWaitSeconds * 1000) {
692692
693- if (checkSchemaAgreement())
693+ if (checkSchemaAgreement(connection, cluster))
694694 return true;
695695
696696 // let's not flood the node too much
@@ -702,11 +702,7 @@
702702 return false;
703703 }
704704
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 {
710706 DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_PEERS));
711707 DefaultResultSetFuture localFuture = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_LOCAL));
712708 connection.write(peersFuture);
@@ -732,6 +728,13 @@
732728 return versions.size() <= 1;
733729 }
734730
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+
735738 boolean isOpen() {
736739 Connection c = connectionRef.get();
737740 return c != null && !c.isClosed();