-
Notifications
You must be signed in to change notification settings - Fork 158
Code cleanup around Pollers #1070
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Code cleanup around Pollers #1070
Conversation
@@ -110,6 +110,7 @@ public ActivityTask poll() { | |||
ProtobufTimeUtils.toM3Duration( | |||
response.getStartedTime(), response.getCurrentAttemptScheduledTime())); | |||
isSuccessful = true; | |||
return new ActivityTask(response, pollSemaphore::release); |
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.
Paired with
if (!isSuccessful) pollSemaphore.release();
in finally, this location of return
is cleaner for the reader.
@@ -168,15 +168,18 @@ public void awaitTermination(long timeout, TimeUnit unit) { | |||
|
|||
@Override | |||
public void suspendPolling() { | |||
log.info("suspendPolling: {}", this); | |||
suspendLatch.set(new CountDownLatch(1)); |
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.
Absense of CAS here may replace and lose the latch which is already used by Pollers to block on. This way they will never be unblocked if suspentPolling was called twice.
if (pollerOptions == null) { | ||
pollerOptions = | ||
PollerOptions.newBuilder() | ||
.setPollBackoffInitialInterval(Duration.ofMillis(200)) |
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 code path is dead. We come here only in some tests where we do
SingleWorkerOptions.newBuilder().build()
and these options and not important for these tests. As a result, these magic values 200 and 20 here are never used and better be removed from the production code paths to don't mislead the reader.
After this cleanup, it's actually clear that we never call PollerOptions#setPollBackoffMaximumInterval
anywhere.
@@ -181,7 +181,7 @@ private static SingleWorkerOptions toLocalActivityOptions( | |||
List<ContextPropagator> contextPropagators, | |||
Scope metricsScope) { | |||
return toSingleWorkerOptions(factoryOptions, options, clientOptions, contextPropagators) | |||
.setPollerOptions(PollerOptions.newBuilder().build()) |
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.
ActivityWorker and WorkflowWorker PollerOptions specify this parameter explicitly.
To simplify the untangling for the reader, let's specify it for LocalActivityWorker explicitly too. 1 is the default value for pollThreadCount used inside PollerOptions.
Fix for potential pollers deadlock if suspendPolling called twice.
Refactorings that make the code around Polling easier to follow.