Elffuss BraidHub

kikocis/java-driver public

JAVA-658 : Provide an option to cancel re-prepare all statements if onUp
Changeset8e68cdab6bd14ad11ca49382ab27e61b1e33a2f6f6e477ff3b4e88f036711775
AuthorKevin Gallardo <kevin.gallardo@datastax.com> · 2015-07-10 10:51 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-08-09 22:43 +02:00
Parentsbb06e23cbd95

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -32,6 +32,7 @@
3232 - [new feature] Make it possible to register for SchemaChange Events (JAVA-151)
3333 - [improvement] Downgrade "Asked to rebuild table" log from ERROR to INFO level (JAVA-861)
3434 - [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)
3536
3637 Merged from 2.0.10_fixes branch:
3738
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +2 −1
@@ -1550,7 +1550,8 @@
15501550 }
15511551
15521552 try {
1553- reusedConnection = prepareAllQueries(host, reusedConnection);
1553+ if (getCluster().getConfiguration().getQueryOptions().isReprepareOnUp())
1554+ reusedConnection = prepareAllQueries(host, reusedConnection);
15541555 } catch (InterruptedException e) {
15551556 Thread.currentThread().interrupt();
15561557 // 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 @@
4646 private volatile ConsistencyLevel serialConsistency = DEFAULT_SERIAL_CONSISTENCY_LEVEL;
4747 private volatile int fetchSize = DEFAULT_FETCH_SIZE;
4848 private volatile boolean defaultIdempotence = DEFAULT_IDEMPOTENCE;
49+ private volatile boolean reprepareOnUp = true;
4950 private volatile Cluster.Manager manager;
5051 private volatile boolean prepareOnAllHosts = true;
5152
@@ -188,9 +189,9 @@
188189 * chance of having been hit by at least one client for each statement.
189190 * <p>
190191 * 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).
194195 *
195196 * @param prepareOnAllHosts the new value to set to indicate whether to prepare
196197 * statements once or on all nodes.
@@ -211,4 +212,41 @@
211212 public boolean isPrepareOnAllHosts() {
212213 return this.prepareOnAllHosts;
213214 }
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+ }
214252 }