Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
report_paths: "**/build/test-results/test/TEST-*.xml"

unit_test_jdk8:
name: Unit test with docker service [JDK8]
name: Unit test with CLI
runs-on: ubuntu-latest-16-cores
timeout-minutes: 30
steps:
Expand All @@ -82,9 +82,9 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@ac396bf1a80af16236baf54bd7330ae21dc6ece5 # v6

- name: Start containerized server and dependencies
- name: Start CLI server
env:
TEMPORAL_CLI_VERSION: 1.6.1-server-1.31.0-151.0
TEMPORAL_CLI_VERSION: 1.7.0
run: |
wget -O temporal_cli.tar.gz https://github.com/temporalio/cli/releases/download/v${TEMPORAL_CLI_VERSION}/temporal_cli_${TEMPORAL_CLI_VERSION}_linux_amd64.tar.gz
tar -xzf temporal_cli.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public ActivityPollTask(
@Nonnull String namespace,
@Nonnull String taskQueue,
@Nonnull String identity,
@Nonnull String workerInstanceKey,
@Nonnull WorkerVersioningOptions versioningOptions,
double activitiesPerSecond,
@Nonnull TrackingSlotSupplier<ActivitySlotInfo> slotSupplier,
Expand All @@ -53,6 +54,7 @@ public ActivityPollTask(
.setNamespace(namespace)
.setIdentity(identity)
.setTaskQueue(TaskQueue.newBuilder().setName(taskQueue));
pollRequest.setWorkerInstanceKey(workerInstanceKey);
if (activitiesPerSecond > 0) {
pollRequest.setTaskQueueMetadata(
TaskQueueMetadata.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public boolean start() {
namespace,
taskQueue,
options.getIdentity(),
options.getWorkerInstanceKey(),
options.getWorkerVersioningOptions(),
taskQueueActivitiesPerSecond,
this.slotSupplier,
Expand All @@ -113,7 +114,7 @@ public boolean start() {
pollerTracker),
this.pollTaskExecutor,
pollerOptions,
namespaceCapabilities.isPollerAutoscaling(),
namespaceCapabilities,
workerMetricsScope);

} else {
Expand All @@ -125,6 +126,7 @@ public boolean start() {
namespace,
taskQueue,
options.getIdentity(),
options.getWorkerInstanceKey(),
options.getWorkerVersioningOptions(),
taskQueueActivitiesPerSecond,
this.slotSupplier,
Expand All @@ -133,7 +135,8 @@ public boolean start() {
pollerTracker),
this.pollTaskExecutor,
pollerOptions,
workerMetricsScope);
workerMetricsScope,
namespaceCapabilities);
}
poller.start();
workerMetricsScope.counter(MetricsType.WORKER_START_COUNTER).inc(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public AsyncActivityPollTask(
@Nonnull String namespace,
@Nonnull String taskQueue,
@Nonnull String identity,
@Nonnull String workerInstanceKey,
@Nonnull WorkerVersioningOptions versioningOptions,
double activitiesPerSecond,
@Nonnull TrackingSlotSupplier<ActivitySlotInfo> slotSupplier,
Expand All @@ -59,6 +60,7 @@ public AsyncActivityPollTask(
.setNamespace(namespace)
.setIdentity(identity)
.setTaskQueue(TaskQueue.newBuilder().setName(taskQueue));
pollRequest.setWorkerInstanceKey(workerInstanceKey);
if (activitiesPerSecond > 0) {
pollRequest.setTaskQueueMetadata(
TaskQueueMetadata.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public AsyncNexusPollTask(
@Nonnull String namespace,
@Nonnull String taskQueue,
@Nonnull String identity,
@Nonnull String workerInstanceKey,
@Nonnull WorkerVersioningOptions versioningOptions,
@Nonnull Scope metricsScope,
@Nonnull Supplier<GetSystemInfoResponse.Capabilities> serverCapabilities,
Expand All @@ -57,6 +58,8 @@ public AsyncNexusPollTask(
.setIdentity(identity)
.setTaskQueue(TaskQueue.newBuilder().setName(taskQueue));

pollRequest.setWorkerInstanceKey(workerInstanceKey);

if (versioningOptions.getWorkerDeploymentOptions() != null) {
pollRequest.setDeploymentOptions(
WorkerVersioningProtoUtils.deploymentOptionsToProto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ final class AsyncPoller<T extends ScalingTask> extends BasePoller<T> {
private final List<PollTaskAsync<T>> asyncTaskPollers;
private final PollerOptions pollerOptions;
private final PollerBehaviorAutoscaling pollerBehavior;
private final boolean serverSupportsAutoscaling;
private final Scope workerMetricsScope;
private Throttler pollRateThrottler;
private final Thread.UncaughtExceptionHandler uncaughtExceptionHandler =
Expand All @@ -43,15 +42,15 @@ final class AsyncPoller<T extends ScalingTask> extends BasePoller<T> {
PollTaskAsync<T> asyncTaskPoller,
ShutdownableTaskExecutor<T> taskExecutor,
PollerOptions pollerOptions,
boolean serverSupportsAutoscaling,
NamespaceCapabilities namespaceCapabilities,
Scope workerMetricsScope) {
this(
slotSupplier,
slotReservationData,
Collections.singletonList(asyncTaskPoller),
taskExecutor,
pollerOptions,
serverSupportsAutoscaling,
namespaceCapabilities,
workerMetricsScope);
}

Expand All @@ -61,9 +60,9 @@ final class AsyncPoller<T extends ScalingTask> extends BasePoller<T> {
List<PollTaskAsync<T>> asyncTaskPollers,
ShutdownableTaskExecutor<T> taskExecutor,
PollerOptions pollerOptions,
boolean serverSupportsAutoscaling,
NamespaceCapabilities namespaceCapabilities,
Scope workerMetricsScope) {
super(taskExecutor);
super(taskExecutor, namespaceCapabilities);
Objects.requireNonNull(slotSupplier, "slotSupplier cannot be null");
Objects.requireNonNull(slotReservationData, "slotReservation data should not be null");
Objects.requireNonNull(asyncTaskPollers, "asyncTaskPollers should not be null");
Expand All @@ -82,7 +81,6 @@ final class AsyncPoller<T extends ScalingTask> extends BasePoller<T> {
+ " is not supported for AsyncPoller. Only PollerBehaviorAutoscaling is supported.");
}
this.pollerBehavior = (PollerBehaviorAutoscaling) pollerOptions.getPollerBehavior();
this.serverSupportsAutoscaling = serverSupportsAutoscaling;
this.pollerOptions = pollerOptions;
this.workerMetricsScope = workerMetricsScope;
}
Expand Down Expand Up @@ -114,7 +112,7 @@ public boolean start() {
pollerBehavior.getMinConcurrentTaskPollers(),
pollerBehavior.getMaxConcurrentTaskPollers(),
pollerBehavior.getInitialConcurrentTaskPollers(),
serverSupportsAutoscaling,
namespaceCapabilities.isPollerAutoscaling(),
(newTarget) -> {
log.debug(
"Updating maximum number of pollers for {} to: {}",
Expand All @@ -136,12 +134,14 @@ public CompletableFuture<Void> shutdown(ShutdownManager shutdownManager, boolean
return super.shutdown(shutdownManager, interruptTasks)
.thenApply(
(f) -> {
for (PollTaskAsync<T> asyncTaskPoller : asyncTaskPollers) {
try {
log.debug("Shutting down async poller: {}", asyncTaskPoller.getLabel());
asyncTaskPoller.cancel(new RuntimeException("Shutting down poller"));
} catch (Throwable e) {
log.error("Error while cancelling poll task", e);
if (!namespaceCapabilities.isGracefulPollShutdown()) {
for (PollTaskAsync<T> asyncTaskPoller : asyncTaskPollers) {
try {
log.debug("Shutting down async poller: {}", asyncTaskPoller.getLabel());
asyncTaskPoller.cancel(new RuntimeException("Shutting down poller"));
} catch (Throwable e) {
log.error("Error while cancelling poll task", e);
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public AsyncWorkflowPollTask(
@Nonnull String taskQueue,
@Nullable String stickyTaskQueue,
@Nonnull String identity,
@Nonnull String workerInstanceKey,
@Nonnull WorkerVersioningOptions versioningOptions,
@Nonnull TrackingSlotSupplier<WorkflowSlotInfo> slotSupplier,
@Nonnull Scope metricsScope,
Expand All @@ -67,6 +68,8 @@ public AsyncWorkflowPollTask(
.setNamespace(Objects.requireNonNull(namespace))
.setIdentity(Objects.requireNonNull(identity));

pollRequestBuilder.setWorkerInstanceKey(workerInstanceKey);

if (versioningOptions.getWorkerDeploymentOptions() != null) {
pollRequestBuilder.setDeploymentOptions(
WorkerVersioningProtoUtils.deploymentOptionsToProto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ abstract class BasePoller<T> implements SuspendableWorker {

protected ExecutorService pollExecutor;

protected BasePoller(ShutdownableTaskExecutor<T> taskExecutor) {
protected final NamespaceCapabilities namespaceCapabilities;

protected BasePoller(
ShutdownableTaskExecutor<T> taskExecutor, NamespaceCapabilities namespaceCapabilities) {
Objects.requireNonNull(taskExecutor, "taskExecutor should not be null");
this.taskExecutor = taskExecutor;
this.namespaceCapabilities =
Objects.requireNonNull(namespaceCapabilities, "namespaceCapabilities should not be null");
}

@Override
Expand All @@ -55,15 +60,24 @@ public CompletableFuture<Void> shutdown(ShutdownManager shutdownManager, boolean
return CompletableFuture.completedFuture(null);
}

return shutdownManager
// it's ok to forcefully shutdown pollers, because they are stuck in a long poll call
// so we don't risk loosing any progress doing that.
.shutdownExecutorNow(pollExecutor, this + "#pollExecutor", Duration.ofSeconds(1))
.exceptionally(
e -> {
log.error("Unexpected exception during shutdown", e);
return null;
});
CompletableFuture<Void> pollExecutorShutdown;
if (namespaceCapabilities.isGracefulPollShutdown()) {
// When graceful poll shutdown is enabled, the server will complete outstanding polls with
// empty responses after ShutdownWorker is called. We simply wait for polls to return.
pollExecutorShutdown =
shutdownManager.shutdownExecutor(
pollExecutor, this + "#pollExecutor", Duration.ofSeconds(80));
} else {
// Old behaviour forcibly stops outstanding polls.
pollExecutorShutdown =
shutdownManager.shutdownExecutorNow(
pollExecutor, this + "#pollExecutor", Duration.ofSeconds(1));
}
return pollExecutorShutdown.exceptionally(
e -> {
log.error("Unexpected exception during shutdown", e);
return null;
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public MultiThreadedPoller(
PollTask<T> pollTask,
ShutdownableTaskExecutor<T> taskExecutor,
PollerOptions pollerOptions,
Scope workerMetricsScope) {
super(taskExecutor);
Scope workerMetricsScope,
NamespaceCapabilities namespaceCapabilities) {
super(taskExecutor, namespaceCapabilities);
Objects.requireNonNull(identity, "identity cannot be null");
Objects.requireNonNull(pollTask, "poll service should not be null");
Objects.requireNonNull(pollerOptions, "pollerOptions should not be null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.temporal.internal.worker;

import io.temporal.api.namespace.v1.NamespaceInfo.Capabilities;
import java.util.concurrent.atomic.AtomicBoolean;

/**
Expand All @@ -9,14 +10,28 @@
*/
public final class NamespaceCapabilities {
private final AtomicBoolean pollerAutoscaling = new AtomicBoolean(false);
private final AtomicBoolean gracefulPollShutdown = new AtomicBoolean(false);
private final AtomicBoolean workerHeartbeats = new AtomicBoolean(false);

public void setFromCapabilities(Capabilities capabilities) {
if (capabilities.getPollerAutoscaling()) {
pollerAutoscaling.set(true);
}
if (capabilities.getWorkerPollCompleteOnShutdown()) {
gracefulPollShutdown.set(true);
}
}

public boolean isPollerAutoscaling() {
return pollerAutoscaling.get();
}

public void setPollerAutoscaling(boolean value) {
pollerAutoscaling.set(value);
public boolean isGracefulPollShutdown() {
return gracefulPollShutdown.get();
}

public void setGracefulPollShutdown(boolean value) {
gracefulPollShutdown.set(value);
}

public boolean isWorkerHeartbeats() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public NexusPollTask(
@Nonnull String namespace,
@Nonnull String taskQueue,
@Nonnull String identity,
@Nonnull String workerInstanceKey,
@Nonnull WorkerVersioningOptions versioningOptions,
@Nonnull TrackingSlotSupplier<NexusSlotInfo> slotSupplier,
@Nonnull Scope metricsScope,
Expand All @@ -49,6 +50,7 @@ public NexusPollTask(
.setNamespace(namespace)
.setIdentity(identity)
.setTaskQueue(TaskQueue.newBuilder().setName(taskQueue));
pollRequest.setWorkerInstanceKey(workerInstanceKey);

if (versioningOptions.getWorkerDeploymentOptions() != null) {
pollRequest.setDeploymentOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ public boolean start() {
namespace,
taskQueue,
options.getIdentity(),
options.getWorkerInstanceKey(),
options.getWorkerVersioningOptions(),
workerMetricsScope,
service.getServerCapabilities(),
this.slotSupplier,
pollerTracker),
this.pollTaskExecutor,
pollerOptions,
namespaceCapabilities.isPollerAutoscaling(),
namespaceCapabilities,
workerMetricsScope);
} else {
poller =
Expand All @@ -129,14 +130,16 @@ public boolean start() {
namespace,
taskQueue,
options.getIdentity(),
options.getWorkerInstanceKey(),
options.getWorkerVersioningOptions(),
this.slotSupplier,
workerMetricsScope,
service.getServerCapabilities(),
pollerTracker),
this.pollTaskExecutor,
pollerOptions,
workerMetricsScope);
workerMetricsScope,
namespaceCapabilities);
}
poller.start();
workerMetricsScope.counter(MetricsType.WORKER_START_COUNTER).inc(1);
Expand Down
Loading
Loading