Skip to content

Conversation

@cchung100m
Copy link
Contributor

What changes were proposed in this pull request?

Use separate loop with periodic check of channel.isTerminated() with overall limit of 5s.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-14430

How was this patch tested?

Existing unit and integration tests

@adoroszlai adoroszlai changed the title HDDS-14430: Fix GrpcOmTransport.shutdown() could wait up to number_of_channels * 5s HDDS-14430. GrpcOmTransport.shutdown() could wait up to number_of_channels * 5s Jan 19, 2026
@adoroszlai
Copy link
Contributor

Thanks @cchung100m for the patch. There is a checkstyle and a findbugs problem each.

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/GrpcOmTransport.java
 26: Unused import - io.grpc.Channel.
M D DLS: Dead store to pollIntervalMillis in org.apache.hadoop.ozone.om.protocolPB.GrpcOmTransport.shutdown()  At GrpcOmTransport.java:[line 306]

(It's best to wait for clean CI run in fork before opening pull request to reduce noise.)

@cchung100m
Copy link
Contributor Author

Hi @adoroszlai
Thanks for prompt reply and suggestions. I will keep the PR as DRAFT until pass CI and existing test cases. 😄

@cchung100m cchung100m marked this pull request as ready for review January 19, 2026 16:15
@adoroszlai
Copy link
Contributor

@yandrey321 please take a look


while (elapsed < maxWaitMillis) {
allTerminated = true;
for (Map.Entry<String, ManagedChannel> entry : channels.entrySet()) {

Choose a reason for hiding this comment

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

  1. collect all channels into the list before the while loop
  2. when channel is terminated remove it from the list (inside while loop)
  3. the last 'for' loop for warning messages can be replaced with a single log with a list of remaining non-closed channels.

Choose a reason for hiding this comment

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

with this approach allTerminated is not needed and can be replaced with check is list of non terminated channel is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @yandrey321

Thanks for suggestions and I updated the part you mentioned.

} catch (Exception e) {
LOG.error("failed to shutdown OzoneManagerServiceGrpc channel {} : {}",
entry.getKey(), e);
Thread.sleep(100);

Choose a reason for hiding this comment

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

use named constant

channel.shutdown();
}

final long maxWaitMillis = TimeUnit.SECONDS.toMillis(5);

Choose a reason for hiding this comment

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

use named constant or config param

@cchung100m cchung100m marked this pull request as draft January 21, 2026 11:49
@cchung100m cchung100m marked this pull request as ready for review January 21, 2026 13:19

private static final String CLIENT_NAME = "GrpcOmTransport";
private static final int SHUTDOWN_WAIT_INTERVAL = 100;
private static final int SHUTDOWN_MAX_WAIT_MILLIS = 5;

Choose a reason for hiding this comment

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

SHUTDOWN_MAX_WAIT_SECONDS = 5;


final long maxWaitMillis = TimeUnit.SECONDS.toMillis(SHUTDOWN_MAX_WAIT_MILLIS);
long deadline = System.currentTimeMillis() + maxWaitMillis;
List<Map.Entry<String, ManagedChannel>> nonTerminated =
Copy link

@yandrey321 yandrey321 Jan 21, 2026

Choose a reason for hiding this comment

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

List<ManagedChannel> nonTerminated = channels.values().stream().collect(Collectors.toList());

}

final long maxWaitMillis = TimeUnit.SECONDS.toMillis(SHUTDOWN_MAX_WAIT_MILLIS);
long deadline = System.currentTimeMillis() + maxWaitMillis;

Choose a reason for hiding this comment

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

use monotonic time: System.nanoTime();

List<Map.Entry<String, ManagedChannel>> nonTerminated =
new ArrayList<>(channels.entrySet());

while (!nonTerminated.isEmpty() && System.currentTimeMillis() < deadline) {

Choose a reason for hiding this comment

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

System.nanoTime();

@cchung100m cchung100m requested a review from yandrey321 January 22, 2026 07:14
Copy link

@yandrey321 yandrey321 left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Contributor

@sodonnel sodonnel left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the change and review.

@adoroszlai adoroszlai merged commit 37a5cc9 into apache:master Jan 22, 2026
44 checks passed
@adoroszlai
Copy link
Contributor

Thanks @cchung100m for the patch, @sodonnel, @yandrey321 for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants