kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 8e68cdab6bd14ad11ca49382ab27e61b1e33a2f6f6e477ff3b4e88f036711775 |
|---|---|
| Author | Kevin Gallardo <kevin.gallardo@datastax.com> · 2015-07-10 10:51 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-08-09 22:43 +02:00 |
| Parents | bb06e23cbd95 |
3 files changed
modified changelog/README.md +1 −0
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | - [new feature] Make it possible to register for SchemaChange Events (JAVA-151) |
| 33 | 33 | - [improvement] Downgrade "Asked to rebuild table" log from ERROR to INFO level (JAVA-861) |
| 34 | 34 | - [improvement] Provide an option to prepare statements only on one node (JAVA-797) |
| 35 | +- [improvement] Provide an option to not re-prepare all statements in onUp (JAVA-658) | |
| 35 | 36 | |
| 36 | 37 | Merged from 2.0.10_fixes branch: |
| 37 | 38 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +2 −1
| @@ -1550,7 +1550,8 @@ | ||
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | try { |
| 1553 | - reusedConnection = prepareAllQueries(host, reusedConnection); | |
| 1553 | + if (getCluster().getConfiguration().getQueryOptions().isReprepareOnUp()) | |
| 1554 | + reusedConnection = prepareAllQueries(host, reusedConnection); | |
| 1554 | 1555 | } catch (InterruptedException e) { |
| 1555 | 1556 | Thread.currentThread().interrupt(); |
| 1556 | 1557 | // Don't propagate because we don't want to prevent other listener to run |
modified driver-core/src/main/java/com/datastax/driver/core/QueryOptions.java +41 −3
| @@ -46,6 +46,7 @@ | ||
| 46 | 46 | private volatile ConsistencyLevel serialConsistency = DEFAULT_SERIAL_CONSISTENCY_LEVEL; |
| 47 | 47 | private volatile int fetchSize = DEFAULT_FETCH_SIZE; |
| 48 | 48 | private volatile boolean defaultIdempotence = DEFAULT_IDEMPOTENCE; |
| 49 | + private volatile boolean reprepareOnUp = true; | |
| 49 | 50 | private volatile Cluster.Manager manager; |
| 50 | 51 | private volatile boolean prepareOnAllHosts = true; |
| 51 | 52 | |
| @@ -188,9 +189,9 @@ | ||
| 188 | 189 | * chance of having been hit by at least one client for each statement. |
| 189 | 190 | * <p> |
| 190 | 191 | * On the other hand, if that assumption turns out to be wrong and one host hasn't |
| 191 | - * prepared a given statement, you will pay a penalty on the first execution of this | |
| 192 | - * statement on this host (one extra roundtrip to resend the query to prepare, and | |
| 193 | - * another to retry the execution). | |
| 192 | + * prepared a given statement, it needs to be re-prepared on the fly the first time | |
| 193 | + * it gets executed; this causes a performance penalty (one extra roundtrip to resend | |
| 194 | + * the query to prepare, and another to retry the execution). | |
| 194 | 195 | * |
| 195 | 196 | * @param prepareOnAllHosts the new value to set to indicate whether to prepare |
| 196 | 197 | * statements once or on all nodes. |
| @@ -211,4 +212,41 @@ | ||
| 211 | 212 | public boolean isPrepareOnAllHosts() { |
| 212 | 213 | return this.prepareOnAllHosts; |
| 213 | 214 | } |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Set whether the driver should re-prepare all cached prepared statements on a host | |
| 218 | + * when it marks it back up. | |
| 219 | + * <p> | |
| 220 | + * This option is enabled by default. | |
| 221 | + * <p> | |
| 222 | + * The reason why you might want to disable it is to optimize reconnection time when | |
| 223 | + * you believe hosts often get marked down because of temporary network issues, rather | |
| 224 | + * than the host really crashing. In that case, the host still has prepared statements | |
| 225 | + * in its cache when the driver reconnects, so re-preparing is redundant. | |
| 226 | + * <p> | |
| 227 | + * On the other hand, if that assumption turns out to be wrong and the host had | |
| 228 | + * really restarted, its prepared statement cache is empty, and statements need to be | |
| 229 | + * re-prepared on the fly the first time they get executed; this causes a performance | |
| 230 | + * penalty (one extra roundtrip to resend the query to prepare, and another to retry | |
| 231 | + * the execution). | |
| 232 | + * | |
| 233 | + * @param reprepareOnUp whether the driver should re-prepare when marking a node up. | |
| 234 | + * @return this {@code QueryOptions} instance. | |
| 235 | + */ | |
| 236 | + public QueryOptions setReprepareOnUp(boolean reprepareOnUp){ | |
| 237 | + this.reprepareOnUp = reprepareOnUp; | |
| 238 | + return this; | |
| 239 | + } | |
| 240 | + | |
| 241 | + /** | |
| 242 | + * Whether the driver should re-prepare all cached prepared statements on a host | |
| 243 | + * when its marks that host back up. | |
| 244 | + * | |
| 245 | + * @return the value. | |
| 246 | + * | |
| 247 | + * @see #setReprepareOnUp(boolean) | |
| 248 | + */ | |
| 249 | + public boolean isReprepareOnUp() { | |
| 250 | + return this.reprepareOnUp; | |
| 251 | + } | |
| 214 | 252 | } |