Skip to content

Commit 11c9f77

Browse files
author
Jim Bisso
committed
Merge branch 'master' of https://github.com/datastax/java-driver
Merging updated files with my Javadocedits still in review.
2 parents c6aa825 + 454a160 commit 11c9f77

32 files changed

Lines changed: 879 additions & 48 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target/
2+
cobertura-history/
23
.settings
34
.classpath
45
.project

driver-core/CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CHANGELOG
2+
=========
3+
4+
* 1.0.0-beta2:
5+
- [JAVA-51] Support blob constants in the query builder.
6+
7+
8+
* 1.0.0-beta1:
9+
- initial release

driver-core/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>org.apache.cassandra</groupId>
4242
<artifactId>cassandra-thrift</artifactId>
43-
<version>1.2.0</version>
43+
<version>1.2.3</version>
4444
</dependency>
4545

4646
<dependency>
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>org.codehaus.jackson</groupId>
6060
<artifactId>jackson-core-asl</artifactId>
61-
<version>1.4.0</version>
61+
<version>1.9.2</version>
6262
</dependency>
6363

6464
<dependency>
@@ -74,7 +74,7 @@
7474
<id>default</id>
7575
<properties>
7676
<env>default</env>
77-
<cassandra.version>1.2.0</cassandra.version>
77+
<cassandra.version>1.2.3</cassandra.version>
7878
</properties>
7979
<activation>
8080
<activeByDefault>true</activeByDefault>
@@ -87,7 +87,7 @@
8787
<plugin>
8888
<groupId>org.apache.maven.plugins</groupId>
8989
<artifactId>maven-surefire-plugin</artifactId>
90-
<version>2.5</version>
90+
<version>2.9</version>
9191
<configuration>
9292
<useFile>false</useFile>
9393
<systemPropertyVariables>

driver-core/src/main/java/com/datastax/driver/core/Host.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void register(StateListener listener) {
155155
* @param listener the {@link Host.StateListener} to unregister.
156156
*/
157157
public void unregister(StateListener listener) {
158-
listeners.add(listener);
158+
listeners.remove(listener);
159159
}
160160

161161
/**

driver-core/src/main/java/com/datastax/driver/core/PreparedStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public ConsistencyLevel getConsistencyLevel() {
225225
* itself). For prepared queries, the current keyspace used is the one at
226226
* the time of the preparation, not the one at execution time. The current
227227
* keyspace at the time of the preparation can be retrieved through
228-
* {@link #getKeyspaceAtPreparation}.
228+
* {@link #getQueryKeyspace}.
229229
*
230230
* @return the query that was prepared to yield this
231231
* {@code PreparedStatement}.

driver-core/src/main/java/com/datastax/driver/core/ResultSetFuture.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ public void onSet(Connection connection, Message.Response response) {
7878
case DROPPED:
7979
if (scc.columnFamily.isEmpty()) {
8080
// If that the one keyspace we are logged in, reset to null (it shouldn't really happen but ...)
81-
if (scc.keyspace.equals(session.poolsState.keyspace))
82-
session.poolsState.setKeyspace(null);
81+
// Note: Actually, Cassandra doesn't do that so we don't either as this could confuse prepared statements.
82+
// We'll add it back if CASSANDRA-5358 changes that behavior
83+
//if (scc.keyspace.equals(session.poolsState.keyspace))
84+
// session.poolsState.setKeyspace(null);
8385
session.cluster.manager.refreshSchema(connection, ResultSetFuture.this, rs, null, null);
8486
} else {
8587
session.cluster.manager.refreshSchema(connection, ResultSetFuture.this, rs, scc.keyspace, null);
@@ -214,7 +216,15 @@ public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutE
214216
}
215217

216218
static void extractCauseFromExecutionException(ExecutionException e) {
217-
extractCause(e.getCause());
219+
// We could just rethrow e.getCause(). However, the cause of the ExecutionException has likely been
220+
// created on the I/O thread receiving the response. Which means that the stacktrace associated
221+
// with said cause will make no mention of the current thread. This is painful for say, finding
222+
// out which execute() statement actually raised the exception. So instead, we re-create the
223+
// exception.
224+
if (e.getCause() instanceof DriverException)
225+
throw ((DriverException)e.getCause()).copy();
226+
else
227+
throw new DriverInternalError("Unexpected exception thrown", e.getCause());
218228
}
219229

220230
static void extractCause(Throwable cause) {

driver-core/src/main/java/com/datastax/driver/core/RetryingCallback.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,15 @@ public void onSet(Connection connection, Message.Response response) {
239239
case OVERLOADED:
240240
// Try another node
241241
logger.warn("Host {} is overloaded, trying next host.", connection.address);
242+
logError(connection.address, "Host overloaded");
242243
if (manager.configuration().isMetricsEnabled())
243244
metrics().getErrorMetrics().getOthers().inc();
244245
retry(false, null);
245246
return;
246247
case IS_BOOTSTRAPPING:
247248
// Try another node
248249
logger.error("Query sent to {} but it is bootstrapping. This shouldn't happen but trying next host.", connection.address);
250+
logError(connection.address, "Host is boostrapping");
249251
if (manager.configuration().isMetricsEnabled())
250252
metrics().getErrorMetrics().getOthers().inc();
251253
retry(false, null);
@@ -262,7 +264,7 @@ public void onSet(Connection connection, Message.Response response) {
262264
return;
263265
}
264266

265-
logger.trace("Preparing required prepared query {}", toPrepare.getQueryString());
267+
logger.trace("Preparing required prepared query {} in keyspace {}", toPrepare.getQueryString(), toPrepare.getQueryKeyspace());
266268
String currentKeyspace = connection.keyspace();
267269
String prepareKeyspace = toPrepare.getQueryKeyspace();
268270
// This shouldn't happen in normal use, because a user shouldn't try to execute
@@ -333,8 +335,27 @@ public Message.Request request() {
333335

334336
public void onSet(Connection connection, Message.Response response) {
335337
// TODO should we check the response ?
336-
logger.trace("Scheduling retry now that query is prepared");
337-
retry(true, null);
338+
switch (response.type) {
339+
case RESULT:
340+
if (((ResultMessage)response).kind == ResultMessage.Kind.PREPARED) {
341+
logger.trace("Scheduling retry now that query is prepared");
342+
retry(true, null);
343+
} else {
344+
logError(connection.address, "Got unexpected response to prepare message: " + response);
345+
retry(false, null);
346+
}
347+
break;
348+
case ERROR:
349+
logError(connection.address, "Error preparing query, got " + response);
350+
if (manager.configuration().isMetricsEnabled())
351+
metrics().getErrorMetrics().getOthers().inc();
352+
retry(false, null);
353+
break;
354+
default:
355+
// Something's wrong, so we return but we let setFinalResult propagate the exception
356+
RetryingCallback.this.setFinalResult(connection, response);
357+
break;
358+
}
338359
}
339360

340361
public void onException(Connection connection, Exception exception) {

driver-core/src/main/java/com/datastax/driver/core/exceptions/AlreadyExistsException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public AlreadyExistsException(String keyspace, String table) {
2929
this.table = table;
3030
}
3131

32+
private AlreadyExistsException(String msg, Throwable cause, String keyspace, String table) {
33+
super(msg, cause);
34+
this.keyspace = keyspace;
35+
this.table = table;
36+
}
37+
3238
private static String makeMsg(String keyspace, String table) {
3339
if (table.isEmpty())
3440
return String.format("Keyspace %s already exists", keyspace);
@@ -71,4 +77,8 @@ public String getKeyspace() {
7177
public String getTable() {
7278
return table.isEmpty() ? null : table;
7379
}
80+
81+
public DriverException copy() {
82+
return new AlreadyExistsException(getMessage(), this, keyspace, table);
83+
}
7484
}

driver-core/src/main/java/com/datastax/driver/core/exceptions/AuthenticationException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public AuthenticationException(InetAddress host, String message) {
2929
this.host = host;
3030
}
3131

32+
private AuthenticationException(String message, Throwable cause, InetAddress host)
33+
{
34+
super(message, cause);
35+
this.host = host;
36+
}
37+
3238
/**
3339
* The host for which the authentication failed.
3440
*
@@ -37,4 +43,8 @@ public AuthenticationException(InetAddress host, String message) {
3743
public InetAddress getHost() {
3844
return host;
3945
}
46+
47+
public DriverException copy() {
48+
return new AuthenticationException(getMessage(), this, host);
49+
}
4050
}

driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverException.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Top level class for exceptions thrown by the driver.
2020
*/
21-
public class DriverException extends RuntimeException {
21+
public abstract class DriverException extends RuntimeException {
2222

2323
DriverException() {
2424
super();
@@ -35,4 +35,17 @@ public class DriverException extends RuntimeException {
3535
DriverException(String message, Throwable cause) {
3636
super(message, cause);
3737
}
38+
39+
/**
40+
* Copy the exception.
41+
* <p>
42+
* This return a new exception, equivalent to the original one, except that
43+
* because a new object is created in the current thread, the top-most
44+
* element in the stacktrace of the exception will refer to the current
45+
* thread (this mainly use for internal use by the driver). The cause of
46+
* the copied exception will be the original exception.
47+
*
48+
* @return a copy/clone of this exception.
49+
*/
50+
public abstract DriverException copy();
3851
}

0 commit comments

Comments
 (0)