Skip to content

Commit

Permalink
Remove @UpdateForV9 in IndexMetadata#withTimestampRanges
Browse files Browse the repository at this point in the history
  • Loading branch information
javanna committed Dec 19, 2024
1 parent 22c2db8 commit 6472d16
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.gateway.MetadataStateFormat;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
Expand Down Expand Up @@ -944,22 +943,12 @@ public IndexMetadata withIncrementedPrimaryTerm(int shardId) {
/**
* @param timestampRange new @timestamp range
* @param eventIngestedRange new 'event.ingested' range
* @param minClusterTransportVersion minimum transport version used between nodes of this cluster
* @return copy of this instance with updated timestamp range
*/
public IndexMetadata withTimestampRanges(
IndexLongFieldRange timestampRange,
IndexLongFieldRange eventIngestedRange,
TransportVersion minClusterTransportVersion
) {
public IndexMetadata withTimestampRanges(IndexLongFieldRange timestampRange, IndexLongFieldRange eventIngestedRange) {
if (timestampRange.equals(this.timestampRange) && eventIngestedRange.equals(this.eventIngestedRange)) {
return this;
}
@UpdateForV9(owner = UpdateForV9.Owner.SEARCH_FOUNDATIONS) // remove this check when 8.15 is no longer communicable
IndexLongFieldRange allowedEventIngestedRange = eventIngestedRange;
if (minClusterTransportVersion.before(TransportVersions.V_8_15_0)) {
allowedEventIngestedRange = IndexLongFieldRange.UNKNOWN;
}
return new IndexMetadata(
this.index,
this.version,
Expand Down Expand Up @@ -990,7 +979,7 @@ public IndexMetadata withTimestampRanges(
this.isSystem,
this.isHidden,
timestampRange,
allowedEventIngestedRange,
eventIngestedRange,
this.priority,
this.creationDate,
this.ignoreDiskWatermarks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.Diff;
import org.elasticsearch.cluster.Diffable;
Expand Down Expand Up @@ -519,7 +518,7 @@ public Metadata withLastCommittedValues(
/**
* Creates a copy of this instance updated with the given {@link IndexMetadata} that must only contain changes to primary terms
* and in-sync allocation ids relative to the existing entries. This method is only used by
* {@link org.elasticsearch.cluster.routing.allocation.IndexMetadataUpdater#applyChanges(Metadata, RoutingTable, TransportVersion)}.
* {@link org.elasticsearch.cluster.routing.allocation.IndexMetadataUpdater#applyChanges(Metadata, RoutingTable)}.
* @param updates map of index name to {@link IndexMetadata}.
* @return updated metadata instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.elasticsearch.cluster.routing.allocation;

import org.apache.logging.log4j.Logger;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
Expand Down Expand Up @@ -106,10 +105,9 @@ public void relocationCompleted(ShardRouting removedRelocationSource) {
*
* @param oldMetadata {@link Metadata} object from before the routing nodes was changed.
* @param newRoutingTable {@link RoutingTable} object after routing changes were applied.
* @param minClusterTransportVersion minimum TransportVersion used between nodes of this cluster
* @return adapted {@link Metadata}, potentially the original one if no change was needed.
*/
public Metadata applyChanges(Metadata oldMetadata, RoutingTable newRoutingTable, TransportVersion minClusterTransportVersion) {
public Metadata applyChanges(Metadata oldMetadata, RoutingTable newRoutingTable) {
Map<Index, List<Map.Entry<ShardId, Updates>>> changesGroupedByIndex = shardChanges.entrySet()
.stream()
.collect(Collectors.groupingBy(e -> e.getKey().getIndex()));
Expand All @@ -122,14 +120,7 @@ public Metadata applyChanges(Metadata oldMetadata, RoutingTable newRoutingTable,
for (Map.Entry<ShardId, Updates> shardEntry : indexChanges.getValue()) {
ShardId shardId = shardEntry.getKey();
Updates updates = shardEntry.getValue();
updatedIndexMetadata = updateInSyncAllocations(
newRoutingTable,
oldIndexMetadata,
updatedIndexMetadata,
shardId,
updates,
minClusterTransportVersion
);
updatedIndexMetadata = updateInSyncAllocations(newRoutingTable, oldIndexMetadata, updatedIndexMetadata, shardId, updates);
updatedIndexMetadata = updates.increaseTerm
? updatedIndexMetadata.withIncrementedPrimaryTerm(shardId.id())
: updatedIndexMetadata;
Expand All @@ -150,8 +141,7 @@ private static IndexMetadata updateInSyncAllocations(
IndexMetadata oldIndexMetadata,
IndexMetadata updatedIndexMetadata,
ShardId shardId,
Updates updates,
TransportVersion minClusterTransportVersion
Updates updates
) {
assert Sets.haveEmptyIntersection(updates.addedAllocationIds, updates.removedAllocationIds)
: "allocation ids cannot be both added and removed in the same allocation round, added ids: "
Expand Down Expand Up @@ -183,8 +173,7 @@ private static IndexMetadata updateInSyncAllocations(
allocationId = RecoverySource.ExistingStoreRecoverySource.FORCED_ALLOCATION_ID;
updatedIndexMetadata = updatedIndexMetadata.withTimestampRanges(
updatedIndexMetadata.getTimestampRange().removeShard(shardId.id(), oldIndexMetadata.getNumberOfShards()),
updatedIndexMetadata.getEventIngestedRange().removeShard(shardId.id(), oldIndexMetadata.getNumberOfShards()),
minClusterTransportVersion
updatedIndexMetadata.getEventIngestedRange().removeShard(shardId.id(), oldIndexMetadata.getNumberOfShards())
);
} else {
assert recoverySource instanceof RecoverySource.SnapshotRecoverySource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public RoutingChangesObserver changes() {
* Returns updated {@link Metadata} based on the changes that were made to the routing nodes
*/
public Metadata updateMetadataWithRoutingChanges(RoutingTable newRoutingTable) {
Metadata metadata = indexMetadataUpdater.applyChanges(metadata(), newRoutingTable, clusterState.getMinTransportVersion());
Metadata metadata = indexMetadataUpdater.applyChanges(metadata(), newRoutingTable);
return resizeSourceIndexUpdater.applyChanges(metadata, newRoutingTable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ public void testClusterStateCreateIndexWithClusterBlockTransformer() {
.numberOfShards(1)
.numberOfReplicas(nbReplicas)
.build()
.withTimestampRanges(IndexLongFieldRange.UNKNOWN, IndexLongFieldRange.UNKNOWN, minTransportVersion),
.withTimestampRanges(IndexLongFieldRange.UNKNOWN, IndexLongFieldRange.UNKNOWN),
null,
MetadataCreateIndexService.createClusterBlocksTransformerForIndexCreation(settings),
TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY
Expand Down

0 comments on commit 6472d16

Please sign in to comment.