forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pause/Resume Auto Follower APIs (elastic#47510)
This commit adds two APIs that allow to pause and resume CCR auto-follower patterns: // pause auto-follower POST /_ccr/auto_follow/my_pattern/pause // resume auto-follower POST /_ccr/auto_follow/my_pattern/resume The ability to pause and resume auto-follow patterns can be useful in some situations, including the rolling upgrades of cluster using a bi-directional cross-cluster replication scheme (see elastic#46665). This committ adds a new active flag to the AutoFollowPattern and adapts the AutoCoordinator and AutoFollower classes so that it stops to fetch remote's cluster state when all auto-follow patterns associate to the remote cluster are paused. When an auto-follower is paused, remote indices that match the pattern are just ignored: they are not added to the pattern's followed indices uids list that is maintained in the local cluster state. This way, when the auto-follow pattern is resumed the indices created in the remote cluster in the meantime will be picked up again and added as new following indices. Indices created and then deleted in the remote cluster will be ignored as they won't be seen at all by the auto-follower pattern at resume time.
- Loading branch information
1 parent
c8d4f14
commit 8e0616a
Showing
25 changed files
with
1,165 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...ain/java/org/elasticsearch/xpack/ccr/action/TransportActivateAutoFollowPatternAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* 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.action; | ||
|
||
import org.elasticsearch.ResourceNotFoundException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeAction; | ||
import org.elasticsearch.cluster.AckedClusterStateUpdateTask; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.block.ClusterBlockLevel; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata; | ||
import org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction; | ||
import org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.Request; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TransportActivateAutoFollowPatternAction extends TransportMasterNodeAction<Request, AcknowledgedResponse> { | ||
|
||
@Inject | ||
public TransportActivateAutoFollowPatternAction(TransportService transportService, ClusterService clusterService, | ||
ThreadPool threadPool, ActionFilters actionFilters, | ||
IndexNameExpressionResolver resolver) { | ||
super(ActivateAutoFollowPatternAction.NAME, transportService, clusterService, threadPool, actionFilters, Request::new, resolver); | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return ThreadPool.Names.SAME; | ||
} | ||
|
||
@Override | ||
protected AcknowledgedResponse read(final StreamInput in) throws IOException { | ||
return new AcknowledgedResponse(in); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(final Request request, final ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
|
||
@Override | ||
protected void masterOperation(final Task task, final Request request, final ClusterState state, | ||
final ActionListener<AcknowledgedResponse> listener) throws Exception { | ||
clusterService.submitStateUpdateTask("activate-auto-follow-pattern-" + request.getName(), | ||
new AckedClusterStateUpdateTask<>(request, listener) { | ||
|
||
@Override | ||
protected AcknowledgedResponse newResponse(final boolean acknowledged) { | ||
return new AcknowledgedResponse(acknowledged); | ||
} | ||
|
||
@Override | ||
public ClusterState execute(final ClusterState currentState) throws Exception { | ||
return innerActivate(request, currentState); | ||
} | ||
}); | ||
} | ||
|
||
static ClusterState innerActivate(final Request request, ClusterState currentState) { | ||
final AutoFollowMetadata autoFollowMetadata = currentState.metaData().custom(AutoFollowMetadata.TYPE); | ||
if (autoFollowMetadata == null) { | ||
throw new ResourceNotFoundException("auto-follow pattern [{}] is missing", request.getName()); | ||
} | ||
|
||
final Map<String, AutoFollowMetadata.AutoFollowPattern> patterns = autoFollowMetadata.getPatterns(); | ||
final AutoFollowMetadata.AutoFollowPattern previousAutoFollowPattern = patterns.get(request.getName()); | ||
if (previousAutoFollowPattern == null) { | ||
throw new ResourceNotFoundException("auto-follow pattern [{}] is missing", request.getName()); | ||
} | ||
|
||
if (previousAutoFollowPattern.isActive() == request.isActive()) { | ||
return currentState; | ||
} | ||
|
||
final Map<String, AutoFollowMetadata.AutoFollowPattern> newPatterns = new HashMap<>(patterns); | ||
newPatterns.put(request.getName(), | ||
new AutoFollowMetadata.AutoFollowPattern( | ||
previousAutoFollowPattern.getRemoteCluster(), | ||
previousAutoFollowPattern.getLeaderIndexPatterns(), | ||
previousAutoFollowPattern.getFollowIndexPattern(), | ||
request.isActive(), | ||
previousAutoFollowPattern.getMaxReadRequestOperationCount(), | ||
previousAutoFollowPattern.getMaxWriteRequestOperationCount(), | ||
previousAutoFollowPattern.getMaxOutstandingReadRequests(), | ||
previousAutoFollowPattern.getMaxOutstandingWriteRequests(), | ||
previousAutoFollowPattern.getMaxReadRequestSize(), | ||
previousAutoFollowPattern.getMaxWriteRequestSize(), | ||
previousAutoFollowPattern.getMaxWriteBufferCount(), | ||
previousAutoFollowPattern.getMaxWriteBufferSize(), | ||
previousAutoFollowPattern.getMaxRetryDelay(), | ||
previousAutoFollowPattern.getReadPollTimeout())); | ||
|
||
return ClusterState.builder(currentState) | ||
.metaData(MetaData.builder(currentState.getMetaData()) | ||
.putCustom(AutoFollowMetadata.TYPE, | ||
new AutoFollowMetadata(newPatterns, autoFollowMetadata.getFollowedLeaderIndexUUIDs(), autoFollowMetadata.getHeaders())) | ||
.build()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.