Skip to content

Commit 59930a9

Browse files
committed
JAVA-888: Add cluster-wide percentile tracker.
1 parent 0d33de3 commit 59930a9

8 files changed

Lines changed: 593 additions & 347 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [bug] JAVA-819: Expose more errors in RetryPolicy + provide idempotent-aware wrapper.
2727
- [improvement] JAVA-1040: SimpleStatement parameters support in QueryLogger.
2828
- [bug] JAVA-1064: getTable create statement doesn't properly handle quotes in primary key.
29+
- [improvement] JAVA-888: Add cluster-wide percentile tracker.
2930

3031
Merged from 2.0 branch:
3132

clirr-ignores.xml

Lines changed: 118 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,126 @@
77
* run `mvn clirr:clirr` at the root directory
88
* check the reports in `<module>/target/site/clirr-report.html`
99
* add new differences if needed. Difference types are explained at http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html
10+
11+
The formatter introduces line breaks that make Clirr unhappy:
12+
@formatter:off
1013
-->
1114
<differences>
1215

13-
<difference>
14-
<differenceType>6006</differenceType> <!-- field now final -->
15-
<className>com/datastax/driver/core/ProtocolVersion</className>
16-
<field>NEWEST_SUPPORTED</field>
17-
<justification>This was an oversight, this field was never intended to be non final</justification>
18-
</difference>
19-
20-
<difference>
21-
<differenceType>8001</differenceType> <!-- class removed -->
22-
<className>com/datastax/driver/core/schemabuilder/ColumnType$NativeColumnType</className>
23-
<justification>This class was accidentally exposed, it was meant to be package-private</justification>
24-
</difference>
25-
26-
<difference>
27-
<differenceType>1001</differenceType> <!-- decreased visibility -->
28-
<className>com/datastax/driver/core/HostConnectionPool$Phase</className>
29-
<justification>False positive: HostConnectionPool is not exposed to clients</justification>
30-
</difference>
31-
32-
<difference>
33-
<differenceType>1001</differenceType> <!-- decreased visibility -->
34-
<className>com/datastax/driver/core/ConvictionPolicy$Factory</className>
35-
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
36-
</difference>
37-
38-
<difference>
39-
<differenceType>8001</differenceType> <!-- class removed -->
40-
<className>com/datastax/driver/core/ConvictionPolicy$Simple</className>
41-
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
42-
</difference>
43-
44-
<difference>
45-
<differenceType>8001</differenceType> <!-- class removed -->
46-
<className>com/datastax/driver/core/ConvictionPolicy$Simple$Factory</className>
47-
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
48-
</difference>
49-
50-
<difference>
51-
<differenceType>1001</differenceType> <!-- decreased visibility -->
52-
<className>com/datastax/driver/mapping/ColumnMapper$Kind</className>
53-
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
54-
</difference>
16+
<difference>
17+
<differenceType>6006</differenceType> <!-- field now final -->
18+
<className>com/datastax/driver/core/ProtocolVersion</className>
19+
<field>NEWEST_SUPPORTED</field>
20+
<justification>This was an oversight, this field was never intended to be non final</justification>
21+
</difference>
22+
23+
<difference>
24+
<differenceType>8001</differenceType> <!-- class removed -->
25+
<className>com/datastax/driver/core/schemabuilder/ColumnType$NativeColumnType</className>
26+
<justification>This class was accidentally exposed, it was meant to be package-private</justification>
27+
</difference>
28+
29+
<difference>
30+
<differenceType>1001</differenceType> <!-- decreased visibility -->
31+
<className>com/datastax/driver/core/HostConnectionPool$Phase</className>
32+
<justification>False positive: HostConnectionPool is not exposed to clients</justification>
33+
</difference>
34+
35+
<difference>
36+
<differenceType>1001</differenceType> <!-- decreased visibility -->
37+
<className>com/datastax/driver/core/ConvictionPolicy$Factory</className>
38+
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
39+
</difference>
40+
41+
<difference>
42+
<differenceType>8001</differenceType> <!-- class removed -->
43+
<className>com/datastax/driver/core/ConvictionPolicy$Simple</className>
44+
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
45+
</difference>
46+
47+
<difference>
48+
<differenceType>8001</differenceType> <!-- class removed -->
49+
<className>com/datastax/driver/core/ConvictionPolicy$Simple$Factory</className>
50+
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
51+
</difference>
52+
53+
<difference>
54+
<differenceType>1001</differenceType> <!-- decreased visibility -->
55+
<className>com/datastax/driver/mapping/ColumnMapper$Kind</className>
56+
<justification>False positive, the enclosing class is package-private so this was never exposed</justification>
57+
</difference>
58+
59+
<difference>
60+
<differenceType>7002</differenceType> <!-- method removed -->
61+
<className>com/datastax/driver/core/PerHostPercentileTracker</className>
62+
<method>com.datastax.driver.core.PerHostPercentileTracker$Builder builderWithHighestTrackableLatencyMillis(long)
63+
</method>
64+
<justification>Renamed (API was marked as beta and still subject to change)</justification>
65+
</difference>
66+
67+
<difference>
68+
<differenceType>7002</differenceType> <!-- method removed -->
69+
<className>com/datastax/driver/core/PerHostPercentileTracker</className>
70+
<method>long getLatencyAtPercentile(com.datastax.driver.core.Host, double)</method>
71+
<justification>Moved to new parent class with more parameters (API was marked as beta and still subject to change)</justification>
72+
</difference>
73+
74+
<difference>
75+
<differenceType>7002</differenceType> <!-- method removed -->
76+
<className>com/datastax/driver/core/PerHostPercentileTracker$Builder</className>
77+
<method>com.datastax.driver.core.PerHostPercentileTracker$Builder withInterval(long, java.util.concurrent.TimeUnit)</method>
78+
<justification>False positive, method now inherited from generic parent class</justification>
79+
</difference>
80+
81+
<difference>
82+
<differenceType>7002</differenceType> <!-- method removed -->
83+
<className>com/datastax/driver/core/PerHostPercentileTracker$Builder</className>
84+
<method>com.datastax.driver.core.PerHostPercentileTracker$Builder withMinRecordedValues(int)</method>
85+
<justification>False positive, method now inherited from generic parent class</justification>
86+
</difference>
87+
88+
<difference>
89+
<differenceType>7002</differenceType> <!-- method removed -->
90+
<className>com/datastax/driver/core/PerHostPercentileTracker$Builder</className>
91+
<method>com.datastax.driver.core.PerHostPercentileTracker$Builder withNumberOfSignificantValueDigits(int)</method>
92+
<justification>False positive, method now inherited from generic parent class</justification>
93+
</difference>
94+
95+
<difference>
96+
<differenceType>7002</differenceType> <!-- method removed -->
97+
<className>com/datastax/driver/core/PerHostPercentileTracker$Builder</className>
98+
<method>com.datastax.driver.core.PerHostPercentileTracker$Builder withNumberOfHosts(int)</method>
99+
<justification>Removed (API was marked as beta and still subject to change)</justification>
100+
</difference>
101+
102+
<difference>
103+
<differenceType>7005</differenceType> <!-- method argument type changed -->
104+
<className>com/datastax/driver/core/QueryLogger$Builder</className>
105+
<method>com.datastax.driver.core.QueryLogger$Builder withDynamicThreshold(com.datastax.driver.core.PerHostPercentileTracker, double)</method>
106+
<to>com.datastax.driver.core.QueryLogger$Builder withDynamicThreshold(com.datastax.driver.core.PercentileTracker, double)</to>
107+
<justification>Introduced more generic parent type PercentileTracker (API was marked as beta and still subject to change)</justification>
108+
</difference>
109+
110+
<difference>
111+
<differenceType>7002</differenceType> <!-- method removed -->
112+
<className>com/datastax/driver/core/QueryLogger$DynamicThresholdQueryLogger</className>
113+
<method>com.datastax.driver.core.PerHostPercentileTracker getPerHostPercentileLatencyTracker()</method>
114+
<justification>Introduced more generic parent type PercentileTracker (API was marked as beta and still subject to change)</justification>
115+
</difference>
116+
117+
<difference>
118+
<differenceType>7002</differenceType> <!-- method removed -->
119+
<className>com/datastax/driver/core/QueryLogger$DynamicThresholdQueryLogger</className>
120+
<method>void setPerHostPercentileLatencyTracker(com.datastax.driver.core.PerHostPercentileTracker)</method>
121+
<justification>Introduced more generic parent type PercentileTracker (API was marked as beta and still subject to change)</justification>
122+
</difference>
123+
124+
<difference>
125+
<differenceType>7005</differenceType> <!-- method argument type changed -->
126+
<className>com/datastax/driver/core/policies/PercentileSpeculativeExecutionPolicy</className>
127+
<method>PercentileSpeculativeExecutionPolicy(com.datastax.driver.core.PerHostPercentileTracker, double, int)</method>
128+
<to>*</to> <!-- didn't find a way to write the new signature -->
129+
<justification>Introduced more generic parent type PercentileTracker (API was marked as beta and still subject to change)</justification>
130+
</difference>
55131

