Skip to content

Commit

Permalink
[Failure store - selector syntax] Replace failureOptions with selecto…
Browse files Browse the repository at this point in the history
…r options internally. (#114812) (#114882)

**Introduction**

> In order to make adoption of failure stores simpler for all users, we
are introducing a new syntactical feature to index expression
resolution: The selector. > > Selectors, denoted with a :: followed by a
recognized suffix will allow users to specify which component of an
index abstraction they would like to operate on within an API call. In
this case, an index abstraction is a concrete index, data stream, or
alias; Any abstraction that can be resolved to a set of indices/shards.
We define a component of an index abstraction to be some searchable unit
of the index abstraction. > > To start, we will support two components:
data and failures. Concrete indices are their own data components, while
the data component for index aliases are all of the indices contained
therein. For data streams, the data component corresponds to their
backing indices. Data stream aliases mirror this, treating all backing
indices of the data streams they correspond to as their data component.
>  > The failure component is only supported by data streams and data
stream aliases. The failure component of these abstractions refer to the
data streams' failure stores. Indices and index aliases do not have a
failure component.

For more details and examples see
#113144. All this work has
been cherry picked from there.

**Purpose of this PR**

This PR is replacing the `FailureStoreOptions` with the
`SelectorOptions`, there shouldn't be any perceivable change to the user
since we kept the query parameter "failure_store" for now. It will be
removed in the next PR which will introduce the parsing of the
expressions. 

_The current PR is just a refactoring and does not and should not change
any existing behaviour._
  • Loading branch information
gmarouli authored Oct 16, 2024
1 parent bfed7f6 commit 6de48b1
Show file tree
Hide file tree
Showing 23 changed files with 304 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ public void setup() throws Exception {
// Initialize the failure store.
RolloverRequest rolloverRequest = new RolloverRequest("with-fs", null);
rolloverRequest.setIndicesOptions(
IndicesOptions.builder(rolloverRequest.indicesOptions())
.failureStoreOptions(b -> b.includeRegularIndices(false).includeFailureIndices(true))
.build()
IndicesOptions.builder(rolloverRequest.indicesOptions()).selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES).build()
);
response = client.execute(RolloverAction.INSTANCE, rolloverRequest).get();
assertTrue(response.isAcknowledged());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ public void testRejectionFromFailureStore() throws IOException {
// Initialize failure store.
var rolloverRequest = new RolloverRequest(dataStream, null);
rolloverRequest.setIndicesOptions(
IndicesOptions.builder(rolloverRequest.indicesOptions())
.failureStoreOptions(opts -> opts.includeFailureIndices(true).includeRegularIndices(false))
.build()
IndicesOptions.builder(rolloverRequest.indicesOptions()).selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES).build()
);
var rolloverResponse = client().execute(RolloverAction.INSTANCE, rolloverRequest).actionGet();
var failureStoreIndex = rolloverResponse.getNewIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ private Set<Index> maybeExecuteForceMerge(ClusterState state, List<Index> indice
UpdateSettingsRequest updateMergePolicySettingsRequest = new UpdateSettingsRequest();
updateMergePolicySettingsRequest.indicesOptions(
IndicesOptions.builder(updateMergePolicySettingsRequest.indicesOptions())
.failureStoreOptions(new IndicesOptions.FailureStoreOptions(true, true))
.selectorOptions(IndicesOptions.SelectorOptions.DATA_AND_FAILURE)
.build()
);
updateMergePolicySettingsRequest.indices(indexName);
Expand Down Expand Up @@ -1409,7 +1409,7 @@ static RolloverRequest getDefaultRolloverRequest(
if (rolloverFailureStore) {
rolloverRequest.setIndicesOptions(
IndicesOptions.builder(rolloverRequest.indicesOptions())
.failureStoreOptions(opts -> opts.includeFailureIndices(true).includeRegularIndices(false))
.selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES)
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RestGetDataStreamsAction extends BaseRestHandler {
IndicesOptions.GatekeeperOptions.IGNORE_THROTTLED,
"verbose"
),
DataStream.isFailureStoreFeatureFlagEnabled() ? Set.of(IndicesOptions.FailureStoreOptions.FAILURE_STORE) : Set.of()
DataStream.isFailureStoreFeatureFlagEnabled() ? Set.of(IndicesOptions.FAILURE_STORE_QUERY_PARAM) : Set.of()
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,11 @@ public void testOperationsExecutedOnce() {
assertThat(clientSeenRequests.get(0), instanceOf(RolloverRequest.class));
RolloverRequest rolloverBackingIndexRequest = (RolloverRequest) clientSeenRequests.get(0);
assertThat(rolloverBackingIndexRequest.getRolloverTarget(), is(dataStreamName));
assertThat(
rolloverBackingIndexRequest.indicesOptions().failureStoreOptions(),
equalTo(new IndicesOptions.FailureStoreOptions(true, false))
);
assertThat(rolloverBackingIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_DATA));
assertThat(clientSeenRequests.get(1), instanceOf(RolloverRequest.class));
RolloverRequest rolloverFailureIndexRequest = (RolloverRequest) clientSeenRequests.get(1);
assertThat(rolloverFailureIndexRequest.getRolloverTarget(), is(dataStreamName));
assertThat(
rolloverFailureIndexRequest.indicesOptions().failureStoreOptions(),
equalTo(new IndicesOptions.FailureStoreOptions(false, true))
);
assertThat(rolloverFailureIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_FAILURES));
List<DeleteIndexRequest> deleteRequests = clientSeenRequests.subList(2, 5)
.stream()
.map(transportRequest -> (DeleteIndexRequest) transportRequest)
Expand Down Expand Up @@ -1549,17 +1543,11 @@ public void testFailureStoreIsManagedEvenWhenDisabled() {
assertThat(clientSeenRequests.get(0), instanceOf(RolloverRequest.class));
RolloverRequest rolloverBackingIndexRequest = (RolloverRequest) clientSeenRequests.get(0);
assertThat(rolloverBackingIndexRequest.getRolloverTarget(), is(dataStreamName));
assertThat(
rolloverBackingIndexRequest.indicesOptions().failureStoreOptions(),
equalTo(new IndicesOptions.FailureStoreOptions(true, false))
);
assertThat(rolloverBackingIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_DATA));
assertThat(clientSeenRequests.get(1), instanceOf(RolloverRequest.class));
RolloverRequest rolloverFailureIndexRequest = (RolloverRequest) clientSeenRequests.get(1);
assertThat(rolloverFailureIndexRequest.getRolloverTarget(), is(dataStreamName));
assertThat(
rolloverFailureIndexRequest.indicesOptions().failureStoreOptions(),
equalTo(new IndicesOptions.FailureStoreOptions(false, true))
);
assertThat(rolloverFailureIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_FAILURES));
assertThat(
((DeleteIndexRequest) clientSeenRequests.get(2)).indices()[0],
is(dataStream.getFailureIndices().getIndices().get(0).getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static TransportVersion def(int id) {
public static final TransportVersion QUERY_RULE_TEST_API = def(8_769_00_0);
public static final TransportVersion ESQL_PER_AGGREGATE_FILTER = def(8_770_00_0);
public static final TransportVersion ML_INFERENCE_ATTACH_TO_EXISTSING_DEPLOYMENT = def(8_771_00_0);
public static final TransportVersion CONVERT_FAILURE_STORE_OPTIONS_TO_SELECTOR_OPTIONS_INTERNALLY = def(8_772_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ public GetIndexRequest() {
super(
DataStream.isFailureStoreFeatureFlagEnabled()
? IndicesOptions.builder(IndicesOptions.strictExpandOpen())
.failureStoreOptions(
IndicesOptions.FailureStoreOptions.builder().includeRegularIndices(true).includeFailureIndices(true)
)
.selectorOptions(IndicesOptions.SelectorOptions.DATA_AND_FAILURE)
.build()
: IndicesOptions.strictExpandOpen()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public ActionRequestValidationException validate() {
);
}

var failureStoreOptions = indicesOptions.failureStoreOptions();
if (failureStoreOptions.includeRegularIndices() && failureStoreOptions.includeFailureIndices()) {
var selectors = indicesOptions.selectorOptions().defaultSelectors();
if (selectors.size() > 1) {
validationException = addValidationError(
"rollover cannot be applied to both regular and failure indices at the same time",
validationException
Expand Down Expand Up @@ -188,7 +188,7 @@ public IndicesOptions indicesOptions() {
* @return true of the rollover request targets the failure store, false otherwise.
*/
public boolean targetsFailureStore() {
return DataStream.isFailureStoreFeatureFlagEnabled() && indicesOptions.failureStoreOptions().includeFailureIndices();
return DataStream.isFailureStoreFeatureFlagEnabled() && indicesOptions.includeFailureIndices();
}

public void setIndicesOptions(IndicesOptions indicesOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState
.matchClosed(request.indicesOptions().expandWildcardsClosed())
.build(),
IndicesOptions.GatekeeperOptions.DEFAULT,
request.indicesOptions().failureStoreOptions()
request.indicesOptions().selectorOptions()
);

return state.blocks()
Expand Down Expand Up @@ -247,7 +247,7 @@ protected void masterOperation(
IndicesOptions.ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS,
IndicesOptions.WildcardOptions.builder().matchClosed(true).allowEmptyExpressions(false).build(),
IndicesOptions.GatekeeperOptions.DEFAULT,
rolloverRequest.indicesOptions().failureStoreOptions()
rolloverRequest.indicesOptions().selectorOptions()
);
IndicesStatsRequest statsRequest = new IndicesStatsRequest().indices(rolloverRequest.getRolloverTarget())
.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void rollOverFailureStores(Runnable runnable) {
RolloverRequest rolloverRequest = new RolloverRequest(dataStream, null);
rolloverRequest.setIndicesOptions(
IndicesOptions.builder(rolloverRequest.indicesOptions())
.failureStoreOptions(new IndicesOptions.FailureStoreOptions(false, true))
.selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES)
.build()
);
// We are executing a lazy rollover because it is an action specialised for this situation, when we want an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private void rollOverDataStreams(
if (targetFailureStore) {
rolloverRequest.setIndicesOptions(
IndicesOptions.builder(rolloverRequest.indicesOptions())
.failureStoreOptions(new IndicesOptions.FailureStoreOptions(false, true))
.selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES)
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public Request() {
.allowFailureIndices(true)
.build()
)
.failureStoreOptions(
IndicesOptions.FailureStoreOptions.builder().includeRegularIndices(true).includeFailureIndices(true).build()
)
.selectorOptions(IndicesOptions.SelectorOptions.DATA_AND_FAILURE)
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.action.support;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* We define as index components the two different sets of indices a data stream could consist of:
* - DATA: represents the backing indices
* - FAILURES: represent the failing indices
* Note: An index is its own DATA component, but it cannot have a FAILURE component.
*/
public enum IndexComponentSelector {
DATA("data"),
FAILURES("failures");

private final String key;

IndexComponentSelector(String key) {
this.key = key;
}

public String getKey() {
return key;
}

private static final Map<String, IndexComponentSelector> REGISTRY;

static {
Map<String, IndexComponentSelector> registry = new HashMap<>(IndexComponentSelector.values().length);
for (IndexComponentSelector value : IndexComponentSelector.values()) {
registry.put(value.getKey(), value);
}
REGISTRY = Collections.unmodifiableMap(registry);
}

public static IndexComponentSelector getByKey(String key) {
return REGISTRY.get(key);
}
}
Loading

0 comments on commit 6de48b1

Please sign in to comment.