Skip to content

Commit

Permalink
Merge branch 'main' into zep_deprecated_sort_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner authored Jan 9, 2025
2 parents d3767cd + a2a4e7c commit 0dfe455
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

package org.elasticsearch.cluster;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlocks;
Expand Down Expand Up @@ -565,7 +564,7 @@ public IndexMetadata randomCreate(String name) {
settingsBuilder.put(randomSettings(Settings.EMPTY)).put(IndexMetadata.SETTING_VERSION_CREATED, randomWriteVersion());
builder.settings(settingsBuilder);
builder.numberOfShards(randomIntBetween(1, 10)).numberOfReplicas(randomInt(10));
builder.eventIngestedRange(IndexLongFieldRange.UNKNOWN, TransportVersion.current());
builder.eventIngestedRange(IndexLongFieldRange.UNKNOWN);
int aliasCount = randomInt(10);
for (int i = 0; i < aliasCount; i++) {
builder.putAlias(randomAlias());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ public static ClusterState resolveTemporaryState(
.build();

final IndexMetadata indexMetadata = IndexMetadata.builder(indexName)
// handle mixed-cluster states by passing in minTransportVersion to reset event.ingested range to UNKNOWN if an older version
.eventIngestedRange(getEventIngestedRange(indexName, simulatedState), simulatedState.getMinTransportVersion())
.eventIngestedRange(getEventIngestedRange(indexName, simulatedState))
.settings(dummySettings)
.build();
return ClusterState.builder(simulatedState)
Expand Down Expand Up @@ -304,8 +303,7 @@ public static Template resolveTemplate(
dummySettings.put(templateSettings);

final IndexMetadata indexMetadata = IndexMetadata.builder(indexName)
// handle mixed-cluster states by passing in minTransportVersion to reset event.ingested range to UNKNOWN if an older version
.eventIngestedRange(getEventIngestedRange(indexName, simulatedState), simulatedState.getMinTransportVersion())
.eventIngestedRange(getEventIngestedRange(indexName, simulatedState))
.settings(dummySettings)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ public ClusterState execute(BatchExecutionContext<StartedShardUpdateTask> batchE
metadataBuilder.put(
IndexMetadata.builder(metadataBuilder.getSafe(updatedTimeRangesEntry.getKey()))
.timestampRange(timeRanges.timestampRange())
.eventIngestedRange(timeRanges.eventIngestedRange(), maybeUpdatedState.getMinTransportVersion())
.eventIngestedRange(timeRanges.eventIngestedRange())
);
}
maybeUpdatedState = ClusterState.builder(maybeUpdatedState).metadata(metadataBuilder).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1703,12 +1703,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalDouble(indexWriteLoadForecast);
out.writeOptionalLong(shardSizeInBytesForecast);
}
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0)) {
eventIngestedRange.writeTo(out);
} else {
assert eventIngestedRange == IndexLongFieldRange.UNKNOWN
: "eventIngestedRange should be UNKNOWN until all nodes are on the new version but is " + eventIngestedRange;
}
eventIngestedRange.writeTo(out);
}

@Override
Expand Down Expand Up @@ -1813,11 +1808,7 @@ public static IndexMetadata readFrom(StreamInput in, @Nullable Function<String,
builder.indexWriteLoadForecast(in.readOptionalDouble());
builder.shardSizeInBytesForecast(in.readOptionalLong());
}
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0)) {
builder.eventIngestedRange(IndexLongFieldRange.readFrom(in), in.getTransportVersion());
} else {
builder.eventIngestedRange(IndexLongFieldRange.UNKNOWN, in.getTransportVersion());
}
builder.eventIngestedRange(IndexLongFieldRange.readFrom(in));
return builder.build(true);
}

Expand Down Expand Up @@ -2180,28 +2171,12 @@ public Builder timestampRange(IndexLongFieldRange timestampRange) {
return this;
}

