Allow channel pool to refresh its channels periodically #805
Allow channel pool to refresh its channels periodically #805
Conversation
Codecov Report
@@ Coverage Diff @@
## master #805 +/- ##
============================================
- Coverage 78.76% 78.68% -0.08%
- Complexity 1126 1146 +20
============================================
Files 200 202 +2
Lines 4983 5091 +108
Branches 398 405 +7
============================================
+ Hits 3925 4006 +81
- Misses 888 912 +24
- Partials 170 173 +3
Continue to review full report at Codecov.
|
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
// if executorService is available, create RefreshingManagedChannel that will get refreshed. | ||
// otherwise create with regular ManagedChannel |
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.
Under what circumstances is the executor not available?
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.
the executor is not available when we want to create a channel pool that's non-refreshing. InstantiatingGrpcChannelProvider creates a channel pool with a null executorService if channelPrimer is not set. See https://github.com/googleapis/gax-java/pull/805/files#diff-25ba434a47d99bcc0b998965a298661cR208-R211.
I suppose we could make every channel pool refresh regardless of whether channelPrimer is set. But that means the channel will refresh at whatever rate we specify in RefreshingManagedChannel and not when the server resets. I'm not sure if this is a desired outcome if the clients don't specify anything.
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.
I think it's ok to make the behavior configureable and off by default. But i don't think we should make it dependent on the presence of an executor service. It's a bit surprising. Maybe add 2 factory methods:
create(int poolSize, ChannelFactory channelFactory)
createRefreshing(int poolSize, ChannelFactory channelFactory, ScheduledExecutorService executor)
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 comment seems stale
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
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 is looking good, I think all race conditions have been addressed. Most comments are cosmetic
// if executorService is available, create RefreshingManagedChannel that will get refreshed. | ||
// otherwise create with regular ManagedChannel |
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.
I think it's ok to make the behavior configureable and off by default. But i don't think we should make it dependent on the presence of an executor service. It's a bit surprising. Maybe add 2 factory methods:
create(int poolSize, ChannelFactory channelFactory)
createRefreshing(int poolSize, ChannelFactory channelFactory, ScheduledExecutorService executor)
gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/SafeShutdownManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/SafeShutdownManagedChannel.java
Outdated
Show resolved
Hide resolved
69f4827
to
6b3968b
Compare
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 is looking good! I have a few more comments on style though:
// if executorService is available, create RefreshingManagedChannel that will get refreshed. | ||
// otherwise create with regular ManagedChannel |
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 comment seems stale
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelFactory.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPrimer.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/SafeShutdownManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java
Outdated
Show resolved
Hide resolved
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.
I don't remember most of the context here, unfortunately. Just a few sudo-nitpicking comments from me. Overall looks good.
gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/SafeShutdownManagedChannel.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/test/java/com/google/api/gax/grpc/ChannelPoolTest.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
Outdated
Show resolved
Hide resolved
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.
LGTM. @vam-google, if this looks good to you, I think we can merge
gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java
Outdated
Show resolved
Hide resolved
gax-grpc/src/main/java/com/google/api/gax/grpc/RefreshingManagedChannel.java
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #805 +/- ##
===========================================
- Coverage 78.76% 78.67% -0.1%
- Complexity 1126 1144 +18
===========================================
Files 200 202 +2
Lines 4983 5092 +109
Branches 398 404 +6
===========================================
+ Hits 3925 4006 +81
- Misses 888 912 +24
- Partials 170 174 +4
Continue to review full report at Codecov.
|
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.
LGTM
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.
one last nit, but ready merge after
This address #804
ChannelPool is modified to managed the lifecycle of its channels, including the initial creation and periodically creating new channels and replacing old channels.
ChannelPrimer will be implemented by the clients to choose what they want to do during channel creation to prime the channel.
InstantiatingGrpcChannelProvider adds the ability to create ChannelPools that will refresh its channels. If ChannelPrimer is not provided, ChannelPool will not refresh its connection, and the functionality will be exactly the same as before.