Skip to content
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

PubSub : Fix Publisher.shutdown should return promptly #4956

Closed

Conversation

abhinav-qlogic
Copy link

Fixes #3687

@abhinav-qlogic abhinav-qlogic requested a review from a team as a code owner April 16, 2019 12:16
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 16, 2019
@pmakani pmakani added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 16, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 16, 2019
@codecov
Copy link

codecov bot commented Apr 16, 2019

Codecov Report

Merging #4956 into master will increase coverage by 0.03%.
The diff coverage is 69.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4956      +/-   ##
============================================
+ Coverage     50.33%   50.36%   +0.03%     
+ Complexity    23676    23667       -9     
============================================
  Files          2238     2233       -5     
  Lines        226057   225866     -191     
  Branches      24961    24959       -2     
============================================
- Hits         113775   113750      -25     
+ Misses       103678   103518     -160     
+ Partials       8604     8598       -6
Impacted Files Coverage Δ Complexity Δ
...ain/java/com/google/cloud/pubsub/v1/Publisher.java 80.93% <69.23%> (-4.6%) 28 <2> (ø)
...google/cloud/bigtable/admin/v2/models/GCRules.java 55.66% <0%> (-13.21%) 12% <0%> (-4%)
...ge/contrib/nio/CloudStorageFileSystemProvider.java 61.26% <0%> (-0.47%) 70% <0%> (-1%)
...n/java/com/google/cloud/bigquery/BigQueryImpl.java 83.83% <0%> (-0.26%) 52% <0%> (-1%)
...ud/storage/contrib/nio/testing/FakeStorageRpc.java 63.54% <0%> (-0.18%) 40% <0%> (-1%)
...cloud/pubsub/v1/StreamingSubscriberConnection.java 64.75% <0%> (ø) 9% <0%> (ø) ⬇️
...loud/compute/v1/InsertNodeTemplateHttpRequest.java 23.92% <0%> (ø) 9% <0%> (ø) ⬇️
...in/java/com/google/cloud/compute/v1/NodeGroup.java 38.6% <0%> (ø) 17% <0%> (ø) ⬇️
...java/com/google/cloud/compute/v1/NodeTemplate.java 36.41% <0%> (ø) 19% <0%> (ø) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac0084f...d792545. Read the comment docs.

for (AutoCloseable closeable : closeables) {
ExecutorAsBackgroundResource executorAsBackgroundResource =
(ExecutorAsBackgroundResource) closeable;
isAwaited = executorAsBackgroundResource.awaitTermination(duration, unit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user is asking for something like: wait for 8 seconds total for termination.

publisherStub.awaitTermination(duration, unit); could take 2.1 seconds. The next await termination should wait 8-2.1 seconds.

Please keep track of the start time, and the number of millis that have gone by since the method was invoked, and then wait the remainder of the users requested timeout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sduskis changes done

for (AutoCloseable closeable : closeables) {
closeable.close();
ExecutorAsBackgroundResource executorAsBackgroundResource =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closable.close() calls shutdown() under the covers. There's no need to cast to a ExecutorAsBackgroundResource

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sduskis changes done

@pmakani pmakani added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 18, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 18, 2019
long remainingDuration = TimeUnit.MILLISECONDS.convert(duration, unit);
messagesWaiter.waitNoMessages();
remainingDuration = getRemainingDuration(remainingDuration, startDuration);
startDuration = System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't update startDuration

@@ -430,7 +429,32 @@ public void shutdown() throws Exception {
* <p>Call this method to make sure all resources are freed properly.
*/
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return publisherStub.awaitTermination(duration, unit);
long startDuration = System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make startDuration final. There's never a need to update it, since startDuration represents the start time when the method was called.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sduskis startDuration needs to be update because it is used(counting) to find elapsed time which occur to execute waitNoMessages method only, so we have to minus this time from actual time pass to duration parameter of awaitTermination method and so on needs to update every time to find elapsed time so we can remove it from total remaining time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what you mean. Let's have a static startTime and totalDurationMs variables that are final. We can use those plus current time to calculate remainingDurationMs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sduskis chnages done

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 23, 2019
@@ -430,7 +429,37 @@ public void shutdown() throws Exception {
* <p>Call this method to make sure all resources are freed properly.
*/
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return publisherStub.awaitTermination(duration, unit);
final long startDuration = System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call this variable startTimeMs

ExecutorAsBackgroundResource executorAsBackgroundResource =
(ExecutorAsBackgroundResource) closeable;
remainingDuration = getRemainingDuration(startDuration, totalDurationMs);
System.out.println(remainingDuration);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this println.

return false;
}
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the else.

} else {
return false;
}
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use return isAwaited

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sduskis changes done

@pmakani pmakani added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 29, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 29, 2019
@sduskis sduskis added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 29, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 29, 2019
Copy link
Contributor

@sduskis sduskis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you had a bad merge here. There are some changes that your PR reverted. Please update the PR to only change the thins you intended to change.

@ajaaym
Copy link
Contributor

ajaaym commented Apr 30, 2019

@abhinav-qlogic closing this PR due to lot of unintended merge/conflict. Please create new with just your change.

@ajaaym ajaaym closed this Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement. 🚨 This issue needs some love.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publisher.shutdown should return promptly
7 participants