56132
</differences>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2012-2015 DataStax Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datastax.driver.core;
17+
18+
/**
19+
* A {@code PercentileTracker} that aggregates all measurements into a single histogram.
20+
* <p/>
21+
* This gives you global latency percentiles for the whole cluster, meaning that latencies of slower hosts will tend to
22+
* appear in higher percentiles.
23+
*/
24+
public class ClusterWidePercentileTracker extends PercentileTracker {
25+
private volatile Cluster cluster;
26+
27+
private ClusterWidePercentileTracker(long highestTrackableLatencyMillis,
28+
int numberOfSignificantValueDigits,
29+
int minRecordedValues,
30+
long intervalMs) {
31+
super(highestTrackableLatencyMillis, numberOfSignificantValueDigits, minRecordedValues, intervalMs);
32+
}
33+
34+
@Override
35+
public void onRegister(Cluster cluster) {
36+
this.cluster = cluster;
37+
}
38+
39+
@Override
40+
protected Cluster computeKey(Host host, Statement statement, Exception exception) {
41+
return cluster;
42+
}
43+
44+
/**
45+
* Returns a builder to create a new instance.
46+
*
47+
* @param highestTrackableLatencyMillis the highest expected latency. If a higher value is reported, it will be
48+
* ignored and a warning will be logged. A good rule of thumb is to set it
49+
* slightly higher than {@link SocketOptions#getReadTimeoutMillis()}.
50+
* @return the builder.
51+
*/
52+
public static Builder builder(long highestTrackableLatencyMillis) {
53+
return new Builder(highestTrackableLatencyMillis);
54+
}
55+
56+
/**
57+
* Helper class to build {@code PerHostPercentileTracker} instances with a fluent interface.
58+
*/
59+
public static class Builder extends PercentileTracker.Builder<Builder, ClusterWidePercentileTracker> {
60+
61+
Builder(long highestTrackableLatencyMillis) {
62+
super(highestTrackableLatencyMillis);
63+
}
64+
65+
@Override
66+
protected Builder self() {
67+
return this;
68+
}
69+
70+
@Override
71+
public ClusterWidePercentileTracker build() {
72+
return new ClusterWidePercentileTracker(highestTrackableLatencyMillis, numberOfSignificantValueDigits,
73+
minRecordedValues, intervalMs);
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)