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 authored Feb 16, 2019
1 parent 5a58c9e commit 2024e33
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 @@ -115,7 +115,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 @@ -136,10 +136,10 @@ protected boolean resolveIndex(final T request) {
public static class Add extends Action<Response> {

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 @@ -153,7 +153,7 @@ public TransportAction(
final IndexNameExpressionResolver indexNameExpressionResolver,
final IndicesService indicesService) {
super(
NAME,
ACTION_NAME,
threadPool,
clusterService,
transportService,
Expand Down Expand Up @@ -186,10 +186,10 @@ public Response newResponse() {
public static class Renew extends Action<Response> {

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 @@ -203,7 +203,7 @@ public TransportAction(
final IndexNameExpressionResolver indexNameExpressionResolver,
final IndicesService indicesService) {
super(
NAME,
ACTION_NAME,
threadPool,
clusterService,
transportService,
Expand Down Expand Up @@ -232,10 +232,10 @@ public Response newResponse() {
public static class Remove extends Action<Response> {

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 @@ -249,7 +249,7 @@ public TransportAction(
final IndexNameExpressionResolver indexNameExpressionResolver,
final IndicesService indicesService) {
super(
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 2024e33

Please sign in to comment.