Skip to content

Cleanup DataTierAllocationDecider #83572

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderContext;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult;
import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService;
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;

import java.io.IOException;
import java.util.List;
Expand All @@ -33,11 +32,9 @@ public class ProactiveStorageDeciderService implements AutoscalingDeciderService

private final DiskThresholdSettings diskThresholdSettings;
private final AllocationDeciders allocationDeciders;
private final DataTierAllocationDecider dataTierAllocationDecider;

public ProactiveStorageDeciderService(Settings settings, ClusterSettings clusterSettings, AllocationDeciders allocationDeciders) {
this.diskThresholdSettings = new DiskThresholdSettings(settings, clusterSettings);
this.dataTierAllocationDecider = new DataTierAllocationDecider();
this.allocationDeciders = allocationDeciders;
}

Expand All @@ -64,8 +61,7 @@ public AutoscalingDeciderResult scale(Settings configuration, AutoscalingDecider
ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState(
context,
diskThresholdSettings,
allocationDeciders,
dataTierAllocationDecider
allocationDeciders
);
long unassignedBytesBeforeForecast = allocationState.storagePreventsAllocation();
assert unassignedBytesBeforeForecast >= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ public class ReactiveStorageDeciderService implements AutoscalingDeciderService
public static final String NAME = "reactive_storage";

private final DiskThresholdSettings diskThresholdSettings;
private final DataTierAllocationDecider dataTierAllocationDecider;
private final AllocationDeciders allocationDeciders;

public ReactiveStorageDeciderService(Settings settings, ClusterSettings clusterSettings, AllocationDeciders allocationDeciders) {
this.diskThresholdSettings = new DiskThresholdSettings(settings, clusterSettings);
this.dataTierAllocationDecider = new DataTierAllocationDecider();
this.allocationDeciders = allocationDeciders;
}

Expand Down Expand Up @@ -108,12 +106,7 @@ public AutoscalingDeciderResult scale(Settings configuration, AutoscalingDecider
return new AutoscalingDeciderResult(null, new ReactiveReason("current capacity not available", -1, -1));
}

AllocationState allocationState = new AllocationState(
context,
diskThresholdSettings,
allocationDeciders,
dataTierAllocationDecider
);
AllocationState allocationState = new AllocationState(context, diskThresholdSettings, allocationDeciders);
long unassignedBytes = allocationState.storagePreventsAllocation();
long assignedBytes = allocationState.storagePreventsRemainOrMove();
long maxShardSize = allocationState.maxShardSize();
Expand Down Expand Up @@ -177,7 +170,6 @@ static Optional<String> singleNoDecision(Decision decision, Predicate<Decision>
public static class AllocationState {
private final ClusterState state;
private final AllocationDeciders allocationDeciders;
private final DataTierAllocationDecider dataTierAllocationDecider;
private final DiskThresholdSettings diskThresholdSettings;
private final ClusterInfo info;
private final SnapshotShardSizeInfo shardSizeInfo;
Expand All @@ -189,13 +181,11 @@ public static class AllocationState {
AllocationState(
AutoscalingDeciderContext context,
DiskThresholdSettings diskThresholdSettings,
AllocationDeciders allocationDeciders,
DataTierAllocationDecider dataTierAllocationDecider
AllocationDeciders allocationDeciders
) {
this(
context.state(),
allocationDeciders,
dataTierAllocationDecider,
diskThresholdSettings,
context.info(),
context.snapshotShardSizeInfo(),
Expand All @@ -207,7 +197,6 @@ public static class AllocationState {
AllocationState(
ClusterState state,
AllocationDeciders allocationDeciders,
DataTierAllocationDecider dataTierAllocationDecider,
DiskThresholdSettings diskThresholdSettings,
ClusterInfo info,
SnapshotShardSizeInfo shardSizeInfo,
Expand All @@ -216,7 +205,6 @@ public static class AllocationState {
) {
this.state = state;
this.allocationDeciders = allocationDeciders;
this.dataTierAllocationDecider = dataTierAllocationDecider;
this.diskThresholdSettings = diskThresholdSettings;
this.info = info;
this.shardSizeInfo = shardSizeInfo;
Expand Down Expand Up @@ -346,7 +334,7 @@ boolean needsThisTier(ShardRouting shard, RoutingAllocation allocation) {
IndexMetadata indexMetadata = indexMetadata(shard, allocation);
Set<Decision.Type> decisionTypes = StreamSupport.stream(allocation.routingNodes().spliterator(), false)
.map(
node -> dataTierAllocationDecider.shouldFilter(
node -> DataTierAllocationDecider.shouldFilter(
indexMetadata,
node.node().getRoles(),
this::highestPreferenceTier,
Expand Down Expand Up @@ -378,7 +366,7 @@ boolean needsThisTier(ShardRouting shard, RoutingAllocation allocation) {

private boolean isAssignedToTier(ShardRouting shard, RoutingAllocation allocation) {
IndexMetadata indexMetadata = indexMetadata(shard, allocation);
return dataTierAllocationDecider.shouldFilter(indexMetadata, roles, this::highestPreferenceTier, allocation) != Decision.NO;
return DataTierAllocationDecider.shouldFilter(indexMetadata, roles, this::highestPreferenceTier, allocation) != Decision.NO;
}

private IndexMetadata indexMetadata(ShardRouting shard, RoutingAllocation allocation) {
Expand Down Expand Up @@ -502,7 +490,6 @@ public AllocationState forecast(long forecastWindow, long now) {
return new AllocationState(
forecastClusterState,
allocationDeciders,
dataTierAllocationDecider,
diskThresholdSettings,
forecastInfo,
shardSizeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public void testForecastNoDates() {
null,
null,
null,
null,
Set.of(),
Set.of()
);
Expand Down Expand Up @@ -209,7 +208,6 @@ public void testForecastZero() {
state,
null,
null,
null,
randomClusterInfo(state),
null,
Sets.newHashSet(state.nodes()),
Expand Down Expand Up @@ -254,7 +252,6 @@ public void testForecast() {
state,
null,
null,
null,
info,
null,
Sets.newHashSet(state.nodes()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)
);

private static final DataTierAllocationDecider DATA_TIER_ALLOCATION_DECIDER = new DataTierAllocationDecider();

private ClusterState state;
private final int hotNodes = randomIntBetween(1, 8);
private final int warmNodes = randomIntBetween(1, 3);
Expand Down Expand Up @@ -366,8 +364,7 @@ private static void verify(
ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState(
createContext(state, Set.of(role)),
DISK_THRESHOLD_SETTINGS,
createAllocationDeciders(allocationDeciders),
DATA_TIER_ALLOCATION_DECIDER
createAllocationDeciders(allocationDeciders)
);
assertThat(subject.invoke(allocationState), equalTo(expected));
}
Expand Down Expand Up @@ -429,7 +426,7 @@ private static AllocationDeciders createAllocationDeciders(AllocationDecider...
Collections.emptyList()
);
return new AllocationDeciders(
Stream.of(Stream.of(extraDeciders), Stream.of(new DataTierAllocationDecider()), systemAllocationDeciders.stream())
Stream.of(Stream.of(extraDeciders), Stream.of(DataTierAllocationDecider.INSTANCE), systemAllocationDeciders.stream())
.flatMap(s -> s)
.collect(Collectors.toList())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ public void validateSizeOf(
clusterState,
null,
null,
null,
info,
null,
Set.of(),
Expand Down Expand Up @@ -358,7 +357,6 @@ private void validateSizeOfSnapshotShard(
null,
null,
null,
null,
shardSizeInfo,
Set.of(),
Set.of()
Expand Down Expand Up @@ -448,7 +446,6 @@ public void testUnmovableSize() {
ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState(
clusterState,
null,
null,
thresholdSettings,
info,
null,
Expand Down Expand Up @@ -521,11 +518,9 @@ public ClusterState addPreference(IndexMetadata indexMetadata, ClusterState clus

public boolean canRemainWithNoNodes(ClusterState clusterState, ShardRouting shardRouting, AllocationDecider... deciders) {
AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(deciders));
DataTierAllocationDecider dataTierAllocationDecider = new DataTierAllocationDecider();
ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState(
clusterState,
allocationDeciders,
dataTierAllocationDecider,
new DiskThresholdSettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)),
ClusterInfo.EMPTY,
null,
Expand Down Expand Up @@ -626,11 +621,9 @@ private void verifyNeedsWarmTier(
AllocationDecider... deciders
) {
AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(deciders));
DataTierAllocationDecider dataTierAllocationDecider = new DataTierAllocationDecider();
ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState(
clusterState,
allocationDeciders,
dataTierAllocationDecider,
new DiskThresholdSettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)),
ClusterInfo.EMPTY,
null,
Expand Down
Loading