Skip to content

Commit a23bd96

Browse files
authored
Include leases in ccr errmsg when ops no longer available (#45681)
The setting index.soft_deletes.retention.operations is no longer needed nor recommended in CCR. We, therefore, should hint users about the retention leases period setting instead when operations are no longer available for replicating.
1 parent e4f30f3 commit a23bd96

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.index.IndexService;
3131
import org.elasticsearch.index.IndexSettings;
3232
import org.elasticsearch.index.engine.MissingHistoryOperationsException;
33+
import org.elasticsearch.index.seqno.RetentionLease;
3334
import org.elasticsearch.index.seqno.SeqNoStats;
3435
import org.elasticsearch.index.shard.IndexShard;
3536
import org.elasticsearch.index.shard.IndexShardNotStartedException;
@@ -44,6 +45,7 @@
4445
import java.io.IOException;
4546
import java.util.ArrayList;
4647
import java.util.Arrays;
48+
import java.util.Collection;
4749
import java.util.List;
4850
import java.util.Objects;
4951
import java.util.concurrent.TimeUnit;
@@ -529,8 +531,10 @@ static Translog.Operation[] getOperations(
529531
}
530532
}
531533
} catch (MissingHistoryOperationsException e) {
532-
String message = "Operations are no longer available for replicating. Maybe increase the retention setting [" +
533-
IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey() + "]?";
534+
final Collection<RetentionLease> retentionLeases = indexShard.getRetentionLeases().leases();
535+
final String message = "Operations are no longer available for replicating. " +
536+
"Existing retention leases [" + retentionLeases + "]; maybe increase the retention lease period setting " +
537+
"[" + IndexSettings.INDEX_SOFT_DELETES_RETENTION_LEASE_PERIOD_SETTING.getKey() + "]?";
534538
// Make it easy to detect this error in ShardFollowNodeTask:
535539
// (adding a metadata header instead of introducing a new exception that extends ElasticsearchException)
536540
ResourceNotFoundException wrapper = new ResourceNotFoundException(message, e);

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/ShardChangesTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import org.elasticsearch.common.xcontent.XContentType;
1818
import org.elasticsearch.index.IndexService;
1919
import org.elasticsearch.index.engine.Engine;
20+
import org.elasticsearch.index.seqno.RetentionLease;
21+
import org.elasticsearch.index.seqno.RetentionLeaseActions;
22+
import org.elasticsearch.index.shard.ShardId;
2023
import org.elasticsearch.index.translog.Translog;
2124
import org.elasticsearch.plugins.Plugin;
2225
import org.elasticsearch.test.ESSingleNodeTestCase;
@@ -128,17 +131,22 @@ public void testMissingOperations() throws Exception {
128131
forceMergeRequest.maxNumSegments(1);
129132
client().admin().indices().forceMerge(forceMergeRequest).actionGet();
130133

134+
client().admin().indices().execute(RetentionLeaseActions.Add.INSTANCE, new RetentionLeaseActions.AddRequest(
135+
new ShardId(resolveIndex("index"), 0), "test", RetentionLeaseActions.RETAIN_ALL, "ccr")).get();
136+
131137
ShardStats shardStats = client().admin().indices().prepareStats("index").get().getIndex("index").getShards()[0];
132138
String historyUUID = shardStats.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY);
139+
Collection<RetentionLease> retentionLeases = shardStats.getRetentionLeaseStats().retentionLeases().leases();
133140
ShardChangesAction.Request request = new ShardChangesAction.Request(shardStats.getShardRouting().shardId(), historyUUID);
134141
request.setFromSeqNo(0L);
135142
request.setMaxOperationCount(1);
136143

137144
{
138145
ResourceNotFoundException e =
139146
expectThrows(ResourceNotFoundException.class, () -> client().execute(ShardChangesAction.INSTANCE, request).actionGet());
140-
assertThat(e.getMessage(), equalTo("Operations are no longer available for replicating. Maybe increase the retention setting " +
141-
"[index.soft_deletes.retention.operations]?"));
147+
assertThat(e.getMessage(), equalTo("Operations are no longer available for replicating. " +
148+
"Existing retention leases [" + retentionLeases + "]; maybe increase the retention lease period setting " +
149+
"[index.soft_deletes.retention_lease.period]?"));
142150

143151
assertThat(e.getMetadataKeys().size(), equalTo(1));
144152
assertThat(e.getMetadata(Ccr.REQUESTED_OPS_MISSING_METADATA_KEY), notNullValue());
@@ -157,7 +165,8 @@ public void testMissingOperations() throws Exception {
157165

158166
ResourceNotFoundException cause = (ResourceNotFoundException) e.getCause();
159167
assertThat(cause.getMessage(), equalTo("Operations are no longer available for replicating. " +
160-
"Maybe increase the retention setting [index.soft_deletes.retention.operations]?"));
168+
"Existing retention leases [" + retentionLeases + "]; maybe increase the retention lease period setting " +
169+
"[index.soft_deletes.retention_lease.period]?"));
161170
assertThat(cause.getMetadataKeys().size(), equalTo(1));
162171
assertThat(cause.getMetadata(Ccr.REQUESTED_OPS_MISSING_METADATA_KEY), notNullValue());
163172
assertThat(cause.getMetadata(Ccr.REQUESTED_OPS_MISSING_METADATA_KEY), contains("0", "0"));

0 commit comments

Comments
 (0)