-
Notifications
You must be signed in to change notification settings - Fork 201
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
Make calls on cacheArtifacts/reconnect/submit/canel non-blocking #556
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ | |
import java.time.Instant; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import javax.annotation.Nullable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
@@ -252,11 +251,11 @@ TaskExecutorRegistration getRegistration() { | |
return this.registration; | ||
} | ||
|
||
protected TaskExecutorGateway getGateway() throws ExecutionException, InterruptedException { | ||
protected CompletableFuture<TaskExecutorGateway> getGatewayAsync() { | ||
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: no need to explicitly call this method async since the type already reflects that. 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. Also, get rid of the blocking method. |
||
if (this.gateway == null) { | ||
throw new IllegalStateException("gateway is null"); | ||
} | ||
return this.gateway.get(); | ||
return this.gateway; | ||
} | ||
|
||
protected CompletableFuture<TaskExecutorGateway> reconnect() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,10 @@ | |
|
||
import akka.actor.AbstractActorWithTimers; | ||
import akka.actor.Props; | ||
import akka.actor.Status.Failure; | ||
import akka.japi.pf.ReceiveBuilder; | ||
import com.netflix.spectator.api.Tag; | ||
import io.mantisrx.common.Ack; | ||
import io.mantisrx.common.metrics.Counter; | ||
import io.mantisrx.common.metrics.Metrics; | ||
import io.mantisrx.common.metrics.MetricsRegistry; | ||
|
@@ -40,6 +42,7 @@ | |
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
import lombok.Value; | ||
|
@@ -112,6 +115,8 @@ public Receive createReceive() { | |
.match(FailedToSubmitScheduleRequestEvent.class, this::onFailedToSubmitScheduleRequestEvent) | ||
.match(RetryCancelRequestEvent.class, this::onRetryCancelRequestEvent) | ||
.match(Noop.class, this::onNoop) | ||
.match(Ack.class, ack -> log.debug("Received ack from {}", sender())) | ||
.match(Failure.class, failure -> log.error("Received failure from {}: {}", sender(), failure)) | ||
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. When is this message sent? |
||
.build(); | ||
} | ||
|
||
|
@@ -139,38 +144,48 @@ private void onInitializeRunningWorkerRequest(InitializeRunningWorkerRequestEven | |
} | ||
|
||
private void onAssignedScheduleRequestEvent(AssignedScheduleRequestEvent event) { | ||
TaskExecutorGateway gateway = null; | ||
TaskExecutorRegistration info = null; | ||
try { | ||
gateway = resourceCluster.getTaskExecutorGateway(event.getTaskExecutorID()).join(); | ||
info = resourceCluster.getTaskExecutorInfo(event.getTaskExecutorID()).join(); | ||
CompletableFuture<TaskExecutorGateway> gatewayFut = resourceCluster.getTaskExecutorGateway(event.getTaskExecutorID()); | ||
TaskExecutorRegistration info = resourceCluster.getTaskExecutorInfo(event.getTaskExecutorID()).join(); | ||
|
||
if (gatewayFut != null && info != null) { | ||
CompletionStage<Object> ackFuture = | ||
gatewayFut | ||
.thenComposeAsync(gateway -> | ||
gateway | ||
.submitTask( | ||
executeStageRequestFactory.of( | ||
event.getScheduleRequestEvent().getRequest(), | ||
info)) | ||
.<Object>thenApply( | ||
dontCare -> new SubmittedScheduleRequestEvent( | ||
event.getScheduleRequestEvent(), | ||
event.getTaskExecutorID())) | ||
.exceptionally( | ||
throwable -> new FailedToSubmitScheduleRequestEvent( | ||
event.getScheduleRequestEvent(), | ||
event.getTaskExecutorID(), throwable)) | ||
.whenCompleteAsync((res, err) -> | ||
{ | ||
if (err == null) { | ||
log.debug("[Submit Task] finish with {}", res); | ||
} | ||
else { | ||
log.error("[Submit Task] fail: {}", event.getTaskExecutorID(), err); | ||
} | ||
}) | ||
|
||
); | ||
pipe(ackFuture, getContext().getDispatcher()).to(self()); | ||
} | ||
} catch (Exception e) { | ||
// we are not able to get the gateway, which either means the node is not great or some transient network issue | ||
// we will retry the request | ||
log.warn( | ||
"Failed to establish connection with the task executor {}; Resubmitting the request", | ||
"Failed to submit task with the task executor {}; Resubmitting the request", | ||
event.getTaskExecutorID(), e); | ||
connectionFailures.increment(); | ||
self().tell(event.getScheduleRequestEvent().onFailure(e), self()); | ||
} | ||
|
||
if (gateway != null && info != null) { | ||
CompletableFuture<Object> ackFuture = | ||
gateway | ||
.submitTask( | ||
executeStageRequestFactory.of(event.getScheduleRequestEvent().getRequest(), | ||
info)) | ||
.<Object>thenApply( | ||
dontCare -> new SubmittedScheduleRequestEvent( | ||
event.getScheduleRequestEvent(), | ||
event.getTaskExecutorID())) | ||
.exceptionally( | ||
throwable -> new FailedToSubmitScheduleRequestEvent( | ||
event.getScheduleRequestEvent(), | ||
event.getTaskExecutorID(), throwable)); | ||
|
||
pipe(ackFuture, getContext().getDispatcher()).to(self()); | ||
} | ||
} | ||
|
||
private void onFailedScheduleRequestEvent(FailedToScheduleRequestEvent event) { | ||
|
@@ -187,6 +202,7 @@ private void onFailedScheduleRequestEvent(FailedToScheduleRequestEvent event) { | |
} | ||
|
||
private void onSubmittedScheduleRequestEvent(SubmittedScheduleRequestEvent event) { | ||
log.debug("[Submit Task]: receive SubmittedScheduleRequestEvent: {}", event); | ||
final TaskExecutorID taskExecutorID = event.getTaskExecutorID(); | ||
try { | ||
final TaskExecutorRegistration info = resourceCluster.getTaskExecutorInfo(taskExecutorID) | ||
|
@@ -222,7 +238,15 @@ private void onFailedToSubmitScheduleRequestEvent(FailedToSubmitScheduleRequestE | |
Throwables.getStackTraceAsString(event.throwable))); | ||
|
||
try { | ||
resourceCluster.reconnectTaskExecutorGateway(event.getTaskExecutorID()).join(); | ||
resourceCluster.reconnectGateway(event.getTaskExecutorID()) | ||
.whenComplete((res, throwable) -> { | ||
if (throwable != null) { | ||
log.error("Failed to request reconnect to gateway for {}", event.getTaskExecutorID(), throwable); | ||
} | ||
else { | ||
log.debug("Acked from reconnection request for {}", event.getTaskExecutorID()); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
log.warn( | ||
"Failed to establish re-connection with the task executor {} on failed schedule request", | ||
|
@@ -237,24 +261,24 @@ private void onCancelRequestEvent(CancelRequestEvent event) { | |
getTimers().cancel(getSchedulingQueueKeyFor(event.getWorkerId())); | ||
final TaskExecutorID taskExecutorID = | ||
resourceCluster.getTaskExecutorAssignedFor(event.getWorkerId()).join(); | ||
final TaskExecutorGateway gateway = | ||
resourceCluster.getTaskExecutorGateway(taskExecutorID).join(); | ||
|
||
CompletableFuture<Object> cancelFuture = | ||
gateway | ||
.cancelTask(event.getWorkerId()) | ||
.<Object>thenApply(dontCare -> Noop.getInstance()) | ||
.exceptionally(exception -> { | ||
Throwable actual = | ||
ExceptionUtils.stripCompletionException( | ||
ExceptionUtils.stripExecutionException(exception)); | ||
// no need to retry if the TaskExecutor does not know about the task anymore. | ||
if (actual instanceof TaskNotFoundException) { | ||
return Noop.getInstance(); | ||
} else { | ||
return event.onFailure(actual); | ||
} | ||
}); | ||
resourceCluster.getTaskExecutorGateway(taskExecutorID) | ||
.thenComposeAsync(gateway -> | ||
gateway | ||
.cancelTask(event.getWorkerId()) | ||
.<Object>thenApply(dontCare -> Noop.getInstance()) | ||
.exceptionally(exception -> { | ||
Throwable actual = | ||
ExceptionUtils.stripCompletionException( | ||
ExceptionUtils.stripExecutionException(exception)); | ||
// no need to retry if the TaskExecutor does not know about the task anymore. | ||
if (actual instanceof TaskNotFoundException) { | ||
return Noop.getInstance(); | ||
} else { | ||
return event.onFailure(actual); | ||
} | ||
})); | ||
|
||
pipe(cancelFuture, context().dispatcher()).to(self()); | ||
} catch (Exception e) { | ||
|
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.
How can this be async?