// only for use within this class file where minClusterTransportVersion is not known (e.g., IndexMetadataDiff.apply)
Builder eventIngestedRange(IndexLongFieldRange eventIngestedRange) {
public Builder eventIngestedRange(IndexLongFieldRange eventIngestedRange) {
assert eventIngestedRange != null : "eventIngestedRange cannot be null";
this.eventIngestedRange = eventIngestedRange;
return this;
}

public Builder eventIngestedRange(IndexLongFieldRange eventIngestedRange, TransportVersion minClusterTransportVersion) {
assert eventIngestedRange != null : "eventIngestedRange cannot be null";
assert minClusterTransportVersion != null || eventIngestedRange == IndexLongFieldRange.UNKNOWN
: "eventIngestedRange must be UNKNOWN when minClusterTransportVersion is null, but minClusterTransportVersion: "
+ minClusterTransportVersion
+ "; eventIngestedRange = "
+ eventIngestedRange;
if (minClusterTransportVersion != null && minClusterTransportVersion.before(TransportVersions.V_8_15_0)) {
this.eventIngestedRange = IndexLongFieldRange.UNKNOWN;
} else {
this.eventIngestedRange = eventIngestedRange;
}
return this;
}

public Builder stats(IndexMetadataStats stats) {
this.stats = stats;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import org.elasticsearch.index.mapper.MapperService.MergeReason;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.shard.IndexLongFieldRange;
import org.elasticsearch.indices.IndexCreationException;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.InvalidIndexNameException;
Expand Down Expand Up @@ -529,8 +528,7 @@ private ClusterState applyCreateIndexWithTemporaryService(
temporaryIndexMeta.getSettings(),
temporaryIndexMeta.getRoutingNumShards(),
sourceMetadata,
temporaryIndexMeta.isSystem(),
currentState.getMinTransportVersion()
temporaryIndexMeta.isSystem()
);
} catch (Exception e) {
logger.info("failed to build index metadata [{}]", request.index());
Expand Down Expand Up @@ -1340,15 +1338,10 @@ static IndexMetadata buildIndexMetadata(
Settings indexSettings,
int routingNumShards,
@Nullable IndexMetadata sourceMetadata,
boolean isSystem,
TransportVersion minClusterTransportVersion
boolean isSystem
) {
IndexMetadata.Builder indexMetadataBuilder = createIndexMetadataBuilder(indexName, sourceMetadata, indexSettings, routingNumShards);
indexMetadataBuilder.system(isSystem);
if (minClusterTransportVersion.before(TransportVersions.V_8_15_0)) {
// promote to UNKNOWN for older versions since they don't know how to handle event.ingested in cluster state
indexMetadataBuilder.eventIngestedRange(IndexLongFieldRange.UNKNOWN, minClusterTransportVersion);
}
// now, update the mappings with the actual source
Map<String, MappingMetadata> mappingsMetadata = new HashMap<>();
DocumentMapper docMapper = documentMapperSupplier.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ static Tuple<ClusterState, List<IndexResult>> closeRoutingTable(
final IndexMetadata.Builder updatedMetadata = IndexMetadata.builder(indexMetadata).state(IndexMetadata.State.CLOSE);
metadata.put(
updatedMetadata.timestampRange(IndexLongFieldRange.NO_SHARDS)
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS, currentState.getMinTransportVersion())
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS)
.settingsVersion(indexMetadata.getSettingsVersion() + 1)
.settings(Settings.builder().put(indexMetadata.getSettings()).put(VERIFIED_BEFORE_CLOSE_SETTING.getKey(), true))
);
Expand Down Expand Up @@ -1133,7 +1133,7 @@ private ClusterState openIndices(final Index[] indices, final ClusterState curre
.settingsVersion(indexMetadata.getSettingsVersion() + 1)
.settings(updatedSettings)
.timestampRange(IndexLongFieldRange.NO_SHARDS)
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS, currentState.getMinTransportVersion())
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS)
.build();

// The index might be closed because we couldn't import it due to an old incompatible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ private static void validateCompositeTemplate(
.put(
IndexMetadata.builder(temporaryIndexName)
// necessary to pass asserts in ClusterState constructor
.eventIngestedRange(IndexLongFieldRange.UNKNOWN, state.getMinTransportVersion())
.eventIngestedRange(IndexLongFieldRange.UNKNOWN)
.settings(finalResolvedSettings)
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
import org.elasticsearch.action.support.IndicesOptions;
Expand Down Expand Up @@ -1399,11 +1398,7 @@ public ClusterState execute(ClusterState currentState) {
currentState.metadata()
);

final IndexMetadata.Builder indexMdBuilder = restoreToCreateNewIndex(
snapshotIndexMetadata,
renamedIndexName,
currentState.getMinTransportVersion()
);
final IndexMetadata.Builder indexMdBuilder = restoreToCreateNewIndex(snapshotIndexMetadata, renamedIndexName);
if (request.includeAliases() == false
&& snapshotIndexMetadata.getAliases().isEmpty() == false
&& isSystemIndex(snapshotIndexMetadata) == false) {
Expand All @@ -1421,11 +1416,7 @@ && isSystemIndex(snapshotIndexMetadata) == false) {
} else {
// Index exists and it's closed - open it in metadata and start recovery
validateExistingClosedIndex(currentIndexMetadata, snapshotIndexMetadata, renamedIndexName, partial);
final IndexMetadata.Builder indexMdBuilder = restoreOverClosedIndex(
snapshotIndexMetadata,
currentIndexMetadata,
currentState.getMinTransportVersion()
);
final IndexMetadata.Builder indexMdBuilder = restoreOverClosedIndex(snapshotIndexMetadata, currentIndexMetadata);

if (request.includeAliases() == false && isSystemIndex(snapshotIndexMetadata) == false) {
// Remove all snapshot aliases
Expand Down Expand Up @@ -1800,26 +1791,18 @@ private static IndexMetadata convertLegacyIndex(
return convertedIndexMetadataBuilder.build();
}

private static IndexMetadata.Builder restoreToCreateNewIndex(
IndexMetadata snapshotIndexMetadata,
String renamedIndexName,
TransportVersion minClusterTransportVersion
) {
private static IndexMetadata.Builder restoreToCreateNewIndex(IndexMetadata snapshotIndexMetadata, String renamedIndexName) {
return IndexMetadata.builder(snapshotIndexMetadata)
.state(IndexMetadata.State.OPEN)
.index(renamedIndexName)
.settings(
Settings.builder().put(snapshotIndexMetadata.getSettings()).put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
)
.timestampRange(IndexLongFieldRange.NO_SHARDS)
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS, minClusterTransportVersion);
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS);
}

private static IndexMetadata.Builder restoreOverClosedIndex(
IndexMetadata snapshotIndexMetadata,
IndexMetadata currentIndexMetadata,
TransportVersion minTransportVersion
) {
private static IndexMetadata.Builder restoreOverClosedIndex(IndexMetadata snapshotIndexMetadata, IndexMetadata currentIndexMetadata) {
final IndexMetadata.Builder indexMdBuilder = IndexMetadata.builder(snapshotIndexMetadata)
.state(IndexMetadata.State.OPEN)
.version(Math.max(snapshotIndexMetadata.getVersion(), 1 + currentIndexMetadata.getVersion()))
Expand All @@ -1828,7 +1811,7 @@ private static IndexMetadata.Builder restoreOverClosedIndex(
.settingsVersion(Math.max(snapshotIndexMetadata.getSettingsVersion(), 1 + currentIndexMetadata.getSettingsVersion()))
.aliasesVersion(Math.max(snapshotIndexMetadata.getAliasesVersion(), 1 + currentIndexMetadata.getAliasesVersion()))
.timestampRange(IndexLongFieldRange.NO_SHARDS)
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS, minTransportVersion)
.eventIngestedRange(IndexLongFieldRange.NO_SHARDS)
.index(currentIndexMetadata.getIndex().getName())
.settings(
Settings.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

package org.elasticsearch.action.admin.cluster.reroute;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
Expand Down Expand Up @@ -347,7 +346,7 @@ private static ClusterState createClusterState() {
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.build()
)
.eventIngestedRange(IndexLongFieldRange.UNKNOWN, TransportVersion.current())
.eventIngestedRange(IndexLongFieldRange.UNKNOWN)
.build(),
false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.elasticsearch.action.search;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.search.CanMatchNodeResponse.ResponseOrFailure;
Expand Down Expand Up @@ -1462,7 +1461,7 @@ private void addIndexMinMaxTimestamps(Index index, String fieldName, long minTim
indexMetadataBuilder.timestampRange(timestampRange);
fields.put(index, new DateFieldRangeInfo(new DateFieldMapper.DateFieldType(fieldName), null, null, null));
} else if (fieldName.equals(IndexMetadata.EVENT_INGESTED_FIELD_NAME)) {
indexMetadataBuilder.eventIngestedRange(timestampRange, TransportVersion.current());
indexMetadataBuilder.eventIngestedRange(timestampRange);
fields.put(index, new DateFieldRangeInfo(null, null, new DateFieldMapper.DateFieldType(fieldName), null));
}

Expand Down Expand Up @@ -1502,7 +1501,7 @@ private void addIndexMinMaxForTimestampAndEventIngested(
.numberOfShards(1)
.numberOfReplicas(0)
.timestampRange(tsTimestampRange)
.eventIngestedRange(eventIngestedTimestampRange, TransportVersion.current());
.eventIngestedRange(eventIngestedTimestampRange);

Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()).put(indexMetadataBuilder);
clusterState = ClusterState.builder(clusterState).metadata(metadataBuilder).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ private ClusterState buildClusterState() throws IOException {
.putRolloverInfo(new RolloverInfo("rolloveAlias", new ArrayList<>(), 1L))
.stats(new IndexMetadataStats(IndexWriteLoad.builder(1).build(), 120, 1))
.indexWriteLoadForecast(8.0)
.eventIngestedRange(IndexLongFieldRange.UNKNOWN, TransportVersions.V_8_0_0)
.eventIngestedRange(IndexLongFieldRange.UNKNOWN)
.build();

return ClusterState.builder(ClusterName.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.apache.lucene.util.automaton.RegExp;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.Alias;
Expand Down Expand Up @@ -1258,16 +1257,7 @@ public void testBuildIndexMetadata() {

Settings indexSettings = indexSettings(IndexVersion.current(), 1, 0).build();
List<AliasMetadata> aliases = List.of(AliasMetadata.builder("alias1").build());
IndexMetadata indexMetadata = buildIndexMetadata(
"test",
aliases,
() -> null,
indexSettings,
4,
sourceIndexMetadata,
false,
TransportVersion.current()
);
IndexMetadata indexMetadata = buildIndexMetadata("test", aliases, () -> null, indexSettings, 4, sourceIndexMetadata, false);

assertThat(indexMetadata.getAliases().size(), is(1));
assertThat(indexMetadata.getAliases().keySet().iterator().next(), is("alias1"));
Expand All @@ -1276,35 +1266,6 @@ public void testBuildIndexMetadata() {
assertThat(indexMetadata.getEventIngestedRange(), equalTo(IndexLongFieldRange.NO_SHARDS));
}

public void testBuildIndexMetadataWithTransportVersionBeforeEventIngestedRangeAdded() {
IndexMetadata sourceIndexMetadata = IndexMetadata.builder("parent")
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build())
.numberOfShards(1)
.numberOfReplicas(0)
.primaryTerm(0, 3L)
.build();

Settings indexSettings = indexSettings(IndexVersion.current(), 1, 0).build();
List<AliasMetadata> aliases = List.of(AliasMetadata.builder("alias1").build());
IndexMetadata indexMetadata = buildIndexMetadata(
"test",
aliases,
() -> null,
indexSettings,
4,
sourceIndexMetadata,
false,
TransportVersions.V_8_0_0
);

assertThat(indexMetadata.getAliases().size(), is(1));
assertThat(indexMetadata.getAliases().keySet().iterator().next(), is("alias1"));
assertThat("The source index primary term must be used", indexMetadata.primaryTerm(0), is(3L));
assertThat(indexMetadata.getTimestampRange(), equalTo(IndexLongFieldRange.NO_SHARDS));
// on versions before event.ingested was added to cluster state, it should default to UNKNOWN, not NO_SHARDS
assertThat(indexMetadata.getEventIngestedRange(), equalTo(IndexLongFieldRange.UNKNOWN));
}

public void testGetIndexNumberOfRoutingShardsWithNullSourceIndex() {
Settings indexSettings = Settings.builder()
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
Expand Down
Loading

0 comments on commit 0dfe455

Please sign in to comment.