= SolrCloud Autoscaling Automatically Adding Replicas
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

Solr provides a way to automatically add replicas for a collection when the number of active replicas drops below
the replication factor specified at the time of the creation of the collection.

== The autoAddReplicas Parameter

The boolean `autoAddReplicas` parameter can be passed to the CREATE command of the Collection API to enable this feature for a given collection.

.Create a collection with autoAddReplicas enabled
[source,text]
http://localhost:8983/solr/admin/collections?action=CREATE&name=my_collection&numShards=1&replicationFactor=5&autoAddReplicas=true

The MODIFYCOLLECTION command can be used to enable or disable this feature for any collection.

.Modify collection to disable autoAddReplicas
[source,text]
http://localhost:8983/solr/admin/collections?action=MODIFYCOLLECTION&collection=my_collection&autoAddReplicas=false

== Implementation Using .autoAddReplicas Trigger

A Trigger named `.autoAddReplicas` is automatically created whenever any collection has the autoAddReplicas feature enabled.

Only one trigger is sufficient to serve all collections having this feature enabled. The `.autoAddReplicas` trigger watches for nodes that are lost from the cluster and uses the default `TriggerActions` to create new replicas to replace the ones which were hosted by the lost node. If the old node comes back online, it unloads the moved replicas and the node is free to host other replicas as and when required.

Since the trigger provides the autoAddReplicas feature for all collections, the `suspend-trigger` and `resume-trigger` Autoscaling API commands can be used to disable and enable this feature for all collections in one API call.

.Suspending autoAddReplicas for all collections
[source,json]
----
{
  "suspend-trigger": {
    "name" : ".autoAddReplicas"
  }
}
----

.Resuming autoAddReplicas for all collections
[source,json]
----
{
  "resume-trigger": {
    "name" : ".autoAddReplicas"
  }
}
----

== Using Cluster Property to Enable autoAddReplicas

A cluster property, also named `autoAddReplicas`, can be set to `false` to disable this feature for all collections.
If this cluster property is missing or set to `true`, the autoAddReplicas is enabled for all collections.

.Deprecation Warning
[WARNING]
====
Using a cluster property to enable or disable autoAddReplicas is deprecated and only supported for back compatibility. Please use the `suspend-trigger` and `resume-trigger` API commands instead.
====
