Skip to content

Commit

Permalink
Do not mark verified from ILM shrink.
Browse files Browse the repository at this point in the history
  • Loading branch information
henningandersen committed Jan 15, 2025
1 parent f1edf02 commit 77243a6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public record AddIndexBlockClusterStateUpdateRequest(
TimeValue masterNodeTimeout,
TimeValue ackTimeout,
APIBlock block,
long taskId,
boolean markVerified, long taskId,
Index[] indices
) {
public AddIndexBlockClusterStateUpdateRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.elasticsearch.action.admin.indices.readonly;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
Expand All @@ -32,12 +33,18 @@ public class AddIndexBlockRequest extends AcknowledgedRequest<AddIndexBlockReque
private final APIBlock block;
private String[] indices;
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
private boolean markVerified = true;

public AddIndexBlockRequest(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
block = APIBlock.readFrom(in);
if (in.getTransportVersion().onOrAfter(TransportVersions.ADD_INDEX_BLOCK_TWO_PHASE)) {
markVerified = in.readBoolean();
} else {
markVerified = false;
}
}

/**
Expand Down Expand Up @@ -103,6 +110,14 @@ public AddIndexBlockRequest indicesOptions(IndicesOptions indicesOptions) {
return this;
}

public boolean markVerified() {
return markVerified;
}

public AddIndexBlockRequest markVerified(boolean markVerified) {
this.markVerified = markVerified;
return this;
}
/**
* Returns the block to be added
*/
Expand All @@ -116,6 +131,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
block.writeTo(out);
if (out.getTransportVersion().onOrAfter(TransportVersions.ADD_INDEX_BLOCK_TWO_PHASE)) {
out.writeBoolean(markVerified);
}
}

@Override
Expand All @@ -136,4 +154,5 @@ public int hashCode() {
result = 31 * result + Arrays.hashCode(indices);
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected void masterOperation(
request.masterNodeTimeout(),
request.ackTimeout(),
request.getBlock(),
request.markVerified(),
task.getId(),
concreteIndices
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public void taskSucceeded(AddBlocksTask task, Map<Index, ClusterBlock> blockedIn
task.request,
blockedIndices,
verifyResults,
clusterService.state()
task.request().markVerified() && clusterService.state()
.getMinTransportVersion()
.onOrAfter(TransportVersions.ADD_INDEX_BLOCK_TWO_PHASE),
delegate2
Expand Down Expand Up @@ -546,7 +546,7 @@ public Tuple<ClusterState, List<AddBlockResult>> executeTask(FinalizeBlocksTask
task.blockedIndices,
task.verifyResults,
task.request.block(),
task.flushed()
task.markVerified()
);
assert finalizeResult.v2().size() == task.verifyResults.size();
return finalizeResult;
Expand All @@ -563,7 +563,7 @@ private record FinalizeBlocksTask(
AddIndexBlockClusterStateUpdateRequest request,
Map<Index, ClusterBlock> blockedIndices,
Map<Index, AddBlockResult> verifyResults,
boolean flushed,
boolean markVerified,
ActionListener<AddIndexBlockResponse> listener
) implements ClusterStateTaskListener {
@Override
Expand Down Expand Up @@ -983,15 +983,15 @@ private void onlyOpenIndices(final OpenIndexClusterStateUpdateRequest request, f
* @param blockedIndices the indices and their temporary UUID-based blocks to convert
* @param verifyResult the index-level results for adding the block
* @param block the full block to convert to
* @param flushed if we are guaranteed that data has been flushed in case of a write-level block.
* @param markVerified if the index should be marked verified in case of a write-level block.
* @return the updated cluster state, as well as the (failed and successful) index-level results for adding the block
*/
private static Tuple<ClusterState, List<AddBlockResult>> finalizeBlock(
final ClusterState currentState,
final Map<Index, ClusterBlock> blockedIndices,
final Map<Index, AddBlockResult> verifyResult,
final APIBlock block,
final boolean flushed
final boolean markVerified
) {
final ClusterBlocks.Builder blocks = ClusterBlocks.builder(currentState.blocks());
final Metadata.Builder metadata = Metadata.builder(currentState.metadata());
Expand Down Expand Up @@ -1043,7 +1043,7 @@ private static Tuple<ClusterState, List<AddBlockResult>> finalizeBlock(
logger.debug("add block {} to index {} succeeded", block.block, index);
effectivelyBlockedIndices.add(index.getName());

if (block.getBlock().contains(ClusterBlockLevel.WRITE) && flushed) {
if (block.getBlock().contains(ClusterBlockLevel.WRITE) && markVerified) {
final IndexMetadata indexMetadata = metadata.getSafe(index);
final IndexMetadata.Builder updatedMetadata = IndexMetadata.builder(indexMetadata).state(IndexMetadata.State.CLOSE);
metadata.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) {
Instant::now
);
// Mark source index as read-only
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, generateDownsampleIndexNameKey, client);
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, generateDownsampleIndexNameKey, client, true);

// Before the downsample action was retry-able, we used to generate a unique downsample index name and delete the previous index in
// case a failure occurred. The downsample action can now retry execution in case of failure and start where it left off, so no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) {
readOnlyKey,
Instant::now
);
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, nextStepKey, client);
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, nextStepKey, client, true);
return List.of(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
*/
public class ReadOnlyStep extends AsyncActionStep {
public static final String NAME = "readonly";
private final boolean markVerified;

public ReadOnlyStep(StepKey key, StepKey nextStepKey, Client client) {
/**
* @param markVerified whether the index should be marked verified after becoming read-only, ensuring that N-2 is supported without
* manual intervention. Should be set to true when the read-only block is not temporary.
*/
public ReadOnlyStep(StepKey key, StepKey nextStepKey, Client client, boolean markVerified) {
super(key, nextStepKey, client);
this.markVerified = markVerified;
}

@Override
Expand All @@ -39,7 +45,8 @@ public void performAction(
.indices()
.execute(
TransportAddIndexBlockAction.TYPE,
new AddIndexBlockRequest(WRITE, indexMetadata.getIndex().getName()).masterNodeTimeout(TimeValue.MAX_VALUE),
new AddIndexBlockRequest(WRITE, indexMetadata.getIndex().getName()).masterNodeTimeout(TimeValue.MAX_VALUE)
.markVerified(markVerified),
listener.delegateFailureAndWrap((l, response) -> {
if (response.isAcknowledged() == false) {
throw new ElasticsearchException("read only add block index request failed to be acknowledged");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey)
readOnlyKey,
Instant::now
);
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, checkTargetShardsCountKey, client);
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, checkTargetShardsCountKey, client, false);
CheckTargetShardsCountStep checkTargetShardsCountStep = new CheckTargetShardsCountStep(
checkTargetShardsCountKey,
cleanupShrinkIndexKey,
Expand Down

0 comments on commit 77243a6

Please sign in to comment.