Briefly, this error occurs when Elasticsearch detects that a repository contains snapshots that are older than the current version. This is a safety measure to prevent potential data loss or corruption. To resolve this issue, you can either delete the old snapshots or upgrade them to the current version. Alternatively, you can create a new repository for the newer version snapshots and keep the old repository for the older version snapshots.
This guide will help you check for common problems that cause the log ” Sleeping for [{}] after modifying repository [{}] because it contains snapshots older than version [{}] ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: plugins, repository, version, repository-s3, repositories.
Overview
A version corresponds to the Elasticsearch built-in tracking system that tracks the changes in each document’s update. When a document is indexed for the first time, it is assigned a version 1 using _version key. When the same document gets a subsequent update, the _version is incremented by 1 with every index, update or delete API call.
What it is used for
A version is used to handle the concurrency issues in Elasticsearch which come into play during simultaneous accessing of an index by multiple users. Elasticsearch handles this issue with an optimistic locking concept using the _version parameter to avoid letting multiple users edit the same document at the same time and protects users from generating incorrect data.
Notes
You cannot see the history of the document using _version. That means Elasticsearch does not use _version to keep a track of original changes that had been performed on the document. For example, if a document has been updated 10 times, it’s _version would be marked by Elasticsearch as 11, but you cannot go back and see what version 5 of the document looked like. This has to be implemented independently.
Common problems
If optimistic locking is not implemented while making updates to a document, Elasticsearch may return a conflict error with the 409 status code, which means that multiple users are trying to update the same version of the document at the same time.
POST /ratings/123?version=50 { "name": "Joker", "rating": 50 }
Log Context
Log “Sleeping for [{}] after modifying repository [{}] because it contains snapshots older than version [{}]” classname is S3Repository.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :
} }; } private void logCooldownInfo() { logger.info("Sleeping for [{}] after modifying repository [{}] because it contains snapshots older than version [{}]" + " and therefore is using a backwards compatible metadata format that requires this cooldown period to avoid " + "repository corruption. To get rid of this message and move to the new repository metadata format; either remove " + "all snapshots older than version [{}] from the repository or create a new repository at an empty location."; coolDown; metadata.name(); SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION; SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION);