Log Updating number_of_replicas to for indices – How To Solve Related Issues


Log Updating number_of_replicas to for indices – How To Solve Related Issues

Opster Team

Jan-20, Version: 1.7-8.0

 

Before you begin reading this guide, we recommend you try running the Elasticsearch Error Check-Up which can resolve issues that cause many errors.

This guide will help you check for common problems that cause the log ” Updating number_of_replicas to for indices ” to appear. It’s important to understand the issues related to the log, so to get started, read the general overview on common issues and tips related to the Elasticsearch concepts: allocation, cluster, indices and routing.

Advanced users might want to skip right to the common problems section in each concept or try running the Check-Up which analyses ES to pinpoint the cause of many errors and provides suitable actionable recommendations how to resolve them (free tool that requires no installation).

Overview

Elasticsearch replica shards can be updated dynamically both manually (by hitting API) or dynamically (based on the number of nodes and configuration) in order to improve search latency. A change in the number of replicas is a critical event, and Elasticsearch logs this event as below:

updating number_of_replicas to {new replicas number} for indices {affected indices list}.

Manual update: 

Using Index update setting for existing indices or Index template for a future index. The Elasticsearch class for executing these changes is MetaDataUpdateSettingsService.java. 

Dynamic update: 

It’s common to upscale and downscale Elasticsearch clusters based on traffic, and for the same reason, having a fixed number of replicas isn’t very useful in cases like these. That’s why Elasticsearch came up with the concept of Index.auto_expand_replicas(default false), which can dynamically increase/decrease the number of replicas based on the configuration and number of nodes in the cluster. 

Example:

If configured (0-5), the number of allocated replicas will match the number of nodes you create. If you increase/decrease, these numbers will also be changed accordingly. Refer to Elasticsearch founder post and this official doc for more details.

org.elasticsearch.cluster.routing.allocation.AllocationService#adaptAutoExpandReplicas This method handles dynamically updating the replicas.

Bottom Line: 

This log is solely for information purposes and there’s nothing much to worry about with them, but if it changes without your knowledge,  there is a scope to take appropriate actions like:

Index.auto_expand_replicas : false

or

Changing the index template to make sure all future indices are not created with fixed settings

Log context

Log “Updating number_of_replicas to [{}] for indices {}” classname is AllocationService.java
We extracted the following from Elasticsearch source code for those seeking an in-depth context :

                     final IndexMetaData indexMetaData = metaDataBuilder.get(index);
                    final IndexMetaData.Builder indexMetaDataBuilder =
                            new IndexMetaData.Builder(indexMetaData).settingsVersion(1 + indexMetaData.getSettingsVersion());
                    metaDataBuilder.put(indexMetaDataBuilder);
                }
                logger.info("updating number_of_replicas to [{}] for indices {}"; numberOfReplicas; indices);
            }
            final ClusterState fixedState = ClusterState.builder(clusterState).routingTable(routingTableBuilder.build())
                .metaData(metaDataBuilder).build();
            assert AutoExpandReplicas.getAutoExpandReplicaChanges(fixedState.metaData(); fixedState.nodes()).isEmpty();
            return fixedState;




 

Optimize Elasticsearch Performance

Try The Tool