Skip to content

Commit 291d81f

Browse files
committed
Merge pull request apache#306 from datastax/java646
Slow Query Logger (JAVA-646)
2 parents 06e11ec + 41456d9 commit 291d81f

18 files changed

Lines changed: 2090 additions & 47 deletions

driver-core/CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ CHANGELOG
2828
- [improvement] Rename threads to indicate that they are for the driver
2929
(JAVA-583)
3030
- [new feature] Expose paging state (JAVA-550)
31+
- [improvement] Slow Query Logger (JAVA-646)
32+
- [improvement] Exclude some errors from measurements in LatencyAwarePolicy
33+
(JAVA-698)
3134

3235
Merged from 2.0.9_fixes branch:
3336

driver-core/Upgrade_guide_to_2.0.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ Other API Changes
155155
will now need to use Host#isUp and Cluster#register if you were using that
156156
class.
157157

158+
11. LatencyTracker#update method now has a different signature and takes two new
159+
parameters: the statement that has been executed (never null), and the exception
160+
thrown while executing the query (or null, if the query executed successfully).
161+
Existing implementations of this interface, once upgraded to the new method
162+
signature, should continue to work as before.
163+
158164

159165

160166

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,9 +1290,9 @@ boolean removeSession(Session session) {
12901290
return sessions.remove(session);
12911291
}
12921292

1293-
void reportLatency(Host host, long latencyNanos) {
1293+
void reportLatency(Host host, Statement statement, Exception exception, long latencyNanos) {
12941294
for (LatencyTracker tracker : trackers) {
1295-
tracker.update(host, latencyNanos);
1295+
tracker.update(host, statement, exception, latencyNanos);
12961296
}
12971297
}
12981298

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
package com.datastax.driver.core;
1717

1818
/**
19-
* Interface for object that are interested in tracking the latencies
19+
* Interface for objects that are interested in tracking the latencies
2020
* of the driver queries to each Cassandra nodes.
2121
* <p>
2222
* An implementation of this interface can be registered against a Cluster
2323
* object trough the {@link Cluster#register} method, after which the
24-
* {@code update} will be called after each query of the driver to a Cassandra
24+
* {@link #update(Host, Statement, Exception, long)} method will be called after each query of the driver to a Cassandra
2525
* host with the latency/duration (in nanoseconds) of this operation.
2626
*/
2727
public interface LatencyTracker {
@@ -31,15 +31,21 @@ public interface LatencyTracker {
3131
* the duration of that operation.
3232
* <p>
3333
* Note that there is no guarantee that this method won't be called
34-
* concurrently by multiple thread, so implementations should synchronize
34+
* concurrently by multiple threads, so implementations should synchronize
3535
* internally if need be.
3636
*
37-
* @param host the Cassandra host on which a request has been performed.
38-
* @param newLatencyNanos the latency in nanoseconds of the operation. This
39-
* latency corresponds to the time elapsed between when the query was send
40-
* to {@code host} and when the response was received by the driver (or the
41-
* operation timed out, in which {@code newLatencyNanos} will approximately
42-
* be the timeout value).
37+
* @param host The Cassandra host on which a request has been performed.
38+
* This parameter is never {@code null}.
39+
* @param statement The {@link com.datastax.driver.core.Statement} that has been executed.
40+
* This parameter is never {@code null}.
41+
* @param exception An {@link Exception} thrown when receiving the response, or {@code null}
42+
* if the response was successful.
43+
* @param newLatencyNanos the latency in nanoseconds of the operation.
44+
* This latency corresponds to the time elapsed between
45+
* when the query was sent to {@code host} and
46+
* when the response was received by the driver
47+
* (or the operation timed out, in which {@code newLatencyNanos}
48+
* will approximately be the timeout value).
4349
*/
44-
public void update(Host host, long newLatencyNanos);
50+
public void update(Host host, Statement statement, Exception exception, long newLatencyNanos);
4551
}

0 commit comments

Comments
 (0)