diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java index 5c705569a0b16..5da1e1d3ba024 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -19,9 +19,9 @@ import org.elasticsearch.cluster.ClusterInfoService; import org.elasticsearch.cluster.ClusterInfoServiceUtils; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.EstimatedHeapUsage; +import org.elasticsearch.cluster.EstimatedHeapUsageCollector; import org.elasticsearch.cluster.InternalClusterInfoService; -import org.elasticsearch.cluster.ShardHeapUsage; -import org.elasticsearch.cluster.ShardHeapUsageCollector; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeUtils; @@ -123,7 +123,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { @Override protected Collection> getPlugins() { - return pluginList(InternalSettingsPlugin.class, BogusShardHeapUsagePlugin.class); + return pluginList(InternalSettingsPlugin.class, BogusEstimatedHeapUsagePlugin.class); } public void testLockTryingToDelete() throws Exception { @@ -264,31 +264,31 @@ public void testExpectedShardSizeIsPresent() throws InterruptedException { public void testHeapUsageEstimateIsPresent() { InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class); ClusterInfoServiceUtils.refresh(clusterInfoService); - Map shardHeapUsages = clusterInfoService.getClusterInfo().getShardHeapUsages(); - assertNotNull(shardHeapUsages); + Map estimatedHeapUsages = clusterInfoService.getClusterInfo().getEstimatedHeapUsages(); + assertNotNull(estimatedHeapUsages); // Not collecting yet because it is disabled - assertTrue(shardHeapUsages.isEmpty()); + assertTrue(estimatedHeapUsages.isEmpty()); - // Enable collection for shard heap usages + // Enable collection for estimated heap usages updateClusterSettings( Settings.builder() - .put(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_SHARD_HEAP_THRESHOLD_DECIDER_ENABLED.getKey(), true) + .put(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED.getKey(), true) .build() ); try { ClusterInfoServiceUtils.refresh(clusterInfoService); ClusterState state = getInstanceFromNode(ClusterService.class).state(); - shardHeapUsages = clusterInfoService.getClusterInfo().getShardHeapUsages(); - assertEquals(state.nodes().size(), shardHeapUsages.size()); + estimatedHeapUsages = clusterInfoService.getClusterInfo().getEstimatedHeapUsages(); + assertEquals(state.nodes().size(), estimatedHeapUsages.size()); for (DiscoveryNode node : state.nodes()) { - assertTrue(shardHeapUsages.containsKey(node.getId())); - ShardHeapUsage shardHeapUsage = shardHeapUsages.get(node.getId()); - assertThat(shardHeapUsage.estimatedFreeBytes(), lessThanOrEqualTo(shardHeapUsage.totalBytes())); + assertTrue(estimatedHeapUsages.containsKey(node.getId())); + EstimatedHeapUsage estimatedHeapUsage = estimatedHeapUsages.get(node.getId()); + assertThat(estimatedHeapUsage.estimatedFreeBytes(), lessThanOrEqualTo(estimatedHeapUsage.totalBytes())); } } finally { updateClusterSettings( Settings.builder() - .putNull(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_SHARD_HEAP_THRESHOLD_DECIDER_ENABLED.getKey()) + .putNull(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED.getKey()) .build() ); } @@ -838,11 +838,11 @@ private static void assertAllIndicesRemovedAndDeletionCompleted(Iterable> listener) } } - public static class BogusShardHeapUsagePlugin extends Plugin implements ClusterPlugin { + public static class BogusEstimatedHeapUsagePlugin extends Plugin implements ClusterPlugin { private final SetOnce clusterService = new SetOnce<>(); diff --git a/server/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.cluster.ShardHeapUsageCollector b/server/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.cluster.EstimatedHeapUsageCollector similarity index 84% rename from server/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.cluster.ShardHeapUsageCollector rename to server/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.cluster.EstimatedHeapUsageCollector index 15b62c8240f25..db3574b0a001b 100644 --- a/server/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.cluster.ShardHeapUsageCollector +++ b/server/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.cluster.EstimatedHeapUsageCollector @@ -7,4 +7,4 @@ # License v3.0 only", or the "Server Side Public License, v 1". # -org.elasticsearch.index.shard.IndexShardIT$BogusShardShardHeapUsageCollector +org.elasticsearch.index.shard.IndexShardIT$BogusEstimatedEstimatedHeapUsageCollector diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java b/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java index 460ed5e119c1a..e8cb0421979c5 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java @@ -57,7 +57,7 @@ public class ClusterInfo implements ChunkedToXContent, Writeable { final Map shardDataSetSizes; final Map dataPath; final Map reservedSpace; - final Map shardHeapUsages; + final Map estimatedHeapUsages; protected ClusterInfo() { this(Map.of(), Map.of(), Map.of(), Map.of(), Map.of(), Map.of(), Map.of()); @@ -72,7 +72,7 @@ protected ClusterInfo() { * @param shardDataSetSizes a shard id to data set size in bytes mapping per shard * @param dataPath the shard routing to datapath mapping * @param reservedSpace reserved space per shard broken down by node and data path - * @param shardHeapUsages shard heap usage broken down by node + * @param estimatedHeapUsages estimated heap usage broken down by node * @see #shardIdentifierFromRouting */ public ClusterInfo( @@ -82,7 +82,7 @@ public ClusterInfo( Map shardDataSetSizes, Map dataPath, Map reservedSpace, - Map shardHeapUsages + Map estimatedHeapUsages ) { this.leastAvailableSpaceUsage = Map.copyOf(leastAvailableSpaceUsage); this.mostAvailableSpaceUsage = Map.copyOf(mostAvailableSpaceUsage); @@ -90,7 +90,7 @@ public ClusterInfo( this.shardDataSetSizes = Map.copyOf(shardDataSetSizes); this.dataPath = Map.copyOf(dataPath); this.reservedSpace = Map.copyOf(reservedSpace); - this.shardHeapUsages = Map.copyOf(shardHeapUsages); + this.estimatedHeapUsages = Map.copyOf(estimatedHeapUsages); } public ClusterInfo(StreamInput in) throws IOException { @@ -103,9 +103,9 @@ public ClusterInfo(StreamInput in) throws IOException { : in.readImmutableMap(nested -> NodeAndShard.from(new ShardRouting(nested)), StreamInput::readString); this.reservedSpace = in.readImmutableMap(NodeAndPath::new, ReservedSpace::new); if (in.getTransportVersion().onOrAfter(TransportVersions.HEAP_USAGE_IN_CLUSTER_INFO)) { - this.shardHeapUsages = in.readImmutableMap(ShardHeapUsage::new); + this.estimatedHeapUsages = in.readImmutableMap(EstimatedHeapUsage::new); } else { - this.shardHeapUsages = Map.of(); + this.estimatedHeapUsages = Map.of(); } } @@ -122,7 +122,7 @@ public void writeTo(StreamOutput out) throws IOException { } out.writeMap(this.reservedSpace); if (out.getTransportVersion().onOrAfter(TransportVersions.HEAP_USAGE_IN_CLUSTER_INFO)) { - out.writeMap(this.shardHeapUsages, StreamOutput::writeWriteable); + out.writeMap(this.estimatedHeapUsages, StreamOutput::writeWriteable); } } @@ -204,7 +204,7 @@ public Iterator toXContentChunked(ToXContent.Params params return builder.endObject(); // NodeAndPath }), endArray() // end "reserved_sizes" - // NOTE: We don't serialize shardHeapUsages at this stage, to avoid + // NOTE: We don't serialize estimatedHeapUsages at this stage, to avoid // committing to API payloads until the feature is settled ); } @@ -216,8 +216,8 @@ public Iterator toXContentChunked(ToXContent.Params params * Also note that the map may not be complete, it may contain none, or a subset of the nodes in * the cluster at any time. It may also contain entries for nodes that have since left the cluster. */ - public Map getShardHeapUsages() { - return shardHeapUsages; + public Map getEstimatedHeapUsages() { + return estimatedHeapUsages; } /** diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java b/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java index ac983672642a7..b47b15f545ed8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java @@ -33,7 +33,7 @@ public class ClusterInfoSimulator { private final CopyOnFirstWriteMap shardSizes; private final Map shardDataSetSizes; private final Map dataPath; - private final Map shardHeapUsages; + private final Map estimatedHeapUsages; public ClusterInfoSimulator(RoutingAllocation allocation) { this.allocation = allocation; @@ -42,7 +42,7 @@ public ClusterInfoSimulator(RoutingAllocation allocation) { this.shardSizes = new CopyOnFirstWriteMap<>(allocation.clusterInfo().shardSizes); this.shardDataSetSizes = Map.copyOf(allocation.clusterInfo().shardDataSetSizes); this.dataPath = Map.copyOf(allocation.clusterInfo().dataPath); - this.shardHeapUsages = allocation.clusterInfo().getShardHeapUsages(); + this.estimatedHeapUsages = allocation.clusterInfo().getEstimatedHeapUsages(); } /** @@ -156,7 +156,7 @@ public ClusterInfo getClusterInfo() { shardDataSetSizes, dataPath, Map.of(), - shardHeapUsages + estimatedHeapUsages ); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/ShardHeapUsage.java b/server/src/main/java/org/elasticsearch/cluster/EstimatedHeapUsage.java similarity index 88% rename from server/src/main/java/org/elasticsearch/cluster/ShardHeapUsage.java rename to server/src/main/java/org/elasticsearch/cluster/EstimatedHeapUsage.java index cc6a00421a292..973df24acc547 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ShardHeapUsage.java +++ b/server/src/main/java/org/elasticsearch/cluster/EstimatedHeapUsage.java @@ -18,14 +18,14 @@ /** * Record representing an estimate of the heap used by allocated shards and ongoing merges on a particular node */ -public record ShardHeapUsage(String nodeId, long totalBytes, long estimatedUsageBytes) implements Writeable { +public record EstimatedHeapUsage(String nodeId, long totalBytes, long estimatedUsageBytes) implements Writeable { - public ShardHeapUsage { + public EstimatedHeapUsage { assert totalBytes >= 0; assert estimatedUsageBytes >= 0; } - public ShardHeapUsage(StreamInput in) throws IOException { + public EstimatedHeapUsage(StreamInput in) throws IOException { this(in.readString(), in.readVLong(), in.readVLong()); } diff --git a/server/src/main/java/org/elasticsearch/cluster/ShardHeapUsageCollector.java b/server/src/main/java/org/elasticsearch/cluster/EstimatedHeapUsageCollector.java similarity index 69% rename from server/src/main/java/org/elasticsearch/cluster/ShardHeapUsageCollector.java rename to server/src/main/java/org/elasticsearch/cluster/EstimatedHeapUsageCollector.java index c3f3213e035ad..36f7b95c92c7f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ShardHeapUsageCollector.java +++ b/server/src/main/java/org/elasticsearch/cluster/EstimatedHeapUsageCollector.java @@ -14,21 +14,21 @@ import java.util.Map; /** - * Collect the shard heap usage for each node in the cluster. + * Collect the estimated heap usage for each node in the cluster. *

* Results are returned as a map of node ID to estimated heap usage in bytes * - * @see ShardHeapUsage + * @see EstimatedHeapUsage */ -public interface ShardHeapUsageCollector { +public interface EstimatedHeapUsageCollector { /** - * This will be used when there is no ShardHeapUsageCollector available + * This will be used when there is no EstimatedHeapUsageCollector available */ - ShardHeapUsageCollector EMPTY = listener -> listener.onResponse(Map.of()); + EstimatedHeapUsageCollector EMPTY = listener -> listener.onResponse(Map.of()); /** - * Collect the shard heap usage for every node in the cluster + * Collect the estimated heap usage for every node in the cluster * * @param listener The listener which will receive the results */ diff --git a/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java b/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java index c792ce377ef33..066667dfaba84 100644 --- a/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java +++ b/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java @@ -83,22 +83,22 @@ public class InternalClusterInfoService implements ClusterInfoService, ClusterSt Property.NodeScope ); - public static final Setting CLUSTER_ROUTING_ALLOCATION_SHARD_HEAP_THRESHOLD_DECIDER_ENABLED = Setting.boolSetting( - "cluster.routing.allocation.shard_heap.threshold_enabled", + public static final Setting CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED = Setting.boolSetting( + "cluster.routing.allocation.estimated_heap.threshold_enabled", false, Property.Dynamic, Property.NodeScope ); private volatile boolean diskThresholdEnabled; - private volatile boolean shardHeapThresholdEnabled; + private volatile boolean estimatedHeapThresholdEnabled; private volatile TimeValue updateFrequency; private volatile TimeValue fetchTimeout; private volatile Map leastAvailableSpaceUsages; private volatile Map mostAvailableSpaceUsages; private volatile Map maxHeapPerNode; - private volatile Map shardHeapUsagePerNode; + private volatile Map estimatedHeapUsagePerNode; private volatile IndicesStatsSummary indicesStatsSummary; private final ThreadPool threadPool; @@ -107,7 +107,7 @@ public class InternalClusterInfoService implements ClusterInfoService, ClusterSt private final Object mutex = new Object(); private final List> nextRefreshListeners = new ArrayList<>(); - private final ShardHeapUsageCollector shardHeapUsageCollector; + private final EstimatedHeapUsageCollector estimatedHeapUsageCollector; private AsyncRefresh currentRefresh; private RefreshScheduler refreshScheduler; @@ -118,16 +118,16 @@ public InternalClusterInfoService( ClusterService clusterService, ThreadPool threadPool, Client client, - ShardHeapUsageCollector shardHeapUsageCollector + EstimatedHeapUsageCollector estimatedHeapUsageCollector ) { this.leastAvailableSpaceUsages = Map.of(); this.mostAvailableSpaceUsages = Map.of(); this.maxHeapPerNode = Map.of(); - this.shardHeapUsagePerNode = Map.of(); + this.estimatedHeapUsagePerNode = Map.of(); this.indicesStatsSummary = IndicesStatsSummary.EMPTY; this.threadPool = threadPool; this.client = client; - this.shardHeapUsageCollector = shardHeapUsageCollector; + this.estimatedHeapUsageCollector = estimatedHeapUsageCollector; this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings); this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings); this.diskThresholdEnabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings); @@ -139,8 +139,8 @@ public InternalClusterInfoService( this::setDiskThresholdEnabled ); clusterSettings.initializeAndWatch( - CLUSTER_ROUTING_ALLOCATION_SHARD_HEAP_THRESHOLD_DECIDER_ENABLED, - this::setShardHeapThresholdEnabled + CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED, + this::setEstimatedHeapThresholdEnabled ); } @@ -148,8 +148,8 @@ private void setDiskThresholdEnabled(boolean diskThresholdEnabled) { this.diskThresholdEnabled = diskThresholdEnabled; } - private void setShardHeapThresholdEnabled(boolean shardHeapThresholdEnabled) { - this.shardHeapThresholdEnabled = shardHeapThresholdEnabled; + private void setEstimatedHeapThresholdEnabled(boolean estimatedHeapThresholdEnabled) { + this.estimatedHeapThresholdEnabled = estimatedHeapThresholdEnabled; } private void setFetchTimeout(TimeValue fetchTimeout) { @@ -202,8 +202,8 @@ void execute() { try (var ignoredRefs = fetchRefs) { maybeFetchIndicesStats(diskThresholdEnabled); - maybeFetchNodeStats(diskThresholdEnabled || shardHeapThresholdEnabled); - maybeFetchNodesHeapUsage(shardHeapThresholdEnabled); + maybeFetchNodeStats(diskThresholdEnabled || estimatedHeapThresholdEnabled); + maybeFetchNodesEstimatedHeapUsage(estimatedHeapThresholdEnabled); } } @@ -231,28 +231,28 @@ private void maybeFetchNodeStats(boolean shouldFetch) { } } - private void maybeFetchNodesHeapUsage(boolean shouldFetch) { + private void maybeFetchNodesEstimatedHeapUsage(boolean shouldFetch) { if (shouldFetch) { try (var ignored = threadPool.getThreadContext().clearTraceContext()) { - fetchNodesHeapUsage(); + fetchNodesEstimatedHeapUsage(); } } else { - logger.trace("skipping collecting shard heap usage from cluster, notifying listeners with empty shard heap usage"); - shardHeapUsagePerNode = Map.of(); + logger.trace("skipping collecting estimated heap usage from cluster, notifying listeners with empty estimated heap usage"); + estimatedHeapUsagePerNode = Map.of(); } } - private void fetchNodesHeapUsage() { - shardHeapUsageCollector.collectClusterHeapUsage(ActionListener.releaseAfter(new ActionListener<>() { + private void fetchNodesEstimatedHeapUsage() { + estimatedHeapUsageCollector.collectClusterHeapUsage(ActionListener.releaseAfter(new ActionListener<>() { @Override - public void onResponse(Map currentShardHeapUsages) { - shardHeapUsagePerNode = currentShardHeapUsages; + public void onResponse(Map currentEstimatedHeapUsages) { + estimatedHeapUsagePerNode = currentEstimatedHeapUsages; } @Override public void onFailure(Exception e) { logger.warn("failed to fetch heap usage for nodes", e); - shardHeapUsagePerNode = Map.of(); + estimatedHeapUsagePerNode = Map.of(); } }, fetchRefs.acquire())); } @@ -479,11 +479,11 @@ private boolean shouldRefresh() { @Override public ClusterInfo getClusterInfo() { final IndicesStatsSummary indicesStatsSummary = this.indicesStatsSummary; // single volatile read - final Map shardHeapUsages = new HashMap<>(); + final Map estimatedHeapUsages = new HashMap<>(); maxHeapPerNode.forEach((nodeId, maxHeapSize) -> { - final Long estimatedHeapUsage = shardHeapUsagePerNode.get(nodeId); + final Long estimatedHeapUsage = estimatedHeapUsagePerNode.get(nodeId); if (estimatedHeapUsage != null) { - shardHeapUsages.put(nodeId, new ShardHeapUsage(nodeId, maxHeapSize.getBytes(), estimatedHeapUsage)); + estimatedHeapUsages.put(nodeId, new EstimatedHeapUsage(nodeId, maxHeapSize.getBytes(), estimatedHeapUsage)); } }); return new ClusterInfo( @@ -493,7 +493,7 @@ public ClusterInfo getClusterInfo() { indicesStatsSummary.shardDataSetSizes, indicesStatsSummary.dataPath, indicesStatsSummary.reservedSpace, - shardHeapUsages + estimatedHeapUsages ); } diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 9b197baef406c..fd6da4fadae60 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -292,7 +292,7 @@ public void apply(Settings value, Settings current, Settings previous) { DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_FROZEN_MAX_HEADROOM_SETTING, DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING, - InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_SHARD_HEAP_THRESHOLD_DECIDER_ENABLED, + InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED, SameShardAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING, InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, diff --git a/server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java b/server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java index 8ef81eb35543a..53c26dc679677 100644 --- a/server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java +++ b/server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java @@ -12,8 +12,8 @@ import org.elasticsearch.action.search.OnlinePrewarmingService; import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.cluster.ClusterInfoService; +import org.elasticsearch.cluster.EstimatedHeapUsageCollector; import org.elasticsearch.cluster.InternalClusterInfoService; -import org.elasticsearch.cluster.ShardHeapUsageCollector; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.breaker.CircuitBreaker; @@ -75,16 +75,16 @@ ClusterInfoService newClusterInfoService( ThreadPool threadPool, NodeClient client ) { - final ShardHeapUsageCollector shardHeapUsageCollector = pluginsService.loadSingletonServiceProvider( - ShardHeapUsageCollector.class, - () -> ShardHeapUsageCollector.EMPTY + final EstimatedHeapUsageCollector estimatedHeapUsageCollector = pluginsService.loadSingletonServiceProvider( + EstimatedHeapUsageCollector.class, + () -> EstimatedHeapUsageCollector.EMPTY ); final InternalClusterInfoService service = new InternalClusterInfoService( settings, clusterService, threadPool, client, - shardHeapUsageCollector + estimatedHeapUsageCollector ); if (DiscoveryNode.isMasterNode(settings)) { // listen for state changes (this node starts/stops being the elected master, or new nodes are added) diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterInfoTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterInfoTests.java index 532f9b649fbf4..25932c9e8b9f3 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterInfoTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterInfoTests.java @@ -46,14 +46,18 @@ public static ClusterInfo randomClusterInfo() { ); } - private static Map randomNodeHeapUsage() { + private static Map randomNodeHeapUsage() { int numEntries = randomIntBetween(0, 128); - Map nodeHeapUsage = new HashMap<>(numEntries); + Map nodeHeapUsage = new HashMap<>(numEntries); for (int i = 0; i < numEntries; i++) { String key = randomAlphaOfLength(32); final int totalBytes = randomIntBetween(0, Integer.MAX_VALUE); - final ShardHeapUsage shardHeapUsage = new ShardHeapUsage(randomAlphaOfLength(4), totalBytes, randomIntBetween(0, totalBytes)); - nodeHeapUsage.put(key, shardHeapUsage); + final EstimatedHeapUsage estimatedHeapUsage = new EstimatedHeapUsage( + randomAlphaOfLength(4), + totalBytes, + randomIntBetween(0, totalBytes) + ); + nodeHeapUsage.put(key, estimatedHeapUsage); } return nodeHeapUsage; } diff --git a/server/src/test/java/org/elasticsearch/cluster/ShardHeapUsageTests.java b/server/src/test/java/org/elasticsearch/cluster/EstimatedHeapUsageTests.java similarity index 54% rename from server/src/test/java/org/elasticsearch/cluster/ShardHeapUsageTests.java rename to server/src/test/java/org/elasticsearch/cluster/EstimatedHeapUsageTests.java index f41cc8fafd887..b79cbbcbeeabc 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ShardHeapUsageTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/EstimatedHeapUsageTests.java @@ -14,24 +14,24 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; -public class ShardHeapUsageTests extends ESTestCase { +public class EstimatedHeapUsageTests extends ESTestCase { public void testEstimatedUsageAsPercentage() { final long totalBytes = randomNonNegativeLong(); final long estimatedUsageBytes = randomLongBetween(0, totalBytes); - final ShardHeapUsage shardHeapUsage = new ShardHeapUsage(randomUUID(), totalBytes, estimatedUsageBytes); - assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), greaterThanOrEqualTo(0.0)); - assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), lessThanOrEqualTo(100.0)); - assertEquals(shardHeapUsage.estimatedUsageAsPercentage(), 100.0 * estimatedUsageBytes / totalBytes, 0.0001); + final EstimatedHeapUsage estimatedHeapUsage = new EstimatedHeapUsage(randomUUID(), totalBytes, estimatedUsageBytes); + assertThat(estimatedHeapUsage.estimatedFreeBytesAsPercentage(), greaterThanOrEqualTo(0.0)); + assertThat(estimatedHeapUsage.estimatedFreeBytesAsPercentage(), lessThanOrEqualTo(100.0)); + assertEquals(estimatedHeapUsage.estimatedUsageAsPercentage(), 100.0 * estimatedUsageBytes / totalBytes, 0.0001); } public void testEstimatedFreeBytesAsPercentage() { final long totalBytes = randomNonNegativeLong(); final long estimatedUsageBytes = randomLongBetween(0, totalBytes); final long estimatedFreeBytes = totalBytes - estimatedUsageBytes; - final ShardHeapUsage shardHeapUsage = new ShardHeapUsage(randomUUID(), totalBytes, estimatedUsageBytes); - assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), greaterThanOrEqualTo(0.0)); - assertThat(shardHeapUsage.estimatedFreeBytesAsPercentage(), lessThanOrEqualTo(100.0)); - assertEquals(shardHeapUsage.estimatedFreeBytesAsPercentage(), 100.0 * estimatedFreeBytes / totalBytes, 0.0001); + final EstimatedHeapUsage estimatedHeapUsage = new EstimatedHeapUsage(randomUUID(), totalBytes, estimatedUsageBytes); + assertThat(estimatedHeapUsage.estimatedFreeBytesAsPercentage(), greaterThanOrEqualTo(0.0)); + assertThat(estimatedHeapUsage.estimatedFreeBytesAsPercentage(), lessThanOrEqualTo(100.0)); + assertEquals(estimatedHeapUsage.estimatedFreeBytesAsPercentage(), 100.0 * estimatedFreeBytes / totalBytes, 0.0001); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java b/server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java index f7e667fd5aa9b..ea9c940793778 100644 --- a/server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java @@ -55,7 +55,7 @@ public void testScheduling() { final Settings.Builder settingsBuilder = Settings.builder() .put(Node.NODE_NAME_SETTING.getKey(), discoveryNode.getName()) - .put(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_SHARD_HEAP_THRESHOLD_DECIDER_ENABLED.getKey(), true); + .put(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED.getKey(), true); if (randomBoolean()) { settingsBuilder.put(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.getKey(), randomIntBetween(10000, 60000) + "ms"); } @@ -78,13 +78,13 @@ protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() { final ClusterService clusterService = new ClusterService(settings, clusterSettings, masterService, clusterApplierService); final FakeClusterInfoServiceClient client = new FakeClusterInfoServiceClient(threadPool); - final ShardHeapUsageCollector mockShardHeapUsageCollector = spy(new StubShardShardHeapUsageCollector()); + final EstimatedHeapUsageCollector mockEstimatedHeapUsageCollector = spy(new StubEstimatedEstimatedHeapUsageCollector()); final InternalClusterInfoService clusterInfoService = new InternalClusterInfoService( settings, clusterService, threadPool, client, - mockShardHeapUsageCollector + mockEstimatedHeapUsageCollector ); clusterService.addListener(clusterInfoService); clusterInfoService.addListener(ignored -> {}); @@ -121,13 +121,13 @@ protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() { deterministicTaskQueue.runAllRunnableTasks(); for (int i = 0; i < 3; i++) { - Mockito.clearInvocations(mockShardHeapUsageCollector); + Mockito.clearInvocations(mockEstimatedHeapUsageCollector); final int initialRequestCount = client.requestCount; final long duration = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings).millis(); runFor(deterministicTaskQueue, duration); deterministicTaskQueue.runAllRunnableTasks(); assertThat(client.requestCount, equalTo(initialRequestCount + 2)); // should have run two client requests per interval - verify(mockShardHeapUsageCollector).collectClusterHeapUsage(any()); // Should poll for heap usage once per interval + verify(mockEstimatedHeapUsageCollector).collectClusterHeapUsage(any()); // Should poll for heap usage once per interval } final AtomicBoolean failMaster2 = new AtomicBoolean(); @@ -144,7 +144,7 @@ protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() { assertFalse(deterministicTaskQueue.hasDeferredTasks()); } - private static class StubShardShardHeapUsageCollector implements ShardHeapUsageCollector { + private static class StubEstimatedEstimatedHeapUsageCollector implements EstimatedHeapUsageCollector { @Override public void collectClusterHeapUsage(ActionListener> listener) { diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java b/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java index 64cd81e1a9ab2..01b11ce97460a 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java @@ -43,7 +43,7 @@ public static class TestPlugin extends Plugin {} private volatile BiFunction diskUsageFunction; public MockInternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) { - super(settings, clusterService, threadPool, client, ShardHeapUsageCollector.EMPTY); + super(settings, clusterService, threadPool, client, EstimatedHeapUsageCollector.EMPTY); } public void setDiskUsageFunctionAndRefresh(BiFunction diskUsageFn) {