Package org.apache.cassandra.locator
Class DynamicEndpointSnitch
- java.lang.Object
-
- org.apache.cassandra.locator.AbstractEndpointSnitch
-
- org.apache.cassandra.locator.DynamicEndpointSnitch
-
- All Implemented Interfaces:
DynamicEndpointSnitchMBean
,IEndpointSnitch
,LatencySubscribers.Subscriber
public class DynamicEndpointSnitch extends AbstractEndpointSnitch implements LatencySubscribers.Subscriber, DynamicEndpointSnitchMBean
A dynamic snitch that sorts endpoints by latency with an adapted phi failure detector
-
-
Field Summary
Fields Modifier and Type Field Description IEndpointSnitch
subsnitch
-
Constructor Summary
Constructors Constructor Description DynamicEndpointSnitch(IEndpointSnitch snitch)
DynamicEndpointSnitch(IEndpointSnitch snitch, java.lang.String instance)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyConfigChanges()
Update configuration fromDatabaseDescriptor
and estart the update-scheduler and reset-scheduler tasks if the configured rates for these tasks have changed.void
close()
int
compareEndpoints(InetAddressAndPort target, Replica a1, Replica a2)
compares two endpoints in relation to the target endpoint, returning as Comparator.compare wouldjava.util.List<java.lang.Double>
dumpTimings(java.lang.String hostname)
double
getBadnessThreshold()
java.lang.String
getDatacenter(InetAddressAndPort endpoint)
returns a String representing the datacenter the given endpoint belongs tojava.lang.String
getRack(InetAddressAndPort endpoint)
returns a String representing the rack the given endpoint belongs toint
getResetInterval()
java.util.Map<java.net.InetAddress,java.lang.Double>
getScores()
java.util.Map<java.lang.String,java.lang.Double>
getScoresWithPort()
double
getSeverity()
java.lang.String
getSubsnitchClassName()
int
getUpdateInterval()
void
gossiperStarting()
called after Gossiper instance exists immediately before it starts gossipingboolean
isWorthMergingForRangeQuery(ReplicaCollection<?> merged, ReplicaCollection<?> l1, ReplicaCollection<?> l2)
Returns whether for a range query doing a query against merged is likely to be faster than 2 sequential queries, one against l1 followed by one against l2.void
receiveTiming(InetAddressAndPort host, long latency, java.util.concurrent.TimeUnit unit)
void
setSeverity(double severity)
Setting a Severity allows operators to inject preference information into the Dynamic Snitch replica selection.<C extends ReplicaCollection<? extends C>>
CsortedByProximity(InetAddressAndPort address, C unsortedAddresses)
Sorts the Collection of node addresses by proximity to the given addressboolean
validate(java.util.Set<java.lang.String> datacenters, java.util.Set<java.lang.String> racks)
Determine if the datacenter or rack values in the current node's snitch conflict with those passed in parameters.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.locator.IEndpointSnitch
getDatacenter, getLocalDatacenter, getLocalRack
-
-
-
-
Field Detail
-
subsnitch
public final IEndpointSnitch subsnitch
-
-
Constructor Detail
-
DynamicEndpointSnitch
public DynamicEndpointSnitch(IEndpointSnitch snitch)
-
DynamicEndpointSnitch
public DynamicEndpointSnitch(IEndpointSnitch snitch, java.lang.String instance)
-
-
Method Detail
-
applyConfigChanges
public void applyConfigChanges()
Update configuration fromDatabaseDescriptor
and estart the update-scheduler and reset-scheduler tasks if the configured rates for these tasks have changed.
-
close
public void close()
-
gossiperStarting
public void gossiperStarting()
Description copied from interface:IEndpointSnitch
called after Gossiper instance exists immediately before it starts gossiping- Specified by:
gossiperStarting
in interfaceIEndpointSnitch
- Overrides:
gossiperStarting
in classAbstractEndpointSnitch
-
getRack
public java.lang.String getRack(InetAddressAndPort endpoint)
Description copied from interface:IEndpointSnitch
returns a String representing the rack the given endpoint belongs to- Specified by:
getRack
in interfaceIEndpointSnitch
-
getDatacenter
public java.lang.String getDatacenter(InetAddressAndPort endpoint)
Description copied from interface:IEndpointSnitch
returns a String representing the datacenter the given endpoint belongs to- Specified by:
getDatacenter
in interfaceIEndpointSnitch
-
sortedByProximity
public <C extends ReplicaCollection<? extends C>> C sortedByProximity(InetAddressAndPort address, C unsortedAddresses)
Description copied from class:AbstractEndpointSnitch
Sorts the Collection of node addresses by proximity to the given address- Specified by:
sortedByProximity
in interfaceIEndpointSnitch
- Overrides:
sortedByProximity
in classAbstractEndpointSnitch
- Parameters:
address
- the address to sort by proximity tounsortedAddresses
- the nodes to sort- Returns:
- a new sorted List
-
compareEndpoints
public int compareEndpoints(InetAddressAndPort target, Replica a1, Replica a2)
Description copied from interface:IEndpointSnitch
compares two endpoints in relation to the target endpoint, returning as Comparator.compare would- Specified by:
compareEndpoints
in interfaceIEndpointSnitch
- Specified by:
compareEndpoints
in classAbstractEndpointSnitch
-
receiveTiming
public void receiveTiming(InetAddressAndPort host, long latency, java.util.concurrent.TimeUnit unit)
- Specified by:
receiveTiming
in interfaceLatencySubscribers.Subscriber
-
getScores
public java.util.Map<java.net.InetAddress,java.lang.Double> getScores()
- Specified by:
getScores
in interfaceDynamicEndpointSnitchMBean
-
getScoresWithPort
public java.util.Map<java.lang.String,java.lang.Double> getScoresWithPort()
- Specified by:
getScoresWithPort
in interfaceDynamicEndpointSnitchMBean
-
getUpdateInterval
public int getUpdateInterval()
- Specified by:
getUpdateInterval
in interfaceDynamicEndpointSnitchMBean
-
getResetInterval
public int getResetInterval()
- Specified by:
getResetInterval
in interfaceDynamicEndpointSnitchMBean
-
getBadnessThreshold
public double getBadnessThreshold()
- Specified by:
getBadnessThreshold
in interfaceDynamicEndpointSnitchMBean
-
getSubsnitchClassName
public java.lang.String getSubsnitchClassName()
- Specified by:
getSubsnitchClassName
in interfaceDynamicEndpointSnitchMBean
-
dumpTimings
public java.util.List<java.lang.Double> dumpTimings(java.lang.String hostname) throws java.net.UnknownHostException
- Specified by:
dumpTimings
in interfaceDynamicEndpointSnitchMBean
- Throws:
java.net.UnknownHostException
-
setSeverity
public void setSeverity(double severity)
Description copied from interface:DynamicEndpointSnitchMBean
Setting a Severity allows operators to inject preference information into the Dynamic Snitch replica selection. When choosing which replicas to participate in a read request, the DSnitch sorts replicas by response latency, and selects the fastest replicas. Latencies are normalized to a score from 0 to 1, with lower scores being faster. The Severity injected here will be added to the normalized score. Thus, adding a Severity greater than 1 will mean the replica will never be contacted (unless needed for ALL or if it is added later for rapid read protection). Conversely, adding a negative Severity means the replica will *always* be contacted. (The "Severity" term is historical and dates to when this was used to represent how badly background tasks like compaction were affecting a replica's performance. See CASSANDRA-3722 for when this was introduced and CASSANDRA-11738 for why it was removed.)- Specified by:
setSeverity
in interfaceDynamicEndpointSnitchMBean
-
getSeverity
public double getSeverity()
- Specified by:
getSeverity
in interfaceDynamicEndpointSnitchMBean
- Returns:
- the current manually injected Severity.
-
isWorthMergingForRangeQuery
public boolean isWorthMergingForRangeQuery(ReplicaCollection<?> merged, ReplicaCollection<?> l1, ReplicaCollection<?> l2)
Description copied from interface:IEndpointSnitch
Returns whether for a range query doing a query against merged is likely to be faster than 2 sequential queries, one against l1 followed by one against l2.- Specified by:
isWorthMergingForRangeQuery
in interfaceIEndpointSnitch
- Overrides:
isWorthMergingForRangeQuery
in classAbstractEndpointSnitch
-
validate
public boolean validate(java.util.Set<java.lang.String> datacenters, java.util.Set<java.lang.String> racks)
Description copied from interface:IEndpointSnitch
Determine if the datacenter or rack values in the current node's snitch conflict with those passed in parameters.- Specified by:
validate
in interfaceIEndpointSnitch
-
-