Skip to content

Commit 6de48b1

Browse files
authored
[Failure store - selector syntax] Replace failureOptions with selector 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._
1 parent bfed7f6 commit 6de48b1

File tree

23 files changed

+304
-199
lines changed

23 files changed

+304
-199
lines changed

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public void setup() throws Exception {
132132
// Initialize the failure store.
133133
RolloverRequest rolloverRequest = new RolloverRequest("with-fs", null);
134134
rolloverRequest.setIndicesOptions(
135-
IndicesOptions.builder(rolloverRequest.indicesOptions())
136-
.failureStoreOptions(b -> b.includeRegularIndices(false).includeFailureIndices(true))
137-
.build()
135+
IndicesOptions.builder(rolloverRequest.indicesOptions()).selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES).build()
138136
);
139137
response = client.execute(RolloverAction.INSTANCE, rolloverRequest).get();
140138
assertTrue(response.isAcknowledged());

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/IngestFailureStoreMetricsIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ public void testRejectionFromFailureStore() throws IOException {
198198
// Initialize failure store.
199199
var rolloverRequest = new RolloverRequest(dataStream, null);
200200
rolloverRequest.setIndicesOptions(
201-
IndicesOptions.builder(rolloverRequest.indicesOptions())
202-
.failureStoreOptions(opts -> opts.includeFailureIndices(true).includeRegularIndices(false))
203-
.build()
201+
IndicesOptions.builder(rolloverRequest.indicesOptions()).selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES).build()
204202
);
205203
var rolloverResponse = client().execute(RolloverAction.INSTANCE, rolloverRequest).actionGet();
206204
var failureStoreIndex = rolloverResponse.getNewIndex();

modules/data-streams/src/main/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ private Set<Index> maybeExecuteForceMerge(ClusterState state, List<Index> indice
946946
UpdateSettingsRequest updateMergePolicySettingsRequest = new UpdateSettingsRequest();
947947
updateMergePolicySettingsRequest.indicesOptions(
948948
IndicesOptions.builder(updateMergePolicySettingsRequest.indicesOptions())
949-
.failureStoreOptions(new IndicesOptions.FailureStoreOptions(true, true))
949+
.selectorOptions(IndicesOptions.SelectorOptions.DATA_AND_FAILURE)
950950
.build()
951951
);
952952
updateMergePolicySettingsRequest.indices(indexName);
@@ -1409,7 +1409,7 @@ static RolloverRequest getDefaultRolloverRequest(
14091409
if (rolloverFailureStore) {
14101410
rolloverRequest.setIndicesOptions(
14111411
IndicesOptions.builder(rolloverRequest.indicesOptions())
1412-
.failureStoreOptions(opts -> opts.includeFailureIndices(true).includeRegularIndices(false))
1412+
.selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES)
14131413
.build()
14141414
);
14151415
}

modules/data-streams/src/main/java/org/elasticsearch/datastreams/rest/RestGetDataStreamsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RestGetDataStreamsAction extends BaseRestHandler {
4343
IndicesOptions.GatekeeperOptions.IGNORE_THROTTLED,
4444
"verbose"
4545
),
46-
DataStream.isFailureStoreFeatureFlagEnabled() ? Set.of(IndicesOptions.FailureStoreOptions.FAILURE_STORE) : Set.of()
46+
DataStream.isFailureStoreFeatureFlagEnabled() ? Set.of(IndicesOptions.FAILURE_STORE_QUERY_PARAM) : Set.of()
4747
)
4848
);
4949

modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleServiceTests.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,11 @@ public void testOperationsExecutedOnce() {
225225
assertThat(clientSeenRequests.get(0), instanceOf(RolloverRequest.class));
226226
RolloverRequest rolloverBackingIndexRequest = (RolloverRequest) clientSeenRequests.get(0);
227227
assertThat(rolloverBackingIndexRequest.getRolloverTarget(), is(dataStreamName));
228-
assertThat(
229-
rolloverBackingIndexRequest.indicesOptions().failureStoreOptions(),
230-
equalTo(new IndicesOptions.FailureStoreOptions(true, false))
231-
);
228+
assertThat(rolloverBackingIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_DATA));
232229
assertThat(clientSeenRequests.get(1), instanceOf(RolloverRequest.class));
233230
RolloverRequest rolloverFailureIndexRequest = (RolloverRequest) clientSeenRequests.get(1);
234231
assertThat(rolloverFailureIndexRequest.getRolloverTarget(), is(dataStreamName));
235-
assertThat(
236-
rolloverFailureIndexRequest.indicesOptions().failureStoreOptions(),
237-
equalTo(new IndicesOptions.FailureStoreOptions(false, true))
238-
);
232+
assertThat(rolloverFailureIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_FAILURES));
239233
List<DeleteIndexRequest> deleteRequests = clientSeenRequests.subList(2, 5)
240234
.stream()
241235
.map(transportRequest -> (DeleteIndexRequest) transportRequest)
@@ -1549,17 +1543,11 @@ public void testFailureStoreIsManagedEvenWhenDisabled() {
15491543
assertThat(clientSeenRequests.get(0), instanceOf(RolloverRequest.class));
15501544
RolloverRequest rolloverBackingIndexRequest = (RolloverRequest) clientSeenRequests.get(0);
15511545
assertThat(rolloverBackingIndexRequest.getRolloverTarget(), is(dataStreamName));
1552-
assertThat(
1553-
rolloverBackingIndexRequest.indicesOptions().failureStoreOptions(),
1554-
equalTo(new IndicesOptions.FailureStoreOptions(true, false))
1555-
);
1546+
assertThat(rolloverBackingIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_DATA));
15561547
assertThat(clientSeenRequests.get(1), instanceOf(RolloverRequest.class));
15571548
RolloverRequest rolloverFailureIndexRequest = (RolloverRequest) clientSeenRequests.get(1);
15581549
assertThat(rolloverFailureIndexRequest.getRolloverTarget(), is(dataStreamName));
1559-
assertThat(
1560-
rolloverFailureIndexRequest.indicesOptions().failureStoreOptions(),
1561-
equalTo(new IndicesOptions.FailureStoreOptions(false, true))
1562-
);
1550+
assertThat(rolloverFailureIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_FAILURES));
15631551
assertThat(
15641552
((DeleteIndexRequest) clientSeenRequests.get(2)).indices()[0],
15651553
is(dataStream.getFailureIndices().getIndices().get(0).getName())

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ static TransportVersion def(int id) {
245245
public static final TransportVersion QUERY_RULE_TEST_API = def(8_769_00_0);
246246
public static final TransportVersion ESQL_PER_AGGREGATE_FILTER = def(8_770_00_0);
247247
public static final TransportVersion ML_INFERENCE_ATTACH_TO_EXISTSING_DEPLOYMENT = def(8_771_00_0);
248+
public static final TransportVersion CONVERT_FAILURE_STORE_OPTIONS_TO_SELECTOR_OPTIONS_INTERNALLY = def(8_772_00_0);
248249

249250
/*
250251
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ public GetIndexRequest() {
9898
super(
9999
DataStream.isFailureStoreFeatureFlagEnabled()
100100
? IndicesOptions.builder(IndicesOptions.strictExpandOpen())
101-
.failureStoreOptions(
102-
IndicesOptions.FailureStoreOptions.builder().includeRegularIndices(true).includeFailureIndices(true)
103-
)
101+
.selectorOptions(IndicesOptions.SelectorOptions.DATA_AND_FAILURE)
104102
.build()
105103
: IndicesOptions.strictExpandOpen()
106104
);

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ public ActionRequestValidationException validate() {
147147
);
148148
}
149149

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

194194
public void setIndicesOptions(IndicesOptions indicesOptions) {

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState
150150
.matchClosed(request.indicesOptions().expandWildcardsClosed())
151151
.build(),
152152
IndicesOptions.GatekeeperOptions.DEFAULT,
153-
request.indicesOptions().failureStoreOptions()
153+
request.indicesOptions().selectorOptions()
154154
);
155155

156156
return state.blocks()
@@ -247,7 +247,7 @@ protected void masterOperation(
247247
IndicesOptions.ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS,
248248
IndicesOptions.WildcardOptions.builder().matchClosed(true).allowEmptyExpressions(false).build(),
249249
IndicesOptions.GatekeeperOptions.DEFAULT,
250-
rolloverRequest.indicesOptions().failureStoreOptions()
250+
rolloverRequest.indicesOptions().selectorOptions()
251251
);
252252
IndicesStatsRequest statsRequest = new IndicesStatsRequest().indices(rolloverRequest.getRolloverTarget())
253253
.clear()

server/src/main/java/org/elasticsearch/action/bulk/BulkOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private void rollOverFailureStores(Runnable runnable) {
212212
RolloverRequest rolloverRequest = new RolloverRequest(dataStream, null);
213213
rolloverRequest.setIndicesOptions(
214214
IndicesOptions.builder(rolloverRequest.indicesOptions())
215-
.failureStoreOptions(new IndicesOptions.FailureStoreOptions(false, true))
215+
.selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES)
216216
.build()
217217
);
218218
// We are executing a lazy rollover because it is an action specialised for this situation, when we want an

0 commit comments

Comments
 (0)