Class Replica

java.lang.Object
org.apache.cassandra.locator.Replica
All Implemented Interfaces:
Comparable<Replica>

public final class Replica extends Object implements 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 Details

  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(Replica o)
      Specified by:
      compareTo in interface Comparable<Replica>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • endpoint

      public final InetAddressAndPort endpoint()
    • isSelf

      public boolean isSelf()
    • range

      public Range<Token> range()
    • 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.
    • contains

      public boolean contains(Range<Token> that)
    • intersectsOnRange

      public boolean intersectsOnRange(Replica replica)
    • decorateSubrange

      public Replica decorateSubrange(Range<Token> subrange)
    • 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)