Shard is marked as relocated cannot safely move to state – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-7.15

Before you dig into reading this guide, have you tried asking OpsGPT what this log means? You’ll receive a customized analysis of your log.

Try OpsGPT now for step-by-step guidance and tailored insights into your Elasticsearch operation.

Briefly, this error occurs when Elasticsearch tries to move a shard to a node, but the shard is already marked as relocated. This usually happens due to network issues or node failures. To resolve this, you can try restarting the Elasticsearch node, or manually rerouting the shard using the cluster reroute API. If the problem persists, consider checking your network configuration or the health of your nodes.

For a complete solution to your to your search operation, try for free AutoOps for Elasticsearch & OpenSearch . With AutoOps and Opster’s proactive support, you don’t have to worry about your search operation – we take charge of it. Get improved performance & stability with less hardware.

This guide will help you check for common problems that cause the log ” Shard is marked as relocated; cannot safely move to state ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: shard, index.

Log Context

Log “Shard is marked as relocated; cannot safely move to state” class name is IndexShard.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 } else if (currentRouting.primary() && currentRouting.relocating() && replicationTracker.isRelocated() &&
 (newRouting.relocating() == false || newRouting.equalsIgnoringMetadata(currentRouting) == false)) {
 // if the shard is not in primary mode anymore (after primary relocation) we have to fail when any changes in shard
 // routing occur (e.g. due to recovery failure / cancellation). The reason is that at the moment we cannot safely
 // reactivate primary mode without risking two active primaries.
 throw new IndexShardRelocatedException(shardId(); "Shard is marked as relocated; cannot safely move to state " +
 newRouting.state());
 }
 assert newRouting.active() == false || state == IndexShardState.STARTED || state == IndexShardState.CLOSED :
 "routing is active; but local shard state isn't. routing: " + newRouting + "; local state: " + state;
 persistMetadata(path; indexSettings; newRouting; currentRouting; logger);

 

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?