Skip to content

Commit d98b3e4

Browse files
authored
Move frozen indices to x-pack module (#44490)
Backport of #44408 and #44286.
1 parent 3a199d0 commit d98b3e4

File tree

26 files changed

+588
-216
lines changed

26 files changed

+588
-216
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/XPackClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import org.elasticsearch.license.LicensingClient;
1313
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
1414
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
15-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeIndexAction;
16-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeRequest;
17-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction.FreezeResponse;
15+
import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
16+
import org.elasticsearch.protocol.xpack.frozen.FreezeResponse;
1817
import org.elasticsearch.xpack.core.action.XPackInfoAction;
1918
import org.elasticsearch.xpack.core.action.XPackInfoRequestBuilder;
2019
import org.elasticsearch.xpack.core.ccr.client.CcrClient;
20+
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
2121
import org.elasticsearch.xpack.core.indexlifecycle.client.ILMClient;
2222
import org.elasticsearch.xpack.core.ml.client.MachineLearningClient;
2323
import org.elasticsearch.xpack.core.monitoring.client.MonitoringClient;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.tasks.Task;
3737
import org.elasticsearch.threadpool.ThreadPool;
3838
import org.elasticsearch.transport.Transport;
39-
import org.elasticsearch.xpack.core.action.TransportFreezeIndexAction;
4039
import org.elasticsearch.xpack.core.action.XPackInfoAction;
4140
import org.elasticsearch.xpack.core.action.XPackUsageAction;
4241
import org.elasticsearch.xpack.core.beats.BeatsFeatureSetUsage;
@@ -58,6 +57,8 @@
5857
import org.elasticsearch.xpack.core.dataframe.transforms.TimeSyncConfig;
5958
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
6059
import org.elasticsearch.xpack.core.flattened.FlattenedFeatureSetUsage;
60+
import org.elasticsearch.xpack.core.frozen.FrozenIndicesFeatureSetUsage;
61+
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
6162
import org.elasticsearch.xpack.core.graph.GraphFeatureSetUsage;
6263
import org.elasticsearch.xpack.core.graph.action.GraphExploreAction;
6364
import org.elasticsearch.xpack.core.indexlifecycle.AllocateAction;
@@ -412,7 +413,7 @@ public List<ActionType<? extends ActionResponse>> getClientActions() {
412413
DeleteSnapshotLifecycleAction.INSTANCE,
413414
ExecuteSnapshotLifecycleAction.INSTANCE,
414415
// Freeze
415-
TransportFreezeIndexAction.FreezeIndexAction.INSTANCE,
416+
FreezeIndexAction.INSTANCE,
416417
// Data Frame
417418
PutDataFrameTransformAction.INSTANCE,
418419
StartDataFrameTransformAction.INSTANCE,
@@ -534,7 +535,9 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
534535
// Vectors
535536
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VECTORS, VectorsFeatureSetUsage::new),
536537
// Voting Only Node
537-
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VOTING_ONLY, VotingOnlyNodeFeatureSetUsage::new)
538+
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VOTING_ONLY, VotingOnlyNodeFeatureSetUsage::new),
539+
// Frozen indices
540+
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.FROZEN_INDICES, FrozenIndicesFeatureSetUsage::new)
538541
);
539542
}
540543

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public final class XPackField {
4343
public static final String VECTORS = "vectors";
4444
/** Name constant for the voting-only-node feature. */
4545
public static final String VOTING_ONLY = "voting_only";
46+
/** Name constant for the frozen index feature. */
47+
public static final String FROZEN_INDICES = "frozen_indices";
4648

4749
private XPackField() {}
4850

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import org.apache.lucene.util.SetOnce;
1111
import org.elasticsearch.SpecialPermission;
1212
import org.elasticsearch.Version;
13-
import org.elasticsearch.action.ActionType;
1413
import org.elasticsearch.action.ActionRequest;
1514
import org.elasticsearch.action.ActionResponse;
15+
import org.elasticsearch.action.ActionType;
1616
import org.elasticsearch.action.support.ActionFilter;
1717
import org.elasticsearch.client.Client;
1818
import org.elasticsearch.client.transport.TransportClient;
@@ -37,10 +37,8 @@
3737
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3838
import org.elasticsearch.env.Environment;
3939
import org.elasticsearch.env.NodeEnvironment;
40-
import org.elasticsearch.index.IndexModule;
4140
import org.elasticsearch.index.IndexSettings;
4241
import org.elasticsearch.index.engine.EngineFactory;
43-
import org.elasticsearch.index.engine.FrozenEngine;
4442
import org.elasticsearch.license.LicenseService;
4543
import org.elasticsearch.license.LicensesMetaData;
4644
import org.elasticsearch.license.Licensing;
@@ -57,14 +55,12 @@
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;
6663
import org.elasticsearch.xpack.core.ml.MlMetadata;
67-
import org.elasticsearch.xpack.core.rest.action.RestFreezeIndexAction;
6864
import org.elasticsearch.xpack.core.rest.action.RestReloadAnalyzersAction;
6965
import org.elasticsearch.xpack.core.rest.action.RestXPackInfoAction;
7066
import org.elasticsearch.xpack.core.rest.action.RestXPackUsageAction;
@@ -272,8 +268,6 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
272268
List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>();
273269
actions.add(new ActionHandler<>(XPackInfoAction.INSTANCE, TransportXPackInfoAction.class));
274270
actions.add(new ActionHandler<>(XPackUsageAction.INSTANCE, TransportXPackUsageAction.class));
275-
actions.add(new ActionHandler<>(TransportFreezeIndexAction.FreezeIndexAction.INSTANCE,
276-
TransportFreezeIndexAction.class));
277271
actions.addAll(licensing.getActions());
278272
actions.add(new ActionHandler<>(ReloadAnalyzerAction.INSTANCE, TransportReloadAnalyzersAction.class));
279273
return actions;
@@ -301,7 +295,6 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
301295
List<RestHandler> handlers = new ArrayList<>();
302296
handlers.add(new RestXPackInfoAction(settings, restController));
303297
handlers.add(new RestXPackUsageAction(settings, restController));
304-
handlers.add(new RestFreezeIndexAction(settings, restController));
305298
handlers.add(new RestReloadAnalyzersAction(settings, restController));
306299
handlers.addAll(licensing.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
307300
indexNameExpressionResolver, nodesInCluster));
@@ -371,8 +364,6 @@ public Map<String, Repository.Factory> getRepositories(Environment env, NamedXCo
371364
public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
372365
if (indexSettings.getValue(SourceOnlySnapshotRepository.SOURCE_ONLY)) {
373366
return Optional.of(SourceOnlySnapshotRepository.getEngineFactory());
374-
} else if (indexSettings.getValue(FrozenEngine.INDEX_FROZEN)) {
375-
return Optional.of(FrozenEngine::new);
376367
}
377368

378369
return Optional.empty();
@@ -382,15 +373,6 @@ public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
382373
public List<Setting<?>> getSettings() {
383374
List<Setting<?>> settings = super.getSettings();
384375
settings.add(SourceOnlySnapshotRepository.SOURCE_ONLY);
385-
settings.add(FrozenEngine.INDEX_FROZEN);
386376
return settings;
387377
}
388-
389-
@Override
390-
public void onIndexModule(IndexModule indexModule) {
391-
if (FrozenEngine.INDEX_FROZEN.get(indexModule.getSettings())) {
392-
indexModule.addSearchOperationListener(new FrozenEngine.ReacquireEngineSearcherListener());
393-
}
394-
super.onIndexModule(indexModule);
395-
}
396378
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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;
7+
8+
import org.elasticsearch.common.io.stream.StreamInput;
9+
import org.elasticsearch.common.io.stream.StreamOutput;
10+
import org.elasticsearch.common.xcontent.XContentBuilder;
11+
import org.elasticsearch.xpack.core.XPackFeatureSet;
12+
import org.elasticsearch.xpack.core.XPackField;
13+
14+
import java.io.IOException;
15+
import java.util.Objects;
16+
17+
public class FrozenIndicesFeatureSetUsage extends XPackFeatureSet.Usage {
18+
19+
private final int numberOfFrozenIndices;
20+
21+
public FrozenIndicesFeatureSetUsage(StreamInput input) throws IOException {
22+
super(input);
23+
numberOfFrozenIndices = input.readVInt();
24+
}
25+
26+
@Override
27+
public void writeTo(StreamOutput out) throws IOException {
28+
super.writeTo(out);
29+
out.writeVInt(numberOfFrozenIndices);
30+
}
31+
32+
public FrozenIndicesFeatureSetUsage(boolean available, boolean enabled, int numberOfFrozenIndices) {
33+
super(XPackField.FROZEN_INDICES, available, enabled);
34+
this.numberOfFrozenIndices = numberOfFrozenIndices;
35+
}
36+
37+
@Override
38+
protected void innerXContent(XContentBuilder builder, Params params) throws IOException {
39+
super.innerXContent(builder, params);
40+
builder.field("indices_count", numberOfFrozenIndices);
41+
}
42+
43+
public int getNumberOfFrozenIndices() {
44+
return numberOfFrozenIndices;
45+
}
46+
47+
@Override
48+
public int hashCode() {
49+
return Objects.hash(available, enabled, numberOfFrozenIndices);
50+
}
51+
52+
@Override
53+
public boolean equals(Object obj) {
54+
if (obj == null) {
55+
return false;
56+
}
57+
if (getClass() != obj.getClass()) {
58+
return false;
59+
}
60+
FrozenIndicesFeatureSetUsage other = (FrozenIndicesFeatureSetUsage) obj;
61+
return Objects.equals(available, other.available) &&
62+
Objects.equals(enabled, other.enabled) &&
63+
Objects.equals(numberOfFrozenIndices, other.numberOfFrozenIndices);
64+
}
65+
}
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+
}

0 commit comments

Comments
 (0)