-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug information to ReactiveReason about assigned and unassigned…
… shards (#86132) We would like to see not only the amount of assigned and unassigned shards, but also the ids of the respective shards. Fixes #85243 * Calculate assigned shards based on storagePreventsRemainOrMove and storagePreventsAllocation0 * Correctly set assignedShardIds * Add a TODO * Add tests for assigned and non-assigned shard ids for ReactiveStorageDeciderService * Remove changes in ProactiveStorageDeciderService * Update docs/changelog/86132.yaml * Return empty list for unassigned shards if can't make a decision * Keep a terse constructor for ReactiveReason * Move assignedBytesUnmovableShards initialization to the original point * Add tests for JSON representation of ReactiveReason * Add a missed LICENSE header * shards ids are empty if the context is null * use shardIds helper * Use ShardId in records * Use record to represent amount of bytes and shard ids * Sort shards by their ids * Limit the amount of assigned shards in the output * Test that we limit the amount of assigned shards in the output * Move to SortedSet * Add tests that shard ids are sorted * Remove internal package protected methods of allocation info * Verify shard ids * Correctly calculate the amount of unmovableShards * Move assignedBytes * Extract the max amount of assigned shard ids to a constant * Extract the shard ids output version to a constant * Rename BytesShardIds to ShardsSize * Extract ShardsSize to a top level class * Keep shards its closer to the total size * Add missed license import * Update docs/changelog/86132.yaml * Fix the test for assigned shard JSON field names * Limit the amount of unassigned shards * Rename the limit to MAX_AMOUNT_OF_SHARDS * Use toList instead of Collections.toList * Bring back public accessors * Precollect unallocated shards to avoid double calculation * Update version to V_8_4_0 * Randomize index name * Coalesce numAllocatableSubjectShards and allocatableShards * Randomize indexName * Add comment about duplicated shard ids
- Loading branch information
Showing
7 changed files
with
324 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 86132 | ||
summary: Add debug information to `ReactiveReason` about assigned and unassigned shards | ||
area: Allocation | ||
type: enhancement | ||
issues: | ||
- 85243 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...gin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ShardsSize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.autoscaling.storage; | ||
|
||
import org.elasticsearch.index.shard.ShardId; | ||
|
||
import java.util.SortedSet; | ||
|
||
record ShardsSize(long sizeInBytes, SortedSet<ShardId> shardIds) {} |
92 changes: 92 additions & 0 deletions
92
...caling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveReasonTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.autoscaling.storage; | ||
|
||
import org.elasticsearch.common.UUIDs; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xcontent.ToXContent; | ||
import org.elasticsearch.xcontent.XContentFactory; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
import org.elasticsearch.xcontent.json.JsonXContent; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.hamcrest.Matchers.greaterThan; | ||
|
||
public class ReactiveReasonTests extends ESTestCase { | ||
|
||
@SuppressWarnings("unchecked") | ||
public void testXContent() throws IOException { | ||
String reason = randomAlphaOfLength(10); | ||
long unassigned = randomNonNegativeLong(); | ||
long assigned = randomNonNegativeLong(); | ||
String indexUUID = UUIDs.randomBase64UUID(); | ||
String indexName = randomAlphaOfLength(10); | ||
SortedSet<ShardId> unassignedShardIds = new TreeSet<>(randomUnique(() -> new ShardId(indexName, indexUUID, randomInt(1000)), 600)); | ||
SortedSet<ShardId> assignedShardIds = new TreeSet<>(randomUnique(() -> new ShardId(indexName, indexUUID, randomInt(1000)), 600)); | ||
var reactiveReason = new ReactiveStorageDeciderService.ReactiveReason( | ||
reason, | ||
unassigned, | ||
unassignedShardIds, | ||
assigned, | ||
assignedShardIds | ||
); | ||
|
||
try ( | ||
XContentParser parser = createParser( | ||
JsonXContent.jsonXContent, | ||
BytesReference.bytes(reactiveReason.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) | ||
) | ||
) { | ||
Map<String, Object> map = parser.map(); | ||
assertEquals(reason, map.get("reason")); | ||
assertEquals(unassigned, map.get("unassigned")); | ||
assertEquals(assigned, map.get("assigned")); | ||
|
||
List<String> xContentUnassignedShardIds = (List<String>) map.get("unassigned_shards"); | ||
assertEquals( | ||
unassignedShardIds.stream() | ||
.map(ShardId::toString) | ||
.limit(ReactiveStorageDeciderService.ReactiveReason.MAX_AMOUNT_OF_SHARDS) | ||
.toList(), | ||
xContentUnassignedShardIds | ||
); | ||
assertSorted(xContentUnassignedShardIds.stream().map(ShardId::fromString).toList()); | ||
assertEquals(unassignedShardIds.size(), map.get("unassigned_shards_count")); | ||
|
||
List<String> xContentAssignedShardIds = (List<String>) map.get("assigned_shards"); | ||
assertEquals( | ||
assignedShardIds.stream() | ||
.map(ShardId::toString) | ||
.limit(ReactiveStorageDeciderService.ReactiveReason.MAX_AMOUNT_OF_SHARDS) | ||
.collect(Collectors.toList()), | ||
xContentAssignedShardIds | ||
); | ||
assertSorted(xContentAssignedShardIds.stream().map(ShardId::fromString).toList()); | ||
assertEquals(assignedShardIds.size(), map.get("assigned_shards_count")); | ||
} | ||
} | ||
|
||
private static void assertSorted(Collection<ShardId> collection) { | ||
ShardId previous = null; | ||
for (ShardId e : collection) { | ||
if (previous != null) { | ||
assertThat(e, greaterThan(previous)); | ||
} | ||
previous = e; | ||
} | ||
} | ||
} |
Oops, something went wrong.