Skip to content

Commit fb322dc

Browse files
authored
Migrate getProject().index calls to lookup index (#124178)
This migrates a number of calls of the form metadata.getProject().getIndexSafe(index) or metadata.getProject().index(index) to metadata.indexMetadata(index) or metadata.findIndex(index)
1 parent e478ce1 commit fb322dc

15 files changed

+16
-17
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportPrevalidateShardPathAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected NodePrevalidateShardPathResponse nodeOperation(NodePrevalidateShardPat
103103
// For each shard we only check whether the shard path exists, regardless of whether the content is a valid index or not.
104104
for (ShardId shardId : request.getShardIds()) {
105105
try {
106-
var indexMetadata = clusterService.state().metadata().getProject().index(shardId.getIndex());
106+
var indexMetadata = clusterService.state().metadata().findIndex(shardId.getIndex()).orElse(null);
107107
String customDataPath = null;
108108
if (indexMetadata != null) {
109109
customDataPath = new IndexSettings(indexMetadata, settings).customDataPath();

server/src/main/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private class IndexRequestContext {
238238
Iterator<ShardRequestContext> getShardRequestContexts() {
239239
try (var shardListeners = new RefCountingListener(1, outerListener.acquire(ignored -> putResults()))) {
240240
final var customDataPath = IndexMetadata.INDEX_DATA_PATH_SETTING.get(
241-
metadata.getProject().index(indexRoutingTable.getIndex()).getSettings()
241+
metadata.indexMetadata(indexRoutingTable.getIndex()).getSettings()
242242
);
243243
final var shardRequestContexts = new ArrayList<ShardRequestContext>(indexRoutingTable.size());
244244
for (int shardNum = 0; shardNum < indexRoutingTable.size(); shardNum++) {

server/src/main/java/org/elasticsearch/cluster/metadata/SystemIndexMetadataUpgradeService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private List<IndexMetadata> updateIndices(ClusterState currentState, List<Index>
240240
Metadata metadata = currentState.metadata();
241241
final List<IndexMetadata> updatedMetadata = new ArrayList<>();
242242
for (Index index : indices) {
243-
IndexMetadata indexMetadata = metadata.getProject().index(index);
243+
IndexMetadata indexMetadata = metadata.indexMetadata(index);
244244
final boolean shouldBeSystem = shouldBeSystem(indexMetadata);
245245
IndexMetadata updatedIndexMetadata = updateIndexIfNecessary(indexMetadata, shouldBeSystem);
246246
if (updatedIndexMetadata != null) {

server/src/main/java/org/elasticsearch/cluster/routing/ExpectedShardSizeEstimator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static boolean shouldReserveSpaceForInitializingShard(ShardRouting shard,
5353
// Snapshot restore (unless it is partial) require downloading all segments locally from the blobstore to start the shard.
5454
// See org.elasticsearch.xpack.searchablesnapshots.action.TransportMountSearchableSnapshotAction.buildIndexSettings
5555
// and DiskThresholdDecider.SETTING_IGNORE_DISK_WATERMARKS
56-
case SNAPSHOT -> metadata.getProject().getIndexSafe(shard.index()).isPartialSearchableSnapshot() == false;
56+
case SNAPSHOT -> metadata.indexMetadata(shard.index()).isPartialSearchableSnapshot() == false;
5757

5858
// shrink/split/clone operation is going to clone existing locally placed shards using file system hard links
5959
// so no additional space is going to be used until future merges

server/src/main/java/org/elasticsearch/cluster/routing/UnassignedInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public static long findNextDelayedAllocation(long currentNanoTime, ClusterState
416416
for (ShardRouting shard : state.getRoutingNodes().unassigned()) {
417417
UnassignedInfo unassignedInfo = shard.unassignedInfo();
418418
if (unassignedInfo.delayed()) {
419-
Settings indexSettings = metadata.getProject().index(shard.index()).getSettings();
419+
Settings indexSettings = metadata.indexMetadata(shard.index()).getSettings();
420420
// calculate next time to schedule
421421
final long newComputedLeftDelayNanos = unassignedInfo.remainingDelay(
422422
currentNanoTime,

server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ default void removeDelayMarkers(RoutingAllocation allocation) {
484484
if (unassignedInfo.delayed()) {
485485
final long newComputedLeftDelayNanos = unassignedInfo.remainingDelay(
486486
allocation.getCurrentNanoTime(),
487-
metadata.getProject().getIndexSafe(shardRouting.index()).getSettings(),
487+
metadata.indexMetadata(shardRouting.index()).getSettings(),
488488
metadata.nodeShutdowns()
489489
);
490490
if (newComputedLeftDelayNanos == 0) {
@@ -714,7 +714,7 @@ private static void disassociateDeadNodes(RoutingAllocation allocation) {
714714

715715
// now, go over all the shards routing on the node, and fail them
716716
for (ShardRouting shardRouting : node.copyShards()) {
717-
final IndexMetadata indexMetadata = allocation.metadata().getProject().getIndexSafe(shardRouting.index());
717+
final IndexMetadata indexMetadata = allocation.metadata().indexMetadata(shardRouting.index());
718718
boolean delayed = delayedDueToKnownRestart
719719
|| INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(indexMetadata.getSettings()).nanos() > 0;
720720

server/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private static Map<String, Long> unaccountedSearchableSnapshotSizes(ClusterState
177177
long totalSize = 0;
178178
for (ShardRouting shard : node.started()) {
179179
if (shard.getExpectedShardSize() > 0
180-
&& clusterState.metadata().getProject().getIndexSafe(shard.index()).isSearchableSnapshot()
180+
&& clusterState.metadata().indexMetadata(shard.index()).isSearchableSnapshot()
181181
&& reservedSpace.containsShardId(shard.shardId()) == false
182182
&& clusterInfo.getShardSize(shard) == null) {
183183
totalSize += shard.getExpectedShardSize();

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterBalanceStats.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ private static NodeBalanceStats createFrom(
231231
long actualShardSize = 0L;
232232

233233
for (ShardRouting shardRouting : routingNode) {
234-
var indexMetadata = metadata.getProject().index(shardRouting.index());
234+
var indexMetadata = metadata.indexMetadata(shardRouting.index());
235235
var shardSize = clusterInfo.getShardSize(shardRouting, 0L);
236-
assert indexMetadata != null;
237236
forecastWriteLoad += writeLoadForecaster.getForecastedWriteLoad(indexMetadata).orElse(0.0);
238237
forecastShardSize += indexMetadata.getForecastedShardSizeInBytes().orElse(shardSize);
239238
actualShardSize += shardSize;

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, Routing
334334
return decision;
335335
}
336336

337-
if (allocation.metadata().getProject().index(shardRouting.index()).ignoreDiskWatermarks()) {
337+
if (allocation.metadata().indexMetadata(shardRouting.index()).ignoreDiskWatermarks()) {
338338
return YES_DISK_WATERMARKS_IGNORED;
339339
}
340340

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
7979
// if its already a NO decision looking at the node, or we aren't configured to look at the host, return the decision
8080
return decision;
8181
}
82-
if (allocation.metadata().getProject().getIndexSafe(shardRouting.index()).getAutoExpandReplicas().expandToAllNodes()) {
82+
if (allocation.metadata().indexMetadata(shardRouting.index()).getAutoExpandReplicas().expandToAllNodes()) {
8383
return YES_AUTO_EXPAND_ALL;
8484
}
8585
if (node.node() != null) {

0 commit comments

Comments
 (0)