-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix DiskThresholdDecider average disk usage with huge filesystems #100599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tlrx
wants to merge
2
commits into
elastic:main
Choose a base branch
from
tlrx:2023/10/10/diskthreshold-decider-huge-filesystems
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
pr: 100599 | ||
summary: Fix `DiskThresholdDecider` average disk usage with huge filesystems | ||
area: Allocation | ||
type: bug | ||
issues: [] |
This file contains hidden or 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 hidden or 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -130,6 +130,74 @@ public void testCanAllocateUsesMaxAvailableSpace() { | |||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public void testAverageDiskUsage() { | ||||||||||||||
var metadata = Metadata.builder() | ||||||||||||||
.put(IndexMetadata.builder("index").settings(settings(IndexVersion.current())).numberOfShards(1).numberOfReplicas(0)) | ||||||||||||||
.build(); | ||||||||||||||
var clusterState = ClusterState.builder(ClusterName.DEFAULT) | ||||||||||||||
.metadata(metadata) | ||||||||||||||
.nodes( | ||||||||||||||
DiscoveryNodes.builder() | ||||||||||||||
.add(DiscoveryNodeUtils.builder("node_0").roles(new HashSet<>(DiscoveryNodeRole.roles())).build()) | ||||||||||||||
.add(DiscoveryNodeUtils.builder("node_1").roles(new HashSet<>(DiscoveryNodeRole.roles())).build()) | ||||||||||||||
.add(DiscoveryNodeUtils.builder("node_2").roles(new HashSet<>(DiscoveryNodeRole.roles())).build()) | ||||||||||||||
Comment on lines
+141
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT:
Suggested change
I believe all roles are added by default so no need to manually set them |
||||||||||||||
) | ||||||||||||||
.routingTable(RoutingTable.builder(TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY).addAsNew(metadata.index("index")).build()) | ||||||||||||||
.build(); | ||||||||||||||
final Map<String, DiskUsage> availableSpaceUsage = new HashMap<>(); | ||||||||||||||
if (randomBoolean()) { | ||||||||||||||
availableSpaceUsage.put("node_0", new DiskUsage("node_0", "node_0", "_na_", Long.MAX_VALUE, randomNonNegativeLong())); | ||||||||||||||
availableSpaceUsage.put("node_1", new DiskUsage("node_0", "node_0", "_na_", Long.MAX_VALUE, randomNonNegativeLong())); | ||||||||||||||
} | ||||||||||||||
var clusterInfo = new ClusterInfo( | ||||||||||||||
availableSpaceUsage, | ||||||||||||||
availableSpaceUsage, | ||||||||||||||
Map.of("[index][0][p]", ByteSizeValue.ofGb(50L).getBytes()), | ||||||||||||||
Map.of(), | ||||||||||||||
Map.of(), | ||||||||||||||
Map.of() | ||||||||||||||
); | ||||||||||||||
var decider = new DiskThresholdDecider( | ||||||||||||||
Settings.EMPTY, | ||||||||||||||
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||||||||||
); | ||||||||||||||
var allocation = new RoutingAllocation( | ||||||||||||||
new AllocationDeciders(Collections.singleton(decider)), | ||||||||||||||
clusterState, | ||||||||||||||
clusterInfo, | ||||||||||||||
null, | ||||||||||||||
System.nanoTime() | ||||||||||||||
); | ||||||||||||||
allocation.debugDecision(true); | ||||||||||||||
|
||||||||||||||
final var node = RoutingNodesHelper.routingNode("node_2", clusterState.nodes().resolveNode("node_2")); | ||||||||||||||
var unassignedShard = ShardRouting.newUnassigned( | ||||||||||||||
new ShardId(clusterState.metadata().index("index").getIndex(), 0), | ||||||||||||||
true, | ||||||||||||||
EmptyStoreRecoverySource.INSTANCE, | ||||||||||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "create index"), | ||||||||||||||
ShardRouting.Role.DEFAULT | ||||||||||||||
); | ||||||||||||||
final Decision decision = switch (randomInt(2)) { | ||||||||||||||
case 0 -> decider.canForceAllocateDuringReplace(unassignedShard, node, allocation); | ||||||||||||||
case 1 -> decider.canAllocate(unassignedShard, node, allocation); | ||||||||||||||
case 2 -> decider.canRemain( | ||||||||||||||
clusterState.metadata().index("index"), | ||||||||||||||
ShardRoutingHelper.moveToStarted(ShardRoutingHelper.initialize(unassignedShard, "node_2")), | ||||||||||||||
node, | ||||||||||||||
allocation | ||||||||||||||
); | ||||||||||||||
default -> throw new AssertionError(); | ||||||||||||||
}; | ||||||||||||||
assertEquals(Decision.Type.YES, decision.type()); | ||||||||||||||
assertThat( | ||||||||||||||
decision.getExplanation(), | ||||||||||||||
availableSpaceUsage.isEmpty() | ||||||||||||||
? containsString("disk usages are unavailable") | ||||||||||||||
: containsString("average disk usage cannot be computed") | ||||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void doTestCannotAllocateDueToLackOfDiskResources(boolean testMaxHeadroom) { | ||||||||||||||
ClusterSettings nss = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); | ||||||||||||||
DiskThresholdDecider decider = new DiskThresholdDecider(Settings.EMPTY, nss); | ||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added before every call
getDiskUsage
that might compute the average.Is there a value of making
getDiskUsage
return null if overflow happens and have it as a signal to return above decision? This way the addition of total and free could be performed only once (ingetDiskUsage
) vs twice (ingetDiskUsage
and the check above).