Skip to content

Commit 1d94c3c

Browse files
committed
Integrate retention leases to recovery from remote (elastic#38829)
This commit is the first step in integrating shard history retention leases with CCR. In this commit we integrate shard history retention leases with recovery from remote. Before we start transferring files, we take out a retention lease on the primary. Then during the file copy phase, we repeatedly renew the retention lease. Finally, when recovery from remote is complete, we disable the background renewing of the retention lease.
1 parent b2a9c15 commit 1d94c3c

File tree

14 files changed

+989
-96
lines changed

14 files changed

+989
-96
lines changed

server/src/main/java/org/elasticsearch/index/seqno/RetentionLeaseActions.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void onFailure(final Exception e) {
120120
}
121121

122122
@Override
123-
protected Response shardOperation(final T request, final ShardId shardId) throws IOException {
123+
protected Response shardOperation(final T request, final ShardId shardId) {
124124
throw new UnsupportedOperationException();
125125
}
126126

@@ -141,10 +141,10 @@ protected boolean resolveIndex(final T request) {
141141
public static class Add extends Action<AddRequest, Response, AddRequestBuilder> {
142142

143143
public static final Add INSTANCE = new Add();
144-
public static final String NAME = "indices:admin/seq_no/add_retention_lease";
144+
public static final String ACTION_NAME = "indices:admin/seq_no/add_retention_lease";
145145

146146
private Add() {
147-
super(NAME);
147+
super(ACTION_NAME);
148148
}
149149

150150
public static class TransportAction extends TransportRetentionLeaseAction<AddRequest> {
@@ -160,7 +160,7 @@ public TransportAction(
160160
final IndicesService indicesService) {
161161
super(
162162
settings,
163-
NAME,
163+
ACTION_NAME,
164164
threadPool,
165165
clusterService,
166166
transportService,
@@ -206,10 +206,10 @@ static class AddRequestBuilder extends ActionRequestBuilder<AddRequest, Response
206206
public static class Renew extends Action<RenewRequest, Response, RenewRequestBuilder> {
207207

208208
public static final Renew INSTANCE = new Renew();
209-
public static final String NAME = "indices:admin/seq_no/renew_retention_lease";
209+
public static final String ACTION_NAME = "indices:admin/seq_no/renew_retention_lease";
210210

211211
private Renew() {
212-
super(NAME);
212+
super(ACTION_NAME);
213213
}
214214

215215
public static class TransportAction extends TransportRetentionLeaseAction<RenewRequest> {
@@ -225,7 +225,7 @@ public TransportAction(
225225
final IndicesService indicesService) {
226226
super(
227227
settings,
228-
NAME,
228+
ACTION_NAME,
229229
threadPool,
230230
clusterService,
231231
transportService,
@@ -267,10 +267,10 @@ static class RenewRequestBuilder extends ActionRequestBuilder<RenewRequest, Resp
267267
public static class Remove extends Action<RemoveRequest, Response, RemoveRequestBuilder> {
268268

269269
public static final Remove INSTANCE = new Remove();
270-
public static final String NAME = "indices:admin/seq_no/remove_retention_lease";
270+
public static final String ACTION_NAME = "indices:admin/seq_no/remove_retention_lease";
271271

272272
private Remove() {
273-
super(NAME);
273+
super(ACTION_NAME);
274274
}
275275

276276
public static class TransportAction extends TransportRetentionLeaseAction<RemoveRequest> {
@@ -286,7 +286,7 @@ public TransportAction(
286286
final IndicesService indicesService) {
287287
super(
288288
settings,
289-
NAME,
289+
ACTION_NAME,
290290
threadPool,
291291
clusterService,
292292
transportService,

server/src/main/java/org/elasticsearch/index/seqno/RetentionLeaseAlreadyExistsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public class RetentionLeaseAlreadyExistsException extends ResourceAlreadyExistsException {
2929

30-
RetentionLeaseAlreadyExistsException(final String id) {
30+
public RetentionLeaseAlreadyExistsException(final String id) {
3131
super("retention lease with ID [" + Objects.requireNonNull(id) + "] already exists");
3232
}
3333

server/src/main/java/org/elasticsearch/index/seqno/RetentionLeaseNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public class RetentionLeaseNotFoundException extends ResourceNotFoundException {
2929

30-
RetentionLeaseNotFoundException(final String id) {
30+
public RetentionLeaseNotFoundException(final String id) {
3131
super("retention lease with ID [" + Objects.requireNonNull(id) + "] not found");
3232
}
3333

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.ccr;
8+
9+
import org.elasticsearch.index.Index;
10+
11+
import java.util.Locale;
12+
13+
public class CcrRetentionLeases {
14+
15+
/**
16+
* The retention lease ID used by followers.
17+
*
18+
* @param localClusterName the local cluster name
19+
* @param followerIndex the follower index
20+
* @param remoteClusterAlias the remote cluster alias
21+
* @param leaderIndex the leader index
22+
* @return the retention lease ID
23+
*/
24+
public static String retentionLeaseId(
25+
final String localClusterName,
26+
final Index followerIndex,
27+
final String remoteClusterAlias,
28+
final Index leaderIndex) {
29+
return String.format(
30+
Locale.ROOT,
31+
"%s/%s/%s-following-%s/%s/%s",
32+
localClusterName,
33+
followerIndex.getName(),
34+
followerIndex.getUUID(),
35+
remoteClusterAlias,
36+
leaderIndex.getName(),
37+
leaderIndex.getUUID());
38+
}
39+
40+
}

0 commit comments

Comments
 (0)