Skip to content

Commit 5271b20

Browse files
authored
[Failure store - selector syntax] Replace failureOptions with selector options internally. (#114812)
**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 64e8659 commit 5271b20

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
@@ -138,9 +138,7 @@ public void setup() throws Exception {
138138
// Initialize the failure store.
139139
RolloverRequest rolloverRequest = new RolloverRequest("with-fs", null);
140140
rolloverRequest.setIndicesOptions(
141-
IndicesOptions.builder(rolloverRequest.indicesOptions())
142-
.failureStoreOptions(b -> b.includeRegularIndices(false).includeFailureIndices(true))
143-
.build()
141+
IndicesOptions.builder(rolloverRequest.indicesOptions()).selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES).build()
144142
);
145143
response = client.execute(RolloverAction.INSTANCE, rolloverRequest).get();
146144
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
@@ -195,9 +195,7 @@ public void testRejectionFromFailureStore() throws IOException {
195195
// Initialize failure store.
196196
var rolloverRequest = new RolloverRequest(dataStream, null);
197197
rolloverRequest.setIndicesOptions(
198-
IndicesOptions.builder(rolloverRequest.indicesOptions())
199-
.failureStoreOptions(opts -> opts.includeFailureIndices(true).includeRegularIndices(false))
200-
.build()
198+
IndicesOptions.builder(rolloverRequest.indicesOptions()).selectorOptions(IndicesOptions.SelectorOptions.ONLY_FAILURES).build()
201199
);
202200
var rolloverResponse = client().execute(RolloverAction.INSTANCE, rolloverRequest).actionGet();
203201
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)
@@ -1552,17 +1546,11 @@ public void testFailureStoreIsManagedEvenWhenDisabled() {
15521546
assertThat(clientSeenRequests.get(0), instanceOf(RolloverRequest.class));
15531547
RolloverRequest rolloverBackingIndexRequest = (RolloverRequest) clientSeenRequests.get(0);
15541548
assertThat(rolloverBackingIndexRequest.getRolloverTarget(), is(dataStreamName));
1555-
assertThat(
1556-
rolloverBackingIndexRequest.indicesOptions().failureStoreOptions(),
1557-
equalTo(new IndicesOptions.FailureStoreOptions(true, false))
1558-
);
1549+
assertThat(rolloverBackingIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_DATA));
15591550
assertThat(clientSeenRequests.get(1), instanceOf(RolloverRequest.class));
15601551
RolloverRequest rolloverFailureIndexRequest = (RolloverRequest) clientSeenRequests.get(1);
15611552
assertThat(rolloverFailureIndexRequest.getRolloverTarget(), is(dataStreamName));
1562-
assertThat(
1563-
rolloverFailureIndexRequest.indicesOptions().failureStoreOptions(),
1564-
equalTo(new IndicesOptions.FailureStoreOptions(false, true))
1565-
);
1553+
assertThat(rolloverFailureIndexRequest.indicesOptions().selectorOptions(), equalTo(IndicesOptions.SelectorOptions.ONLY_FAILURES));
15661554
assertThat(
15671555
((DeleteIndexRequest) clientSeenRequests.get(2)).indices()[0],
15681556
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
@@ -138,8 +138,8 @@ public ActionRequestValidationException validate() {
138138
);
139139
}
140140

141-
var failureStoreOptions = indicesOptions.failureStoreOptions();
142-
if (failureStoreOptions.includeRegularIndices() && failureStoreOptions.includeFailureIndices()) {
141+
var selectors = indicesOptions.selectorOptions().defaultSelectors();
142+
if (selectors.size() > 1) {
143143
validationException = addValidationError(
144144
"rollover cannot be applied to both regular and failure indices at the same time",
145145
validationException
@@ -179,7 +179,7 @@ public IndicesOptions indicesOptions() {
179179
* @return true of the rollover request targets the failure store, false otherwise.
180180
*/
181181
public boolean targetsFailureStore() {
182-
return DataStream.isFailureStoreFeatureFlagEnabled() && indicesOptions.failureStoreOptions().includeFailureIndices();
182+
return DataStream.isFailureStoreFeatureFlagEnabled() && indicesOptions.includeFailureIndices();
183183
}
184184

185185
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)