Skip to content

Commit f7e2fdd

Browse files
authored
Move frozen indices to x-pack module (#44408)
Will facilitate future development of this feature, e.g. backporting of #44286
1 parent 9004b46 commit f7e2fdd

File tree

22 files changed

+371
-219
lines changed

22 files changed

+371
-219
lines changed

docs/reference/rest-api/info.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ Example response:
7575
"available" : true,
7676
"enabled" : true
7777
},
78+
"frozen_indices" : {
79+
"available" : true,
80+
"enabled" : true
81+
},
7882
"graph" : {
7983
"available" : true,
8084
"enabled" : true
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.protocol.xpack.frozen;
7+
8+
import org.elasticsearch.action.ActionRequestValidationException;
9+
import org.elasticsearch.action.IndicesRequest;
10+
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
11+
import org.elasticsearch.action.support.ActiveShardCount;
12+
import org.elasticsearch.action.support.IndicesOptions;
13+
import org.elasticsearch.action.support.master.AcknowledgedRequest;
14+
import org.elasticsearch.common.io.stream.StreamInput;
15+
import org.elasticsearch.common.io.stream.StreamOutput;
16+
import org.elasticsearch.common.util.CollectionUtils;
17+
18+
import java.io.IOException;
19+
20+
import static org.elasticsearch.action.ValidateActions.addValidationError;
21+
22+
public class FreezeRequest extends AcknowledgedRequest<FreezeRequest>
23+
implements IndicesRequest.Replaceable {
24+
private String[] indices;
25+
private boolean freeze = true;
26+
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
27+
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
28+
29+
public FreezeRequest(String... indices) {
30+
this.indices = indices;
31+
}
32+
33+
public FreezeRequest(StreamInput in) throws IOException {
34+
super(in);
35+
indicesOptions = IndicesOptions.readIndicesOptions(in);
36+
indices = in.readStringArray();
37+
freeze = in.readBoolean();
38+
waitForActiveShards = ActiveShardCount.readFrom(in);
39+
}
40+
41+
@Override
42+
public ActionRequestValidationException validate() {
43+
ActionRequestValidationException validationException = null;
44+
if (CollectionUtils.isEmpty(indices)) {
45+
validationException = addValidationError("index is missing", validationException);
46+
}
47+
return validationException;
48+
}
49+
50+
public FreezeRequest setFreeze(boolean freeze) {
51+
this.freeze = freeze;
52+
return this;
53+
}
54+
55+
public boolean freeze() {
56+
return freeze;
57+
}
58+
59+
@Override
60+
public void writeTo(StreamOutput out) throws IOException {
61+
super.writeTo(out);
62+
indicesOptions.writeIndicesOptions(out);
63+
out.writeStringArray(indices);
64+
out.writeBoolean(freeze);
65+
waitForActiveShards.writeTo(out);
66+
}
67+
68+
/**
69+
* @return the indices to be frozen or unfrozen
70+
*/
71+
@Override
72+
public String[] indices() {
73+
return indices;
74+
}
75+
76+
/**
77+
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
78+
* For example indices that don't exist.
79+
*
80+
* @return the current behaviour when it comes to index names and wildcard indices expressions
81+
*/
82+
@Override
83+
public IndicesOptions indicesOptions() {
84+
return indicesOptions;
85+
}
86+
87+
/**
88+
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
89+
* For example indices that don't exist.
90+
*
91+
* @param indicesOptions the desired behaviour regarding indices to ignore and wildcard indices expressions
92+
* @return the request itself
93+
*/
94+
public FreezeRequest indicesOptions(IndicesOptions indicesOptions) {
95+
this.indicesOptions = indicesOptions;
96+
return this;
97+
}
98+
99+
@Override
100+
public IndicesRequest indices(String... indices) {
101+
this.indices = indices;
102+
return this;
103+
}
104+
105+
public ActiveShardCount waitForActiveShards() {
106+
return waitForActiveShards;
107+
}
108+
109+
/**
110+
* Sets the number of shard copies that should be active for indices opening to return.
111+
* Defaults to {@link ActiveShardCount#DEFAULT}, which will wait for one shard copy
112+
* (the primary) to become active. Set this value to {@link ActiveShardCount#ALL} to
113+
* wait for all shards (primary and all replicas) to be active before returning.
114+
* Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
115+
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
116+
* to wait for the desired amount of shard copies to become active before returning.
117+
* Indices opening will only wait up until the timeout value for the number of shard copies
118+
* to be active before returning. Check {@link OpenIndexResponse#isShardsAcknowledged()} to
119+
* determine if the requisite shard copies were all started before returning or timing out.
120+
*
121+
* @param waitForActiveShards number of active shard copies to wait on
122+
*/
123+
public FreezeRequest waitForActiveShards(ActiveShardCount waitForActiveShards) {
124+
this.waitForActiveShards = waitForActiveShards;
125+
return this;
126+
}
127+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.protocol.xpack.frozen;
7+
8+
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
9+
import org.elasticsearch.common.io.stream.StreamInput;
10+
11+
import java.io.IOException;
12+
13+
public class FreezeResponse extends OpenIndexResponse {
14+
public FreezeResponse(StreamInput in) throws IOException {
15+
super(in);
16+
}
17+
18+
public FreezeResponse(boolean acknowledged, boolean shardsAcknowledged) {
19+
super(acknowledged, shardsAcknowledged);
20+
}
21+
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.elasticsearch.plugins.NetworkPlugin;
3131
import org.elasticsearch.plugins.Plugin;
3232
import org.elasticsearch.tasks.Task;
33-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction;
3433
import org.elasticsearch.xpack.core.action.XPackInfoAction;
3534
import org.elasticsearch.xpack.core.action.XPackUsageAction;
3635
import org.elasticsearch.xpack.core.beats.BeatsFeatureSetUsage;
@@ -53,6 +52,7 @@
5352
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
5453
import org.elasticsearch.xpack.core.flattened.FlattenedFeatureSetUsage;
5554
import org.elasticsearch.xpack.core.frozen.FrozenIndicesFeatureSetUsage;
55+
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
5656
import org.elasticsearch.xpack.core.graph.GraphFeatureSetUsage;
5757
import org.elasticsearch.xpack.core.graph.action.GraphExploreAction;
5858
import org.elasticsearch.xpack.core.indexlifecycle.AllocateAction;
@@ -383,7 +383,7 @@ public List<ActionType<? extends ActionResponse>> getClientActions() {
383383
DeleteSnapshotLifecycleAction.INSTANCE,
384384
ExecuteSnapshotLifecycleAction.INSTANCE,
385385
// Freeze
386-
TransportFreezeIndexAction.FreezeIndexAction.INSTANCE,
386+
FreezeIndexAction.INSTANCE,
387387
// Data Frame
388388
PutDataFrameTransformAction.INSTANCE,
389389
StartDataFrameTransformAction.INSTANCE,

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import org.apache.logging.log4j.Logger;
1010
import org.apache.lucene.util.SetOnce;
1111
import org.elasticsearch.SpecialPermission;
12-
import org.elasticsearch.action.ActionType;
1312
import org.elasticsearch.action.ActionRequest;
1413
import org.elasticsearch.action.ActionResponse;
14+
import org.elasticsearch.action.ActionType;
1515
import org.elasticsearch.action.support.ActionFilter;
1616
import org.elasticsearch.action.support.TransportAction;
1717
import org.elasticsearch.client.Client;
@@ -34,10 +34,8 @@
3434
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3535
import org.elasticsearch.env.Environment;
3636
import org.elasticsearch.env.NodeEnvironment;
37-
import org.elasticsearch.index.IndexModule;
3837
import org.elasticsearch.index.IndexSettings;
3938
import org.elasticsearch.index.engine.EngineFactory;
40-
import org.elasticsearch.index.engine.FrozenEngine;
4139
import org.elasticsearch.license.LicenseService;
4240
import org.elasticsearch.license.LicensesMetaData;
4341
import org.elasticsearch.license.Licensing;
@@ -57,17 +55,13 @@
5755
import org.elasticsearch.threadpool.ThreadPool;
5856
import org.elasticsearch.watcher.ResourceWatcherService;
5957
import org.elasticsearch.xpack.core.action.ReloadAnalyzerAction;
60-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction;
6158
import org.elasticsearch.xpack.core.action.TransportReloadAnalyzersAction;
6259
import org.elasticsearch.xpack.core.action.TransportXPackInfoAction;
6360
import org.elasticsearch.xpack.core.action.TransportXPackUsageAction;
6461
import org.elasticsearch.xpack.core.action.XPackInfoAction;
6562
import org.elasticsearch.xpack.core.action.XPackUsageAction;
66-
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
6763
import org.elasticsearch.xpack.core.action.XPackUsageResponse;
68-
import org.elasticsearch.xpack.core.frozen.FrozenIndicesUsageTransportAction;
6964
import org.elasticsearch.xpack.core.ml.MlMetadata;
70-
import org.elasticsearch.xpack.core.rest.action.RestFreezeIndexAction;
7165
import org.elasticsearch.xpack.core.rest.action.RestReloadAnalyzersAction;
7266
import org.elasticsearch.xpack.core.rest.action.RestXPackInfoAction;
7367
import org.elasticsearch.xpack.core.rest.action.RestXPackUsageAction;
@@ -251,9 +245,6 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
251245
List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>();
252246
actions.add(new ActionHandler<>(XPackInfoAction.INSTANCE, getInfoAction()));
253247
actions.add(new ActionHandler<>(XPackUsageAction.INSTANCE, getUsageAction()));
254-
actions.add(new ActionHandler<>(TransportFreezeIndexAction.FreezeIndexAction.INSTANCE,
255-
TransportFreezeIndexAction.class));
256-
actions.add(new ActionHandler<>(XPackUsageFeatureAction.FROZEN_INDICES, FrozenIndicesUsageTransportAction.class));
257248
actions.addAll(licensing.getActions());
258249
actions.add(new ActionHandler<>(ReloadAnalyzerAction.INSTANCE, TransportReloadAnalyzersAction.class));
259250
return actions;
@@ -291,7 +282,6 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
291282
List<RestHandler> handlers = new ArrayList<>();
292283
handlers.add(new RestXPackInfoAction(settings, restController));
293284
handlers.add(new RestXPackUsageAction(settings, restController));
294-
handlers.add(new RestFreezeIndexAction(settings, restController));
295285
handlers.add(new RestReloadAnalyzersAction(settings, restController));
296286
handlers.addAll(licensing.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
297287
indexNameExpressionResolver, nodesInCluster));
@@ -357,8 +347,6 @@ public Map<String, Repository.Factory> getRepositories(Environment env, NamedXCo
357347
public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
358348
if (indexSettings.getValue(SourceOnlySnapshotRepository.SOURCE_ONLY)) {
359349
return Optional.of(SourceOnlySnapshotRepository.getEngineFactory());
360-
} else if (indexSettings.getValue(FrozenEngine.INDEX_FROZEN)) {
361-
return Optional.of(FrozenEngine::new);
362350
}
363351

364352
return Optional.empty();
@@ -368,15 +356,6 @@ public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
368356
public List<Setting<?>> getSettings() {
369357
List<Setting<?>> settings = super.getSettings();
370358
settings.add(SourceOnlySnapshotRepository.SOURCE_ONLY);
371-
settings.add(FrozenEngine.INDEX_FROZEN);
372359
return settings;
373360
}
374-
375-
@Override
376-
public void onIndexModule(IndexModule indexModule) {
377-
if (FrozenEngine.INDEX_FROZEN.get(indexModule.getSettings())) {
378-
indexModule.addSearchOperationListener(new FrozenEngine.ReacquireEngineSearcherListener());
379-
}
380-
super.onIndexModule(indexModule);
381-
}
382361
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public class XPackInfoFeatureAction extends StreamableResponseActionType<XPackIn
3636
public static final XPackInfoFeatureAction FLATTENED = new XPackInfoFeatureAction(XPackField.FLATTENED);
3737
public static final XPackInfoFeatureAction VECTORS = new XPackInfoFeatureAction(XPackField.VECTORS);
3838
public static final XPackInfoFeatureAction VOTING_ONLY = new XPackInfoFeatureAction(XPackField.VOTING_ONLY);
39+
public static final XPackInfoFeatureAction FROZEN_INDICES = new XPackInfoFeatureAction(XPackField.FROZEN_INDICES);
3940

4041
public static final List<XPackInfoFeatureAction> ALL = Arrays.asList(
4142
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, SQL, ROLLUP, INDEX_LIFECYCLE, CCR, DATA_FRAME, FLATTENED,
42-
VECTORS, VOTING_ONLY
43+
VECTORS, VOTING_ONLY, FROZEN_INDICES
4344
);
4445

4546
private XPackInfoFeatureAction(String name) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.core.frozen.action;
7+
8+
import org.elasticsearch.action.ActionType;
9+
import org.elasticsearch.common.io.stream.Writeable;
10+
import org.elasticsearch.protocol.xpack.frozen.FreezeResponse;
11+
12+
public class FreezeIndexAction extends ActionType<FreezeResponse> {
13+
14+
public static final FreezeIndexAction INSTANCE = new FreezeIndexAction();
15+
public static final String NAME = "indices:admin/freeze";
16+
17+
private FreezeIndexAction() {
18+
super(NAME);
19+
}
20+
21+
@Override
22+
public Writeable.Reader<FreezeResponse> getResponseReader() {
23+
return FreezeResponse::new;
24+
}
25+
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/FreezeStep.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import org.elasticsearch.client.Client;
1010
import org.elasticsearch.cluster.ClusterState;
1111
import org.elasticsearch.cluster.metadata.IndexMetaData;
12-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction;
12+
import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
13+
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
1314

1415
/**
1516
* Freezes an index.
@@ -23,8 +24,8 @@ public FreezeStep(StepKey key, StepKey nextStepKey, Client client) {
2324

2425
@Override
2526
public void performDuringNoSnapshot(IndexMetaData indexMetaData, ClusterState currentState, Listener listener) {
26-
getClient().admin().indices().execute(TransportFreezeIndexAction.FreezeIndexAction.INSTANCE,
27-
new TransportFreezeIndexAction.FreezeRequest(indexMetaData.getIndex().getName()),
27+
getClient().admin().indices().execute(FreezeIndexAction.INSTANCE,
28+
new FreezeRequest(indexMetaData.getIndex().getName()),
2829
ActionListener.wrap(response -> listener.onResponse(true), listener::onFailure));
2930
}
3031
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/FreezeStepTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import org.elasticsearch.client.Client;
1515
import org.elasticsearch.client.IndicesAdminClient;
1616
import org.elasticsearch.cluster.metadata.IndexMetaData;
17-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction;
17+
import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
18+
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
1819
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
1920
import org.junit.Before;
2021
import org.mockito.Mockito;
@@ -78,8 +79,8 @@ public void testFreeze() {
7879
Mockito.when(client.admin()).thenReturn(adminClient);
7980
Mockito.when(adminClient.indices()).thenReturn(indicesClient);
8081
Mockito.doAnswer(invocation -> {
81-
assertSame(invocation.getArguments()[0], TransportFreezeIndexAction.FreezeIndexAction.INSTANCE);
82-
TransportFreezeIndexAction.FreezeRequest request = (TransportFreezeIndexAction.FreezeRequest) invocation.getArguments()[1];
82+
assertSame(invocation.getArguments()[0], FreezeIndexAction.INSTANCE);
83+
FreezeRequest request = (FreezeRequest) invocation.getArguments()[1];
8384
@SuppressWarnings("unchecked")
8485
ActionListener<AcknowledgedResponse> listener = (ActionListener<AcknowledgedResponse>) invocation.getArguments()[2];
8586
assertNotNull(request);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
evaluationDependsOn(xpackModule('core'))
2+
3+
apply plugin: 'elasticsearch.esplugin'
4+
esplugin {
5+
name 'frozen-indices'
6+
description 'A plugin for the frozen indices functionality'
7+
classname 'org.elasticsearch.xpack.frozen.FrozenIndices'
8+
extendedPlugins = ['x-pack-core']
9+
}
10+
archivesBaseName = 'x-pack-frozen-indices'
11+
12+
dependencies {
13+
compileOnly project(path: xpackModule('core'), configuration: 'default')
14+
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
15+
if (isEclipse) {
16+
testCompile project(path: xpackModule('core-tests'), configuration: 'testArtifacts')
17+
}
18+
}
19+
20+
// xpack modules are installed in real clusters as the meta plugin, so
21+
// installing them as individual plugins for integ tests doesn't make sense,
22+
// so we disable integ tests
23+
integTest.enabled = false

0 commit comments

Comments
 (0)