Class SimClusterStateProvider

  • All Implemented Interfaces:
    Closeable, AutoCloseable, ClusterStateProvider, SolrCloseable

    public class SimClusterStateProvider
    extends Object
    implements ClusterStateProvider
    Simulated ClusterStateProvider.

    The following behaviors are supported:

    • using autoscaling policy for replica placements
    • maintaining and up-to-date list of /live_nodes and nodeAdded / nodeLost markers
    • running a simulated leader election on collection changes (with throttling), when needed
    • maintaining an up-to-date /clusterstate.json (single file format), which also tracks replica states, leader election changes, replica property changes, etc. Note: this file is only written, but never read by the framework!
    • maintaining an up-to-date /clusterprops.json. Note: this file is only written, but never read by the framework!
    • Field Detail

      • DEFAULT_DOC_SIZE_BYTES

        public static final long DEFAULT_DOC_SIZE_BYTES
        See Also:
        Constant Field Values
    • Constructor Detail

      • SimClusterStateProvider

        public SimClusterStateProvider​(LiveNodesSet liveNodes,
                                       SimCloudManager cloudManager)
                                throws Exception
        The instance needs to be initialized using the sim* methods in order to ensure proper behavior, otherwise it will behave as a cluster with zero replicas.
        Throws:
        Exception
    • Method Detail

      • simSetClusterState

        public void simSetClusterState​(ClusterState initialState)
                                throws Exception
        Initialize from an existing cluster state
        Parameters:
        initialState - initial cluster state
        Throws:
        Exception
      • simResetLeaderThrottles

        public void simResetLeaderThrottles()
        Reset the leader election throttles.
      • simGetRandomNode

        public String simGetRandomNode()
        Get random node id.
        Returns:
        one of the live nodes
      • simGetRandomNode

        public String simGetRandomNode​(Random random)
        Get random node id.
        Parameters:
        random - instance of random.
        Returns:
        one of the live nodes
      • simAddNode

        public void simAddNode​(String nodeId)
                        throws Exception
        Add a new node to the cluster.
        Parameters:
        nodeId - unique node id
        Throws:
        Exception
      • simRemoveNode

        public boolean simRemoveNode​(String nodeId)
                              throws Exception
        Remove node from a cluster. This is equivalent to a situation when a node is lost. All replicas that were assigned to this node are marked as DOWN.
        Parameters:
        nodeId - node id
        Returns:
        true if a node existed and was removed
        Throws:
        Exception
      • simRemoveDeadNodes

        public void simRemoveDeadNodes()
                                throws Exception
        Remove all replica information related to dead nodes.
        Throws:
        Exception
      • simGetOverseerLeader

        public String simGetOverseerLeader()
      • simRestoreNode

        public boolean simRestoreNode​(String nodeId)
                               throws Exception
        Restore a previously removed node. This also simulates a short replica recovery state.
        Parameters:
        nodeId - node id to restore
        Returns:
        true when this operation restored any replicas, false otherwise (empty node).
        Throws:
        Exception
      • simAddReplica

        public void simAddReplica​(ZkNodeProps message,
                                  NamedList results)
                           throws Exception
        Add a new replica. Note that if any details of a replica (node, coreNodeName, SolrCore name, etc) are missing they will be filled in using the policy framework.
        Parameters:
        message - replica details
        results - result of the operation
        Throws:
        Exception
      • simAddReplica

        public void simAddReplica​(String nodeId,
                                  ReplicaInfo replicaInfo,
                                  boolean runLeaderElection)
                           throws Exception
        Add a replica. Note that all details of the replica must be present here, including node, coreNodeName and SolrCore name.
        Parameters:
        nodeId - node id where the replica will be added
        replicaInfo - replica info
        runLeaderElection - if true then run a leader election after adding the replica.
        Throws:
        Exception
      • simRemoveReplica

        public void simRemoveReplica​(String nodeId,
                                     String coreNodeName)
                              throws Exception
        Remove replica.
        Parameters:
        nodeId - node id
        coreNodeName - coreNodeName
        Throws:
        Exception
      • simCreateCollection

        public void simCreateCollection​(ZkNodeProps props,
                                        NamedList results)
                                 throws Exception
        Create a new collection. This operation uses policy framework for node and replica assignments.
        Parameters:
        props - collection details
        results - results of the operation.
        Throws:
        Exception
      • simDeleteCollection

        public void simDeleteCollection​(String collection,
                                        String async,
                                        NamedList results)
                                 throws Exception
        Delete a collection
        Parameters:
        collection - collection name
        async - async id
        results - results of the operation
        Throws:
        Exception
      • simDeleteAllCollections

        public void simDeleteAllCollections()
                                     throws Exception
        Remove all collections.
        Throws:
        Exception
      • simMoveReplica

        public void simMoveReplica​(ZkNodeProps message,
                                   NamedList results)
                            throws Exception
        Move replica. This uses a similar algorithm as MoveReplicaCmd moveNormalReplica(...) method.
        Parameters:
        message - operation details
        results - operation results.
        Throws:
        Exception
      • simCreateShard

        public void simCreateShard​(ZkNodeProps message,
                                   NamedList results)
                            throws Exception
        Create a new shard. This uses a similar algorithm as CreateShardCmd.
        Parameters:
        message - operation details
        results - operation results
        Throws:
        Exception
      • simSplitShard

        public void simSplitShard​(ZkNodeProps message,
                                  NamedList results)
                           throws Exception
        Split a shard. This uses a similar algorithm as SplitShardCmd, including simulating its quirks, and leaving the original parent slice in place.
        Parameters:
        message - operation details
        results - operation results.
        Throws:
        Exception
      • simUpdate

        public UpdateResponse simUpdate​(UpdateRequest req)
                                 throws SolrException,
                                        InterruptedException,
                                        IOException
        Simulate an update by modifying replica metrics. The following core metrics are updated:
        • SEARCHER.searcher.numDocs - increased by added docs, decreased by deleteById and deleteByQuery
        • SEARCHER.searcher.deletedDocs - decreased by deleteById and deleteByQuery by up to numDocs
        • SEARCHER.searcher.maxDoc - always increased by the number of added docs.

        IMPORTANT limitations:

        • document replacements are always counted as new docs
        • delete by ID always succeeds (unless numDocs == 0)
        • deleteByQuery is not supported unless the query is *:*
        Parameters:
        req - update request. This request MUST have the collection param set.
        Returns:
        UpdateResponse
        Throws:
        SolrException - on errors, such as nonexistent collection or unsupported deleteByQuery
        InterruptedException
        IOException
      • simSetClusterProperties

        public void simSetClusterProperties​(Map<String,​Object> properties)
                                     throws Exception
        Set all cluster properties. This also updates the clusterprops.json data in DistribStateManager
        Parameters:
        properties - properties to set
        Throws:
        Exception
      • simSetClusterProperty

        public void simSetClusterProperty​(String key,
                                          Object value)
                                   throws Exception
        Set a cluster property. This also updates the clusterprops.json data in DistribStateManager
        Parameters:
        key - property name
        value - property value
        Throws:
        Exception
      • simSetCollectionProperties

        public void simSetCollectionProperties​(String coll,
                                               Map<String,​Object> properties)
                                        throws Exception
        Set collection properties.
        Parameters:
        coll - collection name
        properties - properties
        Throws:
        Exception
      • simSetCollectionProperty

        public void simSetCollectionProperty​(String coll,
                                             String key,
                                             String value)
                                      throws Exception
        Set collection property.
        Parameters:
        coll - collection name
        key - property name
        value - property value
        Throws:
        Exception
      • simSetSliceProperties

        public void simSetSliceProperties​(String coll,
                                          String slice,
                                          Map<String,​Object> properties)
                                   throws Exception
        Set slice properties.
        Parameters:
        coll - collection name
        slice - slice name
        properties - slice properties
        Throws:
        Exception
      • simSetCollectionValue

        public void simSetCollectionValue​(String collection,
                                          String key,
                                          Object value)
                                   throws Exception
        Set per-collection value (eg. a metric). This value will be applied to each replica.
        Parameters:
        collection - collection name
        key - property name
        value - property value
        Throws:
        Exception
      • simSetCollectionValue

        public void simSetCollectionValue​(String collection,
                                          String key,
                                          Object value,
                                          boolean delta,
                                          boolean divide)
                                   throws Exception
        Set per-collection value (eg. a metric). This value will be applied to each replica.
        Parameters:
        collection - collection name
        key - property name
        value - property value
        divide - if the value is a Number and this param is true, then the value will be evenly divided by the number of replicas.
        Throws:
        Exception
      • simSetShardValue

        public void simSetShardValue​(String collection,
                                     String shard,
                                     String key,
                                     Object value)
                              throws Exception
        Set per-collection value (eg. a metric). This value will be applied to each replica in a selected shard.
        Parameters:
        collection - collection name
        shard - shard name. If null then all shards will be affected.
        key - property name
        value - property value
        Throws:
        Exception
      • simSetShardValue

        public void simSetShardValue​(String collection,
                                     String shard,
                                     String key,
                                     Object value,
                                     boolean delta,
                                     boolean divide)
                              throws Exception
        Set per-collection value (eg. a metric). This value will be applied to each replica in a selected shard.
        Parameters:
        collection - collection name
        shard - shard name. If null then all shards will be affected.
        key - property name
        value - property value
        delta - if true then treat the numeric value as delta to add to the existing value (or set the value to delta if missing)
        divide - if the value is a Number and this is true, then the value will be evenly divided by the number of replicas.
        Throws:
        Exception
      • simGetReplicaInfos

        public List<ReplicaInfo> simGetReplicaInfos​(String node)
        Return all replica infos for a node.
        Parameters:
        node - node id
        Returns:
        copy of the list of replicas on that node, or empty list if none