-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add Pause/Resume Auto Follower APIs #47510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e59148
Add Pause/Resume Auto Follower APIs
tlrx c1bdf88
Skip Rest tests
tlrx fd72431
more fixes
tlrx 98c63ad
Merge branch 'master' into pause-auto-followers
elasticmachine 0348221
Merge branch 'master' into pause-auto-followers
elasticmachine e79c8f3
mvg feedback
tlrx 0a551a2
jason feedback
tlrx c985832
Merge branch 'master' into pause-auto-followers
tlrx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is
Math.max(1L, nextMetadataVersion)
needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm reading it again, I'm not sure it is really needed. I'll dig into that.