Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
A driver for Scylla and Apache Cassandra 1.2+ that works exclusively with the Cassandra Query Language version 3
(CQL3) and Cassandra's binary protocol.
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datastax.driver.core;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import com.datastax.driver.core.exceptions.BootstrappingException;
import com.datastax.driver.core.exceptions.DriverInternalError;
import com.datastax.driver.core.exceptions.OverloadedException;
import com.datastax.driver.core.exceptions.QueryValidationException;
import com.datastax.driver.core.exceptions.UnavailableException;
import com.datastax.driver.core.exceptions.UnpreparedException;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.HdrHistogram.Histogram;
import org.HdrHistogram.Recorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A {@link LatencyTracker} that records query latencies over a sliding time interval, and exposes
* an API to retrieve the latency at a given percentile.
*
*
Percentiles may be computed separately for different categories of requests; this is
* implementation-dependent and determined by {@link #computeKey(Host, Statement, Exception)}.
*
*
This class is used by percentile-aware components such as {@link
* QueryLogger.Builder#withDynamicThreshold(PercentileTracker, double)} QueryLogger} and {@link
* com.datastax.driver.core.policies.PercentileSpeculativeExecutionPolicy}.
*
*
It uses HdrHistogram to record
* latencies: for each category, there is a "live" histogram where current latencies are recorded,
* and a "cached", read-only histogram that is used when clients call {@link
* #getLatencyAtPercentile(Host, Statement, Exception, double)}. Each time the cached histogram
* becomes older than the interval, the two histograms are switched. Statistics will not be
* available during the first interval at cluster startup, since we don't have a cached histogram
* yet.
*/
public abstract class PercentileTracker implements LatencyTracker {
private static final Logger logger = LoggerFactory.getLogger(PercentileTracker.class);
private final long highestTrackableLatencyMillis;
private final int numberOfSignificantValueDigits;
private final int minRecordedValues;
private final long intervalMs;
// The "live" recorders: this is where we store the latencies received from the cluster
private final ConcurrentMap