-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Transform] finalize feature reset integration (#71133)
This commit updates transform feature reset to: - wait for transform tasks to complete - wait for all indexing actions to transform indices to complete - and prevents transform audit messages from being written while the reset is being processed related to #70008 & #69581
- Loading branch information
Showing
21 changed files
with
775 additions
and
192 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
131 changes: 131 additions & 0 deletions
131
...rc/main/java/org/elasticsearch/xpack/core/action/AbstractTransportSetResetModeAction.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,131 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.action; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.elasticsearch.ElasticsearchTimeoutException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.AcknowledgedTransportMasterNodeAction; | ||
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.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
public abstract class AbstractTransportSetResetModeAction extends AcknowledgedTransportMasterNodeAction<SetResetModeActionRequest> { | ||
|
||
private static final Logger logger = LogManager.getLogger(AbstractTransportSetResetModeAction.class); | ||
private final ClusterService clusterService; | ||
|
||
@Inject | ||
public AbstractTransportSetResetModeAction( | ||
String actionName, | ||
TransportService transportService, | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver) { | ||
super( | ||
actionName, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
SetResetModeActionRequest::new, | ||
indexNameExpressionResolver, | ||
ThreadPool.Names.SAME | ||
); | ||
this.clusterService = clusterService; | ||
} | ||
|
||
protected abstract boolean isResetMode(ClusterState clusterState); | ||
|
||
protected abstract String featureName(); | ||
|
||
protected abstract ClusterState setState(ClusterState oldState, SetResetModeActionRequest request); | ||
|
||
@Override | ||
protected void masterOperation(Task task, | ||
SetResetModeActionRequest request, | ||
ClusterState state, | ||
ActionListener<AcknowledgedResponse> listener) throws Exception { | ||
|
||
final boolean isResetModeEnabled = isResetMode(state); | ||
// Noop, nothing for us to do, simply return fast to the caller | ||
if (request.isEnabled() == isResetModeEnabled) { | ||
logger.debug(() -> new ParameterizedMessage("Reset mode noop for [{}]", featureName())); | ||
listener.onResponse(AcknowledgedResponse.TRUE); | ||
return; | ||
} | ||
|
||
logger.debug( | ||
() -> new ParameterizedMessage( | ||
"Starting to set [reset_mode] for [{}] to [{}] from [{}]", | ||
featureName(), | ||
request.isEnabled(), | ||
isResetModeEnabled | ||
) | ||
); | ||
|
||
ActionListener<AcknowledgedResponse> wrappedListener = ActionListener.wrap( | ||
r -> { | ||
logger.debug(() -> new ParameterizedMessage("Completed reset mode request for [{}]", featureName())); | ||
listener.onResponse(r); | ||
}, | ||
e -> { | ||
logger.debug( | ||
() -> new ParameterizedMessage("Completed reset mode for [{}] request but with failure", featureName()), | ||
e | ||
); | ||
listener.onFailure(e); | ||
} | ||
); | ||
|
||
ActionListener<AcknowledgedResponse> clusterStateUpdateListener = ActionListener.wrap( | ||
acknowledgedResponse -> { | ||
if (acknowledgedResponse.isAcknowledged() == false) { | ||
wrappedListener.onFailure(new ElasticsearchTimeoutException("Unknown error occurred while updating cluster state")); | ||
return; | ||
} | ||
wrappedListener.onResponse(acknowledgedResponse); | ||
}, | ||
wrappedListener::onFailure | ||
); | ||
|
||
clusterService.submitStateUpdateTask(featureName() + "-set-reset-mode", | ||
new AckedClusterStateUpdateTask(request, clusterStateUpdateListener) { | ||
|
||
@Override | ||
protected AcknowledgedResponse newResponse(boolean acknowledged) { | ||
logger.trace(() -> new ParameterizedMessage("Cluster update response built for [{}]: {}", featureName(), acknowledged)); | ||
return AcknowledgedResponse.of(acknowledged); | ||
} | ||
|
||
@Override | ||
public ClusterState execute(ClusterState currentState) { | ||
logger.trace(() -> new ParameterizedMessage("Executing cluster state update for [{}]", featureName())); | ||
return setState(currentState, request); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(SetResetModeActionRequest request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...gin/core/src/main/java/org/elasticsearch/xpack/core/action/SetResetModeActionRequest.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,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.action; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class SetResetModeActionRequest extends AcknowledgedRequest<SetResetModeActionRequest> implements ToXContentObject { | ||
public static SetResetModeActionRequest enabled() { | ||
return new SetResetModeActionRequest(true); | ||
} | ||
|
||
public static SetResetModeActionRequest disabled() { | ||
return new SetResetModeActionRequest(false); | ||
} | ||
|
||
private final boolean enabled; | ||
|
||
private static final ParseField ENABLED = new ParseField("enabled"); | ||
public static final ConstructingObjectParser<SetResetModeActionRequest, Void> PARSER = | ||
new ConstructingObjectParser<>("set_reset_mode_action_request", a -> new SetResetModeActionRequest((Boolean)a[0])); | ||
|
||
static { | ||
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), ENABLED); | ||
} | ||
|
||
SetResetModeActionRequest(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public SetResetModeActionRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.enabled = in.readBoolean(); | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeBoolean(enabled); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(enabled); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null || obj.getClass() != getClass()) { | ||
return false; | ||
} | ||
SetResetModeActionRequest other = (SetResetModeActionRequest) obj; | ||
return Objects.equals(enabled, other.enabled); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(ENABLED.getPreferredName(), enabled); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
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
Oops, something went wrong.