org.apache.solr.common.cloud

## Class PerReplicaStatesOps

- java.lang.Object
- - org.apache.solr.common.cloud.PerReplicaStatesOps

    public class PerReplicaStatesOps
    extends Object

This is a helper class that encapsulates various operations performed on the per-replica states Do not directly manipulate the per replica states as it can become difficult to debug them

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static PerReplicaStatesOps` `addReplica(String replica, Replica.State state, boolean isLeader, PerReplicaStates rs)`
`static PerReplicaStatesOps` `deleteReplica(String replica, PerReplicaStates rs)` Delete a replica entry from per-replica states
`static PerReplicaStatesOps` `downReplicas(List<String> replicas, PerReplicaStates rs)` mark a bunch of replicas as DOWN
`static PerReplicaStatesOps` `flipLeader(Set<String> allReplicas, String next, PerReplicaStates rs)` Flip the leader replica to a new one
`static PerReplicaStatesOps` `flipState(String replica, Replica.State newState, PerReplicaStates rs)` state of a replica is changed
`List<PerReplicaStates.Operation>` `get()`
`List<PerReplicaStates.Operation>` `get(PerReplicaStates rs)`
`PerReplicaStates` `getPerReplicaStates()`
`boolean` `isPreOp()` To be executed before collection state.json is persisted
`static PerReplicaStatesOps` `modifyCollection(DocCollection coll, boolean enable, PerReplicaStates rs)` Switch a collection from/to perReplicaState=true
`void` `persist(String znode, SolrZkClient zkClient)` This is a persist operation with retry if a write fails due to stale state
`String` `toString()`
`static PerReplicaStatesOps` `touchChildren()` Just creates and deletes a dummy entry so that the `Stat.getCversion()` of states.json is updated

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Method Detail

#### persist

    public void persist(String znode,
                        SolrZkClient zkClient)
                 throws org.apache.zookeeper.KeeperException,
                        InterruptedException

This is a persist operation with retry if a write fails due to stale state

Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### getPerReplicaStates

    public PerReplicaStates getPerReplicaStates()

#### flipState

    public static PerReplicaStatesOps flipState(String replica,
                                                Replica.State newState,
                                                PerReplicaStates rs)

state of a replica is changed

Parameters:
  `newState` - the new state

#### modifyCollection

    public static PerReplicaStatesOps modifyCollection(DocCollection coll,
                                                       boolean enable,
                                                       PerReplicaStates rs)

Switch a collection from/to perReplicaState=true

#### flipLeader

    public static PerReplicaStatesOps flipLeader(Set<String> allReplicas,
                                                 String next,
                                                 PerReplicaStates rs)

Flip the leader replica to a new one

Parameters:
  `allReplicas` - allReplicas of the shard
  `next` - next leader

#### deleteReplica

    public static PerReplicaStatesOps deleteReplica(String replica,
                                                    PerReplicaStates rs)

Delete a replica entry from per-replica states

Parameters:
  `replica` - name of the replica to be deleted

#### addReplica

    public static PerReplicaStatesOps addReplica(String replica,
                                                 Replica.State state,
                                                 boolean isLeader,
                                                 PerReplicaStates rs)

#### downReplicas

    public static PerReplicaStatesOps downReplicas(List<String> replicas,
                                                   PerReplicaStates rs)

mark a bunch of replicas as DOWN

#### touchChildren

    public static PerReplicaStatesOps touchChildren()

Just creates and deletes a dummy entry so that the `Stat.getCversion()` of states.json is updated

#### get

    public List<PerReplicaStates.Operation> get()

#### get

    public List<PerReplicaStates.Operation> get(PerReplicaStates rs)

#### isPreOp

    public boolean isPreOp()

To be executed before collection state.json is persisted

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`