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

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.

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?