Skip to content

impl(bigtable): add remaining methods to DynamicChannelPool#16048

Open
scotthart wants to merge 3 commits intogoogleapis:mainfrom
scotthart:bigtable_dynamic_pool_impl_3
Open

impl(bigtable): add remaining methods to DynamicChannelPool#16048
scotthart wants to merge 3 commits intogoogleapis:mainfrom
scotthart:bigtable_dynamic_pool_impl_3

Conversation

@scotthart
Copy link
Member

@scotthart scotthart commented Mar 17, 2026

This PR adds methods to select a channel and maintain the channel pool size and health.

@product-auto-label product-auto-label bot added the api: bigtable Issues related to the Bigtable API. label Mar 17, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request completes the implementation of the dynamic channel pool for Bigtable, significantly enhancing its ability to manage gRPC channels. It introduces sophisticated mechanisms for selecting the least-used healthy channels, proactively identifying and evicting unhealthy ones, and dynamically resizing the pool based on real-time load and health metrics. These changes aim to improve the client's resilience and performance by ensuring efficient and reliable channel utilization.

Highlights

  • Dynamic Channel Selection Logic Implemented: The GetChannelRandomTwoLeastUsed method has been fully implemented to intelligently select channels based on their outstanding RPCs, including logic to handle cases where channels are unhealthy or the pool is empty.
  • Bad Channel Management: A new private helper method, HandleBadChannels, was added to manage and evict unhealthy channels from the pool, ensuring that only functional channels are used for RPCs. This includes logic to find alternative healthy channels and schedule their removal.
  • Dynamic Pool Sizing and Health Checks: The EvictBadChannels and CheckPoolChannelHealth methods are now fully implemented. CheckPoolChannelHealth dynamically adjusts the channel pool size based on average outstanding RPCs and predefined sizing policies, scheduling channel additions or removals as needed.
  • Comprehensive Unit Tests: New unit tests were added to cover various scenarios for channel selection, including pools with one channel, empty pools, and situations involving one or more bad channels, ensuring the robustness of the new dynamic channel pool features.
Changelog
  • google/cloud/bigtable/internal/dynamic_channel_pool.h
    • Removed unused include for google/cloud/internal/clock.h.
    • Updated comment for GetChannelRandomTwoLeastUsed to reflect new behavior.
    • Implemented GetChannelRandomTwoLeastUsed method with channel selection, health checks, and bad channel handling.
    • Added ChannelSelectionData struct to facilitate channel selection logic.
    • Implemented HandleBadChannels method to process and manage unhealthy channels.
    • Implemented EvictBadChannels method to move bad channels to a draining state and remove them from the active pool.
    • Implemented CheckPoolChannelHealth method to dynamically adjust pool size based on RPC load and health thresholds.
  • google/cloud/bigtable/internal/dynamic_channel_pool_test.cc
    • Added test wrapper methods for HandleBadChannels, EvictBadChannels, and CheckPoolChannelHealth to enable testing of private members.
    • Added ChannelSelectionData type alias to the test wrapper.
    • Added SelectLeastUsedFromTwoChannels test case to verify channel selection from two healthy channels.
    • Added OneInitialChannel test case to verify behavior when the pool starts with a single channel.
    • Added EmptyInitialPool test case to ensure a new channel is created when the pool is initially empty.
    • Added HandleBadChannelsTwoChannelsOneBad test case to verify handling when one of two selected channels is unhealthy.
    • Added HandleBadChannelsTwoChannelsOtherOneBad test case for the inverse scenario of the above.
    • Added HandleBadChannelsThreeChannelsOneBad test case to verify handling with multiple channels and one bad channel.
    • Added HandleBadChannelsAllChannelsBad test case to verify pool behavior when all channels are initially unhealthy.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the core logic for DynamicChannelPool, including channel selection, health checking, and resizing. The implementation of the "random two least used" selection strategy is a significant addition. My review identified a critical issue with iterator invalidation that could lead to undefined behavior and crashes. I also found a couple of high-severity issues where failed channel creation is not handled correctly, which could lead to unhandled exceptions. These findings align with the repository's preference for defensive coding practices, such as explicit ok() checks for StatusOr results. I've provided detailed comments and suggestions to address these points, primarily recommending safer patterns like using indices instead of iterators and properly checking StatusOr return values.

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 98.01085% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.67%. Comparing base (043638c) to head (b64f2e6).

Files with missing lines Patch % Lines
...oud/bigtable/internal/dynamic_channel_pool_test.cc 98.03% 9 Missing ⚠️
...gle/cloud/bigtable/internal/dynamic_channel_pool.h 97.91% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16048      +/-   ##
==========================================
+ Coverage   92.66%   92.67%   +0.01%     
==========================================
  Files        2341     2341              
  Lines      215646   216207     +561     
==========================================
+ Hits       199823   200365     +542     
- Misses      15823    15842      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@scotthart scotthart force-pushed the bigtable_dynamic_pool_impl_3 branch from fc6e744 to b64f2e6 Compare March 17, 2026 23:17
@scotthart scotthart marked this pull request as ready for review March 17, 2026 23:19
@scotthart scotthart requested a review from a team as a code owner March 17, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the Bigtable API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant