kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 99eff8eb2fee30fa9bedd9ccb34d884d82d5dca7856daeb8081747c4e53d36a0 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-02-06 16:18 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-02-11 12:39 +01:00 |
| Parents | b71ec2203d70 |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +13 −21
| @@ -403,31 +403,23 @@ | ||
| 403 | 403 | return; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - logger.info("Query {} is not prepared on {}, preparing before retrying executing. " | |
| 407 | - + "Seeing this message a few times is fine, but seeing it a lot may be source of performance problems", | |
| 408 | - toPrepare.getQueryString(), connection.address); | |
| 409 | 406 | String currentKeyspace = connection.keyspace(); |
| 410 | 407 | String prepareKeyspace = toPrepare.getQueryKeyspace(); |
| 411 | - // This shouldn't happen in normal use, because a user shouldn't try to execute | |
| 412 | - // a prepared statement with the wrong keyspace set. However, if it does, we'd rather | |
| 413 | - // prepare the query correctly and let the query executing return a meaningful error message | |
| 414 | - if (prepareKeyspace != null && (currentKeyspace == null || !currentKeyspace.equals(prepareKeyspace))) | |
| 415 | - { | |
| 416 | - logger.debug("Setting keyspace for prepared query to {}", prepareKeyspace); | |
| 417 | - connection.setKeyspace(prepareKeyspace); | |
| 408 | + if (prepareKeyspace != null && (currentKeyspace == null || !currentKeyspace.equals(prepareKeyspace))) { | |
| 409 | + // This shouldn't happen in normal use, because a user shouldn't try to execute | |
| 410 | + // a prepared statement with the wrong keyspace set. | |
| 411 | + // Fail fast (we can't change the keyspace to reprepare, because we're using a pooled connection | |
| 412 | + // that's shared with other requests). | |
| 413 | + throw new IllegalStateException(String.format("Statement was prepared on keyspace %s, can't execute it on %s (%s)", | |
| 414 | + toPrepare.getQueryKeyspace(), connection.keyspace(), toPrepare.getQueryString())); | |
| 418 | 415 | } |
| 419 | 416 | |
| 420 | - try { | |
| 421 | - releaseConnection = false; // we're reusing it for the prepare call | |
| 422 | - write(connection, prepareAndRetry(toPrepare.getQueryString())); | |
| 423 | - } finally { | |
| 424 | - // Always reset the previous keyspace if needed | |
| 425 | - if (connection.keyspace() == null || !connection.keyspace().equals(currentKeyspace)) | |
| 426 | - { | |
| 427 | - logger.debug("Setting back keyspace post query preparation to {}", currentKeyspace); | |
| 428 | - connection.setKeyspace(currentKeyspace); | |
| 429 | - } | |
| 430 | - } | |
| 417 | + logger.info("Query {} is not prepared on {}, preparing before retrying executing. " | |
| 418 | + + "Seeing this message a few times is fine, but seeing it a lot may be source of performance problems", | |
| 419 | + toPrepare.getQueryString(), connection.address); | |
| 420 | + | |
| 421 | + releaseConnection = false; // we're reusing it for the prepare call | |
| 422 | + write(connection, prepareAndRetry(toPrepare.getQueryString())); | |
| 431 | 423 | // we're done for now, the prepareAndRetry callback will handle the rest |
| 432 | 424 | return; |
| 433 | 425 | default: |