Skip to content

Commit

Permalink
Integrate retention leases to recovery from remote (#38829)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor committed Feb 16, 2019
1 parent b2a9c15 commit 1d94c3c
Show file tree
Hide file tree
Showing 14 changed files with 989 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void onFailure(final Exception e) {
}

@Override
protected Response shardOperation(final T request, final ShardId shardId) throws IOException {
protected Response shardOperation(final T request, final ShardId shardId) {
throw new UnsupportedOperationException();
}

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

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

private Add() {
super(NAME);
super(ACTION_NAME);
}

public static class TransportAction extends TransportRetentionLeaseAction<AddRequest> {
Expand All @@ -160,7 +160,7 @@ public TransportAction(
final IndicesService indicesService) {
super(
settings,
NAME,
ACTION_NAME,
threadPool,
clusterService,
transportService,
Expand Down Expand Up @@ -206,10 +206,10 @@ static class AddRequestBuilder extends ActionRequestBuilder<AddRequest, Response
public static class Renew extends Action<RenewRequest, Response, RenewRequestBuilder> {

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

private Renew() {
super(NAME);
super(ACTION_NAME);
}

public static class TransportAction extends TransportRetentionLeaseAction<RenewRequest> {
Expand All @@ -225,7 +225,7 @@ public TransportAction(
final IndicesService indicesService) {
super(
settings,
NAME,
ACTION_NAME,
threadPool,
clusterService,
transportService,
Expand Down Expand Up @@ -267,10 +267,10 @@ static class RenewRequestBuilder extends ActionRequestBuilder<RenewRequest, Resp
public static class Remove extends Action<RemoveRequest, Response, RemoveRequestBuilder> {

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

private Remove() {
super(NAME);
super(ACTION_NAME);
}

public static class TransportAction extends TransportRetentionLeaseAction<RemoveRequest> {
Expand All @@ -286,7 +286,7 @@ public TransportAction(
final IndicesService indicesService) {
super(
settings,
NAME,
ACTION_NAME,
threadPool,
clusterService,
transportService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class RetentionLeaseAlreadyExistsException extends ResourceAlreadyExistsException {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class RetentionLeaseNotFoundException extends ResourceNotFoundException {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.ccr;

import org.elasticsearch.index.Index;

import java.util.Locale;

public class CcrRetentionLeases {

/**
* The retention lease ID used by followers.
*
* @param localClusterName the local cluster name
* @param followerIndex the follower index
* @param remoteClusterAlias the remote cluster alias
* @param leaderIndex the leader index
* @return the retention lease ID
*/
public static String retentionLeaseId(
final String localClusterName,
final Index followerIndex,
final String remoteClusterAlias,
final Index leaderIndex) {
return String.format(
Locale.ROOT,
"%s/%s/%s-following-%s/%s/%s",
localClusterName,
followerIndex.getName(),
followerIndex.getUUID(),
remoteClusterAlias,
leaderIndex.getName(),
leaderIndex.getUUID());
}

}
Loading

0 comments on commit 1d94c3c

Please sign in to comment.