Package org.apache.cassandra.locator
Class Replica
- java.lang.Object
-
- org.apache.cassandra.locator.Replica
-
- All Implemented Interfaces:
java.lang.Comparable<Replica>
public final class Replica extends java.lang.Object implements java.lang.Comparable<Replica>
A Replica represents an owning node for a copy of a portion of the token ring. It consists of: - the logical token range that is being replicated (i.e. for the first logical replica only, this will be equal to one of its owned portions of the token ring; all other replicas will have this token range also) - an endpoint (IP and port) - whether the range is replicated in full, or transiently (CASSANDRA-14404) In general, it is preferred to use a Replica to a Range<Token>, particularly when users of the concept depend on knowledge of the full/transient status of the copy. That means you should avoid unwrapping and rewrapping these things and think hard about subtraction and such and what the result is WRT to transientness. Definitely avoid creating fake Replicas with misinformation about endpoints, ranges, or transientness.
-
-
Constructor Summary
Constructors Constructor Description Replica(InetAddressAndPort endpoint, Range<Token> range, boolean full)Replica(InetAddressAndPort endpoint, Token start, Token end, boolean full)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Replica o)booleancontains(Range<Token> that)ReplicadecorateSubrange(Range<Token> subrange)InetAddressAndPortendpoint()booleanequals(java.lang.Object o)static ReplicafullReplica(InetAddressAndPort endpoint, Range<Token> range)static ReplicafullReplica(InetAddressAndPort endpoint, Token start, Token end)inthashCode()booleanintersectsOnRange(Replica replica)booleanisFull()booleanisSelf()booleanisTransient()Range<Token>range()RangesAtEndpointsubtractIgnoreTransientStatus(Range<Token> subtract)Don't use this method and ignore transient status unless you are explicitly handling it outside this method.RangesAtEndpointsubtractSameReplication(RangesAtEndpoint toSubtract)This is used exclusively in TokenMetadata to check if a portion of a range is already replicated by an endpoint so that we only mark as pending the portion that is either not replicated sufficiently (transient when we need full) or at all.java.lang.StringtoString()static ReplicatransientReplica(InetAddressAndPort endpoint, Range<Token> range)static ReplicatransientReplica(InetAddressAndPort endpoint, Token start, Token end)
-
-
-
Constructor Detail
-
Replica
public Replica(InetAddressAndPort endpoint, Range<Token> range, boolean full)
-
Replica
public Replica(InetAddressAndPort endpoint, Token start, Token end, boolean full)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
compareTo
public int compareTo(Replica o)
- Specified by:
compareToin interfacejava.lang.Comparable<Replica>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
endpoint
public final InetAddressAndPort endpoint()
-
isSelf
public boolean isSelf()
-
isFull
public final boolean isFull()
-
isTransient
public final boolean isTransient()
-
subtractSameReplication
public RangesAtEndpoint subtractSameReplication(RangesAtEndpoint toSubtract)
This is used exclusively in TokenMetadata to check if a portion of a range is already replicated by an endpoint so that we only mark as pending the portion that is either not replicated sufficiently (transient when we need full) or at all. If it's not replicated at all it needs to be pending because there is no data. If it's replicated but only transiently and we need to replicate it fully it must be marked as pending until it is available fully otherwise a read might treat this replica as full and not read from a full replica that has the data.
-
subtractIgnoreTransientStatus
public RangesAtEndpoint subtractIgnoreTransientStatus(Range<Token> subtract)
Don't use this method and ignore transient status unless you are explicitly handling it outside this method. This helper method is used by StorageService.calculateStreamAndFetchRanges to perform subtraction. It ignores transient status because it's already being handled in calculateStreamAndFetchRanges.
-
intersectsOnRange
public boolean intersectsOnRange(Replica replica)
-
fullReplica
public static Replica fullReplica(InetAddressAndPort endpoint, Range<Token> range)
-
fullReplica
public static Replica fullReplica(InetAddressAndPort endpoint, Token start, Token end)
-
transientReplica
public static Replica transientReplica(InetAddressAndPort endpoint, Range<Token> range)
-
transientReplica
public static Replica transientReplica(InetAddressAndPort endpoint, Token start, Token end)
-
-