Skip to content

Commit 282d196

Browse files
authored
InternalClusterInfoService should not ignore hidden indices (#62995) (#63049)
Today InternalClusterInfoService ignores hidden indices when retrieving shard stats of the cluster. This can lead to suboptimal shard allocation decisions as the size of shards are taken into account when allocating new shards or rebalancing existing shards.
1 parent bfbd616 commit 282d196

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
import org.elasticsearch.index.shard.IndexShard;
4242
import org.elasticsearch.index.store.Store;
4343
import org.elasticsearch.indices.IndicesService;
44+
import org.elasticsearch.indices.SystemIndexDescriptor;
4445
import org.elasticsearch.plugins.ActionPlugin;
4546
import org.elasticsearch.plugins.Plugin;
47+
import org.elasticsearch.plugins.SystemIndexPlugin;
4648
import org.elasticsearch.test.ESIntegTestCase;
4749
import org.elasticsearch.test.InternalTestCluster;
4850
import org.elasticsearch.test.transport.MockTransportService;
@@ -51,7 +53,9 @@
5153

5254
import java.util.Arrays;
5355
import java.util.Collection;
56+
import java.util.Collections;
5457
import java.util.List;
58+
import java.util.Locale;
5559
import java.util.Set;
5660
import java.util.concurrent.atomic.AtomicBoolean;
5761

@@ -70,7 +74,9 @@
7074
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
7175
public class ClusterInfoServiceIT extends ESIntegTestCase {
7276

73-
public static class TestPlugin extends Plugin implements ActionPlugin {
77+
private static final String TEST_SYSTEM_INDEX_NAME = ".test-cluster-info-system-index";
78+
79+
public static class TestPlugin extends Plugin implements ActionPlugin, SystemIndexPlugin {
7480

7581
private final BlockingActionFilter blockingActionFilter;
7682

@@ -82,6 +88,12 @@ public TestPlugin() {
8288
public List<ActionFilter> getActionFilters() {
8389
return singletonList(blockingActionFilter);
8490
}
91+
92+
@Override
93+
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) {
94+
return Collections.singletonList(new SystemIndexDescriptor(TEST_SYSTEM_INDEX_NAME,
95+
"System index for [" + getTestClass().getName() + ']'));
96+
}
8597
}
8698

8799
public static class BlockingActionFilter extends org.elasticsearch.action.support.ActionFilter.Simple {
@@ -117,13 +129,18 @@ private void setClusterInfoTimeout(String timeValue) {
117129

118130
public void testClusterInfoServiceCollectsInformation() {
119131
internalCluster().startNodes(2);
120-
assertAcked(prepareCreate("test").setSettings(Settings.builder()
121-
.put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), 0)
122-
.put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), EnableAllocationDecider.Rebalance.NONE).build()));
132+
133+
final String indexName = randomBoolean() ? randomAlphaOfLength(5).toLowerCase(Locale.ROOT) : TEST_SYSTEM_INDEX_NAME;
134+
assertAcked(prepareCreate(indexName)
135+
.setSettings(Settings.builder()
136+
.put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), 0)
137+
.put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), EnableAllocationDecider.Rebalance.NONE)
138+
.put(IndexMetadata.SETTING_INDEX_HIDDEN, randomBoolean())
139+
.build()));
123140
if (randomBoolean()) {
124-
assertAcked(client().admin().indices().prepareClose("test"));
141+
assertAcked(client().admin().indices().prepareClose(indexName));
125142
}
126-
ensureGreen("test");
143+
ensureGreen(indexName);
127144
InternalTestCluster internalTestCluster = internalCluster();
128145
// Get the cluster info service on the master node
129146
final InternalClusterInfoService infoService = (InternalClusterInfoService) internalTestCluster

server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected CountDownLatch updateIndicesStats(final ActionListener<IndicesStatsRes
262262
final IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
263263
indicesStatsRequest.clear();
264264
indicesStatsRequest.store(true);
265-
indicesStatsRequest.indicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_CLOSED);
265+
indicesStatsRequest.indicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_CLOSED_HIDDEN);
266266

267267
client.admin().indices().stats(indicesStatsRequest, new LatchedActionListener<>(listener, latch));
268268
return latch;
@@ -417,8 +417,8 @@ static void buildShardLevelInfo(Logger logger, ShardStats[] stats, ImmutableOpen
417417
}
418418

419419
static void fillDiskUsagePerNode(Logger logger, List<NodeStats> nodeStatsArray,
420-
ImmutableOpenMap.Builder<String, DiskUsage> newLeastAvaiableUsages,
421-
ImmutableOpenMap.Builder<String, DiskUsage> newMostAvaiableUsages) {
420+
ImmutableOpenMap.Builder<String, DiskUsage> newLeastAvailableUsages,
421+
ImmutableOpenMap.Builder<String, DiskUsage> newMostAvailableUsages) {
422422
for (NodeStats nodeStats : nodeStatsArray) {
423423
if (nodeStats.getFs() == null) {
424424
logger.warn("Unable to retrieve node FS stats for {}", nodeStats.getNode().getName());
@@ -449,7 +449,7 @@ static void fillDiskUsagePerNode(Logger logger, List<NodeStats> nodeStatsArray,
449449
nodeId, leastAvailablePath.getTotal().getBytes());
450450
}
451451
} else {
452-
newLeastAvaiableUsages.put(nodeId, new DiskUsage(nodeId, nodeName, leastAvailablePath.getPath(),
452+
newLeastAvailableUsages.put(nodeId, new DiskUsage(nodeId, nodeName, leastAvailablePath.getPath(),
453453
leastAvailablePath.getTotal().getBytes(), leastAvailablePath.getAvailable().getBytes()));
454454
}
455455
if (mostAvailablePath.getTotal().getBytes() < 0) {
@@ -458,7 +458,7 @@ static void fillDiskUsagePerNode(Logger logger, List<NodeStats> nodeStatsArray,
458458
nodeId, mostAvailablePath.getTotal().getBytes());
459459
}
460460
} else {
461-
newMostAvaiableUsages.put(nodeId, new DiskUsage(nodeId, nodeName, mostAvailablePath.getPath(),
461+
newMostAvailableUsages.put(nodeId, new DiskUsage(nodeId, nodeName, mostAvailablePath.getPath(),
462462
mostAvailablePath.getTotal().getBytes(), mostAvailablePath.getAvailable().getBytes()));
463463
}
464464

0 commit comments

Comments
 (0)