Failed to prepare shard for recovery – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-8.9

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 is unable to prepare a shard for recovery due to issues like insufficient disk space, network connectivity problems, or corrupted data. To resolve this, you can try freeing up disk space, checking network connectivity, or restoring the shard from a backup. If the shard is corrupted and there’s no backup, you may need to delete and recreate it. Also, ensure that the Elasticsearch cluster health is green and all nodes are functioning properly.

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 ” failed to prepare shard for recovery ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: shard, recovery, indices.

Log Context

Log “failed to prepare shard for recovery” class name is PeerRecoveryTargetService.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 final var cleanupOnly = ActionListener.notifyOnce(ActionListener.runBefore(ActionListener.noop().delegateResponse((l; e) -> {
 // this will be logged as warning later on...
 logger.trace("unexpected error while preparing shard for peer recovery; failing recovery"; e);
 onGoingRecoveries.failRecovery(
 recoveryId;
 new RecoveryFailedException(recoveryTarget.state(); "failed to prepare shard for recovery"; e);
 true
 );
 }); onCompletion::close));  if (indexShard.routingEntry().isPromotableToPrimary() == false) {

 

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?