Skip to content

Commit

Permalink
disable TEs on scaleDown (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyz26 authored Oct 9, 2023
1 parent d94a7b0 commit d1bef3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -247,6 +248,16 @@ private void onGetClusterIdleInstancesResponse(GetClusterIdleInstancesResponse r
.idleInstances(response.getInstanceIds())
.build(),
self());

// also disable the scale down targets to avoid them being used during the scale down process.
response.getInstanceIds().forEach(id ->
this.resourceClusterActor.tell(new DisableTaskExecutorsRequest(
Collections.emptyMap(),
this.clusterId,
Instant.now().plus(Duration.ofHours(24)),
Optional.of(id)),
self()
));
}

private void onTriggerClusterUsageRequest(TriggerClusterUsageRequest req) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.mantisrx.server.master.resourcecluster.ContainerSkuID;
import io.mantisrx.server.master.resourcecluster.TaskExecutorID;
import io.mantisrx.shaded.com.google.common.collect.ImmutableList;
import io.mantisrx.shaded.com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.time.Clock;
import java.time.Duration;
Expand Down Expand Up @@ -172,7 +173,9 @@ public void testScaler() {
.build()));

// Test callback from fetch idle list.
ImmutableList<TaskExecutorID> idleInstances = ImmutableList.of(TaskExecutorID.of("agent1"));
ImmutableList<TaskExecutorID> idleInstances = ImmutableList.of(
TaskExecutorID.of("agent1"),
TaskExecutorID.of("agent2"));
scalerActor.tell(
GetClusterIdleInstancesResponse.builder()
.clusterId(CLUSTER_ID)
Expand All @@ -192,6 +195,17 @@ public void testScaler() {
.build(),
hostActorProbe.expectMsgClass(ScaleResourceRequest.class));

// validate the idle intances are disabled
io.mantisrx.master.resourcecluster.DisableTaskExecutorsRequest disableTEReq =
clusterActorProbe.expectMsgClass(io.mantisrx.master.resourcecluster.DisableTaskExecutorsRequest.class);
io.mantisrx.master.resourcecluster.DisableTaskExecutorsRequest disableTEReq2 =
clusterActorProbe.expectMsgClass(io.mantisrx.master.resourcecluster.DisableTaskExecutorsRequest.class);
assertTrue(disableTEReq.getTaskExecutorID().isPresent());
assertTrue(disableTEReq2.getTaskExecutorID().isPresent());
assertEquals(
ImmutableSet.of(disableTEReq2.getTaskExecutorID().get(), disableTEReq.getTaskExecutorID().get()),
ImmutableSet.copyOf(idleInstances));

// Test trigger again
GetClusterUsageRequest req2 = clusterActorProbe.expectMsgClass(GetClusterUsageRequest.class);
assertEquals(CLUSTER_ID, req2.getClusterID());
Expand Down

0 comments on commit d1bef3c

Please sign in to comment.