Class ReplicaCount

java.lang.Object
org.apache.solr.common.cloud.ReplicaCount

public final class ReplicaCount extends Object
Tracks the number of replicas per replica type. This class is mutable.
  • Method Details

    • empty

      public static ReplicaCount empty()
    • of

      public static ReplicaCount of(Replica.Type type, Integer count)
    • of

      public static ReplicaCount of(Integer nrtReplicas, Integer tlogReplicas, Integer pullReplicas)
    • fromMessage

      public static ReplicaCount fromMessage(ZkNodeProps message)
    • fromMessage

      public static ReplicaCount fromMessage(ZkNodeProps message, DocCollection collection)
    • fromMessage

      public static ReplicaCount fromMessage(ZkNodeProps message, DocCollection collection, Integer defaultReplicationFactor)
      Creates a ReplicaCount from a message.

      This method has a rich logic for defaulting parameters. A collection can optionally be provided as a fallback for all properties. Among all properties, replica factor is applied as the number of replicas for the default replica type. The default replica type can be provided as a property, or else comes from Replica.Type.defaultType().

      Not all capabilities apply on every call of this method. For example, the message may not contain any replication factor.

      Parameters:
      message - a message.
      collection - an optional collection providing defaults.
      defaultReplicationFactor - an additional optional default replica factor, if none is found in the collection.
    • fromProps

      public static ReplicaCount fromProps(Map<String,Object> propMap)
      Creates a ReplicaCount from a properties map.

      This method is much simpler than fromMessage(org.apache.solr.common.cloud.ZkNodeProps), as it only considers properties containing a number of replicas (and ignores other properties such as the replication factor).

      Parameters:
      propMap - a properties map
    • get

      public int get(Replica.Type type)
      Returns the number of replicas for a given type.
      Parameters:
      type - a replica type
    • contains

      public boolean contains(Replica.Type type)
      Returns whether the number of replicas for a given type was explicitly defined.
      Parameters:
      type - a replica type
    • keySet

      public Set<Replica.Type> keySet()
      Returns the replica types for which a number of replicas was explicitly defined.
    • writeProps

      public void writeProps(Map<String,Object> propMap)
      Add properties for replica counts as integers to a properties map.
      Parameters:
      propMap - a properties map.
    • writeProps

      public void writeProps(ModifiableSolrParams params)
      Add properties for replica counts as integers to Solr parameters.
      Parameters:
      params - a set of modifiable Solr parameters.
    • put

      public void put(Replica.Type type, Integer count)
      Defines the number of replicas for a given type.
      Parameters:
      type - a replica type
      count - a number of replicas (if null, mark the value as missing)
    • increment

      public void increment(Replica.Type type)
      Increment the number of replicas for a given type.
      Parameters:
      type - a replica type
    • decrement

      public void decrement(Replica.Type type)
      Decrement the number of replicas for a given type.
      Parameters:
      type - a replica type
    • total

      public int total()
      Returns the total number of replicas.
    • hasLeaderReplica

      public boolean hasLeaderReplica()
      Returns whether there is at least one replica which can be a leader.
    • getLeaderType

      public Replica.Type getLeaderType()
      Returns the first non-zero replica type that can be a leader.
      Throws:
      SolrException - if no such replica exists
    • equals

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

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

      public String toString()
      Returns a representation of this class which can be used for debugging.
      Overrides:
      toString in class Object