Skip to content

Commit

Permalink
Merge branch 'main' into lucene_snapshot_9_12
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Sep 30, 2024
2 parents b2d6ebc + 176f070 commit 6dbd33c
Show file tree
Hide file tree
Showing 33 changed files with 326 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.cluster.metadata.DataStreamOptions;
import org.elasticsearch.cluster.metadata.DataStreamTestHelper;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
.setAllowCustomRouting(true)
.setIndexMode(IndexMode.STANDARD)
.setLifecycle(new DataStreamLifecycle())
.setFailureStoreEnabled(true)
.setDataStreamOptions(DataStreamOptions.FAILURE_STORE_ENABLED)
.setFailureIndices(DataStream.DataStreamIndices.failureIndicesBuilder(failureStores).build())
.build();

Expand Down Expand Up @@ -186,7 +187,7 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
.setAllowCustomRouting(true)
.setIndexMode(IndexMode.STANDARD)
.setLifecycle(new DataStreamLifecycle(null, null, false))
.setFailureStoreEnabled(true)
.setDataStreamOptions(DataStreamOptions.FAILURE_STORE_ENABLED)
.setFailureIndices(DataStream.DataStreamIndices.failureIndicesBuilder(failureStores).build())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle.Downsampling;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle.Downsampling.Round;
import org.elasticsearch.cluster.metadata.DataStreamOptions;
import org.elasticsearch.cluster.metadata.DataStreamTestHelper;
import org.elasticsearch.cluster.metadata.IndexAbstraction;
import org.elasticsearch.cluster.metadata.IndexGraveyard;
Expand Down Expand Up @@ -1495,6 +1496,13 @@ public void testTargetIndices() {
String dataStreamName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
int numBackingIndices = 3;
int numFailureIndices = 2;
int mutationBranch = randomIntBetween(0, 2);
DataStreamOptions dataStreamOptions = switch (mutationBranch) {
case 0 -> DataStreamOptions.EMPTY;
case 1 -> DataStreamOptions.FAILURE_STORE_ENABLED;
case 2 -> DataStreamOptions.FAILURE_STORE_DISABLED;
default -> throw new IllegalStateException("Unexpected value: " + mutationBranch);
};
Metadata.Builder builder = Metadata.builder();
DataStream dataStream = createDataStream(
builder,
Expand All @@ -1504,7 +1512,7 @@ public void testTargetIndices() {
settings(IndexVersion.current()),
new DataStreamLifecycle(),
now
).copy().setFailureStoreEnabled(randomBoolean()).build(); // failure store is managed even when disabled
).copy().setDataStreamOptions(dataStreamOptions).build(); // failure store is managed even when disabled
builder.put(dataStream);
Metadata metadata = builder.build();
Set<Index> indicesToExclude = Set.of(dataStream.getIndices().get(0), dataStream.getFailureIndices().getIndices().get(0));
Expand Down Expand Up @@ -1536,7 +1544,7 @@ public void testFailureStoreIsManagedEvenWhenDisabled() {
settings(IndexVersion.current()),
DataStreamLifecycle.newBuilder().dataRetention(0).build(),
now
).copy().setFailureStoreEnabled(false).build(); // failure store is managed even when it is disabled
).copy().setDataStreamOptions(DataStreamOptions.FAILURE_STORE_DISABLED).build(); // failure store is managed even when disabled
builder.put(dataStream);

ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(builder).build();
Expand Down
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ tests:
- class: org.elasticsearch.xpack.esql.EsqlAsyncSecurityIT
method: testLimitedPrivilege
issue: https://github.com/elastic/elasticsearch/issues/113419
- class: org.elasticsearch.index.mapper.extras.TokenCountFieldMapperTests
method: testBlockLoaderFromRowStrideReaderWithSyntheticSource
issue: https://github.com/elastic/elasticsearch/issues/113427
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
method: test {categorize.Categorize}
issue: https://github.com/elastic/elasticsearch/issues/113428
Expand Down Expand Up @@ -305,9 +302,6 @@ tests:
- class: org.elasticsearch.smoketest.MlWithSecurityIT
method: test {yaml=ml/3rd_party_deployment/Test start and stop multiple deployments}
issue: https://github.com/elastic/elasticsearch/issues/101458
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
method: test {p0=search/540_ignore_above_synthetic_source/ignore_above mapping level setting on arrays}
issue: https://github.com/elastic/elasticsearch/issues/113648
- class: org.elasticsearch.xpack.ml.integration.MlJobIT
method: testGetJobs_GivenMultipleJobs
issue: https://github.com/elastic/elasticsearch/issues/113654
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.apache.http.util.EntityUtils;
import org.elasticsearch.Build;
import org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
Expand Down Expand Up @@ -43,6 +42,7 @@
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.test.rest.RestTestLegacyFeatures;
import org.elasticsearch.test.rest.TestResponseParsers;
import org.elasticsearch.transport.Compression;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -1861,7 +1861,7 @@ public void testTransportCompressionSetting() throws IOException {
final Request getSettingsRequest = new Request("GET", "/_cluster/settings");
final Response getSettingsResponse = client().performRequest(getSettingsRequest);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, getSettingsResponse.getEntity().getContent())) {
final Settings settings = RestClusterGetSettingsResponse.fromXContent(parser).getPersistentSettings();
final Settings settings = TestResponseParsers.parseClusterSettingsResponse(parser).getPersistentSettings();
assertThat(REMOTE_CLUSTER_COMPRESS.getConcreteSettingForNamespace("foo").get(settings), equalTo(Compression.Enabled.TRUE));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
private static MedianAbsoluteDeviationAggregationBuilder randomBuilder() {
final MedianAbsoluteDeviationAggregationBuilder builder = new MedianAbsoluteDeviationAggregationBuilder("mad");
if (randomBoolean()) {
builder.compression(randomDoubleBetween(25, 1000, false));
builder.compression(randomDoubleBetween(30, 1000, false));
}
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ static TransportVersion def(int id) {
public static final TransportVersion ML_INFERENCE_CHUNKING_SETTINGS = def(8_751_00_0);
public static final TransportVersion SEMANTIC_QUERY_INNER_HITS = def(8_752_00_0);
public static final TransportVersion RETAIN_ILM_STEP_INFO = def(8_753_00_0);
public static final TransportVersion REGEX_AND_RANGE_INTERVAL_QUERIES = def(8_754_00_0);
public static final TransportVersion ADD_DATA_STREAM_OPTIONS = def(8_754_00_0);
public static final TransportVersion REGEX_AND_RANGE_INTERVAL_QUERIES = def(8_755_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;

/**
* This response is specific to the REST client. {@link org.elasticsearch.action.admin.cluster.state.ClusterStateResponse}
* is used on the transport layer.
Expand All @@ -33,23 +27,9 @@ public class RestClusterGetSettingsResponse implements ToXContentObject {
private final Settings transientSettings;
private final Settings defaultSettings;

static final String PERSISTENT_FIELD = "persistent";
static final String TRANSIENT_FIELD = "transient";
static final String DEFAULTS_FIELD = "defaults";

private static final ConstructingObjectParser<RestClusterGetSettingsResponse, Void> PARSER = new ConstructingObjectParser<>(
"cluster_get_settings_response",
true,
a -> {
Settings defaultSettings = a[2] == null ? Settings.EMPTY : (Settings) a[2];
return new RestClusterGetSettingsResponse((Settings) a[0], (Settings) a[1], defaultSettings);
}
);
static {
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), new ParseField(PERSISTENT_FIELD));
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), new ParseField(TRANSIENT_FIELD));
PARSER.declareObject(optionalConstructorArg(), (p, c) -> Settings.fromXContent(p), new ParseField(DEFAULTS_FIELD));
}
public static final String PERSISTENT_FIELD = "persistent";
public static final String TRANSIENT_FIELD = "transient";
public static final String DEFAULTS_FIELD = "defaults";

public RestClusterGetSettingsResponse(Settings persistentSettings, Settings transientSettings, Settings defaultSettings) {
this.persistentSettings = Objects.requireNonNullElse(persistentSettings, Settings.EMPTY);
Expand Down Expand Up @@ -120,10 +100,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

public static RestClusterGetSettingsResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,18 @@
import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

/**
* A response for a create index action.
*/
public class CreateIndexResponse extends ShardsAcknowledgedResponse {

private static final ParseField INDEX = new ParseField("index");

private static final ConstructingObjectParser<CreateIndexResponse, Void> PARSER = new ConstructingObjectParser<>(
"create_index",
true,
args -> new CreateIndexResponse((boolean) args[0], (boolean) args[1], (String) args[2])
);

static {
declareFields(PARSER);
}

protected static <T extends CreateIndexResponse> void declareFields(ConstructingObjectParser<T, Void> objectParser) {
declareAcknowledgedAndShardsAcknowledgedFields(objectParser);
objectParser.declareField(constructorArg(), (parser, context) -> parser.textOrNull(), INDEX, ObjectParser.ValueType.STRING);
}
public static final ParseField INDEX = new ParseField("index");

private final String index;

Expand Down Expand Up @@ -74,10 +54,6 @@ protected void addCustomFields(XContentBuilder builder, Params params) throws IO
builder.field(INDEX.getPreferredName(), index());
}

public static CreateIndexResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public boolean equals(Object o) {
if (super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

/**
* A response to an action which updated the cluster state, but needs to report whether any relevant nodes failed to apply the update. For
* instance, a {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} may update a mapping in the index metadata, but
Expand All @@ -39,16 +33,6 @@ public class AcknowledgedResponse extends ActionResponse implements IsAcknowledg
public static final AcknowledgedResponse FALSE = new AcknowledgedResponse(false);

public static final String ACKNOWLEDGED_KEY = "acknowledged";
private static final ParseField ACKNOWLEDGED = new ParseField(ACKNOWLEDGED_KEY);

public static <T extends AcknowledgedResponse> void declareAcknowledgedField(ConstructingObjectParser<T, Void> objectParser) {
objectParser.declareField(
constructorArg(),
(parser, context) -> parser.booleanValue(),
ACKNOWLEDGED,
ObjectParser.ValueType.BOOLEAN
);
}

protected final boolean acknowledged;

Expand Down Expand Up @@ -93,28 +77,6 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params)

protected void addCustomFields(XContentBuilder builder, Params params) throws IOException {}

/**
* A generic parser that simply parses the acknowledged flag
*/
private static final ConstructingObjectParser<Boolean, Void> ACKNOWLEDGED_FLAG_PARSER = new ConstructingObjectParser<>(
"acknowledged_flag",
true,
args -> (Boolean) args[0]
);

static {
ACKNOWLEDGED_FLAG_PARSER.declareField(
constructorArg(),
(parser, context) -> parser.booleanValue(),
ACKNOWLEDGED,
ObjectParser.ValueType.BOOLEAN
);
}

public static AcknowledgedResponse fromXContent(XContentParser parser) throws IOException {
return AcknowledgedResponse.of(ACKNOWLEDGED_FLAG_PARSER.apply(parser, null));
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,15 @@

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

public class ShardsAcknowledgedResponse extends AcknowledgedResponse {

protected static final ParseField SHARDS_ACKNOWLEDGED = new ParseField("shards_acknowledged");

public static <T extends ShardsAcknowledgedResponse> void declareAcknowledgedAndShardsAcknowledgedFields(
ConstructingObjectParser<T, Void> objectParser
) {
declareAcknowledgedField(objectParser);
objectParser.declareField(
constructorArg(),
(parser, context) -> parser.booleanValue(),
SHARDS_ACKNOWLEDGED,
ObjectParser.ValueType.BOOLEAN
);
}
public static final ParseField SHARDS_ACKNOWLEDGED = new ParseField("shards_acknowledged");

public static final ShardsAcknowledgedResponse NOT_ACKNOWLEDGED = new ShardsAcknowledgedResponse(false, false);
private static final ShardsAcknowledgedResponse SHARDS_NOT_ACKNOWLEDGED = new ShardsAcknowledgedResponse(true, false);
Expand Down
Loading

0 comments on commit 6dbd33c

Please sign in to comment.