Skip to content

Commit

Permalink
removed channel from _ping_and_warm_instances
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Nov 1, 2024
1 parent 7bd5259 commit 8521287
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions google/cloud/bigtable/data/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,22 @@ async def close(self, timeout: float = 2.0):
self._channel_refresh_task = None

async def _ping_and_warm_instances(
self, channel: grpc.aio.Channel, instance_key: _WarmedInstanceKey | None = None
self, instance_key: _WarmedInstanceKey | None = None
) -> list[BaseException | None]:
"""
Prepares the backend for requests on a channel
Pings each Bigtable instance registered in `_active_instances` on the client
Args:
channel: grpc channel to warm
instance_key: if provided, only warm the instance associated with the key
Returns:
list[BaseException | None]: sequence of results or exceptions from the ping requests
"""
instance_list = (
[instance_key] if instance_key is not None else self._active_instances
)
ping_rpc = channel.unary_unary(
ping_rpc = self.transport._grpc_channel.unary_unary(
"/google.bigtable.v2.Bigtable/PingAndWarm",
request_serializer=PingAndWarmRequest.serialize,
)
Expand Down Expand Up @@ -289,15 +288,15 @@ async def _manage_channel(
next_sleep = max(first_refresh - time.monotonic(), 0)
if next_sleep > 0:
# warm the current channel immediately
await self._ping_and_warm_instances(self.transport._grpc_channel)
await self._ping_and_warm_instances()
# continuously refresh the channel every `refresh_interval` seconds
while True:
await asyncio.sleep(next_sleep)
start_timestamp = time.time()
# prepare new channel for use
old_channel = self.transport._grpc_channel
new_channel = self.transport_create_channel()
await self._ping_and_warm_instances(new_channel)
await self._ping_and_warm_instances()
# cycle channel out of use, with long grace window before closure
self.transport._grpc_channel = new_channel
await old_channel.close(grace_period)
Expand Down

0 comments on commit 8521287

Please sign in to comment.